trekawek / air-quality-info

An attractive way to display air quality in your neighbourhood.
Other
49 stars 16 forks source link

No thresholds on graph in "Instantaneous" and "30d" modes #56

Closed dblachut closed 3 years ago

dblachut commented 3 years ago

As in the title - there is no horizontal line with thresholds on the graph in some display modes.

dblachut commented 3 years ago

Oh, I guess the reason is that there are no official thresholds for these periods? https://www.airqualitynow.eu/about_indices_definition.php

My proposal:

diff --git a/src/htdocs/public/js/graph.js b/src/htdocs/public/js/graph.js
index 8eeaa31..6489c57 100644
--- a/src/htdocs/public/js/graph.js
+++ b/src/htdocs/public/js/graph.js
@@ -243,12 +243,19 @@ function renderGraph(ctx, data, type, avgType) {

         var pm25Limit = null;
         var pm10Limit = null;
-        if (avgType == 1) {
+        var contentSuffix = '';
+        if (avgType == 1 || avgType == 0) {
             pm25Limit = CONFIG.pm25Limit1h;
             pm10Limit = CONFIG.pm10Limit1h;
-        } else if (avgType == 24) {
+            if (avgType == 0) {
+                contentSuffix = ' / 1h';
+            }
+        } else if (avgType == 24 || avgType == 720) {
             pm25Limit = CONFIG.pm25Limit24h;
             pm10Limit = CONFIG.pm10Limit24h;
+            if (avgType == 720) {
+                contentSuffix = ' / 24h';
+            }
         }
         config.options.annotation = { annotations: [] };

@@ -261,7 +268,7 @@ function renderGraph(ctx, data, type, avgType) {
                 borderColor: 'purple',
                 borderWidth: 1,
                 label: {
-                  content: __('PM₂.₅ limit'),
+                  content: __('PM₂.₅ limit') + contentSuffix,
                   enabled: true,
                   position: 'left',
                          backgroundColor: 'rgba(0,0,0,0.3)'
@@ -277,7 +284,7 @@ function renderGraph(ctx, data, type, avgType) {
                 borderColor: 'orange',
                 borderWidth: 1,
                 label: {
-                  content: __('PM₁₀ limit'),
+                  content: __('PM₁₀ limit') + contentSuffix,
                   enabled: true,
                   position: 'left',
                          backgroundColor: 'rgba(0,0,0,0.3)'

Unfortunately I am unable to check it as the build instructions are incomplete and by default it starts with error. First two errors are because csv_root and cache_root does not have write permissions. I am also unsure how to display some device page, is there some stub/test data to work with?

trekawek commented 3 years ago

Looks good. Could you make it a PR?

First two errors are because csv_root and cache_root does not have write permissions. Also I think the CSV uploader will fail if the CSV_ROOT is not created yet. This should address it: 3a833c1caccb3ec8a4087a8644440e5e1750cb52.

Could you say what kind of permissions you had to add or create a PR to README.md? On Mac it works without any extra steps (just checked).

dblachut commented 3 years ago

I meant I had an error while trying to run docker-compose up

fpm_1             | 172.20.0.9 -  26/Mar/2021:15:35:59 +0000 "GET /index.php" 302
fpm_1             | NOTICE: PHP message: PHP Warning:  mkdir(): Permission denied in /var/www/html/boot.php on line 55
fpm_1             | NOTICE: PHP message: PHP Fatal error:  Uncaught Nette\DirectoryNotFoundException: Directory '/var/aqi/cache' not found. in /var/www/html/vendor/nette/caching/src/Caching/Storages/FileStorage.php:69
fpm_1             | Stack trace:
fpm_1             | #0 /var/www/html/boot.php(57): Nette\Caching\Storages\FileStorage->__construct('/var/aqi/cache')
fpm_1             | #1 /var/www/html/lib/di_container.php(65): AirQualityInfo\{closure}()
fpm_1             | #2 /var/www/html/lib/di_container.php(43): AirQualityInfo\Lib\DiContainer->getParamValue(Object(ReflectionParameter))
fpm_1             | #3 /var/www/html/routing/admin_routing.php(133): AirQualityInfo\Lib\DiContainer->injectClass('\\AirQualityInfo...')
fpm_1             | #4 /var/www/html/index.php(8): require('/var/www/html/r...')
fpm_1             | #5 {main}
fpm_1             |   thrown in /var/www/html/vendor/nette/caching/src/Caching/Storages/FileStorage.php on line 69
fpm_1             | 172.20.0.9 -  26/Mar/2021:15:35:59 +0000 "GET /index.php" 500

and

csv-uploader_1    | Starting upload-csv
csv-uploader_1    | PHP Fatal error:  Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/var/aqi/csv): failed to open dir: No such file or directory in /usr/local/bin/aqi/upload-csv.php:78
csv-uploader_1    | Stack trace:
csv-uploader_1    | #0 /usr/local/bin/aqi/upload-csv.php(78): RecursiveDirectoryIterator->__construct('/var/aqi/csv')
csv-uploader_1    | #1 {main}
csv-uploader_1    |   thrown in /usr/local/bin/aqi/upload-csv.php on line 78

Changing config fixed it (ugly workaround):

  'csv_root' => '/tmp',
  'cache_root' => '/tmp/cache',

Sure I will make a PR, but as I said - unfortunately I don't know how to test it.

BTW should devices from aqi.eco domain work on locally hosted service? E.g. http://mosina.aqi.eco.localhost:8080/? Is there any way I can use some test data to verify my code?

trekawek commented 3 years ago

First two errors are because csv_root and cache_root does not have write permissions.

Updated README: 2c7e194c740c5d7a8ccc7e5f0f4cce577a393184

Is there any way I can use some test data to verify my code?

  1. Click http://aqi.eco.localhost:8080/user/settings
  2. Check Allow pull sensors
  3. Click http://aqi.eco.localhost:8080/sensor/create
  4. Choose any sensor.community device.

Your local instance will pull data from sensor.community for this device.

This can be made better by downloading the historic data from madavi.de for such external sensor.community, but it's not supported yet.

BTW should devices from aqi.eco domain work on locally hosted service? E.g. http://mosina.aqi.eco.localhost:8080/?

No. You need to add data yourself.

dblachut commented 3 years ago

Yeah I see, it works now and the instructions are more complete.

The downside of data pulling is that it only pulls current results so you need to wait a while for the data to be filled. Historic data import even through some local script and db insert would be great. Anyway - great work and thanks for the help!

BTW Any plans on making the thresholds configurable? E.g. in Kanarek you can use EU or PL air quality index and different norms. The lowest threshold in the Polish AQI (https://powietrze.gios.gov.pl/pjp/current?lang=en) is 20.