Skip to content

Commit

Permalink
2020-03-24-18-04 dev to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-armour committed Mar 25, 2020
1 parent 0b0f713 commit 6359e3d
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 370 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions stable/covid-19-viz-3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name=description
content="View the COVID-19 data from John Hopkins University GitHub repository in interactive 3D">
<meta name=keywords content="Three.js,WebGL,JavaScript,GitHub,FOSS,3D,STEM">
<meta name=version content="2020-03-24-15-33">
<meta name=version content="2020-03-24-18-04">

<title>COVID-19 Viz3D</title>

Expand Down Expand Up @@ -76,6 +76,8 @@ <h2>
<button id=butRecoveries onclick=toggleBars(groupDeathsNew) style=background-color:lavender;width:100%; >
New deaths today&nbsp;</button></p>

<div id=divDates style=background-color:white;padding:1ch;></div>

<div id=divStats style=background-color:white;padding:1ch;></div>

<div id=divSettings style=background-color:white;padding:1ch; ></div>
Expand All @@ -97,7 +99,7 @@ <h2>

<button onclick=controls.reset(); class=ftrButton title="reset the view" >&CirclePlus;</button>
&nbsp;
<button onclick=THR.onStop() title="stop the rotation"
<button onclick=THR.controls.autoRotate=!THR.controls.autoRatate title="stop the rotation"
class=ftrButton "Stop all rotation" >&circlearrowright;</button>
&nbsp;
<button onclick=groupPlacards.visible=!groupPlacards.visible title="toggle placards" class=ftrButton >&sdotb;</button>
Expand Down
131 changes: 59 additions & 72 deletions stable/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -89,7 +92,6 @@ function init () {




function requestFile ( url, callback ) {

const xhr = new XMLHttpRequest();
Expand Down Expand Up @@ -124,26 +126,37 @@ function onLoadCases ( xhr ) {

resetGroups();

divStats.innerHTML = `<select id=selDate onchange=updateBars(this.selectedIndex); size=10 style=width:100%; ></select>`;
divDates.innerHTML = `<select id=selDate onchange=updateBars(this.selectedIndex); size=10 style=width:100%; ></select>`;

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 => `<option>${ date }</option>` );

selDate.selectedIndex = dates.length - 1;

}



function onLoadDeaths ( xhr ) {

linesDeaths = xhr.target.response.split( "\n" ).map( line => line.split( "," ) )
//console.log( 'linesDeaths', linesDeaths );

updateBars( linesDeaths[ 0 ].length - 1 );

getStats();

}


Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -363,50 +351,50 @@ function getStats () {

divStats.innerHTML = `<details id=detStats>
<summary><b>global data ${ today.slice( 0, -4 ) }</b></summary>
<summary><b>global data </b></summary>
<p>
<b>global totals </b><br>
cases: ${ globalCases.toLocaleString() }<br>
cases today: ${ globalCasesNew.toLocaleString() }<br>
cases new: ${ globalCasesNew.toLocaleString() }<br>
deaths: ${ globalDeaths.toLocaleString() }<br>
recoveries: ${ globalRecoveries.toLocaleString() }<br>
deaths new: ${ globalDeathsNew.toLocaleString() }<br>
deaths/cases: ${ globalDeathsToCases.toLocaleString() }%<br>
</p>
<p>
<b>China totals</b><br>
cases: ${ chinaCases.toLocaleString() }<br>
cases today: ${ chinaCasesNew.toLocaleString() }<br>
cases new: ${ chinaCasesNew.toLocaleString() }<br>
deaths: ${ chinaDeaths.toLocaleString() }<br>
recoveries: ${ chinaRecoveries.toLocaleString() }<br>
deaths new: ${ chinaDeathsNew.toLocaleString() }<br>
deaths/cases: ${ chinaDeathsToCases.toLocaleString() }%<br>
</p>
<p>
<b>Europe totals</b><br>
<b>Europe totals</b><br>
cases: ${ europeCases.toLocaleString() }<br>
cases today: ${ europeCasesNew.toLocaleString() }<br>
deaths: ${ chinaDeaths.toLocaleString() }<br>
recoveries: ${ europeRecoveries.toLocaleString() }<br>
cases new: ${ europeCasesNew.toLocaleString() }<br>
deaths: ${ europeDeaths.toLocaleString() }<br>
deaths new: ${ europeDeathsNew.toLocaleString() }<br>
deaths/cases: ${ europeDeathsToCases.toLocaleString() }%<br>
</p>
<p>
<b>USA totals</b><br>
cases: ${ usaCases.toLocaleString() }<br>
cases today: ${ usaCasesNew.toLocaleString() }<br>
cases new: ${ usaCasesNew.toLocaleString() }<br>
deaths: ${ usaDeaths.toLocaleString() }<br>
recoveries: ${ usaRecoveries.toLocaleString() }<br>
deaths new: ${ usaDeathsNew.toLocaleString() }<br>
deaths/cases: ${ usaDeathsToCases.toLocaleString() }%<br>
</p>
<p>
<p>
<b>rest of world totals</b><br>
cases: ${ rowCases.toLocaleString() }<br>
cases today: ${ rowCasesNew.toLocaleString() }<br>
deaths: ${ rowDeaths.toLocaleString() }<br>
recoveries: ${ rowRecoveries.toLocaleString() }<br>
deaths new: ${ rowDeathsNew.toLocaleString() }<br>
deaths/cases: ${ rowDeathsToCases.toLocaleString() }%<br>
</p>
Expand Down Expand Up @@ -484,7 +472,6 @@ function toggleBars ( group = groupCases ) {
groupCasesNew.visible = false;
groupDeaths.visible = false;
groupDeathsNew.visible = false;

group.visible = true;

}
Expand Down Expand Up @@ -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 ];

Expand Down
8 changes: 5 additions & 3 deletions stable/js/ncd-new-cases-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 `<p><mark>${ NCD.json.message }</mark></p><p>Try again later</p>`;

}
//console.log( 'c/p', country, place );

Expand Down Expand Up @@ -170,5 +174,3 @@ NCD.drawChart = function ( arr ) {
};



NCD.init();
Loading

0 comments on commit 6359e3d

Please sign in to comment.