Published
Edited
Apr 1, 2021
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
air_raw = d3
.json(
`https://data.stadt-zuerich.ch/api/3/action/datastore_search?resource_id=4466ec4a-b215-4134-8973-2f360e53c33d&sort=Datum%20desc&limit=32000&filters={%22Standort%22:%22${air_sensor}%22}`
)
.then(function(r) {
r.result.records.forEach(function(d) {
d.date = dateParser(d.Datum);
d.value = +d.Wert;
d.unit = d.Einheit;
});
return r.result.records;
})
Insert cell
Insert cell
air_sums = d3.rollup(
air_raw,
v => d3.mean(v, d => d.value),
d => d.Parameter,
d => dateWithoutTime(d.date)
)
Insert cell
Insert cell
Insert cell
velo = d3.json(`https://data.stadt-zuerich.ch/api/3/action/datastore_search?resource_id=ebe5e78c-a99f-4607-bedc-051f33d75318&sort=DATUM%20desc&filters={%22FK_STANDORT%22:%22${bike_sensor}%22}&limit=32000`).then( function(r) {
r.result.records.forEach(function(d) {
d.date = dateParser2(d.DATUM);
d.value = +d['VELO_IN'] + +d['VELO_OUT'];
d.unit = 'Velos';
});
return r.result.records
})
Insert cell
Insert cell
fuss = d3.json(`https://data.stadt-zuerich.ch/api/3/action/datastore_search?resource_id=ebe5e78c-a99f-4607-bedc-051f33d75318&sort=DATUM%20desc&filters={%22FK_STANDORT%22:%22${people_sensor}%22}&limit=32000`).then( function(r) {
r.result.records.forEach(function(d) {
d.date = dateParser2(d.DATUM);
d.value = +d['FUSS_IN'] + +d['FUSS_OUT'];
d.unit = 'Personen';
});
return r.result.records
})
Insert cell
Insert cell
Insert cell
dateParser = d3.timeParse("%Y-%m-%dT%H:%M%Z");
Insert cell
dateParser2 = d3.timeParse("%Y-%m-%dT%H:%M");
Insert cell
dateParser2("2021-01-01T02:30")
Insert cell
f = d3.formatLocale(".","'");
Insert cell
locale = d3.formatLocale({
decimal: ".",
thousands: "'",
grouping: [3],
currency: ["", "\u00a0CHF"],
})
Insert cell
fformat = locale.format(",.4r")
Insert cell
fformat(1564)
Insert cell
lookup = function(array,parameter,key) {
return array.filter(d => d.Parameter === parameter)[0][key]
}
Insert cell
countSum = function(array,valueKey){
return fformat(array.map(d => d[valueKey]).reduce((accumulator, currentValue) => accumulator + currentValue))
}
Insert cell
[ ...d3.rollup(velo, v => d3.sum(v, d => d.value), d => dateWithoutTime(d.date)).values() ]
Insert cell
d3.rollup(fuss, v => d3.sum(v, d => d.value), d => dateWithoutTime(d.date))
Insert cell
groupedDayAverage = function(array){
let sums = [ ...d3.rollup(array, v => d3.sum(v, d => d.value), d => dateWithoutTime(d.date)).values() ]
return fformat(sums.reduce((total, val) => total + val) / sums.length)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dateWithoutTime = function(d){
return new Date(d.getFullYear(),d.getMonth(), d.getDate())
}
Insert cell
tformatter = d3.timeFormat('%d.%m. %H:%M')
Insert cell
tformatter_short = d3.timeFormat('%d.%m.')
Insert cell
d3 = require("d3", "d3-array")
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