Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ app.get('/', async (req, res, next) => {
});

// global historical chart
app.get(['/history/all/:chartType(cases|deaths)?', '/history/'], async (req, res, next) => {
app.get(['/history/all/:chartType(cases|deaths|recovered|actives)?', '/history/'], async (req, res, next) => {
const userAgent = req.headers['user-agent'],
api = await axios.get(`${apiBaseURL}/all`),
chartType = req.params.chartType || 'cases',
history = await axios.get(`${apiBaseURL}/v2/historical/all?lastdays=all`),
h = history.data;
data = api.data;

if (util.isCommandline(userAgent)) {
await res.send(covid19.historyGlobalTracker(
data.cases, data.deaths,
Expand Down Expand Up @@ -76,8 +76,8 @@ app.get('/:country', async (req, res, next) => {
d = api.data;
if (util.isCommandline(userAgent)) {
await res.send(covid19.covid19countrytracker(
d.country, d.cases, d.todayCases,
d.deaths, d.todayDeaths, d.recovered,
d.country, d.cases, d.todayCases,
d.deaths, d.todayDeaths, d.recovered,
d.active, d.critical, d.casesPerOneMillion,
d.updated
));
Expand All @@ -94,8 +94,8 @@ app.get(['/plain/:country','/cmd/:country','/basic/:country'], async (req, res,
d = api.data;
if (util.isCommandline(userAgent)) {
await res.send(covid19.plaincountrytracker(
d.country, d.cases, d.todayCases,
d.deaths, d.todayDeaths, d.recovered,
d.country, d.cases, d.todayCases,
d.deaths, d.todayDeaths, d.recovered,
d.active, d.critical, d.casesPerOneMillion,
d.updated
));
Expand All @@ -105,7 +105,7 @@ app.get(['/plain/:country','/cmd/:country','/basic/:country'], async (req, res,
});

// historical chart by country
app.get('/history/:country/:chartType(cases|deaths)?', async (req, res, next) => {
app.get('/history/:country/:chartType(cases|deaths|recovered|actives)?', async (req, res, next) => {
const userAgent = req.headers['user-agent'],
countryData = req.params.country,
chartType = req.params.chartType || 'cases',
Expand All @@ -117,8 +117,8 @@ app.get('/history/:country/:chartType(cases|deaths)?', async (req, res, next) =>
if (util.isCommandline(userAgent)) {
await res.send(
covid19.historyCountryTracker(
s.country, s.cases, s.todayCases,
s.deaths, s.todayDeaths, s.recovered,
s.country, s.cases, s.todayCases,
s.deaths, s.todayDeaths, s.recovered,
s.active, s.critical, s.casesPerOneMillion,
s.updated, h, chartType
)
Expand Down
42 changes: 29 additions & 13 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const color = require('ansi-styles'),
say = require('../sayings/threads.json'); // sayings

// ansi colors
const
const
// table color
tblclr = (border) => cyan(border),
// normal ansi colors
Expand Down Expand Up @@ -53,18 +53,18 @@ let ts = Date.now(),
// table configuration
const borders = { 'top': tblclr('═'),
'top-mid': tblclr('╤'),
'top-left': tblclr('╔'),
'top-left': tblclr('╔'),
'top-right': tblclr('╗'),
'bottom': tblclr('═'),
'bottom-mid': tblclr('╧'),
'bottom-left': tblclr('╚'),
'bottom': tblclr('═'),
'bottom-mid': tblclr('╧'),
'bottom-left': tblclr('╚'),
'bottom-right': tblclr('╝'),
'left': tblclr('║'),
'left-mid': tblclr('╟'),
'mid': tblclr('─'),
'left': tblclr('║'),
'left-mid': tblclr('╟'),
'mid': tblclr('─'),
'mid-mid': tblclr('┼'),
'right': tblclr('║'),
'right-mid': tblclr('╢'),
'right': tblclr('║'),
'right-mid': tblclr('╢'),
'middle': tblclr('│')};

// additional informaton
Expand Down Expand Up @@ -271,13 +271,21 @@ exports.plaincountrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
};

exports.historyGlobalTracker = (c, d, r, u, h, chartType) => {
const dates = Object.keys(h['cases']);

if (chartType == 'actives') {
h.actives = {}
dates.forEach((date) => {
h.actives[date] = h.cases[date] - h.deaths[date] - h.recovered[date];
});
}

const cases = c, deaths = d, recovered = r, asof = new Date(u),
mortalityPercentage = (d/c)*100, recoveredPercentage = (r/c)*100,
table = new table3({
head: [{colSpan:5,content:white('COVID-19 Tracker CLI v'+pkg.version+' - Global Historical Chart')}],
chars: borders
}),
dates = Object.keys(h[chartType]),
from = dates[0],
to = dates[dates.length - 1],
chartData = chart.generate(h, chartType);
Expand All @@ -294,12 +302,20 @@ exports.historyGlobalTracker = (c, d, r, u, h, chartType) => {
}

exports.historyCountryTracker = (n, c, tC, d, tD, r, a, cl, cPOM, u, h, chartType) => {
const dates = Object.keys(h.timeline['cases']);

if (chartType == 'actives') {
h.timeline.actives = {}
dates.forEach((date) => {
h.timeline.actives[date] = h.timeline.cases[date] - h.timeline.deaths[date] - h.timeline.recovered[date];
});
}

const name = n, cases = c, todayCases = tC,
deaths = d, todayDeaths = tD, recovered = r,
active = a, critical = cl, casesPerOneMillion = cPOM,
mortalityPercentage = (d/c)*100, recoveredPercentage = (r/c)*100,
asof = new Date(u),
dates = Object.keys(h.timeline[chartType]),
from = dates[0],
to = dates[dates.length - 1],
table = new table3({
Expand All @@ -321,7 +337,7 @@ exports.historyCountryTracker = (n, c, tC, d, tD, r, a, cl, cPOM, u, h, chartTyp
const tableFooter = table.toString()+br+br+space+green(randomSay()),
defaultfooter = footerOne+ansiBMC+footerTwo+ansiTwitter+br+br,
specialfooter = footerOne+ansiGCash+br+' '+ansiBMC+footerTwo+ansiTwitter+br+br;

return n == 'Philippines' ? tableFooter+specialfooter : tableFooter+defaultfooter;
};

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.