earthquakeData = {
const startYear = 2016;
const endYear = 2021;
const months = []
for (let year = startYear; year <= endYear; year += 1) {
for (let jsMonth = 0; jsMonth < 12; jsMonth += 1) {
const monthStart = new Date(year, jsMonth, 1, 0, 0, 0).toISOString();
const monthEnd = new Date(year, jsMonth + 1, 0, 23, 59, 59).toISOString();
const queryUrl = `https://earthquake.usgs.gov/fdsnws/event/1/query.csv?starttime=${monthStart}&endtime=${monthEnd}&minmagnitude=2.0&orderby=time`;
months.push(d3.csv(queryUrl).then(response => response.map(event => {
const { id, latitude, longitude, mag, place, time, type, depth } = event;
return ({
id,
latitude: parseFloat(latitude, 10),
longitude: parseFloat(longitude, 10),
mag: parseFloat(mag, 10),
place,
time: new Date(time),
type,
depth: parseFloat(depth, 10)
})
}))
)
}
}
return Promise.all(months).then( d => d.flat())
}