diff --git a/README.md b/README.md index 903fa3d..a3c75d2 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,10 @@ Data sources * https://nssac.bii.virginia.edu/covid-19/dashboard/ * http://globalcovid19.live/index.php/148-2/ +Compare sources + +* https://ourworldindata.org/covid-sources-comparison + Dependencies diff --git a/stable/covid-19-viz-3d.html b/stable/covid-19-viz-3d.html index 868dd90..77bf79b 100644 --- a/stable/covid-19-viz-3d.html +++ b/stable/covid-19-viz-3d.html @@ -7,7 +7,7 @@ - + COVID-19 Viz3D @@ -76,6 +76,8 @@

+
+
@@ -97,7 +99,7 @@

  -   diff --git a/stable/js/main.js b/stable/js/main.js index 4d631ca..e3febd1 100644 --- a/stable/js/main.js +++ b/stable/js/main.js @@ -81,6 +81,9 @@ function init () { getNotes(); + + NCD.init(); + //document.addEventListener( 'mousemove', onDocumentMouseMove, false ); renderer.domElement.addEventListener( 'mousedown', onDocumentMouseMove, false ); renderer.domElement.addEventListener( 'touchstart', onDocumentTouchStart, false ); @@ -89,7 +92,6 @@ function init () { - function requestFile ( url, callback ) { const xhr = new XMLHttpRequest(); @@ -124,19 +126,28 @@ function onLoadCases ( xhr ) { resetGroups(); - divStats.innerHTML = ``; + divDates.innerHTML = ``; + + response = xhr.target.response + + response = response.replace( /"Korea, South"/, "South Korea" ) + // .replace( /"Gambia, The"/, "The Gambia" ) + // .replace( /"Bahamas, The"/, "The Bahamas" ); + // .replace( /"Virgin Islands,/, "Virgin Islands"); - linesCases = xhr.target.response.split( "\n" ).map( line => line.split( "," ) ) + linesCases = response.split( "\n" ).map( line => line.split( "," ) ); //console.log( 'lines', lines ); const dates = linesCases[ 0 ].slice( 4 ); selDate.innerHTML = dates.map( date => `` ); + selDate.selectedIndex = dates.length - 1; } + function onLoadDeaths ( xhr ) { linesDeaths = xhr.target.response.split( "\n" ).map( line => line.split( "," ) ) @@ -144,6 +155,8 @@ function onLoadDeaths ( xhr ) { updateBars( linesDeaths[ 0 ].length - 1 ); + getStats(); + } @@ -238,79 +251,54 @@ function getStats () { const europe = [ "Albania", "Andorra", "Armenia", "Austria", "Azerbaijan", "Belarus", "Belgium", "Bosnia and Herzegovina", "Bulgaria", "Croatia", "Cyprus", "Czechia", "Denmark", "EstoniaF", "Finland", "France", "Georgia", "Germany", "Greece", "Hungary", "Iceland", "Ireland", "Italy", "Kazakhstan", "Kosovo", "Latvia", "Liechtenstein", "Lithuania", "Luxembourg", "Malta", "Moldova", "Monaco", "Montenegro", "Netherlands", "North Macedonia", "Norway", "Poland", "Portugal", "Romania", "Russia", "San Marino", "Serbia", "Slovakia", "Slovenia", "Spain", "Sweden", "Switzerland", "Turkey", "Ukraine", "United Kingdom", "Holy See" ]; - const globalCases = lines.reduce( ( sum, line ) => { - let cases = Number( line[ 7 ] ); - //cases = isNaN( cases ) ? 0 : cases; + const index = 4 + selDate.selectedIndex + + const globalCases = linesCases.slice( 1 ).reduce( ( sum, line ) => { + let cases = Number( line[ index] ); return sum + cases; }, 0 ); + //console.log( 'globalCases', globalCases ); - const globalCasesNew = 999999; // lines.reduce( ( sum, line ) => { - // let caseNew = Number( line[ 8 ] ); - // caseNew = isNaN( caseNew ) ? 0 : caseNew; - // return sum + caseNew; - // }, 0 ); - console.log( 'globalCasesNew', globalCasesNew ); - - // const lat = Number( line[ 5 ] ) - // //const lat = isNaN( l5 ) ? 0 : l5; - - // const lon= Number( line[ 6 ] ) - // //const lon = isNaN( l6 ) ? 0 : l6; - - // const cases = Number( line[ 7 ] ); - // //cases = isNaN( l7 ) ? 0 : l7; - - // const deaths = Number( line[ 8 ] ); - // //const deaths = isNaN( l8 ) ? 0 : l8; - - // const recoveries = Number( line[ 9 ] ); - // //const recoveries = isNaN( l9 ) ? 0 : l9; - - // const active = Number( line[ 10 ] ); - - const globalDeaths = lines.reduce( ( sum, line ) => sum + Number( line[ 8 ] ), 0 ); - const globalRecoveries = lines.reduce( ( sum, line ) => sum + Number( line[ 9 ] ), 0 ); + const globalCasesNew = linesCases.slice( 1 ).reduce( ( sum, line ) => sum + ( line[ index ] - line[ index - 1 ] ), 0 ); + //console.log( 'globalCasesNew', globalCasesNew ); + const globalDeaths = linesDeaths.slice( 1 ).reduce( ( sum, line ) => sum + Number( line[ index ] ), 0 ); + const globalDeathsNew = linesDeaths.slice( 1 ).reduce( ( sum, line ) => sum + ( line[ index ] - line[ index - 1 ] ), 0 ); const globalDeathsToCases = 100 * ( globalDeaths / globalCases ); - const chinaDeaths = lines.reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? Number( line[ 8 ] ) : 0, 0 ); - const chinaCasesNew = 0; //lines.reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? line[ 8 ] : 0, 0 ); - const chinaCases = lines.reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? Number( line[ 7 ] ) : 0, 0 ); - const chinaRecoveries = lines.reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? Number( line[ 9 ] ) : 0, 0 ); + const chinaCases = linesCases.slice( 1 ).reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? Number( line[ index ] ) : 0, 0 ); + const chinaCasesNew = linesCases.slice( 1 ).reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? line[ index ] - line[ index - 1]: 0, 0 ); + const chinaDeaths = linesDeaths.slice( 1 ).reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? Number( line[ index ] ) : 0, 0 ); + const chinaDeathsNew = linesDeaths.slice( 1 ).reduce( ( sum, line ) => sum += line[ 1 ] === "China" ? line[ index ] - line[ index - 1] : 0, 0 ); const chinaDeathsToCases = 100 * chinaDeaths / chinaCases; - const europeDeaths = lines.reduce( ( sum, line ) => sum += europe.includes( line[ 3 ] ) ? - Number( line[ 8 ] ) : 0, 0 ); - const europeCasesNew = 0; //lines.reduce( ( sum, line ) => sum += europe.includes( line[ 3 ] ) ? line[ 8 ] : 0, 0 ); - const europeCases = lines.reduce( ( sum, line ) => sum += europe.includes( line[ 3 ] ) ? Number( line[ 7 ] ) : 0, 0 ); - const europeRecoveries = lines.reduce( ( sum, line ) => sum += europe.includes( line[ 3 ] ) ? Number( line[ 9 ] ) : 0, 0 ); + const europeCases = linesCases.reduce( ( sum, line ) => sum += europe.includes( line[ 1 ] ) ? Number( line[ index ] ) : 0, 0 ); + const europeCasesNew = linesCases.reduce( ( sum, line ) => sum += europe.includes( line[ 1 ] ) ? line[ index ] - line[ index - 1] : 0, 0 ); + const europeDeaths = linesDeaths.reduce( ( sum, line ) => sum += europe.includes( line[ 1 ] ) ? Number( line[ index ] ) : 0, 0 ); + const europeDeathsNew = linesDeaths.reduce( ( sum, line ) => sum += europe.includes( line[ 1 ] ) ? ( line[ index ] - line[ index - 1] ) : 0, 0 ); const europeDeathsToCases = 100 * europeDeaths / europeCases; - const usaCases = lines.reduce( ( sum, line ) => sum += line[ 3 ] === "US" ? Number( line[ 7 ] ) : 0, 0 ); - const usaCasesNew = 0; //lines.reduce( ( sum, line ) => sum += line[ 3 ] === "US" ? line[ 8 ] : 0, 0 ); - const usaDeaths = lines.reduce( ( sum, line ) => sum += line[ 3 ] === "US" ? Number( line[ 8 ] ) : 0, 0 ); - const usaRecoveries = lines.reduce( ( sum, line ) => sum += line[ 3 ] === "US" ? Number( line[ 9 ] ) : 0, 0 ); + const usaCases = linesCases.reduce( ( sum, line ) => sum += line[ 1 ] === "US" ? Number( line[ index ] ) : 0, 0 ); + const usaCasesNew = linesCases.reduce( ( sum, line ) => sum += line[ 1 ] === "US" ? line[ index ] - line[ index - 1] : 0, 0 ); + const usaDeaths = linesDeaths.reduce( ( sum, line ) => sum += line[ 1 ] === "US" ? Number( line[ index ] ) : 0, 0 ); + const usaDeathsNew = linesDeaths.reduce( ( sum, line ) => sum += line[ 1 ] === "US" ? ( line[ index ] - line[ index - 1 ] ) : 0, 0 ); const usaDeathsToCases = 100 * ( usaDeaths / usaCases ); const rowCases = globalCases - chinaCases - europeCases - usaCases; const rowCasesNew = globalCasesNew - chinaCasesNew - europeCasesNew - usaCasesNew; const rowDeaths = globalDeaths - chinaDeaths - europeDeaths - usaDeaths; - const rowRecoveries = globalRecoveries - chinaRecoveries - europeRecoveries - usaRecoveries; + const rowDeathsNew = globalDeathsNew - chinaDeathsNew - europeDeathsNew - usaDeathsNew; const rowDeathsToCases = 100 * ( rowDeaths / rowCases ); - // butNew.innerHTML += globalCasesNew.toLocaleString(); - // butCases.innerHTML += globalCases.toLocaleString(); - // butDeaths.innerHTML += globalDeaths.toLocaleString(); - // butRecoveries.innerHTML += globalRecoveries.toLocaleString(); // [text], scale, color, x, y, z ) - groupPlacards.add( THR.drawPlacard( "Null Island", "0.01", 1, 60, 0, 0 ) ); + groupPlacards.add( THR.drawPlacard( "Null Island", "0.01", 1, 80, 0, 0 ) ); const totalsGlobal = [ `Global`, `cases: ${ globalCases.toLocaleString() }`, - `cases today: ${ globalCasesNew.toLocaleString() }`, + `cases new: ${ globalCasesNew.toLocaleString() }`, `deaths: ${ globalDeaths.toLocaleString() }`, - `recoveries: ${ globalRecoveries.toLocaleString() }`, + `deaths new: ${ globalDeathsNew.toLocaleString() }`, `deaths/cases: ${ globalDeathsToCases.toLocaleString() }%` ]; vGlo = latLonToXYZ( 75, 65, -20 ); @@ -321,7 +309,7 @@ function getStats () { `cases: ${ chinaCases.toLocaleString() }`, `cases today: ${ chinaCasesNew.toLocaleString() }`, `deaths: ${ chinaDeaths.toLocaleString() }`, - `recoveries: ${ chinaRecoveries.toLocaleString() }`, + `deaths new: ${ chinaDeathsNew.toLocaleString() }`, `deaths/cases: ${ chinaDeathsToCases.toLocaleString() }%` ]; vChi = latLonToXYZ( 85, 50, 110 ); @@ -332,7 +320,7 @@ function getStats () { `cases: ${ europeCases.toLocaleString() }`, `cases today: ${ europeCasesNew.toLocaleString() }`, `deaths: ${ europeDeaths.toLocaleString() }`, - `recoveries: ${ europeRecoveries.toLocaleString() }`, + `deaths new: ${ europeDeathsNew.toLocaleString() }`, `deaths/cases: ${ europeDeathsToCases.toLocaleString() }%` ]; const vEur = latLonToXYZ( 80, 60, 20 ); @@ -343,7 +331,7 @@ function getStats () { `cases: ${ usaCases.toLocaleString() }`, `cases today: ${ usaCasesNew.toLocaleString() }`, `deaths: ${ usaDeaths.toLocaleString() }`, - `recoveries: ${ usaRecoveries.toLocaleString() }`, + `deaths new: ${ usaDeathsNew.toLocaleString() }`, `deaths/cases: ${ usaDeathsToCases.toLocaleString() }%` ]; const vUsa = latLonToXYZ( 80, 40, -120 ); @@ -354,7 +342,7 @@ function getStats () { `cases: ${ rowCases.toLocaleString() }`, `cases today: ${ rowCasesNew.toLocaleString() }`, `deaths: ${ rowDeaths.toLocaleString() }`, - `recoveries: ${ rowRecoveries.toLocaleString() }`, + `deaths new: ${ rowDeathsNew.toLocaleString() }`, `deaths/cases: ${ rowDeathsToCases.toLocaleString() }%` ]; const vRow = latLonToXYZ( 90, 30, 180 ); @@ -363,50 +351,50 @@ function getStats () { divStats.innerHTML = `
- global data ${ today.slice( 0, -4 ) } + global data

global totals
cases: ${ globalCases.toLocaleString() }
- cases today: ${ globalCasesNew.toLocaleString() }
+ cases new: ${ globalCasesNew.toLocaleString() }
deaths: ${ globalDeaths.toLocaleString() }
- recoveries: ${ globalRecoveries.toLocaleString() }
+ deaths new: ${ globalDeathsNew.toLocaleString() }
deaths/cases: ${ globalDeathsToCases.toLocaleString() }%

China totals
cases: ${ chinaCases.toLocaleString() }
- cases today: ${ chinaCasesNew.toLocaleString() }
+ cases new: ${ chinaCasesNew.toLocaleString() }
deaths: ${ chinaDeaths.toLocaleString() }
- recoveries: ${ chinaRecoveries.toLocaleString() }
+ deaths new: ${ chinaDeathsNew.toLocaleString() }
deaths/cases: ${ chinaDeathsToCases.toLocaleString() }%

- Europe totals
+ Europe totals
cases: ${ europeCases.toLocaleString() }
- cases today: ${ europeCasesNew.toLocaleString() }
- deaths: ${ chinaDeaths.toLocaleString() }
- recoveries: ${ europeRecoveries.toLocaleString() }
+ cases new: ${ europeCasesNew.toLocaleString() }
+ deaths: ${ europeDeaths.toLocaleString() }
+ deaths new: ${ europeDeathsNew.toLocaleString() }
deaths/cases: ${ europeDeathsToCases.toLocaleString() }%

USA totals
cases: ${ usaCases.toLocaleString() }
- cases today: ${ usaCasesNew.toLocaleString() }
+ cases new: ${ usaCasesNew.toLocaleString() }
deaths: ${ usaDeaths.toLocaleString() }
- recoveries: ${ usaRecoveries.toLocaleString() }
+ deaths new: ${ usaDeathsNew.toLocaleString() }
deaths/cases: ${ usaDeathsToCases.toLocaleString() }%

-

+

rest of world totals
cases: ${ rowCases.toLocaleString() }
cases today: ${ rowCasesNew.toLocaleString() }
deaths: ${ rowDeaths.toLocaleString() }
- recoveries: ${ rowRecoveries.toLocaleString() }
+ deaths new: ${ rowDeathsNew.toLocaleString() }
deaths/cases: ${ rowDeathsToCases.toLocaleString() }%

@@ -484,7 +472,6 @@ function toggleBars ( group = groupCases ) { groupCasesNew.visible = false; groupDeaths.visible = false; groupDeathsNew.visible = false; - group.visible = true; } @@ -533,7 +520,7 @@ function onDocumentMouseMove ( event ) { const lineDeaths = linesDeaths[ index ]; - dateIndex = selDate.selectedIndex > -1 ? selDate.selectedIndex : line.length - 1 ; + const dateIndex = selDate.selectedIndex > -1 ? 4 + selDate.selectedIndex : line.length - 1 ; const country = line[ 1 ]; diff --git a/stable/js/ncd-new-cases-date.js b/stable/js/ncd-new-cases-date.js index 3835101..08324e8 100644 --- a/stable/js/ncd-new-cases-date.js +++ b/stable/js/ncd-new-cases-date.js @@ -40,7 +40,7 @@ NCD.requestFile = function ( url, callback ) { const xhr = new XMLHttpRequest(); xhr.open( 'GET', url, true ); xhr.onerror = ( xhr ) => console.log( 'error:', xhr ); - //xhr.onprogress = ( xhr ) => NCDdivChartMmg.innerHTML = 'bytes loaded:' + xhr.loaded; + //xhr.onprogress = ( xhr ) => console.log( 'bytes loaded', xhr.loaded, xhr.target.status ); xhr.onload = callback; xhr.send( null ); @@ -102,6 +102,10 @@ NCD.getDates = function ( country = "France", place = "France" ) { return "It may take a while to load all the data. Keep trying every ten seconds or so."; + } else if ( NCD.json.message ) { + + return `

${ NCD.json.message }

Try again later

`; + } //console.log( 'c/p', country, place ); @@ -170,5 +174,3 @@ NCD.drawChart = function ( arr ) { }; - -NCD.init(); \ No newline at end of file diff --git a/stable/tmp/covid-19-viz-3d.html b/stable/tmp/covid-19-viz-3d.html index 12c6796..868dd90 100644 --- a/stable/tmp/covid-19-viz-3d.html +++ b/stable/tmp/covid-19-viz-3d.html @@ -7,7 +7,7 @@ - + COVID-19 Viz3D @@ -61,22 +61,22 @@

- + -
+
@@ -86,15 +86,11 @@

- 18:51 PST ~ JHU file format has changed. Working on fixes!! + New database format. JHU made a silly update. Fixes are in progress Touch the screen to stop rotation
Click or touch a country "stick" to pop-up statistics
Two fingers or mousewheel to zoom
- New today
- Mouse over no longer works
- pop-ups show province or state data
- pop-up bars show new cases and dates as tooltips
@@ -109,18 +105,18 @@

- + + +