Clean up in analytics
This
- converts PercentileCalculator to sort entries, as previously suggested,
- adds the number of values to the dump of a PercentileCalculator, and
- fixes the name of a class to conform to conventions.
Change-Id: Icb25a3adfc922b6d5b394883853eeeff968e4b89
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245460
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/analytics/percentile_calculator.dart b/pkg/analysis_server/lib/src/analytics/percentile_calculator.dart
index b1a313c..d818ab5 100644
--- a/pkg/analysis_server/lib/src/analytics/percentile_calculator.dart
+++ b/pkg/analysis_server/lib/src/analytics/percentile_calculator.dart
@@ -35,16 +35,17 @@
return 0;
}
var targetIndex = _valueCount * percentile / 100;
- var values = _counts.keys.toList()..sort();
+ var entries = _counts.entries.toList()
+ ..sort((first, second) => first.key.compareTo(second.key));
// The number of values represented by walking the counts.
var accumulation = 0;
- for (var i = 0; i < values.length; i++) {
- var value = values[i];
- accumulation += _counts[value]!;
+ for (var i = 0; i < entries.length; i++) {
+ var entry = entries[i];
+ accumulation += entry.value;
if (accumulation >= targetIndex) {
// We've now accounted for [targetIndex] values, which includes the
// median value.
- return value;
+ return entry.key;
}
}
throw StateError('');
@@ -53,6 +54,7 @@
/// Return a string that is suitable for sending to the analytics service.
String toAnalyticsString() {
var buffer = StringBuffer();
+ buffer.write(_valueCount);
buffer.write('[');
for (var p = 5; p <= 100; p += 5) {
if (p > 5) {
diff --git a/pkg/analysis_server/test/src/analytics/percentile_calculator_test.dart b/pkg/analysis_server/test/src/analytics/percentile_calculator_test.dart
index a6a1047..657961b 100644
--- a/pkg/analysis_server/test/src/analytics/percentile_calculator_test.dart
+++ b/pkg/analysis_server/test/src/analytics/percentile_calculator_test.dart
@@ -8,12 +8,12 @@
void main() {
defineReflectiveSuite(() {
- defineReflectiveTests(PercentileTest);
+ defineReflectiveTests(PercentileCalculatorTest);
});
}
@reflectiveTest
-class PercentileTest {
+class PercentileCalculatorTest {
var calculator = PercentileCalculator();
void test_clear() {
@@ -22,12 +22,12 @@
}
calculator.clear();
expect(calculator.toAnalyticsString(),
- '[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
+ '0[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
}
void test_toAnalyticsString_empty() {
expect(calculator.toAnalyticsString(),
- '[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
+ '0[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
}
void test_toAnalyticsString_evenDistribution() {
@@ -35,6 +35,6 @@
calculator.addValue(i);
}
expect(calculator.toAnalyticsString(),
- '[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]');
+ '100[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]');
}
}