Skip to content

Commit 005c5d7

Browse files
jwrencommit-bot@chromium.org
authored andcommitted
Add an additional MMR "Max Rank 5" metric to the output of the completion_metrics.dart
Change-Id: I00ff65853eaef85bd33d76e930d7ba1d39783a14 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138882 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jaime Wren <[email protected]>
1 parent 52ad8dc commit 005c5d7

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ class C {
10081008
}
10091009

10101010
Future<void> test_constructor_param_prefix() async {
1011-
addTestSource('class A { A(^) {}}');
1011+
addTestSource('class A { A(t^) {}}');
10121012
await computeSuggestions();
10131013
assertSuggestKeywords(constructorParameter);
10141014
}

pkg/analysis_server/test/tool/completion_metrics/metrics_util_test.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void main() {
4646
var mrrc = MeanReciprocalRankComputer();
4747
expect(mrrc.rankCount, equals(0));
4848
expect(mrrc.ranks, isEmpty);
49-
expect(mrrc.mrr, equals(0));
49+
expect(mrrc.getMRR(), equals(0));
5050
});
5151

5252
test('clear', () {
@@ -69,7 +69,7 @@ void main() {
6969
mrrc.addRank(3);
7070
expect(mrrc.rankCount, equals(5));
7171
expect(mrrc.ranks, equals([3, 3, 3, 3, 3]));
72-
expect(mrrc.mrr, doubleEquals(1 / 3));
72+
expect(mrrc.getMRR(), doubleEquals(1 / 3));
7373
});
7474

7575
test('mmr- example', () {
@@ -79,7 +79,17 @@ void main() {
7979
mrrc.addRank(1);
8080
expect(mrrc.rankCount, equals(3));
8181
expect(mrrc.ranks, equals([3, 2, 1]));
82-
expect(mrrc.mrr, doubleEquals(11 / 18));
82+
expect(mrrc.getMRR(), doubleEquals(11 / 18));
83+
});
84+
85+
test('mmr- max rank', () {
86+
var mrrc = MeanReciprocalRankComputer();
87+
mrrc.addRank(3);
88+
mrrc.addRank(2);
89+
mrrc.addRank(1);
90+
expect(mrrc.rankCount, equals(3));
91+
expect(mrrc.ranks, equals([3, 2, 1]));
92+
expect(mrrc.getMRR(2), doubleEquals(1 / 2));
8393
});
8494
});
8595

pkg/analysis_server/tool/completion_metrics/metrics_util.dart

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,21 @@ class MeanReciprocalRankComputer {
6565
final List<int> ranks = [];
6666
MeanReciprocalRankComputer();
6767

68-
double get mrr {
69-
if (ranks.isEmpty) {
68+
double getMRR([int maxRank = 0]) {
69+
if (ranks.isEmpty || maxRank < 0) {
7070
return 0;
7171
}
72-
7372
double sum = 0;
7473
ranks.forEach((rank) {
75-
sum += rank != 0 ? (1 / rank) : 0;
74+
if (maxRank == 0) {
75+
if (rank != 0) {
76+
sum += 1 / rank;
77+
}
78+
} else {
79+
if (rank != 0 && rank <= maxRank) {
80+
sum += 1 / rank;
81+
}
82+
}
7683
});
7784
return sum / rankCount;
7885
}
@@ -86,9 +93,15 @@ class MeanReciprocalRankComputer {
8693
void clear() => ranks.clear();
8794

8895
void printMean() {
89-
var mrrVal = mrr;
90-
print('Mean Reciprocal Rank = ${mrrVal.toStringAsFixed(5)}');
91-
print('Harmonic Mean (inverse) = ${(1 / mrrVal).toStringAsFixed(2)}');
96+
var mrrVal = getMRR();
97+
print(
98+
'Mean Reciprocal Rank = ${mrrVal.toStringAsFixed(6)} '
99+
'(inverse = ${(1 / mrrVal).toStringAsFixed(3)})');
100+
101+
var mrrVal5 = getMRR(5);
102+
print(
103+
'Mean Reciprocal Rank (max rank 5) = ${mrrVal5.toStringAsFixed(6)} '
104+
'(inverse = ${(1 / mrrVal5).toStringAsFixed(3)})');
92105
}
93106
}
94107

0 commit comments

Comments
 (0)