Coder Social home page Coder Social logo

aqi-wtf's Introduction

I got tired of checking PurpleAir all the time to see the AQI near me, so I wrote this. It uses their API, finds the nearest sensor, and displays the AQandU adjusted AQI information.

AQI level descriptions

Descriptions about who should be concerned about the current AQI come EPA report EPA-456/F-15-005 retrieved from https://www.airnow.gov/sites/default/files/2018-04/air-quality-guide_pm_2015_0.pdf on September 11, 2020

Feature Matrix

Feature Support
Local air quality βœ…
Bear attacks 🚫

aqi-wtf's People

Contributors

agillette avatar danisyellis avatar drewzar avatar obra avatar ramatevish avatar skalnik avatar slightlyoff avatar sshirokov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aqi-wtf's Issues

App shows β€œ-” instead of AQI

Hi,

I noticed that aqi.wtf has been showing - for the AQI recently:

19945775-A6A7-433A-8F7B-605554444E1D

It is because the sensors are no longer returning the humidity:

aqi-wtf/app.js

Line 93 in 03e5090

let humidity = sensor.results[0].humidity;

Console output:

> sensor.results[0]
{ID: 37185, Label: "NBN - Bushwick and McKibbin", DEVICE_LOCATIONTYPE: "outside", THINGSPEAK_PRIMARY_ID: "843861", THINGSPEAK_PRIMARY_ID_READ_KEY: "88BKCTH44MUS6WL9", …}
> sensor.results[0].humidity 
undefined

the undefined humidity causes aqiFromPM to return a hyphen instead of the AQI calculation.

Occasional stalls on "Finding nearby sensors"

I haven't been able to reliably make this happen to debug this, but I have seen this happen to me a few times where it just stalls out on "Finding nearby sensors" and never progresses. Clearing the cache and reloading does nothing.

AQI numbers are dangerously misleading when one of the channels from the sensor is busted.

A friend in Seattle reported that aqi.wtf didn't match purpleair.
image
image

It appears that this sensor has one "degraded" channel, so it's only getting AQI data from the B sensor. I believe aqi.wtf is doing the wrong thing when averaging the good and bad channels.

The bad sensor is at https://www.purpleair.com/map?opt=1/i/mAQI/a0/cC1&select=20759#13.18/47.5699/-122.39299

Raw sensor data from what purpleair's map is currently seeing is inline below:

{
  "mapVersion": "0.18",
  "baseVersion": "7",
  "mapVersionString": "",
  "results": [
    {
      "ID": 20759,
      "Label": "North Admiral",
      "DEVICE_LOCATIONTYPE": "outside",
      "THINGSPEAK_PRIMARY_ID": "644662",
      "THINGSPEAK_PRIMARY_ID_READ_KEY": "R3BQTJCIEGGCCLW5",
      "THINGSPEAK_SECONDARY_ID": "644665",
      "THINGSPEAK_SECONDARY_ID_READ_KEY": "C9HWY21W209QHQAF",
      "Lat": 47.586074,
      "Lon": -122.383009,
      "PM2_5Value": "0.0",
      "LastSeen": 1599604445,
      "Type": "PMS5003+PMS5003+BME280",
      "Hidden": "false",
      "DEVICE_BRIGHTNESS": "15",
      "DEVICE_HARDWAREDISCOVERED": "2.0+BME280+PMSX003-B+PMSX003-A",
      "Version": "6.01",
      "LastUpdateCheck": 1599601323,
      "Created": 1544041613,
      "Uptime": "540598",
      "RSSI": "-75",
      "Adc": "0.0",
      "p_0_3_um": "0.0",
      "p_0_5_um": "0.0",
      "p_1_0_um": "0.0",
      "p_2_5_um": "0.0",
      "p_5_0_um": "0.0",
      "p_10_0_um": "0.0",
      "pm1_0_cf_1": "0.0",
      "pm2_5_cf_1": "0.0",
      "pm10_0_cf_1": "0.0",
      "pm1_0_atm": "0.0",
      "pm2_5_atm": "0.0",
      "pm10_0_atm": "0.0",
      "isOwner": 0,
      "humidity": "17",
      "temp_f": "81",
      "pressure": "1011.24",
      "AGE": 1,
      "Stats": "{\"v\":0.0,\"v1\":0.0,\"v2\":0.0,\"v3\":0.0,\"v4\":0.0,\"v5\":0.0,\"v6\":0.0,\"pm\":0.0,\"lastModified\":1599604445640,\"timeSinceModified\":119967}"
    },
    {
      "ID": 20760,
      "ParentID": 20759,
      "Label": "North Admiral B",
      "THINGSPEAK_PRIMARY_ID": "644666",
      "THINGSPEAK_PRIMARY_ID_READ_KEY": "KQZOSQYCSX6TN5HK",
      "THINGSPEAK_SECONDARY_ID": "644667",
      "THINGSPEAK_SECONDARY_ID_READ_KEY": "TFLYCY302WYLGZHH",
      "Lat": 47.586074,
      "Lon": -122.383009,
      "PM2_5Value": "53.98",
      "LastSeen": 1599604445,
      "Hidden": "false",
      "Created": 1544041613,
      "Adc": "0.00",
      "p_0_3_um": "10503.0",
      "p_0_5_um": "3068.66",
      "p_1_0_um": "386.09",
      "p_2_5_um": "24.43",
      "p_5_0_um": "5.84",
      "p_10_0_um": "0.39",
      "pm1_0_cf_1": "61.27",
      "pm2_5_cf_1": "81.91",
      "pm10_0_cf_1": "85.59",
      "pm1_0_atm": "40.12",
      "pm2_5_atm": "53.98",
      "pm10_0_atm": "66.71",
      "isOwner": 0,
      "AGE": 1,
      "Stats": "{\"v\":53.98,\"v1\":54.53,\"v2\":54.97,\"v3\":56.62,\"v4\":55.3,\"v5\":29.27,\"v6\":9.6,\"pm\":53.98,\"lastModified\":1599604445641,\"timeSinceModified\":119967}"
    }
  ]
}

