Comments (5)
No problem! Really helpful website you built...
By the way, the new API is vastly improved, faster, etc. -- I think they also plan to add some average and calculated metrics to the response over time.
from aqi-wtf.
Closed with #82
Thanks again for the report @jamiesteven!
from aqi-wtf.
Given I previously forked your project for my own uses and have diverged a bit since then, a pull request isn't suitable. However, here is my newly updated version of your AQI calculation script that uses the appropriate fields from Purple's new authenticated API:
// From https://www.epa.gov/sites/default/files/2021-05/documents/toolsresourceswebinar_purpleairsmoke_210519b.pdf final slide
function epaAQIFromPMandHumidity(pm, humidity) {
if (pm < 50) {
return aqiFromPM(0.52 * pm - 0.086 * humidity + 5.75)
} else if (pm < 229) {
return aqiFromPM(0.786 * pm - 0.086 * humidity + 5.75)
} else {
return aqiFromPM(0.69 * pm + 8.84 * Math.pow(10, -4) * Math.pow(pm, 2) + 2.97)
}
}
function aqiFromPM(pm) {
if (isNaN(pm)) return '-'
if (pm == undefined) return '-'
if (pm < 0) return 0
if (pm > 1000) return '-'
if (pm > 350.5) {
return calcAQI(pm, 500, 401, 500, 350.5)
} else if (pm > 250.5) {
return calcAQI(pm, 400, 301, 350.4, 250.5)
} else if (pm > 150.5) {
return calcAQI(pm, 300, 201, 250.4, 150.5)
} else if (pm > 55.5) {
return calcAQI(pm, 200, 151, 150.4, 55.5)
} else if (pm > 35.5) {
return calcAQI(pm, 150, 101, 55.4, 35.5)
} else if (pm > 12.1) {
return calcAQI(pm, 100, 51, 35.4, 12.1)
} else if (pm >= 0) {
return calcAQI(pm, 50, 0, 12, 0)
} else {
return undefined
}
}
function calcAQI(Cp, Ih, Il, BPh, BPl) {
// The AQI equation https://forum.airnowtech.org/t/the-aqi-equation/169
var a = Ih - Il
var b = BPh - BPl
var c = Cp - BPl
return Math.round((a / b) * c + Il)
}
function getAQI(reading) {
let humidity = reading.sensor.humidity
const pm25 = reading.sensor['pm2.5_cf_1']
const aqi = epaAQIFromPMandHumidity(pm25, humidity)
return aqi
}
export function getAQIClass(aqi) {
if (aqi >= 401) {
return 'very-hazardous'
} else if (aqi >= 301) {
return 'hazardous'
} else if (aqi >= 201) {
return 'very-unhealthy'
} else if (aqi >= 151) {
return 'unhealthy'
} else if (aqi >= 101) {
return 'unhealthy-for-sensitive-groups'
} else if (aqi >= 51) {
return 'moderate'
} else if (aqi >= 0) {
return 'good'
} else {
return undefined
}
}
export function getAQIClassFromReading(reading) {
const aqi = getAQI(reading)
return getAQIClass(aqi)
}
export function getAQIFromReading(reading) {
const aqi = getAQI(reading)
return aqi
}
from aqi-wtf.
Thanks for this! I'll get this fixed up. Super appreciate the report + code 💖
from aqi-wtf.
For anyone following along, I've slowly started poking at this and am awaiting an API key.
from aqi-wtf.
Related Issues (20)
- need error checking around "getAQIDescription" HOT 2
- We need to recalculate the nearest sensor when we update the AQI HOT 3
- Parse rate limit messages from PA and set our own timer to refresh after the timeout.
- Make error page a bit more useful HOT 3
- Error page is a dead end when launching from an iOS home screen bookmark. HOT 1
- on iOS when launched from homescreen, the credits are covered by system UI HOT 2
- AQI numbers are dangerously misleading when one of the channels from the sensor is busted. HOT 5
- iPhone X series phone notch cuts into page when phone in landscape HOT 1
- Use 10 minute average instead of instantaneous data HOT 4
- Improve broken sensor detection
- Average multiple sensors? HOT 1
- Feature request: specify location manually
- App should explain why it needs geolocation before prompting
- Claim that geolocation "never leaves your device" appears inaccurate. HOT 1
- App shows “-” instead of AQI HOT 4
- Occasional stalls on "Finding nearby sensors" HOT 2
- Adjust EPA algorithm HOT 2
- Calculation issue? HOT 1
- New API and thus everything is broken HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aqi-wtf.