Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Mortality rate script for the data #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions utils/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function format(num){
var n = num.toFixed(2);
return n+"%";
}
4 changes: 3 additions & 1 deletion utils/getCountries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
]);
});

Expand Down
4 changes: 3 additions & 1 deletion utils/getCountry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion utils/getStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
]);
});

Expand Down
4 changes: 3 additions & 1 deletion utils/getWorldwide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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))
]);
}

Expand Down
11 changes: 7 additions & 4 deletions utils/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = {
`Recovered`,
`Active`,
`Critical`,
`Per Million`
`Per Million`,
`Mortality Rate`
],
colored: [
`#`,
Expand All @@ -27,7 +28,8 @@ module.exports = {
`${green(`Recovered`)}`,
`${yellow(`Active`)}`,
`${red(`Critical`)}`,
`Per Million`
`Per Million`,
`${red(`Mortality Rate`)}`,
],
singleStates: [
`#`,
Expand All @@ -36,7 +38,7 @@ module.exports = {
`Cases ${dim(`(today)`)}`,
`Deaths`,
`Deaths ${dim(`(today)`)}`,
`Active`
`Active`,
],
coloredStates: [
`#`,
Expand All @@ -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: {
Expand Down
2 changes: 2 additions & 0 deletions utils/theEnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
`)
);

Expand All @@ -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
`)
);

Expand Down