forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.ts
More file actions
118 lines (102 loc) · 3.69 KB
/
handlers.ts
File metadata and controls
118 lines (102 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { generateOutput } from "./generateOutput";
import { generateAsciichart } from "./generateAsciichart";
import { getAllInfo, getCountryInfo, getHistorical } from "./getInformation";
/**
* historyPerCountry shows a tablechart of the <mode> of a country
* Shows Cases, Deaths, Recovered, Active, Cases/Million
* Today Cases, Today Deaths, Critical, Mortality %, Recovery in a chart
* @param country country code or country name that the user wants to query
* @param mode Mode that the user wants to query must be: "cases" | "deaths" | "recoveries"
* @param quiet tells the response to be in quiet mode or not
*/
export const historyPerCountry: (
country: string,
mode: "cases" | "deaths" | "recovered",
quiet: boolean
) => Promise<string> = async (country, mode, quiet) => {
// Get summary info about a country
let [updated, apiCountryname, countryName, rows] = (await getCountryInfo(
country
)) as [number, string, string, (string[] | string)[]];
// Fetch chart data and generate historical graph;
let historicalData = await getHistorical(mode, apiCountryname);
const chart = generateAsciichart(historicalData.chart).split("\n");
// add chart label and chart
rows.push(historicalData.date.magenta);
rows = rows.concat(chart);
// Generate table
let response = generateOutput(
`${countryName} Historical Chart`,
updated,
rows,
quiet
);
return response;
};
/**
* globalHistory shows a tablechart of the cases of all the countries
* Shows Cases, Deaths, Recovered, Active, Cases/Million
* and a graph of a country's cases
* @param mode Mode that the user wants to query must be: "cases" | "deaths" | "recoveries"
* @param quiet tells the response to be in quiet mode or not
*/
export const globalHistory: (
mode: "cases" | "deaths" | "recovered",
quiet: boolean
) => Promise<string> = async (mode, quiet) => {
// Get summary info
let [updated, rows] = (await getAllInfo()) as [
number,
(string[] | string)[]
];
// Fetch chart data and generate historical graph;
const historicalData = await getHistorical(mode);
const chart = generateAsciichart(historicalData.chart).split("\n");
rows.push(historicalData.date.magenta);
rows = rows.concat(chart);
let response = generateOutput(
"Global Historical Chart",
updated,
rows,
quiet
);
return response;
};
/**
* informationPerCountry tracks the info of a country
* Shows Cases, Deaths, Recovered, Active, Cases/Million
* Today Cases, Today Deaths, Critical, Mortality %, Recovery in a chart
* @param country country code or country name that the user wants to query
* @param quiet tells the response to be in quiet mode or not
*/
export const informationPerCountry: (
country: string,
quiet: boolean
) => Promise<string> = async (country, quiet) => {
// prettier-ignore
let [updated, _, countryName, rows] = (await getCountryInfo(country)) as [
number, string, string, (string[] | string)[]];
let response = generateOutput(
`${countryName} Update`,
updated,
rows,
quiet
);
// return response;
return response;
};
/**
* globalInformation tracks the info of all countries
* Shows Cases, Deaths, Recovered, Mortality %, Recovered% in a chart
* @param quiet tells the response to be in quiet mode or not
*/
export const globalInformation: (quiet: boolean) => Promise<string> = async (
quiet
) => {
const [updated, rowsOfData] = (await getAllInfo()) as [
number,
(string[] | string)[]
];
let response = generateOutput("Global Update", updated, rowsOfData, quiet);
return response;
};