Public
Back
Version 3
6/19/2023
export async function nowCastPMAQI({ location_id }) {
const { results } = await stevekrouse.fetchJSON(
"https://api.openaq.org/v2/measurements?" +
new URLSearchParams({
limit: "100",
page: "1",
location_id,
date_from: new Date(Date.now() - 12 * stevekrouse.msHour)
.toISOString(),
date_to: new Date().toISOString(),
parameter: "pm25",
order_by: "datetime",
}),
);
return {
now: results.at(-1),
then: results.at(0),
aqi: stevekrouse.nowcastPMAqi(results.map((o) => o.value)),
};
}
// Forked from @stevekrouse.nowCastPMAQI
Updated: October 23, 2023