Public
Edited
Oct 10, 2022
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
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
dataRegiones
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
total25 = _.chain(dataCasosNotificacion)
.reduce((memo, d) => memo + d.casos25, 0)
.value()
Insert cell
total18 = _.chain(dataCasosNotificacion)
.reduce((memo, d) => memo + d.casos18, 0)
.value()
Insert cell
total25 - total18
Insert cell
db
SELECT t25.Fecha as fecha, sum(t25.Casos)::Int as casos25, sum(t18.Casos)::Int as casos18, (sum(t25.Casos) - sum(t18.Casos))::Int as dif
FROM notificacionSintomas20220525 t25
LEFT JOIN notificacionSintomas20220518 t18
ON t25.Fecha = t18.Fecha AND t25.Categoria = t18.Categoria AND t25.Serie = t18.Serie
WHERE t25.Categoria = 'Fecha notificación'
GROUP BY t25.Fecha
ORDER BY t25.Fecha DESC
Insert cell
{
return _.chain(dataNotificadosEPI)
.groupBy((d) => d.serie)
.map((items, serie) => ({
serie: serie,
total28: _.reduce(items, (memo, d) => memo + d.casos28, 0),
total25: _.reduce(items, (memo, d) => memo + d.casos25, 0),
total21: _.reduce(items, (memo, d) => memo + d.casos21, 0),
total18: _.reduce(items, (memo, d) => memo + d.casos18, 0)
}))
.value();
}
Insert cell
{
let accum = 0;
const dataPlot = _.chain(dataNotificadosEPI)
.sortBy((d) => d.fecha)
.slice(-60)
.value();

return Plot.plot({
marks: [
Plot.rectY(dataPlot, {
x: "fecha",
y: "dif28_21",
interval: d3.utcDay,
fill: "grey"
}),
Plot.ruleY([0])
]
});
}
Insert cell
db
SELECT t.Fecha as fecha,
sum(t.Casos)::Int as casos,
sum(t28.Casos)::Int as casos28,
sum(t25.Casos)::Int as casos25,
sum(t21.Casos)::Int as casos21,
sum(t18.Casos)::Int as casos18,
COALESCE((sum(t28.Casos)::Int - sum(t21.Casos)::Int), sum(t28.Casos)::Int) as dif28_21

FROM notificacionSintomas t
LEFT JOIN notificacionSintomas20220528 t28
ON t.Fecha = t28.Fecha AND t.Categoria = t28.Categoria AND t.Serie = t28.Serie
LEFT JOIN notificacionSintomas20220525 t25
ON t.Fecha = t25.Fecha AND t.Categoria = t25.Categoria AND t.Serie = t25.Serie
LEFT JOIN notificacionSintomas20220521 t21
ON t.Fecha = t21.Fecha AND t.Categoria = t21.Categoria AND t.Serie = t21.Serie
LEFT JOIN notificacionSintomas20220518 t18
ON t.Fecha = t18.Fecha AND t.Categoria = t18.Categoria AND t.Serie = t18.Serie
WHERE t.Categoria = 'Fecha notificación' AND (t.Serie = 'confirmada' OR t.Serie = 'no notificada' OR t.Serie = 'probable')
GROUP BY t.Fecha
ORDER BY t.Fecha DESC

