Skip to content
This repository was archived by the owner on Nov 2, 2021. It is now read-only.

Fix/2462 negative cases issue #2463

Closed
wants to merge 5 commits into from
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
10 changes: 5 additions & 5 deletions src/components/MapVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const [width, height] = [432, 488];

const colorInterpolator = (statistic) => {
switch (statistic) {
case 'confirmed':
case STATISTIC_CONFIGS.confirmed.displayName:
return (t) => interpolateReds(t * 0.85);
case 'active':

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grin

case STATISTIC_CONFIGS.active.displayName:
return (t) => interpolateBlues(t * 0.85);
case 'recovered':
case STATISTIC_CONFIGS.recovered.displayName:
return (t) => interpolateGreens(t * 0.85);
case 'deceased':
case STATISTIC_CONFIGS.deceased.displayName:
return (t) => interpolateGreys(t * 0.85);
case 'tested':
case STATISTIC_CONFIGS.tested.displayName:
return (t) => interpolatePurples(t * 0.85);
default:
return (t) => interpolateOranges(t * 0.85);
Expand Down
4 changes: 2 additions & 2 deletions src/components/StateHeader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import StateDropdown from './StateDropdown';

import {SPRING_CONFIG_NUMBERS} from '../constants.js';
import {SPRING_CONFIG_NUMBERS, STATISTIC_CONFIGS} from '../constants.js';
import {formatDate, formatNumber, getStatistic} from '../utils/commonFunctions';

import {memo, useMemo} from 'react';
Expand All @@ -24,7 +24,7 @@ function StateHeader({data, stateCode}) {
}, []);

const spring = useSpring({
total: getStatistic(data, 'total', 'tested'),
total: getStatistic(data, 'total', STATISTIC_CONFIGS.tested.displayName),
config: SPRING_CONFIG_NUMBERS,
});

Expand Down
36 changes: 26 additions & 10 deletions src/components/StateMeta.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import StateMetaCard from './StateMetaCard';

import {STATE_NAMES} from '../constants';
import {STATE_NAMES, STATISTIC_CONFIGS} from '../constants';
import {
formatDate,
formatNumber,
Expand All @@ -25,10 +25,15 @@ function StateMeta({stateCode, data, timeseries}) {
const lastConfirmed = getStatistic(
timeseries?.[lastDate],
'total',
'confirmed'
STATISTIC_CONFIGS.confirmed.displayName
);
const prevWeekConfirmed =
lastConfirmed - getStatistic(timeseries?.[lastDate], 'delta7', 'confirmed');
lastConfirmed -
getStatistic(
timeseries?.[lastDate],
'delta7',
STATISTIC_CONFIGS.confirmed.displayName
);

const prevWeekDate = formatISO(subDays(parseIndiaDate(lastDate), 7));

Expand All @@ -38,23 +43,34 @@ function StateMeta({stateCode, data, timeseries}) {
'confirmed',
{perMillion: true}
);
const testPerMillion = getStatistic(data[stateCode], 'total', 'tested', {
perMillion: true,
});
const testPerMillion = getStatistic(
data[stateCode],
'total',
STATISTIC_CONFIGS.tested.displayName,
{perMillion: true}
);
const totalConfirmedPerMillion = getStatistic(
data['TT'],
'total',
'confirmed',
STATISTIC_CONFIGS.confirmed.displayName,
{perMillion: true}
);

const activePercent = getStatistic(data[stateCode], 'total', 'activeRatio');
const activePercent = getStatistic(
data[stateCode],
'total',
STATISTIC_CONFIGS.activeRatio.displayName
);
const recoveryPercent = getStatistic(
data[stateCode],
'total',
'recoveryRatio'
STATISTIC_CONFIGS.recoveryRatio.displayName
);
const deathPercent = getStatistic(
data[stateCode],
'total',
STATISTIC_CONFIGS.cfr.displayName
);
const deathPercent = getStatistic(data[stateCode], 'total', 'cfr');

const growthRate =
(Math.pow(lastConfirmed / prevWeekConfirmed, 1 / 7) - 1) * 100;
Expand Down
16 changes: 9 additions & 7 deletions src/utils/commonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,25 @@ export const getStatistic = (
}

let count;
if (key === 'population') {
if (key === STATISTIC_CONFIGS.population.displayName) {
count = type === 'total' ? data?.meta?.population : 0;
} else if (key === 'tested') {
} else if (key === STATISTIC_CONFIGS.tested.displayName) {
count = data?.[type]?.tested;
} else if (key === 'active') {
} else if (key === STATISTIC_CONFIGS.active.displayName) {
const confirmed = data?.[type]?.confirmed || 0;
const deceased = data?.[type]?.deceased || 0;
const recovered = data?.[type]?.recovered || 0;
const other = data?.[type]?.other || 0;
count = confirmed - deceased - recovered - other;
count = count > 0 ? count : 0;
} else {
count = data?.[type]?.[key];
count = data?.[type]?.[key] > 0 ? data?.[type]?.[key] : 0;
}

if (normalizeBy) {
count /= getStatistic(
data,
normalizeBy === 'population' ? 'total' : type,
normalizeBy === STATISTIC_CONFIGS.population.displayName ? 'total' : type,
normalizeBy
);
}
Expand All @@ -177,8 +178,9 @@ export const getTableStatistic = (data, statistic, args, lastUpdatedTT) => {
const statisticDefinition = STATISTIC_CONFIGS[statistic]?.definition;

const expired =
(statisticDefinition?.key === 'tested' ||
statisticDefinition?.normalizeByKey === 'tested') &&
(statisticDefinition?.key === STATISTIC_CONFIGS.tested.displayName ||
statisticDefinition?.normalizeByKey ===
STATISTIC_CONFIGS.tested.displayName) &&
differenceInDays(
lastUpdatedTT,
parseIndiaDate(data.meta?.tested?.['last_updated'])
Expand Down