Public
Edited
Feb 20, 2023
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
//resp_old = sql`
// select
// year(datahora) as ano,
// month(datahora) as mes,
// day(datahora) as dia,
// max(${indicador}) as valor,
// avg(temperatura_c) as temperatura_c_media
// from
// "amplia-sisam"
// where
// ${municipio=="TODA A UF"?
// "mun_uf_nome='"+UF+"'":
// "mun_geocodsdv="+municipios.find(d=>d.municipio==municipio).codigo_sdv}
// group by
// 1,2,3
//`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//data={
let ret=[]
resp.forEach(dict=>{
if (dict.ano<anoinicial||dict.ano>anofinal) //faz recorte de anos
return

//convert to epidemiological week
let date=new Date(Date.UTC(dict.ano,dict.mes-1,dict.dia)) //utc month starts at 0
for (let i of semanas_epidemiologicas) {
if (date>=new Date(i.inicio)&&date<=new Date(i.termino)){
dict["semana"]=+i.semana
break
}
}

if (dict.mes==1&&dict.semana==53){
dict.ano-=1
dict.mes=12
}
ret.push(dict)
})

//grouping by ano and semana
let ret2=[]
for (let i of ret){
let f=ret2.find(d=>d.ano==i.ano&&d.semana==i.semana)
if (f){
f.valor+=i.valor
//if (f.valor<i.valor)
// f.valor=i.valor
f.temperatura_c_media+=i.temperatura_c_media
f.cont+=1
}
else
ret2.push({ano:i.ano, semana:i.semana, valor:i.valor||0, temperatura_c_media:i.temperatura_c_media, cont:1})
}
ret2=ret2.map(d=>{d.valor/=d.cont; d.temperatura_c_media/=d.cont; delete d.cont; return d;}).filter(d=>d.semana)
//ret2=ret2.map(d=>{d.temperatura_c_media/=d.cont; delete d.cont; return d;}).filter(d=>d.semana)
return ret2
}
Insert cell
//resp=db.query(query)
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

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