diff --git a/utils/format.js b/utils/format.js new file mode 100644 index 0000000..dc5f114 --- /dev/null +++ b/utils/format.js @@ -0,0 +1,4 @@ +module.exports = function format(num){ + var n = num.toFixed(2); + return n+"%"; +} \ No newline at end of file diff --git a/utils/getCountries.js b/utils/getCountries.js index dadd169..e6f076f 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -7,6 +7,7 @@ const { sortingKeys } = require('./table.js'); const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); +const format = require('./format'); module.exports = async ( spinner, @@ -45,7 +46,8 @@ module.exports = async ( comma(oneCountry.recovered), comma(oneCountry.active), comma(oneCountry.critical), - comma(oneCountry.casesPerOneMillion) + comma(oneCountry.casesPerOneMillion), + comma(format((oneCountry.deaths/oneCountry.cases)*100)) ]); }); diff --git a/utils/getCountry.js b/utils/getCountry.js index 554e9ce..3ec82c2 100644 --- a/utils/getCountry.js +++ b/utils/getCountry.js @@ -5,6 +5,7 @@ const comma = require('comma-number'); const red = chalk.red; const to = require('await-to-js').default; const handleError = require('cli-handle-error'); +const format = require('./format'); module.exports = async (spinner, table, states, countryName, options) => { if (countryName && !states && !options.chart) { @@ -34,7 +35,8 @@ module.exports = async (spinner, table, states, countryName, options) => { comma(thisCountry.recovered), comma(thisCountry.active), comma(thisCountry.critical), - comma(thisCountry.casesPerOneMillion) + comma(thisCountry.casesPerOneMillion), + comma(format((thisCountry.deaths/thisCountry.cases)*100)) ]); spinner.stopAndPersist(); console.log(table.toString()); diff --git a/utils/getStates.js b/utils/getStates.js index 7985c05..64c07ce 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -7,6 +7,7 @@ const { sortingStateKeys } = require('./table.js'); const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); +const format = require('./format'); module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { if (states) { @@ -32,7 +33,8 @@ module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { comma(oneState.todayCases), comma(oneState.deaths), comma(oneState.todayDeaths), - comma(oneState.active) + comma(oneState.active), + comma(format((oneState.deaths/oneState.cases)*100)) ]); }); diff --git a/utils/getWorldwide.js b/utils/getWorldwide.js index efdd1e6..8505845 100644 --- a/utils/getWorldwide.js +++ b/utils/getWorldwide.js @@ -2,6 +2,7 @@ const axios = require('axios'); const comma = require('comma-number'); const to = require('await-to-js').default; const handleError = require('cli-handle-error'); +const format = require('./format'); module.exports = async (table, states) => { const [err, response] = await to( @@ -23,7 +24,8 @@ module.exports = async (table, states) => { comma(allData.recovered), comma(allData.active), comma(allData.critical), - comma(allData.casesPerOneMillion) + comma(allData.casesPerOneMillion), + comma(format((allData.deaths/allData.cases)*100)) ]); } diff --git a/utils/table.js b/utils/table.js index 6a410b6..76d214c 100644 --- a/utils/table.js +++ b/utils/table.js @@ -15,7 +15,8 @@ module.exports = { `Recovered`, `Active`, `Critical`, - `Per Million` + `Per Million`, + `Mortality Rate` ], colored: [ `#`, @@ -27,7 +28,8 @@ module.exports = { `${green(`Recovered`)}`, `${yellow(`Active`)}`, `${red(`Critical`)}`, - `Per Million` + `Per Million`, + `${red(`Mortality Rate`)}`, ], singleStates: [ `#`, @@ -36,7 +38,7 @@ module.exports = { `Cases ${dim(`(today)`)}`, `Deaths`, `Deaths ${dim(`(today)`)}`, - `Active` + `Active`, ], coloredStates: [ `#`, @@ -45,7 +47,8 @@ module.exports = { `Cases ${dim(`(today)`)}`, `${red(`Deaths`)}`, `${red(`Deaths (today)`)}`, - `${yellow(`Active`)}` + `${yellow(`Active`)}`, + `${red(`Mortality Rate`)}` ], style: { head: ['cyan'] }, borderless: { diff --git a/utils/theEnd.js b/utils/theEnd.js index 91c4554..4cd9bf8 100644 --- a/utils/theEnd.js +++ b/utils/theEnd.js @@ -14,6 +14,7 @@ ${dim(`❯ `)}${cyan(`Deaths:`)} Total number of deaths in a state ${dim(`❯ `)}${cyan(`Deaths (today):`)} Deaths in 24 hours GMT/UTC ${dim(`❯ `)}${cyan(`Recovered:`)} Total number of recovered people ${dim(`❯ `)}${cyan(`Active:`)} Total number of active patients +${dim(`❯ `)}${cyan(`Mortality Rate:`)} Death percentage `) ); @@ -30,6 +31,7 @@ ${dim(`❯ `)}${cyan(`Recovered:`)} Total number of recovered people ${dim(`❯ `)}${cyan(`Active:`)} Total number of active patients ${dim(`❯ `)}${cyan(`Critical:`)} Total number of critical patients ${dim(`❯ `)}${cyan(`Per Million:`)} Affected patients per million +${dim(`❯ `)}${cyan(`Mortality Rate:`)} Death percentage `) );