Published
Edited
Jul 15, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
datepointsRunning(70).slice(158)
Insert cell
ratioData(datepointsRunning(70),'confirmed','hospital',-2).slice(-3)
Insert cell
13680/865
Insert cell
ratioData = function(series, nom, denom, off) {
const offLeft = Math.floor((off+1) / 2);
const offRight = off - offLeft;
//return [offLeft, offRight];
return series
.map((d, indx, arr) => ({
date: d.date,
value: !chkbounds(arr.length, indx, offLeft, offRight)
? null
: [arr[indx + offLeft][nom], arr[indx - offRight][denom]]
}))
.map((d, indx, arr) => ({
date: d.date,
value: d.value ? ratio(d.value[0], d.value[1]) : null
}))
.filter(d => (d.value || d.value===0));
}
Insert cell
function seriesData(series, key) {
return series.map((d, indx, arr) => ({
date: d.date,
value: d[key]
})).filter(d => (+d.value || d.value===0));
};
Insert cell
gauss3date = function(d, indx, arr) {
const krnl = [0.27901,0.44198,0.27901];
const avgval = (indx < 1 || indx > arr.length - 2)
? null
: (krnl[0]*arr[indx-1].value + krnl[1]*arr[indx].value + krnl[2]*arr[indx+1].value);
return ({
date: d.date,
value: (+avgval || avgval === 0) ? avgval : null
});
}
Insert cell
chkbounds(162, 34, 35, 35)
Insert cell
chkbounds = function(len, indx, padLeft, padRight) {
const pad = Math.max(Math.abs(padLeft), Math.abs(padRight));
return indx >= pad && indx < len - pad;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
weights_hospitalization=[
2.8, 1.1, 2.3, 3.7, 4.4, 6.6, 13.8, 27.5, 28.5,
3.5, 1.2, 2.1, 4.0, 7.3, 12.1, 22.6, 38.4, 44.3
].map(a => a/100);
Insert cell
weights_hosp_EPISARI_dec_feb = [
0.032822757, 0.002592353, 0.000666667, 0.000978234, 0.002803829, 0.007854194, 0.02610685, 0.091454633, 0.176411627, 0.184586108,
0.015717092, 0, 0.000469704, 0.002033812, 0.00827601, 0.019358469, 0.060459325, 0.15269257, 0.262322473, 0.314180929
];
Insert cell
stats[250]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
weighted(stats[200],[1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0])
Insert cell
function weighted_sari(s, weights) {
let ret = 0;
agePropNames.slice(0, 10).forEach((p, i) => {
ret += s[p] * weights[i];
});
agePropNames.slice(10).forEach((p, i) => {
ret += s[p] * weights[i];
});
return ret;
}
Insert cell
function weighted(s, weights) {
let ret = 0;
let prev = 0;
agePropNames.slice(0, 10).forEach((p, i) => {
const cur = s[p];
if (i != 0) {
ret += (prev + cur) * 0.5 * weights[i-1];
}
prev = cur;
});
agePropNames.slice(10).forEach((p, i) => {
const cur = s[p];
if (i != 0) {
ret += (prev + cur) * 0.5 * weights[9 + i - 1];
}
prev = cur;
});
return ret;
}
Insert cell
Insert cell
agePropNames.slice(0,10)
Insert cell
datepoints[3]
Insert cell
datepointsOffset = function(startIdx, data = datepoints) {
const ref = data[startIdx];
return data.slice(startIdx).map((a, idx, arr) => {
const ret = {};
for (let key in a) {
ret[key] = a[key] - ref[key];
if (key.includes('active')) {
ret[key] = a[key];
}
}
ret.day = a.day;
ret.date = a.date;
return ret;
}).filter(a => a!=null);
}
Insert cell
Insert cell
function geomavg(arr, startIdx, endIdx) {
let cum = 1;
let cnt = 0;
for (let idx = startIdx; idx <= endIdx; idx++) {
if (arr[idx]) {
cum = cum * arr[idx];
cnt++;
}
}
return Math.pow(cum, 1/cnt);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more