Published
Edited
Apr 27, 2021
Importers
Insert cell
Insert cell
Table(fukuokaCases)
Insert cell
uri = `https://ckan.open-governmentdata.org/dataset/8a9688c2-7b9f-4347-ad6e-de3b339ef740/resource/44c15434-6082-4b61-bad5-d7e98bbaeef1/download/400009_pref_fukuoka_covid19_patients1.csv`
Insert cell
populationMap
Insert cell
weekBeforeLastData.get('')
Insert cell
getLength(weekBeforeLastData, 90, '男性')
Insert cell
getLength = (data, age, sex) => {
if (data.get(age)) {
if (data.get(age).get(sex)) {
return data.get(age).get(sex).length;
} else {
return 0;
}
} else {
return 0;
}
}
Insert cell
ages = d3.range(80, -10, -10)
Insert cell
sexes = ['男性', '女性']
Insert cell
weekBeforeLastData = d3.group(
weekBeforeLastCases.filter(d => d.age >= 0),
d => d.age,
d => d.sex
)
Insert cell
lastData = d3.group(
lastWeekCases.filter(d => d.age >= 0),
d => d.age,
d => d.sex
)
Insert cell
weekBeforeLastCases = filterDates(cases, new Date(2021, 3 - 1, 13))
Insert cell
lastWeekCases = filterDates(cases, new Date(2021, 3 - 1, 20))
Insert cell
filterDates = (data, date, duration = 7) => {
return data.filter(
d =>
d.date.getTime() >= date.getTime() &&
d.date.getTime() <= date.getTime() + (duration - 1) * 1000 * 60 * 60 * 24
);
}
Insert cell
latestDate = d3.max(cases, d => d.date)
Insert cell
d3.group(cases, d => d.age)
Insert cell
d3.group(cases, d => d.sex)
Insert cell
cases = fukuokaCases
Insert cell
fukuokaCases = (
await d3.csv("https://sugi2000cors.herokuapp.com/" + uri, d3.autoType)
)
.map((d) => ({
date: new Date(d.公表_年月日),
sex: d.性別,
age: ageGroup(d.年代 ? d.年代 : ""),
...d
}))
.filter((d) => d.age >= 0)
.filter((d) => d.sex === "男性" || d.sex === "女性")
Insert cell
ageGroup = (rawAge) => {
let ageGroup;
switch (rawAge) {
case "100歳以上":
case "90代以上":
case "90代":
ageGroup = 80;
break;
case "10歳未満":
ageGroup = 0;
break;
case "不明":
ageGroup = -1;
break;
case "-":
ageGroup = -1;
break;
default:
ageGroup = +rawAge.substr(0, 2);
break;
}
return ageGroup;
}
Insert cell
populationMap = new Map(
ages.map(age => [
age,
new Map(sexes.map(sex => [sex, getPopulation(age, sex)]))
])
)
Insert cell
getPopulation(0, '男性')
Insert cell
getPopulation = (age, sex) => {
const startAge = age;
const endAge = startAge + 10;

return (
d3.sum(
population.filter(d => +d.age >= startAge && +d.age < endAge),
d => +d[sex]
) * 1000
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
XLSX = xlsx
Insert cell
import { loadExcel, loadExcelWorkbook } from "@sugi2000/load-excel-file"
Insert cell
xlsx = require('xlsx@0.16.9/dist/xlsx.full.min.js')
Insert cell
import { Table } from "@observablehq/inputs"
Insert cell
d3 = require('d3@6')
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