Use 10 minute average instead of instantaneous data

Someone requested we use the 10 minute average instead of the latest value. I think that'd be good, but I believe we'll need to poll ThingSpeak instead of PA for that. Unsure how hard that'd be to implement, but I wanted to make note of it.

Average multiple sensors?

Related to #67 - Since we don't start off having even 2 minutes of data, I've been thinking about whether we might want to consider finding the 3 nearest sensors (ideally in different directions) and averaging them.

Use standard instead of prettier

Some cool kids told me how they prefer standard over prettier. I don't really care but they're cool and it seems like a nicer tool. Probably worth switching over the auto-formatter to that instead!

Vague error when no sensors found

Recently a coworker loaded up AQI.WTF and got an error! Turns out they're in the Caribbean and there's no sensors near them within the bounding box we've setup with #85.

We should handle this state a bit better by either:

  1. Expanding the bounding box
  2. Showing a nicer error state where we say something like Hey, there's no sensors within Nkm of you!

Right now it just errors on this line: https://github.com/skalnik/aqi-wtf/blob/main/app.js#L116

Incorrect value in SF Mission

Site is saying AQI is 30 rn, but it is very smoky in the SF Mission, and this is reflected on PurpleAir.

Either you're getting the wrong location (seems unlikely, geolocation seems to work correctly on other sites) or maybe you're not excluding indoor sensors?

More descriptive errors

This may surprise everyone, but our codes don't seem to be perfect. Occasionally errors occur! I often get screenshots of this but the error state really doesn't have much to go off of. Perhaps some more info like at least line number or maybe some dumped state would be helpful.

New API and thus everything is broken

Uhhh I gotta update some stuff again. I was able to at least generate an API key locked to the domains deployed to:

BA110377-679A-11EE-A8AF-42010A80000A

Hitting rate limit often

I've started to get more reports (and some anecdotal experience too) that the rate limit is being hit more regularly. Unsure if it's related to #15 or something else. I think we can also move the refreshing up a bit, since I think the sensors just update once a minute based on the age being in minutes in the API.

Make error page a bit more useful

By the time we've gotten to the error page, we almost always have a lat/lon. We could at least throw a link to the purpleair map there.

Feature request: specify location manually

Hello, thanks for making this very useful tool.

Request: I'd really like to be able to pick a location or sensor manually rather than relying on the location API prompt.

Context:
I'm always leery of granting location API permission, even though the app says that it's only used on my device. It's possible that the nearest sensor to me isn't great β€” it may be poorly installed and not representative of the actual air quality nearby. I also want to use aqi.wtf with Flotato, to create a compact standalone app window, and Flotato doesn't support the location API.

Dark mode

It'd be nice to not have a super bright loading page if we can detect the browser wants dark mode!

More background color variation

Right now it’s just a few specific colors. Purple Air has the color change slowly over a gradient to reflect the AQI. This should too.

Claim that geolocation "never leaves your device" appears inaccurate.

Looking at the source code, it appears the geolocation is send to purpleair.com, making the claim that it never leaves your device rather deceiving.
At the very least it seems to code could try to round to whole degrees or something to not upload the exact location. But even then the current claim would still be wrong.

Calculation issue?

This morning in the East Bay, our numbers appeared to be wildly inflated. They looked to correlate with the uncorrected PurpleAir numbers. οΏΌ I was seeing numbers in the 130s when I believe I should have been seeing numbers in the 90s. At this moment, they look goodοΏΌ

Link to PurpleAir

Can link straight to the map view with: https://www.purpleair.com/map?opt=1/i/mAQI/a10/cC4&select=<SENSOR_ID>#14/<LAT>/<LONG>. 14 appears to be the zoom level.

App should explain why it needs geolocation before prompting

On mobile, the initial load presents a screen like

Geolocation prompt on top of explanatory text

where the prompt hides the text that, on desktop, would explain what the prompt is for. Especially in combination with #69, it would be better to explain the prompt and have the user express their desire to use geolocation before calling the browser API.

Live Updating

Once the page is open and nearest sensor is found, it'd be great to live update

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.