Published
Edited
Sep 29, 2021
Insert cell
Insert cell
DOM.download(serialize(data), "Results.csv", "Download CSV")
Insert cell
data = {
let data = [];
//flatten
for (let riding of rawdata.data.ridings) {
for (let party of riding.parties) {
data.push({
id: riding.id,
ridingNumber: riding.ridingNumber,
englishName: riding.englishName,
regionsList: riding.regionsList.join("|"),
totalVoters: riding.totalVoters,
totalPolls: riding.totalPolls,
previousElectedPartyCode: riding.previousElectedPartyCode,
resultStatus: riding.resultStatus.join("|"),
isCandidateElected: riding.isCandidateElected,
pollsReported: riding.pollsReported,
totalVotesReported: riding.totalVotesReported,
lastResultTime: riding.lastResultTime,
candidateVotesLead: riding.candidateVotesLead,
leadingPartyCode: riding.leadingPartyCode,
partyId: party.partyId,
englishCode: party.englishCode,
candidateFirstName: party.candidateFirstName,
candidateLastName: party.candidateLastName,
incumbentCode: party.incumbentCode,
incumbent: party.incumbent,
votesPercentage: party.votesPercentage,
votesLead: party.votesLead,
votes: party.votes,
candidateId: party.candidateId,
votesPosition: party.votesPosition
});
}
}
return data;
}
Insert cell
rawdata = FileAttachment("results.json").json()
Insert cell
import { serialize } from "@palewire/saving-csv"
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