diff --git a/python/educational-core/resources/META-INF/plugin.xml b/python/educational-core/resources/META-INF/plugin.xml
index 797022d968be..83ddbb6ed724 100644
--- a/python/educational-core/resources/META-INF/plugin.xml
+++ b/python/educational-core/resources/META-INF/plugin.xml
@@ -174,7 +174,7 @@
-
+
diff --git a/python/educational-core/src/com/jetbrains/edu/learning/statistics/EduStatistics.java b/python/educational-core/src/com/jetbrains/edu/learning/statistics/EduStatistics.java
new file mode 100644
index 000000000000..6715fa413d04
--- /dev/null
+++ b/python/educational-core/src/com/jetbrains/edu/learning/statistics/EduStatistics.java
@@ -0,0 +1,43 @@
+package com.jetbrains.edu.learning.statistics;
+
+import com.intellij.openapi.components.PersistentStateComponent;
+import com.intellij.openapi.components.RoamingType;
+import com.intellij.openapi.components.State;
+import com.intellij.openapi.components.Storage;
+import com.jetbrains.edu.learning.StudySerializationUtils;
+import gnu.trove.TObjectIntHashMap;
+import org.jdom.Element;
+import org.jetbrains.annotations.Nullable;
+
+@State(
+ name = "Edu.Statistics",
+ storages = @Storage(value = "edu.stats.xml", roamingType = RoamingType.DISABLED)
+)
+public class EduStatistics implements PersistentStateComponent {
+ private static final String DESCRIPTORS = "descriptors";
+ private TObjectIntHashMap myUsageDescriptors = new TObjectIntHashMap<>();
+
+ @Nullable
+ @Override
+ public Element getState() {
+ Element descriptors = new Element(DESCRIPTORS);
+ myUsageDescriptors.forEachEntry((a, b) -> {
+ StudySerializationUtils.Xml.addChildWithName(descriptors, a, b);
+ return true;
+ });
+ return descriptors;
+ }
+
+ @Override
+ public void loadState(Element state) {
+ for (Element element : state.getChildren()) {
+ String key = element.getAttributeValue(StudySerializationUtils.Xml.NAME);
+ Integer value = Integer.valueOf(element.getAttributeValue(StudySerializationUtils.Xml.VALUE));
+ myUsageDescriptors.put(key, value);
+ }
+ }
+
+ public TObjectIntHashMap getUsageDescriptors() {
+ return myUsageDescriptors;
+ }
+}
diff --git a/python/educational-core/src/com/jetbrains/edu/learning/statistics/EduUsagesCollector.java b/python/educational-core/src/com/jetbrains/edu/learning/statistics/EduUsagesCollector.java
index 0399965e65d6..d68223724935 100644
--- a/python/educational-core/src/com/jetbrains/edu/learning/statistics/EduUsagesCollector.java
+++ b/python/educational-core/src/com/jetbrains/edu/learning/statistics/EduUsagesCollector.java
@@ -15,7 +15,6 @@
*/
package com.jetbrains.edu.learning.statistics;
-import com.intellij.internal.statistic.CollectUsagesException;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -29,8 +28,6 @@ import java.util.Set;
public class EduUsagesCollector extends UsagesCollector {
private static final String GROUP_ID = "educational";
- private final TObjectIntHashMap myUsageDescriptors = new TObjectIntHashMap<>();
-
public static void projectTypeCreated(@NotNull String projectTypeId) {
advanceKey("project.created." + projectTypeId);
}
@@ -40,34 +37,34 @@ public class EduUsagesCollector extends UsagesCollector {
}
public static void taskChecked() {
- advanceKey("checkTask.");
+ advanceKey("checkTask");
}
public static void hintShown() {
- advanceKey("showHint.");
+ advanceKey("showHint");
}
public static void taskNavigation() {
- advanceKey("navigateToTask.");
+ advanceKey("navigateToTask");
}
public static void courseUploaded() {
- advanceKey("uploadCourse.");
+ advanceKey("uploadCourse");
}
public static void createdCourseArchive() {
- advanceKey("courseArchive.");
+ advanceKey("courseArchive");
}
@NotNull
@Override
- public Set getUsages() throws CollectUsagesException {
+ public Set getUsages() {
HashSet descriptors = new HashSet<>();
- myUsageDescriptors.forEachEntry((key, value) -> {
+ getDescriptors().forEachEntry((key, value) -> {
descriptors.add(new UsageDescriptor(key, value));
return true;
});
- myUsageDescriptors.clear();
+ getDescriptors().clear();
return descriptors;
}
@@ -79,8 +76,12 @@ public class EduUsagesCollector extends UsagesCollector {
}
private static void advanceKey(@NotNull String key) {
- TObjectIntHashMap descriptors = ServiceManager.getService(EduUsagesCollector.class).myUsageDescriptors;
+ TObjectIntHashMap descriptors = getDescriptors();
int oldValue = descriptors.get(key);
descriptors.put(key, oldValue + 1);
}
+
+ private static TObjectIntHashMap getDescriptors() {
+ return ServiceManager.getService(EduStatistics.class).getUsageDescriptors();
+ }
}