Published
Edited
Jan 25, 2021
Importers
Insert cell
Insert cell
osakaData.slice(-11)
Insert cell
osakaData = getDateOfDates({ dates: dates })
Insert cell
dates.slice(-1)
Insert cell
dates = d3.range(70).map(d => new Date(2020, 10, 16 + d))
Insert cell
getDateOfDates = async ({ dates } = {}) => {
let result = [];
for (let date of dates) {
result.push(await getData({ date }));
// result.push(date);
}
return result.flat();
}
Insert cell
dates[54]
Insert cell
getData({ date: dates[47] })
Insert cell
getData = async ({ date } = {}) => {
const dateStr = d3.timeFormat('%Y-%m-%d')(date);
const uri = getSource({
date: dateStr
});
const buffer = await d3.buffer(uri);
const array = new Uint8Array(buffer);
// return array;
const wb = xlsx.read(array, { type: 'array' });

const ws = wb.Sheets[wb.SheetNames[1]];
const json = xlsx.utils.sheet_to_json(ws);

const headerRow = json.findIndex(d => d.__EMPTY == '未就学児');
const [header, number] = json.slice(headerRow, headerRow + 2);
const result = [];
for (let key of Object.keys(header)) {
result.push({
date: dateStr,
age:
header[key] === '未就学児' || header[key] === '就学児'
? 0
: +header[key].replace(/(\d+).+/, '$1'),
cases: number[key]
});
}
if (result[0].age === 0 && result[1].age === 0) {
result[1].cases += result[0].cases;
result.shift();
}
return result;
}
Insert cell
sources.get('2020-11-16')
Insert cell
getSource = ({ date } = {}) =>
'https://sugi2000cors.herokuapp.com/' + sources.get(date)
Insert cell
Insert cell
sources = new Map(
dates.map(d => [
d3.timeFormat('%Y-%m-%d')(d),
`${urlPaths.get(d3.timeFormat('%Y-%m')(d))}${d3.timeFormat('%m%d')(d)}${
suffix.get(d3.timeFormat('%Y-%m-%d')(d))
? suffix.get(d3.timeFormat('%Y-%m-%d')(d))
: ''
}.xlsx`
])
)
Insert cell
urlPaths = new Map([
[`2020-11`, `http://www.pref.osaka.lg.jp/attach/23711/00381255/`],
[`2020-12`, `http://www.pref.osaka.lg.jp/attach/23711/00382605/`],
[`2021-01`, `http://www.pref.osaka.lg.jp/attach/23711/00376069/`]
])
Insert cell
suffix.get('2020-11-17')
Insert cell
suffix = new Map(
suffixStr
.trim()
.split('\n')
.map(d => d.split(','))
)
Insert cell
suffixStr = `
2021-01-16,
2021-01-13,
2021-01-12,
2021-01-06,
2020-12-31,
2020-12-30,
2020-12-29,
2020-12-25,
2020-12-13,
2020-12-12,
2020-12-09,
2020-12-04,
2020-11-30,
2020-11-29,syusei
2020-11-27,
2020-11-25,
2020-11-24,
2020-11-23,syusei
2020-11-22,syusei
2020-11-18,syusei
`
Insert cell
sourcesStr = `
2020-11-16,http://www.pref.osaka.lg.jp/attach/23711/00376069/1116.xlsx
`
Insert cell
xlsx = require('xlsx@0.16.9/dist/xlsx.full.min.js')
// xlsx = require('xlsx@0.16.9/dist/xlsx.min.js')
Insert cell
xlsx14 = require('https://bundle.run/xlsx@0.14.1')
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