allData = fetch(
"https://notions.stringer.io/precipitation?stationid=GHCND:USW00094846"
)
.then((response) => {
if (!response.ok) {
return response.text().then((text) => {
throw new Error(text);
});
}
return response.json();
})
.then((data) => {
const timeParse = d3.timeParse("%Y-%m-%d");
const cumulative = new Map();
const result = [];
data.forEach(([d, p]) => {
let date = timeParse(d);
let year = date.getFullYear();
let inches = p / 254;
let item = {
date,
precipitation: inches,
year,
cumulative: cumulative.has(year)
? cumulative.get(year) + inches
: inches,
dateInYear: toDateInYear(date)
};
cumulative.set(item.year, item.cumulative);
result.push(item);
});
return result;
})