diff --git a/app.js b/app.js index a43d548..2beeb19 100644 --- a/app.js +++ b/app.js @@ -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, @@ -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 )); @@ -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 )); @@ -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', @@ -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 ) diff --git a/lib/cli/index.js b/lib/cli/index.js index 43ec357..78330ae 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -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 @@ -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 @@ -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); @@ -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({ @@ -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; }; diff --git a/package-lock.json b/package-lock.json index f832d6c..cd94f9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "covid19-tracker-cli", - "version": "3.0.0", + "version": "3.1.0", "lockfileVersion": 1, "requires": true, "dependencies": {