mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cumulative statistics for all fixes (IDEA-88318)
This commit is contained in:
+2
@@ -28,6 +28,7 @@ import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.featureStatistics.FeatureUsageTrackerImpl;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
@@ -142,6 +143,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler {
|
||||
public static boolean chooseActionAndInvoke(PsiFile hostFile, final Editor hostEditor, final IntentionAction action, final String text) {
|
||||
final Project project = hostFile.getProject();
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.quickFix");
|
||||
((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getFixesStats().registerInvocation();
|
||||
|
||||
Pair<PsiFile, Editor> pair = chooseBetweenHostAndInjected(hostFile, hostEditor, new PairProcessor<PsiFile, Editor>() {
|
||||
public boolean process(PsiFile psiFile, Editor editor) {
|
||||
|
||||
+2
-27
@@ -15,41 +15,16 @@
|
||||
*/
|
||||
package com.intellij.featureStatistics;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class CompletionStatistics {
|
||||
public class CompletionStatistics extends CumulativeStatistics {
|
||||
public int sparedCharacters = 0;
|
||||
public int invocations = 0;
|
||||
public long startDate = 0;
|
||||
public int dayCount = 0;
|
||||
public long lastDate = 0;
|
||||
|
||||
public void registerInvocation(int spared) {
|
||||
invocations++;
|
||||
registerInvocation();
|
||||
if (spared > 0) {
|
||||
sparedCharacters += spared;
|
||||
}
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
long today = cal.getTimeInMillis();
|
||||
|
||||
if (startDate == 0) {
|
||||
startDate = today;
|
||||
}
|
||||
if (lastDate == 0) {
|
||||
lastDate = today;
|
||||
dayCount = 1;
|
||||
} else if (today != lastDate) {
|
||||
lastDate = today;
|
||||
dayCount++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.featureStatistics;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 7/5/12
|
||||
*/
|
||||
public class CumulativeStatistics {
|
||||
public int invocations = 0;
|
||||
public long startDate = 0;
|
||||
public int dayCount = 0;
|
||||
public long lastDate = 0;
|
||||
|
||||
public void registerInvocation() {
|
||||
invocations++;
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
long today = cal.getTimeInMillis();
|
||||
|
||||
if (startDate == 0) {
|
||||
startDate = today;
|
||||
}
|
||||
if (lastDate == 0) {
|
||||
lastDate = today;
|
||||
dayCount = 1;
|
||||
}
|
||||
else if (today != lastDate) {
|
||||
lastDate = today;
|
||||
dayCount++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -38,6 +38,7 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
private static final long DAY = HOUR * 24;
|
||||
private long FIRST_RUN_TIME = 0;
|
||||
private CompletionStatistics myCompletionStats = new CompletionStatistics();
|
||||
private CumulativeStatistics myFixesStats = new CumulativeStatistics();
|
||||
boolean HAVE_BEEN_SHOWN = false;
|
||||
|
||||
private final ProductivityFeaturesRegistry myRegistry;
|
||||
@@ -48,6 +49,7 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
@NonNls private static final String ATT_ID = "id";
|
||||
@NonNls private static final String ATT_FIRST_RUN = "first-run";
|
||||
@NonNls private static final String COMPLETION_STATS_TAG = "completionStatsTag";
|
||||
@NonNls private static final String FIXES_STATS_TAG = "fixesStatsTag";
|
||||
@NonNls private static final String ATT_HAVE_BEEN_SHOWN = "have-been-shown";
|
||||
|
||||
public FeatureUsageTrackerImpl(ProductivityFeaturesRegistry productivityFeaturesRegistry) {
|
||||
@@ -101,6 +103,10 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
return myCompletionStats;
|
||||
}
|
||||
|
||||
public CumulativeStatistics getFixesStats() {
|
||||
return myFixesStats;
|
||||
}
|
||||
|
||||
public long getFirstRunTime() {
|
||||
if (FIRST_RUN_TIME == 0) {
|
||||
FIRST_RUN_TIME = System.currentTimeMillis();
|
||||
@@ -131,6 +137,11 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
myCompletionStats = XmlSerializer.deserialize(stats, CompletionStatistics.class);
|
||||
}
|
||||
|
||||
Element fStats = element.getChild(FIXES_STATS_TAG);
|
||||
if (fStats != null) {
|
||||
myCompletionStats = XmlSerializer.deserialize(fStats, CompletionStatistics.class);
|
||||
}
|
||||
|
||||
HAVE_BEEN_SHOWN = Boolean.valueOf(element.getAttributeValue(ATT_HAVE_BEEN_SHOWN)).booleanValue();
|
||||
SHOW_IN_OTHER_PROGRESS = Boolean.valueOf(element.getAttributeValue(ATT_SHOW_IN_OTHER, Boolean.toString(true))).booleanValue();
|
||||
SHOW_IN_COMPILATION_PROGRESS = Boolean.valueOf(element.getAttributeValue(ATT_SHOW_IN_COMPILATION, Boolean.toString(true))).booleanValue();
|
||||
@@ -152,6 +163,10 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
XmlSerializer.serializeInto(myCompletionStats, statsTag);
|
||||
element.addContent(statsTag);
|
||||
|
||||
Element fstatsTag = new Element(FIXES_STATS_TAG);
|
||||
XmlSerializer.serializeInto(myFixesStats, fstatsTag);
|
||||
element.addContent(fstatsTag);
|
||||
|
||||
element.setAttribute(ATT_FIRST_RUN, String.valueOf(getFirstRunTime()));
|
||||
element.setAttribute(ATT_HAVE_BEEN_SHOWN, String.valueOf(HAVE_BEEN_SHOWN));
|
||||
element.setAttribute(ATT_SHOW_IN_OTHER, String.valueOf(SHOW_IN_OTHER_PROGRESS));
|
||||
|
||||
+9
-1
@@ -162,8 +162,16 @@ public class ShowFeatureUsageStatisticsDialog extends DialogWrapper {
|
||||
String total = formatCharacterCount(stats.sparedCharacters, true);
|
||||
String perDay = formatCharacterCount(stats.sparedCharacters / stats.dayCount, false);
|
||||
labelText += "<br>Code completion has saved you from typing at least " + total + " since " + DateFormatUtil.formatDate(stats.startDate) +
|
||||
" (\u2245" + perDay + " per working day)";
|
||||
" (~" + perDay + " per working day)";
|
||||
}
|
||||
|
||||
CumulativeStatistics fstats = ((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getFixesStats();
|
||||
if (fstats.dayCount > 0 && fstats.invocations > 0) {
|
||||
labelText +=
|
||||
"<br>Quick fixes have saved you from " + fstats.invocations + " possible bugs since " + DateFormatUtil.formatDate(fstats.startDate) +
|
||||
" (~" + fstats.invocations / fstats.dayCount + " per working day)";
|
||||
}
|
||||
|
||||
controlsPanel.add(new JLabel("<html><body>" + labelText + "</body></html>"), BorderLayout.NORTH);
|
||||
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
|
||||
Reference in New Issue
Block a user