@@ -82,13 +82,22 @@ double calculateLinearRegressionSlope(List<num> yValues) {
8282/// assessed by comparing the sum of its downloads over the available history
8383/// (up to [analysisWindowDays] ) against a [minThirtyDaysDownloadThreshold] .
8484double computeTrendScore (List <int > totalDownloads) {
85- final n = min (analysisWindowDays, totalDownloads.length);
86- final thirtydaySum = totalDownloads.isEmpty
85+ final lastNonZeroIndex = totalDownloads.lastIndexWhere ((e) => e != 0 );
86+
87+ // We trim trailing zeros to ensure an accurate calculation of the trend. The
88+ // zeros represent the time before the package was published. Leaving them in
89+ // would artificially flatten the calculated growth rate.
90+ final downloads = lastNonZeroIndex >= 0
91+ ? totalDownloads.sublist (0 , lastNonZeroIndex + 1 )
92+ : < int > [];
93+
94+ final n = min (analysisWindowDays, downloads.length);
95+ final thirtydaySum = downloads.isEmpty
8796 ? 0
88- : totalDownloads .sublist (0 , n).reduce ((prev, element) => prev + element);
97+ : downloads .sublist (0 , n).reduce ((prev, element) => prev + element);
8998 final sigmoid = calculateSigmoidScaleScore (total30Downloads: thirtydaySum);
9099
91- return computeRelativeGrowthRate (totalDownloads ) * sigmoid;
100+ return computeRelativeGrowthRate (downloads ) * sigmoid;
92101}
93102
94103/// Transforms a list of numbers to their natural logarithm.
0 commit comments