Commit 9f6dc0b0 authored by Michał Woźniak's avatar Michał Woźniak
Browse files

stats per country work now

parent 4d4274ea
Pipeline #75 passed with stage
in 0 seconds
......@@ -352,13 +352,40 @@ document.addEventListener('DOMContentLoaded', (e)=>{
countrySelect.appendChild(cOpt);
}
// handle user interaction
countrySelect.addEventListener('change', (e) => {
var country = event.target.value;
console.log(`+-- fetching data for: ${country}`)
getCountryCases(country)
.then((data)=>{
var ratio = data[data.length-1].cases / data[data.length-2].cases
var cases = data[data.length-1].cases
console.log(` +-- as of: ${data[data.length-1].date}`)
console.log(` +-- cases: ${cases}`)
console.log(` +-- previous day day: ${data[data.length-2].cases}`)
console.log(` +-- ratio: ${ratio}`)
getCountryPopulation(country)
.then((population)=>{
var countryData = document.getElementById("country-data");
countryData.innerHTML = `
<div><span class="label">Population: </span><span class="value">${population}</span></div>
<div><span class="label">Cases: </span><span class="value">${cases}</span></div>
<div><span class="label">Infected as percent of population: </span><span class="value">${Math.round((cases/population)*10000)/100}%</span></div>
<div><span class="label">Day to day infection rate: </span><span class="value">${Math.round((ratio - 1) * 10000) / 100}%</span></div>
<div><span class="label">Cases double every: </span><span class="value">${Math.round(Math.log(2)/Math.log(ratio))} days</span></div>
<div><span class="label">Half of population infected in: </span><span class="value">${Math.log(population*0.5/cases)/Math.log(ratio)} days</span></div>
<div><span class="label">90% of population infected in: </span><span class="value">${Math.log(population*0.90/cases)/Math.log(ratio)} days</span></div>`
})
})
});
// fill out the covid data box
getCovidData()
.then((data)=>{
document.querySelector('#covid-stats > #confirmed > .value').innerHTML = data.confirmed
document.querySelector('#covid-stats > #deaths > .value').innerHTML = data.deaths
document.querySelector('#covid-stats > #recovered > .value').innerHTML = data.recovered
document.querySelector('#covid-stats > #mortality > .value').innerHTML = "~" + Math.round(data.mortality * 10000) / 100
document.querySelector('#covid-stats > #mortality > .value').innerHTML = "~" + Math.round(data.mortality * 10000) / 100 + '%'
})
});
......
......@@ -5,7 +5,7 @@
</head>
<body>
<h1>Scary COVID-19 data</h1>
<p><strong>Disclaimer:</strong> this is all back-of-the-napkin math using data from Wikipedia. Take with a grain (or preferably, a spoonfull) of salt. Check your own sources.</p>
<p><strong>Disclaimer:</strong> this is all back-of-the-napkin math using data from Wikipedia. Take with a grain (or preferably, a spoonfull) of salt. Check your own sources; some great resources: <a href="http://covid.hi.is/">University of Iceland's COVID data model</a> (and its <a href="https://github.com/bgautijonsson/covid19/">sources</a>).</p>
<div id="covid-stats">
<h2>Global stats</h2>
<div id="confirmed"><span class="label">Confirmed cases:</span> <span class="value"></span></div>
......@@ -21,6 +21,7 @@
<option value="select one">(select one)</option>
</select>
</div>
<div id="country-data"><div>
<hr/>
<footer>
<p>License: <a href="./LICENSE">Affero GPL</a>; uses <a href="https://github.com/spencermountain/wtf_wikipedia"><code>wtf_wikipedia</code></a>, licensed under the MIT license. Data from Wikipedia.</p>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment