|
1 | 1 | import logger from "../utils/logger";
|
2 | 2 | import { getAnalyticsErrorMessage } from "./errors";
|
3 | 3 | import * as reports from "./reports";
|
| 4 | +import { |
| 5 | + AllTimePeriodReport, |
| 6 | + ChartReport, |
| 7 | + TextReport, |
| 8 | +} from "./reports/reports"; |
4 | 9 |
|
5 | 10 | async function cliReport() {
|
6 | 11 | const events = await reports.fetchEventsForReportGenerator();
|
7 | 12 |
|
8 |
| - printTitle("TOTAL REPORT"); |
9 |
| - showReportInCLI(await reports.generateTotalReport(events)); |
| 13 | + printReportTitle("TOTAL REPORT"); |
| 14 | + printReportInCLI(await reports.generateTotalReport(events)); |
10 | 15 |
|
11 |
| - printTitle("DAILY REPORT"); |
12 |
| - showReportInCLI(await reports.generateDailyReport(events)); |
| 16 | + printReportTitle("DAILY REPORT"); |
| 17 | + printReportInCLI(await reports.generateDailyReport(events)); |
13 | 18 |
|
14 |
| - printTitle("WEEKLY REPORT"); |
15 |
| - showReportInCLI(await reports.generateWeeklyReport(events)); |
| 19 | + printReportTitle("WEEKLY REPORT"); |
| 20 | + printReportInCLI(await reports.generateWeeklyReport(events)); |
16 | 21 |
|
17 |
| - printTitle("MONTHLY REPORT"); |
18 |
| - showReportInCLI(await reports.generateMonthlyReport(events)); |
| 22 | + printReportTitle("MONTHLY REPORT"); |
| 23 | + printReportInCLI(await reports.generateMonthlyReport(events)); |
19 | 24 |
|
20 |
| - printTitle("ALL TIME MONTHLY REPORT (CSVs)"); |
21 |
| - await allTimeMonthlyActiveUsersAndProjectsCsvCliReport(events); |
| 25 | + printReportTitle("ALL TIME MONTHLY REPORT (CSVs)"); |
| 26 | + printAllTimeMonthlyReportCsvInCLI( |
| 27 | + await reports.generateAllTimeMonthlyReport(events), |
| 28 | + ); |
22 | 29 | }
|
23 | 30 |
|
24 | 31 | // Outputs CSV of total metrics since the start of tracking them,
|
25 | 32 | // while skipping cohort analytis because that would be too complex.
|
26 | 33 | // Useful for manually producing charts that show total progress of Wasp.
|
27 |
| -async function allTimeMonthlyActiveUsersAndProjectsCsvCliReport(events) { |
28 |
| - const report = await reports.generateAllTimeMonthlyReport(events); |
| 34 | +function printAllTimeMonthlyReportCsvInCLI( |
| 35 | + allTimePeriodReort: AllTimePeriodReport, |
| 36 | +) { |
| 37 | + const { userActivityReport, projectsReport } = allTimePeriodReort; |
29 | 38 |
|
30 | 39 | console.log("\n[CSV] Num active users");
|
31 |
| - const activeUsersReport = report[0]; |
32 |
| - for (const row of activeUsersReport.csv) { |
| 40 | + for (const row of userActivityReport.csv) { |
33 | 41 | console.log(row.join(","));
|
34 | 42 | }
|
35 | 43 |
|
36 | 44 | console.log("\n[CSV] Num projects");
|
37 |
| - console.log(",created diff,created cumm,built diff,built cumm"); |
38 |
| - const projectsReport = report[1]; |
| 45 | + console.log("created diff,created cumm,built diff,built cumm"); |
39 | 46 | for (const row of projectsReport.csv) {
|
40 | 47 | console.log(row.join(","));
|
41 | 48 | }
|
42 | 49 | }
|
43 | 50 |
|
44 |
| -function showReportInCLI(report) { |
45 |
| - for (const metric of report) { |
| 51 | +function printReportInCLI( |
| 52 | + compositeReport: Record<string, Partial<TextReport & ChartReport>>, |
| 53 | +) { |
| 54 | + for (const simpleReport of Object.values(compositeReport)) { |
46 | 55 | console.log();
|
47 |
| - if (metric.text) { |
48 |
| - for (const textLine of metric.text) { |
| 56 | + if (simpleReport.text) { |
| 57 | + for (const textLine of simpleReport.text) { |
49 | 58 | console.log(textLine);
|
50 | 59 | }
|
51 | 60 | }
|
52 |
| - if (metric.chart) { |
53 |
| - console.log("- Chart: ", metric.chart.toURL()); |
| 61 | + if (simpleReport.chart) { |
| 62 | + console.log("- Chart: ", simpleReport.chart.toURL()); |
54 | 63 | }
|
55 | 64 | }
|
56 | 65 | }
|
57 | 66 |
|
58 |
| -function printTitle(text) { |
| 67 | +function printReportTitle(text) { |
59 | 68 | console.log(`\x1b[33m \n\n${text} \x1b[0m`);
|
60 | 69 | }
|
61 | 70 |
|
|
0 commit comments