forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplainHandlers.ts
More file actions
98 lines (87 loc) · 3.19 KB
/
plainHandlers.ts
File metadata and controls
98 lines (87 loc) · 3.19 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
import { generateAsciichart } from "./generateAsciichart";
import { generatePlainOutput } from "./generatePlainOutput";
import {
getAllInfo,
getCountryInfo,
getHistorical,
PlainData,
} from "./getInformation";
/**
* 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 globalHistoryPlain: (
mode: "cases" | "deaths" | "recovered",
quiet: boolean
) => Promise<string> = async (mode, quiet) => {
// Get summary info
const info = (await getAllInfo(true)) as PlainData;
// Get data from API
const historicalData = await getHistorical(mode);
// Generate historical graph
const chart = generateAsciichart(historicalData.chart, true, 7);
return generatePlainOutput(info, `Global Historical Chart`, quiet, [
historicalData.date,
chart,
]);
};
/**
* 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 historyPerCountryPlain: (
country: string,
mode: "cases" | "deaths" | "recovered",
quiet: boolean
) => Promise<string> = async (country, mode, quiet) => {
// Get summary info about a country
const info = (await getCountryInfo(country, true)) as PlainData;
const historicalData = await getHistorical(
mode,
info.metainfo.countryName as string
);
// Generate historical graph
const chart = generateAsciichart(historicalData.chart, true, 7);
return generatePlainOutput(
info,
`${info.metainfo.countryName} Chart`,
quiet,
[historicalData.date, chart]
);
};
/**
* 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 informationPerCountryPlain: (
country: string,
quiet: boolean
) => Promise<string> = async (country, quiet) => {
const info = (await getCountryInfo(country, true)) as PlainData;
return generatePlainOutput(
info,
`${info.metainfo.countryName} Update`,
quiet
);
};
/**
* 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 globalInformationPlain: (
quiet: boolean
) => Promise<string> = async (quiet) => {
const info = (await getAllInfo(true)) as PlainData;
return generatePlainOutput(info, "Global Update", quiet);
};