Commit 18110a4f authored by Michał Woźniak's avatar Michał Woźniak
Browse files

calculating the deltas

parent af40f437
Pipeline #142 passed with stage
in 1 second
......@@ -633,6 +633,27 @@ let getCovidData = () => {
}
/*
* calculate the deltas for a COVID data series
*/
let calculateDeltas = (data) => {
// perhaps we have that data already?
if ("delta" in data.data[0]) {
return data;
}
// calculate the deltas
data.data = data.data.map((cur, i, d)=>{
if (i==0) {
cur.delta = 0;
} else {
cur.delta = cur.confirmed - d[i-1].confirmed
}
return cur;
})
return data;
}
/*
* get (and clean up) the cases data for a given Wikipedia-recognized outbreak site
*
......@@ -647,7 +668,7 @@ let getSiteCases = (site) => {
if ( ( site in siteData )
&& ( 'data' in siteData[site] ) ) {
console.log(`+-- using cached covid data for ${site}`)
return Promise.resolve(siteData[site]);
return Promise.resolve(siteData[site]).then((data)=>{ return calculateDeltas(data) });
}
// snowflake templates are snowflake
......@@ -802,19 +823,9 @@ let getSiteCases = (site) => {
gaps_filled = data
}
// calculate the deltas
with_deltas = gaps_filled.map((cur, i, d)=>{
if (i==0) {
cur.delta = 0;
} else {
cur.delta = cur.confirmed - d[i-1].confirmed
}
return cur;
})
// we have everything
site_data = {
data: with_deltas,
data: gaps_filled,
source_link: `https://en.wikipedia.org/?curid=${tdata.pageID}`,
source_title: tdata.title
}
......@@ -827,6 +838,8 @@ let getSiteCases = (site) => {
// return it
return site_data
})
// calculate the deltas
.then((data)=>{ return calculateDeltas(data) });
}
......
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