Skip to content

Commit c038e3b

Browse files
bwilkersonCommit Bot
authored and
Commit Bot
committed
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 <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent b197d00 commit c038e3b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pkg/analysis_server/lib/src/analytics/percentile_calculator.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ class PercentileCalculator {
3535
return 0;
3636
}
3737
var targetIndex = _valueCount * percentile / 100;
38-
var values = _counts.keys.toList()..sort();
38+
var entries = _counts.entries.toList()
39+
..sort((first, second) => first.key.compareTo(second.key));
3940
// The number of values represented by walking the counts.
4041
var accumulation = 0;
41-
for (var i = 0; i < values.length; i++) {
42-
var value = values[i];
43-
accumulation += _counts[value]!;
42+
for (var i = 0; i < entries.length; i++) {
43+
var entry = entries[i];
44+
accumulation += entry.value;
4445
if (accumulation >= targetIndex) {
4546
// We've now accounted for [targetIndex] values, which includes the
4647
// median value.
47-
return value;
48+
return entry.key;
4849
}
4950
}
5051
throw StateError('');
@@ -53,6 +54,7 @@ class PercentileCalculator {
5354
/// Return a string that is suitable for sending to the analytics service.
5455
String toAnalyticsString() {
5556
var buffer = StringBuffer();
57+
buffer.write(_valueCount);
5658
buffer.write('[');
5759
for (var p = 5; p <= 100; p += 5) {
5860
if (p > 5) {

pkg/analysis_server/test/src/analytics/percentile_calculator_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
88

99
void main() {
1010
defineReflectiveSuite(() {
11-
defineReflectiveTests(PercentileTest);
11+
defineReflectiveTests(PercentileCalculatorTest);
1212
});
1313
}
1414

1515
@reflectiveTest
16-
class PercentileTest {
16+
class PercentileCalculatorTest {
1717
var calculator = PercentileCalculator();
1818

1919
void test_clear() {
@@ -22,19 +22,19 @@ class PercentileTest {
2222
}
2323
calculator.clear();
2424
expect(calculator.toAnalyticsString(),
25-
'[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
25+
'0[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
2626
}
2727

2828
void test_toAnalyticsString_empty() {
2929
expect(calculator.toAnalyticsString(),
30-
'[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
30+
'0[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]');
3131
}
3232

3333
void test_toAnalyticsString_evenDistribution() {
3434
for (int i = 1; i <= 100; i++) {
3535
calculator.addValue(i);
3636
}
3737
expect(calculator.toAnalyticsString(),
38-
'[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]');
38+
'100[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]');
3939
}
4040
}

0 commit comments

Comments
 (0)