Published
Edited
Jan 3, 2021
1 star
Insert cell
Insert cell
firstRespondent = {
const firstRespondent = mostRecentSurvey[0];
const creationDateStrings = mostRecentSurvey.map(d => d.createdAt["$date"]);
if (firstRespondent.createdAt["$date"] !== d3.min(creationDateStrings)) {
throw "Not the first respondent chronologically";
}
return firstRespondent;
}
Insert cell
firstRespondent.user_info.how_did_user_find_out_about_the_survey
Insert cell
Insert cell
mostRecentSurvey = rawData.filter(d => d.year === 2020)
Insert cell
rawData = {
const utf8Decoder = new TextDecoder();
const decodedText = utf8Decoder.decode(decompressedFileBuffer);
return JSON.parse(decodedText);
}
Insert cell
decompressedFileBuffer = {
const decompressedFileBuffer = await archive.file("state_of_css_2019-2020.json").async("arraybuffer") // utf-8 encoded
mutable sizeLiteral = `${formatMegabytes(compressedFileBuffer.byteLength)} in size, ${formatMegabytes(decompressedFileBuffer.byteLength)} unzipped`;
return decompressedFileBuffer;
}
Insert cell
archive = {
const jszip = await require("jszip@3/dist/jszip.min.js"); // see: https://observablehq.com/@mbostock/hello-jszip
return jszip.loadAsync(compressedFileBuffer);
}
Insert cell
compressedFileBuffer = FileAttachment("state_of_css_2019-2020.json.zip").arrayBuffer()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
participationByCountry
Insert cell
Insert cell
Insert cell
difference = {
const a = participationByCountry.completion.count;
const b = d3.sum(participationByCountry.buckets, d => d.count);
return Math.abs(a - b);
}
Insert cell
Insert cell
participantCountByCountry = d3.rollup(countrySpecificRespondents, v => v.length, d => d.country_alpha3)
Insert cell
countrySpecificRespondents = mostRecentSurvey.map(d => d.user_info)
.filter(d => d.country_alpha3 !== undefined)
Insert cell
Insert cell
missingCountryNames = [...missingCountryCodes].map(code => {
return countrySpecificRespondents.find(d => d.country_alpha3 === code).country_name;
})
Insert cell
missingCountryCodes = {
const a = [...participantCountByCountry.keys()].sort();
const b = participationByCountry.buckets.map(d => d.id);
return d3.difference(a, b);
}
Insert cell
missingRespondents = countrySpecificRespondents.filter(d => missingCountryCodes.has(d.country_alpha3))
Insert cell
Insert cell
Insert cell
// see: https://observablehq.com/@observablehq/introduction-to-mutable-state
mutable sizeLiteral = "I’ve added some ~~elevator music~~ metalcore [below](#metalcore) to cover downloading and decompression"
Insert cell
formatMegabytes = (bytes) => `${Math.round(bytes / (1024 * 1024))} MB`
Insert cell
d3 = require("d3-array@2")
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