forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregularHandlers.ts
More file actions
120 lines (104 loc) · 3.74 KB
/
regularHandlers.ts
File metadata and controls
120 lines (104 loc) · 3.74 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
119
120
import { generateRegularOutput } from "./generateRegularOutput";
import { generateAsciichart } from "../../libs/generateAsciichart";
import { getHistorical } from "../../getInformation";
import { countryInfo, globalInfo } from "./regularParser";
/**
* 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 {
apiCountryName,
formalCountryName,
rowsOfData,
timeUpdated,
} = await countryInfo(country);
// Fetch chart data and generate historical graph;
let historicalData = await getHistorical(mode, apiCountryName);
const chart = generateAsciichart(historicalData.chartData).split("\n");
// add chart label and chart
rowsOfData.push(historicalData.date.magenta);
rowsOfData = rowsOfData.concat(chart);
// Generate table
let response = generateRegularOutput(
`${formalCountryName} Historical Chart`,
timeUpdated,
rowsOfData,
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 { timeUpdated, rowsOfData } = await globalInfo();
// Fetch chart data and generate historical graph;
const historicalData = await getHistorical(mode);
const chart = generateAsciichart(historicalData.chartData).split("\n");
rowsOfData.push(historicalData.date.magenta);
rowsOfData = rowsOfData.concat(chart);
let response = generateRegularOutput(
"Global Historical Chart",
timeUpdated,
rowsOfData,
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 {timeUpdated, formalCountryName, rowsOfData} = await countryInfo(country);
let response = generateRegularOutput(
`${formalCountryName} Update`,
timeUpdated,
rowsOfData,
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 { timeUpdated, rowsOfData } = await globalInfo();
let response = generateRegularOutput(
"Global Update",
timeUpdated,
rowsOfData,
quiet
);
return response;
};