Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4ac8780
covidDataTypes:newconfirmed
Johnpc123 Apr 11, 2020
ad799b8
info (blue) colour for new confirmed
Johnpc123 Apr 12, 2020
31857ba
daily new deaths
Johnpc123 Apr 12, 2020
6549429
slice dataRows indexes
Johnpc123 Apr 12, 2020
45f52b8
% mortality daily
Johnpc123 Apr 12, 2020
308ab31
daily mortality percentage - by region
Johnpc123 Apr 12, 2020
d3c3db5
average when dataType is dailymortality
Johnpc123 Apr 12, 2020
0ab0408
label
Johnpc123 Apr 12, 2020
2acaa42
countrys with regions are borked
Johnpc123 Apr 14, 2020
f6309bf
average region average when grouping by country
Johnpc123 Apr 15, 2020
6f613fb
Average region mortality%
Johnpc123 Apr 15, 2020
0879310
q.d. stands for "quaque die" (Latin, once a day)
Johnpc123 Apr 15, 2020
072027a
average when dataType is dailymortality
Johnpc123 Apr 12, 2020
82abb04
average region average when grouping by country
Johnpc123 Apr 15, 2020
005ac62
Average region mortality%
Johnpc123 Apr 15, 2020
90c3200
q.d. stands for "quaque die" (Latin, once a day)
Johnpc123 Apr 15, 2020
f5f93ba
Fork of: trekhleb.github.io/covid-19
Johnpc123 Apr 16, 2020
e4092a9
removed daily mortality due to bug
Johnpc123 May 30, 2020
487f48e
mortality to lethality
Johnpc123 Jul 20, 2020
8fd8bae
mortality to lethality
Johnpc123 Jul 20, 2020
ece2625
mortality to lethality
Johnpc123 Jul 20, 2020
bfccd36
Merge branch 'newconfirmeddaily' of github.com:Johnpc123/covid-19 int…
Johnpc123 Jul 20, 2020
636e627
Merge branch 'master' into newconfirmeddaily
Johnpc123 Jul 20, 2020
d5ffcc1
mortality to lethality
Johnpc123 Jul 20, 2020
fb878b4
.gitignore fix
Johnpc123 Jul 20, 2020
18414a4
replace original title - COVID-19 Dashboard
Johnpc123 Jul 20, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.vscode
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<title>COVID-19 Dashboard</title>
<meta name="description" content="Coronavirus (COVID-19) dashboard to show the dynamics of Сoronavirus distribution per country">
<title>COVID-19 Dashboard </title>
<meta name="description" content="Coronavirus (COVID-19) dashboard browsable per country">
<meta name="author" content="Oleksii Trekhleb">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://kit.fontawesome.com/4add81f750.js" crossorigin="anonymous"></script>
Expand All @@ -35,7 +35,7 @@
<div class="col-sm">
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="navbar-brand mb-0 h1">
<i class="fas fa-chart-bar"></i> <a class="navbar-brand" href="https://trekhleb.github.io/covid-19/">COVID-19 Dashboard</a>
<i class="fas fa-chart-bar"></i> <a class="navbar-brand" href="https://trekhleb.github.io/covid-19/">COVID-19 Dashboard</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand Down
123 changes: 117 additions & 6 deletions js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,31 @@ const covidDataTypes = {
borderColor: deathsPalette,
alertClass: 'alert-danger',
badgeClass: 'badge-danger',
},
newconfirmed: {
key: 'newconfirmed',
title: 'Confirmed qd',
dataSourceUrl: `${covidDataBaseURL}/time_series_covid19_confirmed_global.csv`,
borderColor: confirmedPalette,
alertClass: 'alert-info',
badgeClass: 'badge-info',
},
newdeaths: {
key: 'newdeaths',
title: 'Deaths qd',
dataSourceUrl: `${covidDataBaseURL}/time_series_covid19_deaths_global.csv`,
borderColor: deathsPalette,
alertClass: 'alert-danger',
badgeClass: 'badge-danger',
},
// dailymortality: {
// key: 'dailymortality',
// title: 'Mortality % qd',
// dataSourceUrl: `${covidDataBaseURL}/time_series_covid19_deaths_global.csv`,
// borderColor: deathsPalette,
// alertClass: 'alert-danger',
// badgeClass: 'badge-danger',
// },
};

const covidCountries = {
Expand All @@ -64,9 +88,17 @@ const covidSorts = {
key: 'deaths',
dataKey: covidDataTypes.deaths.key,
},
newdeaths: {
key: 'newdeaths',
dataKey: covidDataTypes.newdeaths.key,
},
lethality: {
key: 'lethality',
},
newconfirmed: {
key: 'newconfirmed',
dataKey: covidDataTypes.newconfirmed.key,
},
};

