Data talk:2019–20 coronavirus outbreak.tab

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Credits and notes[edit]

The first version of this dataset was derived from en:Template:2019–20 coronavirus outbreak data. The credits for collecting and organizing the data can be found in history page of the relevant page in enwiki. To simplify the dataset I omitted sources - most of the data is based on Coronavirus COVID-19 Global Cases by Johns Hopkins CSSE. gisanddata.maps.arcgis.com. Retrieved on 3 March 2020.. Eran (talk) 21:37, 6 March 2020 (UTC)[reply]

How to update the table[edit]

To update the table based on Data Repository by Johns Hopkins CSSE you can

  1. Open developer console (F12 in most browsers)
  2. run the following code
  3. copy from console the data

Use show changes to review before save to verify the change looks correct.

var casesQuery = $.get('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'),
deathsQuery = $.get('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv'),
recoveriesQuery = $.get('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv');

function updateTeritories(dataCountryKey, d, curCol)
{
	var d = d.replace(/"([^"]+),([^"]+)"/g, '"$1 $2"').split('\n');
	var data=[]; for(var i in d) { data.push(d[i].split(',')) }
	var latestCol = data[0].length-1;
	for(var i=1;i<data.length;i++) {
		if ((!data[i][1]) || (data[i][latestCol]=='')) continue;
		if (!dataCountryKey[data[i][1]]) dataCountryKey[data[i][1]] = [data[i][1], 0,0,0];
		if(isNaN(data[i][latestCol])) {
			console.error('Cant parse for country ' + data[i][1] + ' col '+curCol+'. Value: ' + data[i][latestCol]);
		}
		dataCountryKey[data[i][1]][curCol] += parseInt(data[i][latestCol]);
	}
}

$.when(casesQuery, deathsQuery, recoveriesQuery).done(function(cases,  deaths, recoveries){
	var dataCountryKey={};
	updateTeritories(dataCountryKey, cases[0] , 1);
	updateTeritories(dataCountryKey, deaths[0] , 2);
	updateTeritories(dataCountryKey, recoveries[0] , 3);

	var dataTable = []; for(var k in dataCountryKey) dataTable.push(dataCountryKey[k]);
        dataTable.sort(function(a,b) { return a[1]!=b[1] ? b[1]-a[1] : b[0]-a[0];});

	//for(var i=0;i<dataTable.length;i++) res+=JSON.stringify(dataTable[i]) +',\n';
	var res=JSON.stringify(dataTable, '    ', ' ');
	console.log(res)
});

Eran (talk) 09:31, 7 March 2020 (UTC)[reply]