@@ -43,29 +43,34 @@ Future<void> upload30DaysTotal(Map<String, int> counts) async {
4343 jsonUtf8Encoder.convert (counts));
4444}
4545
46- Future <({List <int > weeklyPoints, DateTime ? newestDate})> computeWeeklyDownloads (
47- String package) async {
48- final weeklyPoints = List .filled (52 , 0 );
46+ /// Computes `weeklyDownloads` starting from `newestDate` for [package] .
47+ ///
48+ /// Each number in `weeklyDownloads` is the total number of downloads for
49+ /// a given 7 day period starting from the newest date with download counts
50+ /// data available.
51+ Future <({List <int > weeklyDownloads, DateTime ? newestDate})>
52+ computeWeeklyDownloads (String package) async {
53+ final weeklyDownloads = List .filled (52 , 0 );
4954 final countData =
5055 await downloadCountsBackend.lookupDownloadCountData (package);
5156 if (countData == null ) {
52- return (weeklyPoints : < int > [], newestDate: null );
57+ return (weeklyDownloads : < int > [], newestDate: null );
5358 }
5459
5560 final totals = countData.totalCounts;
5661
5762 var sum = 0 ;
5863 for (int i = 0 ; i < 52 * 7 ; i++ ) {
5964 if (totals[i] < 0 ) {
60- weeklyPoints [(i ~ / 7 )] = sum;
65+ weeklyDownloads [(i ~ / 7 )] = sum;
6166 // There is no more available data.
6267 break ;
6368 }
6469 sum += totals[i];
6570 if ((i + 1 ) % 7 == 0 ) {
66- weeklyPoints [(i ~ / 7 )] = sum;
71+ weeklyDownloads [(i ~ / 7 )] = sum;
6772 sum = 0 ;
6873 }
6974 }
70- return (weeklyPoints : weeklyPoints , newestDate: countData.newestDate! );
75+ return (weeklyDownloads : weeklyDownloads , newestDate: countData.newestDate! );
7176}
0 commit comments