# pm to aqi

stuff
unknown
plain_text
2 years ago
1.3 kB
2
Indexable
Never
```def round_up(aqi_float: float) -> int:
print("og:", aqi_float) # debug
split_num = str(aqi_float).split('.')
int_part = int(split_num[0])
decimal_part = int(split_num[1][0])
print("decimalpart:", decimal_part) # Debug
if decimal_part >= 5:
return int_part + 1
else:
return int_part

def PM25_to_AQI(pm: int or float) -> int:
"""
Categorizes each PM into the AQI values
:param pm:
:return:
"""
if pm < 12.1:
return pm * 50 / 12.0
elif pm < 35.5:
y = 51 + ((pm - 12.0) * (100 - 51)) / (35.5 - 12.0)
return (y)
# return round_up(y)
elif pm < 55.5:
y = 101 + ((pm - 35.0) * (150 - 101)) / (55.5 - 35.0)
return (y)
return round_up(y)
elif pm < 150.5:
y = 151 + ((pm - 55.5) * (200 - 151)) / (150.5 - 55.5)
return round_up(y)
elif pm < 250.5:
y = 201 + ((pm - 150.5) * (300 - 201)) / (250 - 150.5)
return round_up(y)
elif pm < 350.5:
y = 301 + ((pm - 250.5) * (400 - 301)) / (350.5 - 250.5)
return round_up(y)
elif pm < 500.5:
y = 401 + ((pm - 350.5) * (500 - 401)) / (500.5 - 350.5)
return round_up(y)
elif pm >= 500.5:
return 501
else:
return 0
```