Public
Edited
Jan 22, 2024
Importers
Insert cell
Insert cell
Insert cell
fetchedDataPS = await FileAttachment("fetchedDataPS@2.csv").csv({
typed: true
})
Insert cell
// Data structure: Group by school municipalities (SGEM), assign BFS per SGEM, and rename properties.
// Important to understand:
// 1) Several political municipalities (BFS) can be assigned to each SGEM. This is the case when a school municipality (SGEM) assumes primary school tasks for several political municipalities.
// 2) Each SGEM has one specific municipality type (GDEART: U, PS, S)

dataPS = fetchedDataPS.reduce((groups, d) => {
// group by SGEM
const group = groups.find((g) => g.code === d.code);

const currentValue = {
// assign BFS code per SGEM
code: d.code,
gebiet_name: d.name,
gemeinde: d.gemeindename,
anschlussvertrag: d.anschlussvertrag,
typ: d.anschlussvertrag === "NA" ? d.typ : "Anschlussvertrag",
label: d.anschlussvertrag === "NA" ? "Gemeindegebiet:" : "Anschlussvertrag:"
};

const bfsCodes = {
// assign BFS code per SGEM
code: d.code,
gebiet_name: d.name,

// gemeinde: d.gemeindename,
schulgebiet: d.schulgebiet,
anschlussvertrag: d.anschlussvertrag
};

if (group) {
group.gdeInfo.push(bfsCodes);
group.typesByCode[currentValue.code] = currentValue.type;
} else {
groups.push({
// Properties of the SGEM (code, name, typ)
code: d.code,
gebiet_name: d.name,

name: d.gemeindename,
typ: d.anschlussvertrag === "NA" ? d.typ : "Anschlussvertrag",
anschlussvertrag: d.anschlussvertrag,
label:
d.anschlussvertrag === "NA" ? "Gemeindegebiet" : "Anschlussvertrag",
// All assigned BFS codes per SGEM type U and S
gdeInfo: [bfsCodes],
typesByCode: {
[currentValue.code]: currentValue.typ
}
});
}

return groups.sort(asc((d) => d.code));
}, [])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Inputs.table(dataPS)
Insert cell
Insert cell
gemeinden = await FileAttachment("schulgemeinden@2.csv").csv({
typed: true
})
Insert cell
primarGemeinden = gemeinden.filter((d) => d.primar == 1)
Insert cell
primarNamen = [...new Set(d3.map(primarGemeinden, (d) => d.gemeinde_name))]
Insert cell
selectedRegionName = "Flaach"
Insert cell
selectedPrimar = primarGemeinden
.filter((d) => d.code !== 0)
.map((d) => ({
id: d.code,
label: d.gemeinde_name,
selected: selectedRegionName.includes(d.gemeinde_name)
}))
Insert cell
selectedPrimar.filter((d) => d.selected == true)[0].id
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