Insert cell
Plot.plot({
marks: [
Plot.rectY(
dataChileNotif.slice(-14),
Plot.windowY({
k: 7,
anchor: "end",
reduce: "sum",
x: "fecha",
y: "casos",
interval: d3.utcDay
})
),
Plot.text(
dataChileNotif.slice(-14),
Plot.windowY({
k: 7,
anchor: "end",
reduce: "sum",
x: "fecha",
y: "casos",
interval: d3.utcDay,
textAnchor: "start",
dy: -10
})
),
Plot.ruleY([0])
]
})
Insert cell
db
SELECT Fecha as fecha, sum(Casos)::Int as casos
FROM notificacionSintomas
WHERE Categoria = 'Fecha notificación'
GROUP BY Fecha
ORDER BY Fecha ASC
Insert cell
db.describe("notificacionSintomas")
Insert cell
## Código
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
### Código Vacunación
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
## Parámetros & configuración
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
## Datos
Insert cell
Insert cell
descuadres = {
const dict = {};

const accumSemanal = {};

datosRegionales.forEach((d) => {
const lastWeek = moment(d.Fecha).subtract(1, "week").format("YYYY-MM-DD");
accumSemanal[d.Region] = accumSemanal[d.Region] || 0;
dict[d.Region] = dict[d.Region] || {};
dict[d.Region][d.Fecha] = dict[d.Region][d.Fecha] || {
fecha: d.Fecha,
region: d.Region
};
dict[d.Region][d.Fecha][d.Categoria] = +d.Total;

if (d.Categoria == "Casos nuevos totales") {
accumSemanal[d.Region] +=
+d.Total -
(dict[d.Region][lastWeek]
? +dict[d.Region][lastWeek]["Casos nuevos totales"]
: 0);
dict[d.Region][d.Fecha]["acumulado_semanal"] = accumSemanal[d.Region];
}

if (d.Categoria == "Casos acumulados") {
dict[d.Region][d.Fecha]["diferencia_semanal"] =
+d["Total"] -
(dict[d.Region][lastWeek]
? +dict[d.Region][lastWeek]["Casos acumulados"]
: 0);
}
});

return dict;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
_.chain(dataChile)
.filter((d) => d.localidad == "Chile")
.last()
.value()
Insert cell
_.chain(dataChile_)
.filter((d) => d.localidad == "Chile")
.last()
.value()
Insert cell
Insert cell
manuallyUpdatedRecords = manuallyUpdatedRecordOneDayRegions.map((d) =>
processManuallyUpdatedRecord(d)
)
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
dataNotificacionInicioSintomas = d3.csv(
"https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/master/output/producto39/NotificacionInicioSintomas_std.csv"
)
Insert cell
dataNotificacionesSintomas20220528 = d3.csv(
"https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/4fe3666828868f233bd84c29c6e89fc4a177d188/output/producto39/NotificacionInicioSintomas_std.csv"
)
Insert cell
dataNotificacionesSintomas20220521 = d3.csv(
"https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/31c1f5912c9a67f89d8c3e4bd4c1bf99ad5e02c1/output/producto39/NotificacionInicioSintomas_std.csv"
)
Insert cell
dataNotificacionesSintomas20220518 = d3.csv(
"https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/425deb72dcfbb8cbef248ae5dc3017f59df97079/output/producto39/NotificacionInicioSintomas_std.csv"
)
Insert cell
dataNotificacionesSintomas20220525 = d3.csv(
"https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/c013cc6aadc8230e3176ebdcd11bff5d510b0fcc/output/producto39/NotificacionInicioSintomas_std.csv"
)
Insert cell
db.describe()
Insert cell
db = {
const db = new dbClient.DuckDBClient();
await insertCSVTable(
db,
dataNotificacionInicioSintomas,
"notificacionSintomas"
);

await insertCSVTable(
db,
dataNotificacionesSintomas20220528,
"notificacionSintomas20220528"
);
await insertCSVTable(
db,
dataNotificacionesSintomas20220525,
"notificacionSintomas20220525"
);

await insertCSVTable(
db,
dataNotificacionesSintomas20220521,
"notificacionSintomas20220521"
);

await insertCSVTable(
db,
dataNotificacionesSintomas20220518,
"notificacionSintomas20220518"
);

return db;
}
Insert cell
import { dbClient, insertCSVTable } from "@elaval/utils"
Insert cell
html`
<style>


svg.vaccines .header {
font-family:sans-serif;
font-size:24px;
fill: #333;
}


svg.vaccines.combinada .header .total {
font-size:20px;
fill: black;
}

svg.vaccines circle {
fill: #bdbdbd
}

svg.vaccines.combinada circle.dosis1_mas_unica {
fill: #FF7F0E;
}

svg.vaccines.combinada circle.completa {
fill: #2171b5;
}

svg.vaccines.combinada circle.refuerzo {
fill: #2CA02C;
}

svg.vaccines.combinada circle.cuarta {
fill: #013220;
}

svg.vaccines.combinada .groupInfo text {
font-family:sans-serif;
font-size:18px;
font-weight: bold;
}

svg.vaccines.combinada .groupInfo text.total {
fill: grey;
}

svg.vaccines.combinada .groupInfo text.dosis1.line1,text.dosis1.line2 {
fill: #FF7F0E;
}

svg.vaccines.combinada .groupInfo text.completa {
fill: #2171b5;
}


svg.vaccines.combinada .groupInfo text.refuerzo {
fill: #2CA02C;
}

svg.vaccines.combinada .groupInfo text.cuarta {
fill: #013220;
}

svg.vaccines.combinada .groupInfo text.nocompleto {
fill: grey;
}






</style>`
Insert cell
Insert cell
style_fontawesome
Insert cell
md`## Librerías externas`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
_ = require("lodash")
Insert cell
d3 = require("d3")
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