Skip to content

Commit d734421

Browse files
committed
Remove threshold from growthrate function
1 parent 9223ece commit d734421

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

app/lib/service/download_counts/package_trends.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
const minAvgDailyDownloadsThreshold = 1000;
65
const analysisWindowDays = 30;
7-
const weightAge = 0.25;
8-
const weightGrowthRate = 0.75;
96

107
/// Calculates the relative daily growth rate of a package's downloads.
118
///
@@ -14,12 +11,6 @@ const weightGrowthRate = 0.75;
1411
/// over the last ([analysisWindowDays]) days to determine how fast a package is
1512
/// growing relative to its own current download volume.
1613
///
17-
/// Returns -double.maxFinite:
18-
/// - If the [totalDownloads] list has fewer data points than
19-
/// [analysisWindowDays].
20-
/// - If the average daily downloads over the [analysisWindowDays] period are
21-
/// less than [minAvgDailyDownloadsThreshold].
22-
///
2314
/// Otherwise, it returns the calculated relative growth rate. A positive value
2415
/// indicates an upward trend in downloads, while a negative value indicates a
2516
/// downward trend. The magnitude represents the growth (or decline) rate
@@ -29,21 +20,22 @@ const weightGrowthRate = 0.75;
2920
/// relative growth) than for a package with 10000 average daily downloads (0.1%
3021
/// relative growth).
3122
double computeRelativeGrowthRate(List<int> totalDownloads) {
23+
final List<int> data;
3224
if (totalDownloads.length < analysisWindowDays) {
33-
// insufficient data points.
34-
return -double.maxFinite;
25+
data = [
26+
...totalDownloads,
27+
...List.filled(analysisWindowDays - totalDownloads.length, 0)
28+
];
29+
} else {
30+
data = totalDownloads;
3531
}
3632

37-
final recentDownloads = totalDownloads.sublist(0, analysisWindowDays);
33+
final recentDownloads = data.sublist(0, analysisWindowDays);
3834

3935
final averageRecentDownloads =
4036
recentDownloads.reduce((prev, element) => prev + element) /
4137
recentDownloads.length;
4238

43-
if (averageRecentDownloads < minAvgDailyDownloadsThreshold) {
44-
// Package does not meet the minimum average download threshold.
45-
return -double.maxFinite;
46-
}
4739
// We reverse the recentDownloads list for regression, since the first entry
4840
// is the newest point in time. By reversing, we pass the data in
4941
// chronological order.

app/test/service/download_counts/package_trends_test.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ void main() {
2020
});
2121

2222
group('computeRelativeGrowthRate', () {
23-
test('returns -double.maxFinite for insufficient data', () {
24-
final downloads = List<int>.generate(analysisWindowDays - 1, (i) => 1500);
25-
expect(computeRelativeGrowthRate(downloads), -double.maxFinite);
26-
});
27-
28-
test('returns -double.maxFinite for average downloads below threshold', () {
29-
final downloads = List<int>.generate(
30-
analysisWindowDays, (i) => minAvgDailyDownloadsThreshold - 1);
31-
expect(computeRelativeGrowthRate(downloads), -double.maxFinite);
32-
});
33-
3423
test('returns 0.0 for stable downloads meeting threshold', () {
3524
final downloads = List<int>.generate(analysisWindowDays, (i) => 2000);
3625
expect(computeRelativeGrowthRate(downloads), 0.0);

0 commit comments

Comments
 (0)