persist statistics and fix ids (EDU-1033)

This commit is contained in:
Liana.Bakradze
2017-09-08 13:33:27 +03:00
parent d64f741ae5
commit 4fc1151e3d
3 changed files with 57 additions and 13 deletions
@@ -174,7 +174,7 @@
<renameHandler implementation="com.jetbrains.edu.learning.StudyRenameHandler"/>
<refactoring.moveHandler implementation="com.jetbrains.edu.learning.StudyMoveDelegate" order="first"/>
<statistics.usagesCollector implementation="com.jetbrains.edu.learning.statistics.EduUsagesCollector"/>
<applicationService serviceImplementation="com.jetbrains.edu.learning.statistics.EduUsagesCollector"/>
<applicationService serviceImplementation="com.jetbrains.edu.learning.statistics.EduStatistics"/>
<applicationService serviceImplementation="com.jetbrains.edu.learning.StudySettings"/>
<editorTabTitleProvider implementation="com.jetbrains.edu.learning.StudyTabTitleProvider"/>
<typedHandler implementation="com.jetbrains.edu.learning.StudyTypeHandlerDelegate" order="first, before completionAutoPopup"/>
@@ -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<Element> {
private static final String DESCRIPTORS = "descriptors";
private TObjectIntHashMap<String> 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<String> getUsageDescriptors() {
return myUsageDescriptors;
}
}
@@ -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<String> 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<UsageDescriptor> getUsages() throws CollectUsagesException {
public Set<UsageDescriptor> getUsages() {
HashSet<UsageDescriptor> 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<String> descriptors = ServiceManager.getService(EduUsagesCollector.class).myUsageDescriptors;
TObjectIntHashMap<String> descriptors = getDescriptors();
int oldValue = descriptors.get(key);
descriptors.put(key, oldValue + 1);
}
private static TObjectIntHashMap<String> getDescriptors() {
return ServiceManager.getService(EduStatistics.class).getUsageDescriptors();
}
}