const covidSortDirections = {
Expand Down Expand Up @@ -127,6 +159,7 @@ function loadCovidData() {
const dataType = Object.keys(covidDataTypes)[dataTypeIndex];
const dataTypeTicks = Papa.parse(dataTypeTicksCSV).data;
dataContainer.labels = dataTypeTicks.shift();

dataContainer.ticks[dataType] = dataTypeTicks
.filter(regionTicks => {
return regionTicks.length === dataContainer.labels.length;
Expand All @@ -152,13 +185,58 @@ function loadCovidData() {
}
return 0;
});

if(dataType==='newconfirmed'||dataType==='newdeaths'){
const newCasesDaily = dataContainer.ticks[dataType].map(function(dataRow){
// store the index columns to allow mapping of the difference calculation
const index = dataRow.slice(0,4);
const dataTicks = dataRow.slice(4);
// calculate yesterday minus today into a new array of ticks
const newCases = dataTicks.slice(1).map(function(n, i) { return n - dataTicks[i]; });
// re-prefix the index columns
return index.concat(newCases);
});
//replace the cumulative ticks with with the daily new cases
dataContainer.ticks[dataType] = newCasesDaily;
}

if(dataType==="dailymortality"){
// dailymortality dataType loads data from the deathNumber timeseries url
const dailyMortality = dataContainer.ticks['dailymortality'].map(function(dataRow){
const deathsIndex = dataRow.slice(0,4);
const deathsDataTicks = dataRow.slice(4);

// Refrence the confirmedNumber with the identical index
const confirmedDataTicks = dataContainer.ticks['confirmed'].find((arr) => (arrayEqual(arr.slice(0,4))(deathsIndex.slice(0,4)))).slice(4);

// using => calculateMortality(confirmedNumber, deathsNumber)
const dailyMortality = deathsDataTicks.map((deathTickValue,i)=>calculateMortality(confirmedDataTicks[i],deathTickValue));
return deathsIndex.concat(dailyMortality);
});
dataContainer.ticks[dataType] = dailyMortality;

}

return dataContainer;
},
defaultDataContainer
);
});
}

const arrayCompare = f => ([x,...xs]) => ([y,...ys]) =>
x === undefined && y === undefined
? true
: Boolean (f (x) (y)) && arrayCompare (f) (xs) (ys)

// equal :: a -> a -> Bool
const equal = x => y =>
x === y // notice: triple equal

// arrayEqual :: [a] -> [a] -> Bool
const arrayEqual =
arrayCompare (equal)

function getRegionKey(regionTicks) {
if (!regionTicks || !regionTicks.length) {
return null;
Expand All @@ -180,8 +258,13 @@ function getRegionByKey(covidData, dataTypeKey, regionKey) {
}

function getGlobalTicks(covidData, dataTypeKey) {

const totalTicks = covidData.ticks[dataTypeKey][0].length;
const globalTicks = new Array(totalTicks).fill(0);
let mutxDoAverage = false;
let itemCount=0;
// go easy

globalTicks[covidSchema.stateColumn] = '';
globalTicks[covidSchema.countryColumn] = covidCountries.all.title;
globalTicks[covidSchema.latColumn] = '';
Expand All @@ -191,10 +274,13 @@ function getGlobalTicks(covidData, dataTypeKey) {
if (tickIndex < covidSchema.dateStartColumn) {
return;
}
globalTicks[tickIndex] += regionTick;
globalTicks[tickIndex] += regionTick;
});
});
return globalTicks;

// return the average when dataType is dailymortality
return (dataTypeKey==='dailymortality')?globalTicks.map(i => {return i/covidData.ticks.dailymortality.length}):globalTicks;

}

function getTotalCount(covidData, dataTypeKey, regionKeys) {
Expand Down Expand Up @@ -260,20 +346,45 @@ function groupCovidDataByCountries(covidData) {
ticks: {},
};
covidDataByCountries.labels = [...covidData.labels];

Object.values(covidDataTypes).forEach((covidDataType) => {

covidDataByCountries.ticks[covidDataType.key] = Object.values(covidData.ticks[covidDataType.key]
.reduce((countriesTicksMap, regionTicks) => {

const countryName = regionTicks[covidSchema.countryColumn];

if (!countriesTicksMap[countryName]) {
countriesTicksMap[countryName] = [...regionTicks];
countriesTicksMap[countryName][covidSchema.stateColumn] = '';
return countriesTicksMap;
}
for (let columnIndex = covidSchema.dateStartColumn; columnIndex < regionTicks.length; columnIndex += 1) {
countriesTicksMap[countryName][columnIndex] += regionTicks[columnIndex];
}
for (let columnIndex = covidSchema.dateStartColumn; columnIndex < regionTicks.length; columnIndex += 1) {
countriesTicksMap[countryName][columnIndex] += regionTicks[columnIndex];
}
return countriesTicksMap;
}, {}));

}, {})
);

//if covid data type is dailymortality average the averages calculated earlier for each region by dividing by num regions just summed
if(covidDataType.key==='dailymortality'){
//map each covidDataByCountries country
covidDataByCountries.ticks[covidDataType.key] = covidDataByCountries.ticks[covidDataType.key].map(countryTicksMap => {
const countryName = countryTicksMap[covidSchema.countryColumn];
//get the number of regions from the Country name and the covidData with regions
const numRegions = covidData.ticks[covidDataType.key].filter(countryData => {return countryData[covidSchema.countryColumn]===countryName}).length
const dailymortalityIndex = countryTicksMap.slice(0,4);
const dailymortalityDataTicks = countryTicksMap.slice(4);
return dailymortalityIndex.concat(dailymortalityDataTicks.map(dayData => {return dayData / numRegions}));
})


}




});
return covidDataByCountries;
}
Expand Down
5 changes: 4 additions & 1 deletion js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,16 @@ function DataType({covidData, selectedRegions, dataType, checked, onTypeChange})
const onChange = () => {
onTypeChange(dataType.key);
};

const totalCountBadge = (dataType.key==="dailymortality")?undefined:e('span', {className: `badge ${badgeClass} ml-2`},totalCount.toLocaleString());

return (
e('label', {className: `alert ${alertClass} mr-3 mb-3`},
e('div', {className: 'form-group form-check mb-0'},
e('input', {type: 'checkbox', className: 'form-check-input', checked, onChange}),
e('div', {className: 'form-check-label'},
dataType.title,
e('span', {className: `badge ${badgeClass} ml-2`}, totalCount.toLocaleString())
totalCountBadge
)
)
)
Expand Down