python-aqi icon indicating copy to clipboard operation
python-aqi copied to clipboard

Handle out of scale value

Open hrbonz opened this issue 10 years ago • 4 comments

Handle negative and out of scale values.

Add an option to force out of scale calculation

hrbonz avatar Aug 05 '15 10:08 hrbonz

while doing some experiments with a air sensor in a room for smokers I played with the data and got the following error trying to convert the high PM numbers the PM10 number was 566.8 as you can see below in the trace and error I believe this is exactly what this bug mentions

Traceback (most recent call last): File "./aqi-test.py", line 24, in (aqi.POLLUTANT_PM10, row[5]), File "/usr/lib/python2.7/site-packages/aqi/init.py", line 45, in to_aqi return _aqi.aqi(ccs) File "/usr/lib/python2.7/site-packages/aqi/algos/base.py", line 36, in aqi _iaqi = self.iaqi(elem, cc) File "/usr/lib/python2.7/site-packages/aqi/algos/base.py", line 78, in iaqi (aqilo, aqihi) = self.piecewise['aqi'][idx] IndexError: list index out of range list index out of range error with row: (u'2017-09-17 17:55:00', 269.8, 514.2, 173.9, 297.3, 566.8, 191.8)

brettowe avatar Sep 18 '17 04:09 brettowe

Now with fire in Australia Ozone and PM value go too high

File "/home/rva/.local/lib/python3.6/site-packages/aqi/init.py", line 45, in to_aqi return _aqi.aqi(ccs) File "/home/rva/.local/lib/python3.6/site-packages/aqi/algos/base.py", line 36, in aqi _iaqi = self.iaqi(elem, cc) File "/home/rva/.local/lib/python3.6/site-packages/aqi/algos/base.py", line 91, in iaqi (aqilo, aqihi) = self.piecewise['aqi'][idx] IndexError: list index out of range

allairgoo avatar Dec 05 '19 13:12 allairgoo

Fundamentally, the correct behavior would be to raise an exception that qualifies the value as out of AQI calculation range.

hrbonz avatar Dec 08 '19 09:12 hrbonz

Hey @hrbonz How about returning float('inf') if the pollutant value is above the maximum threshold? That should be backward-compatible in most cases and will have predictable behavior in numerical comparisons.

tomasz-lewicki avatar May 26 '20 00:05 tomasz-lewicki