Skip to content

Commit 3923e96

Browse files
authored
Jsonify report (#7385)
1 parent d5af968 commit 3923e96

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

app/lib/admin/actions/uploader_count_report.dart

+7-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ final uploaderCountReport = AdminAction(
3131
Returns a report of the number of uploaders for each of the last 12 months.
3232
3333
The report is based on "UploadEvents".
34-
35-
To pretty-print in the terminal pipe through `| jq -r .record'.
3634
''',
3735
invoke: (args) async {
3836
final buckets = <DateTime, Set<String>>{};
@@ -49,14 +47,15 @@ To pretty-print in the terminal pipe through `| jq -r .record'.
4947
DateTime(created.year, created.month), () => {});
5048
bucket.add(agent);
5149
}
52-
final buffer = StringBuffer();
53-
buffer.writeln('Monthly unique uploading users:');
54-
50+
final report = <Map<String, Object>>[];
5551
for (int i = 11; i >= 0; i--) {
5652
final month = DateTime(now.year, now.month - i);
5753
final bucket = buckets[month] ?? {};
58-
buffer.writeln(
59-
'${_monthNames[month.month]} ${month.year}: ${bucket.length}');
54+
report.add({
55+
'year': month.year,
56+
'month': _monthNames[month.month]!,
57+
'unique uploading users': bucket.length,
58+
});
6059
}
61-
return {'report': buffer.toString()};
60+
return {'report': report};
6261
});

app/test/tool/utils/uploader_count_report_test.dart

+14-15
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,20 @@ environment:
6565
AdminInvokeActionArguments(arguments: {}),
6666
);
6767

68-
expect(response.output['report'], '''
69-
Monthly unique uploading users:
70-
January 2022: 1
71-
February 2022: 3
72-
March 2022: 0
73-
April 2022: 0
74-
May 2022: 0
75-
June 2022: 0
76-
July 2022: 0
77-
August 2022: 0
78-
September 2022: 0
79-
October 2022: 0
80-
November 2022: 0
81-
December 2022: 1
82-
''');
68+
expect(response.output['report'], [
69+
{'year': 2022, 'month': 'January', 'unique uploading users': 1},
70+
{'year': 2022, 'month': 'February', 'unique uploading users': 3},
71+
{'year': 2022, 'month': 'March', 'unique uploading users': 0},
72+
{'year': 2022, 'month': 'April', 'unique uploading users': 0},
73+
{'year': 2022, 'month': 'May', 'unique uploading users': 0},
74+
{'year': 2022, 'month': 'June', 'unique uploading users': 0},
75+
{'year': 2022, 'month': 'July', 'unique uploading users': 0},
76+
{'year': 2022, 'month': 'August', 'unique uploading users': 0},
77+
{'year': 2022, 'month': 'September', 'unique uploading users': 0},
78+
{'year': 2022, 'month': 'October', 'unique uploading users': 0},
79+
{'year': 2022, 'month': 'November', 'unique uploading users': 0},
80+
{'year': 2022, 'month': 'December', 'unique uploading users': 1}
81+
]);
8382
});
8483
});
8584
}

0 commit comments

Comments
 (0)