Published
Edited
Sep 28, 2022
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof byMun = dt
.groupby("ciudad_municipio")
.count()
.view()
Insert cell
mapByMun = new Map(byMun.objects().map(d => ["" + d.ciudad_municipio, d.count]))
Insert cell
// update(new Map(filtered.map))
Insert cell
filteredData[0]
Insert cell
// vl.markPoint()
// .data(fechasPromedioPorDia)
// .encode(vl.y().fieldN("departamento"))
Insert cell
data = getData()
Insert cell
dateParse = d3.timeParse("%d/%m/%Y %H:%M:%S")
Insert cell
async function* getData() {
console.log("get Data");
yield(await FileAttachment("fullDataOct31_2020_head.csv").csv()).map(
d3.autoType
);

console.log("returning cached");

// Disabling live data
// // 900k + a 20k cases per day since Oct 31
// const start_offset =
// 950000 + Math.floor((+new Date() - +new Date(2020, 9, 31)) / 24 / 360);

// const before = new Date();
// const gen = loadSocrata(
// "https://www.datos.gov.co/resource/gt2j-8ykr.csv",
// // "https://www.datos.gov.co/resource/gt2j-8ykr.csv?$ORDER=fecha_reporte_web DESC",
// {
// // max_pages: 2,
// progressive: false,
// start_offset
// }
// );

// const data = (await gen.next()).value.map(d => {
// d = d3.autoType(d);
// columnFechas.forEach(f => {
// if (d[f]) d[f] = dateParse(d[f]);
// });
// return d;
// });
// console.log("got data, time= ", (new Date() - before) / 1000);
// yield data;
// // yield new Promise((resolve, reject) => {
// // resolve(recentData);
// // });

console.log("returning bigger one");
}
Insert cell
viewof columnFechasSelected = checkbox({
options: columnFechas,
value: columnFechas,
title: "Fechas Visualizadas"
})
Insert cell
columnFechas = [
"fecha_inicio_sintomas",
"fecha_muerte",
"fecha_reporte_web",
"fecha_recuperado",
"fecha_de_notificaci_n",
"fecha_diagnostico"
]
Insert cell
deriveFechas = Object.fromEntries(
columnFechasSelected.map(f => [
`${f}_rel`,
`d => d["${f}"] ? ( d["${referenceDate}"] - d["${f}"])/86400000 : null` // in days
])
)
Insert cell
Insert cell
viewof dt = aq
.from(filteredData)
.view({ limit: 25 })
Insert cell
{
const points = vl
.markPoint({ size: 2, tooltip: true, dx: 50 })
.encode(vl.color().fieldN("key"), vl.detail().fieldT(referenceDate));

return vl
.layer(points)
.encode(
vl
.x()
.fieldQ("value")
.title("Días desde la notificación hasta la publicación")
// .scale({ type: "sqrt" })
.axis({
tickCount: 100,
labelExpr:
"datum.value%7 === 0 ? floor(datum.value/7) + ' sems ' : ''",
gridDash: {
condition: {
test: "+datum.value % 7 == 0",
value: []
},
value: [0, 20]
},
tickSize: 0
}),
vl
.y()
.fieldO("id_de_caso")
.axis(false)
)
.data(fechas)
.width(width * .8)
.height(600)
.title("Tiempo medio de espera para procesar pruebas PCR")
.render();
}
Insert cell
byDept.count()
Insert cell
viewof byDept = dt
.groupby(["departamento_nom", "ciudad_municipio_nom"])
.rollup({ edadMedia: d => op.mean(d.edad), count: op.count() })
.orderby(aq.desc("count"))
.view({ limit: 25 })
Insert cell
vl
.markPoint({ size: 2, tooltip: true })
.data(dt)
.encode(
vl.x().fieldT(referenceDate),
vl
.y()
.fieldO("id_de_caso")
.axis(null)
)
.width(width * .8)
.height(600)
.render()
Insert cell
import { aq, op } from '@uwdata/arquero'
Insert cell
import { file, checkbox, select } from "@jashkenas/inputs"
Insert cell
import { vl } from "@john-guerra/vega-lite-api"
Insert cell
d3 = require("d3@6")
Insert cell
import { navio } from "@john-guerra/navio"
Insert cell
import { loadSocrata } from "@john-guerra/socrata-load-multiples-pages"
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