Commit 8b4c86cc authored by Michał Woźniak's avatar Michał Woźniak
Browse files

infection rate change is now calculated using a sliding average over 3 days

parent 1d3301fb
Pipeline #208 passed with stage
in 4 seconds
......@@ -700,7 +700,7 @@ let calculateDeltas = (data) => {
cur.active = cur.confirmed - removed
cur.new_active = cur.active - d[i-1].active
// case fatality ratio
// case fatality rate
if (removed > 0) {
cur.cfr = cur.deaths / removed
cur.new_cfr = cur.cfr - d[i-1].cfr
......@@ -979,6 +979,22 @@ let genArr = (start, length, step) => {
}
/*
* calculating the rate of infection on a site
* averaging over all available datapoints
*
* getting data averaged over the last 5 datapoints is as simple as
* calculateAverageRate(data.slice(-5))
*/
let calculateAverageRate = (data) => {
var a = data.reduce((acc, el, i, d)=>{
if (i==0) return acc;
acc += el / d[i-1];
return acc
}, 0)
return a / (data.length - 1)
}
/*
* handling a .sites-select change
*/
......@@ -1016,7 +1032,7 @@ let selectSite = (e) => {
.then((wikiData)=>{
var data = wikiData.data
if (! ("ratio" in data[data.length-1]) ) {
data[data.length-1].ratio = data[data.length-1].confirmed / data[data.length-2].confirmed
data[data.length-1].ratio = calculateAverageRate(data.slice(-4).map(d=>d.confirmed))
}
var confirmed = data[data.length-1].confirmed
console.log(`+-- covid data for: ${site}`
......@@ -1755,10 +1771,10 @@ document.addEventListener('DOMContentLoaded', (e)=>{
var bdata = siteData[b].data
// get the ratios (unless already there)
if (! ("ratio" in adata[adata.length-1]) ) {
adata[adata.length-1].ratio = adata[adata.length - 1].confirmed / adata[adata.length - 2].confirmed
adata[adata.length-1].ratio = calculateAverageRate(adata.slice(-4).map(d=>d.confirmed))
}
if (! ("ratio" in bdata[bdata.length-1]) ) {
bdata[bdata.length-1].ratio = bdata[bdata.length - 1].confirmed / bdata[bdata.length - 2].confirmed
bdata[bdata.length-1].ratio = calculateAverageRate(bdata.slice(-4).map(d=>d.confirmed))
}
// return ratio comparison
return bdata[bdata.length-1].ratio - adata[adata.length-1].ratio;
......
Markdown is supported
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