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 ;
65const 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).
3122double 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.
0 commit comments