adjoint-bass commited on
Commit
af5a939
1 Parent(s): ac54e04
Files changed (3) hide show
  1. __pycache__/functions.cpython-39.pyc +0 -0
  2. app.py +3 -4
  3. functions.py +6 -6
__pycache__/functions.cpython-39.pyc ADDED
Binary file (4.85 kB). View file
 
app.py CHANGED
@@ -3,7 +3,7 @@ import hopsworks
3
  import joblib
4
  import pandas as pd
5
  import datetime
6
- from functions import get_weather_data_weekly, data_encoder, get_aplevel, get_color
7
  from PIL import Image
8
 
9
 
@@ -49,8 +49,7 @@ fancy_header("Making AQI predictions for the next 7 days")
49
 
50
  preds = model.predict(data_encoder(weekly_data)).astype(int)
51
 
52
- air_pollution_level = ['Good', 'Moderate', 'Unhealthy for sensitive Groups','Unhealthy' ,'Very Unhealthy', 'Hazardous']
53
- poll_level = get_aplevel(preds.T.reshape(-1, 1), air_pollution_level)
54
 
55
  next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]
56
  next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days in next_week_datetime]
@@ -58,6 +57,6 @@ next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days
58
  df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week_str)
59
 
60
  st.write("Here they are!")
61
- st.dataframe(df.style.apply(get_color, subset=(["Air pollution level"], slice(None))))
62
 
63
  st.button("Re-run")
 
3
  import joblib
4
  import pandas as pd
5
  import datetime
6
+ from functions import get_weather_data_weekly, data_encoder, get_info
7
  from PIL import Image
8
 
9
 
 
49
 
50
  preds = model.predict(data_encoder(weekly_data)).astype(int)
51
 
52
+ color_level, poll_level = get_info(preds.reshape(1, -1))
 
53
 
54
  next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]
55
  next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days in next_week_datetime]
 
57
  df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week_str)
58
 
59
  st.write("Here they are!")
60
+ st.dataframe(df)
61
 
62
  st.button("Re-run")
functions.py CHANGED
@@ -172,9 +172,9 @@ def get_aplevel(temps:np.ndarray, table:list):
172
  level = [table[el] for el in cat[1]]
173
  return level
174
 
175
- def get_color(level:list):
176
- air_pollution_level = ['Good', 'Moderate', 'Unhealthy for sensitive Groups','Unhealthy' ,'Very Unhealthy', 'Hazardous']
177
- color_list = ["Green", "Yellow", "DarkOrange", "Red", "Purple", "DarkRed"]
178
- ind = [air_pollution_level.index(lel) for lel in level]
179
- text = [f"color:{color_list[idex]};" for idex in ind]
180
- return text
 
172
  level = [table[el] for el in cat[1]]
173
  return level
174
 
175
+ def get_info(level:list):
176
+ air_pollution_level = {1:[50, 'Good', 'Green'], 2:[100, 'Moderate','Yellow'], 3:[150, 'Unhealthy for sensitive Groups','DarkOrange'],4:[200, 'Unhealthy','Red'] ,5:[300, 'Very Unhealthy','Purple'], 6:[1000, 'Hazardous','DarkRed']}
177
+ ind = [np.max(np.nonzero( el >= [air_pollution_level[key][0] for key in air_pollution_level.keys()])) for el in level]
178
+ color_text = [f"color:{air_pollution_level[idex][2]};" for idex in ind]
179
+ pollution_level = [air_pollution_level[idex][1] for idex in ind]
180
+ return color_text, pollution_level