Skip to content

Commit 28e5691

Browse files
committed
Update name and documentation
1 parent 672423d commit 28e5691

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

app/lib/service/download_counts/computations.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/test/service/download_counts/computations_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void main() {
160160
..addAll(List.filled(11, 0));
161161
final expectedNewstDate = date.addCalendarDays(7 * 40);
162162

163-
expect(res.weeklyPoints, expectedList);
163+
expect(res.weeklyDownloads, expectedList);
164164
expect(res.newestDate, expectedNewstDate);
165165
});
166166
});

0 commit comments

Comments
 (0)