Skip to content

Commit 278202d

Browse files
committed
Normalize trend by overall average
1 parent 8d0c76e commit 278202d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

app/lib/service/download_counts/package_trends.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:math';
66

77
const analysisWindowDays = 30;
8+
const totalTrendWindowDays = 330;
89
const minThirtyDaysDownloadThreshold = 30000;
910

1011
/// Calculates the relative daily growth rate of a package's downloads.
@@ -38,7 +39,12 @@ double computeRelativeGrowthRate(List<int> totalDownloads) {
3839
recentDownloads.reduce((prev, element) => prev + element) /
3940
recentDownloads.length;
4041

41-
if (averageRecentDownloads == 0) {
42+
final m = min(totalDownloads.length, totalTrendWindowDays);
43+
final averageTotalDownloads =
44+
totalDownloads.sublist(0, m).reduce((prev, element) => prev + element) /
45+
m;
46+
47+
if (averageRecentDownloads == 0 || averageTotalDownloads == 0) {
4248
return 0;
4349
}
4450

@@ -51,7 +57,7 @@ double computeRelativeGrowthRate(List<int> totalDownloads) {
5157
// Normalize slope by average downloads to represent relative growth.
5258
// This measures how much the download count is growing relative to its
5359
// current volume.
54-
return growthRate / averageRecentDownloads;
60+
return growthRate / averageTotalDownloads;
5561
}
5662

5763
/// Computes the slope of the best-fit line for a given list of data points

app/test/service/download_counts/computations_test.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,16 @@ void main() {
314314
'fake_download_counts_data_for_trend2.jsonl'));
315315
await processDownloadCounts(d);
316316
}
317-
final neonTrend = computeTrendScore(
318-
[...List.filled(15, 2000), ...List.filled(15, 1000)]);
319-
final oxygenTrend = computeTrendScore(
320-
[...List.filled(15, 5000), ...List.filled(15, 3000)]);
317+
final neonTrend = computeTrendScore([
318+
...List.filled(15, 2000),
319+
...List.filled(15, 1000),
320+
...List.filled(701, -1)
321+
]);
322+
final oxygenTrend = computeTrendScore([
323+
...List.filled(15, 5000),
324+
...List.filled(15, 3000),
325+
...List.filled(701, -1)
326+
]);
321327

322328
expect(await computeTrend(),
323329
{'flutter_titanium': 0.0, 'neon': neonTrend, 'oxygen': oxygenTrend});

0 commit comments

Comments
 (0)