kk90ujhun commited on
Commit
0262e90
·
1 Parent(s): 8f641be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -103
app.py CHANGED
@@ -35,116 +35,109 @@ feature_view = fs.get_feature_view(
35
  st.write("Successfully connected!✔️")
36
  progress_bar.progress(20)
37
 
38
- # st.write(36 * "-")
39
- # fancy_header('\n☁️ Getting batch data from Feature Store...')
40
-
41
- # start_date = datetime.now() - timedelta(days=1)
42
- # start_time = int(start_date.timestamp()) * 1000
43
-
44
- # # X = feature_view.get_batch_data(start_time=start_time)
45
-
46
- # # 1662652800000
47
- # X = feature_view.get_batch_data(start_time=1662652800000)
48
- # progress_bar.progress(50)
49
-
50
- # print(X.date.values)
51
-
52
- # latest_date_unix = str(X.date.values[0])[:10]
53
- # latest_date = time.ctime(int(latest_date_unix))
54
-
55
- # st.write(f"⏱ Data for {latest_date}")
56
-
57
- # X = X.drop(columns=["date"]).fillna(0)
58
- # print("X is \n %s" % X)
59
-
60
- # data_to_display = decode_features(X, feature_view=feature_view)
61
-
62
- # progress_bar.progress(60)
63
-
64
- # st.write(36 * "-")
65
- # fancy_header(f"🗺 Processing the map...")
66
-
67
- # fig = Figure(width=550,height=350)
68
-
69
- # my_map = folium.Map(location=[58, 20], zoom_start=3.71)
70
- # fig.add_child(my_map)
71
- # folium.TileLayer('Stamen Terrain').add_to(my_map)
72
- # folium.TileLayer('Stamen Toner').add_to(my_map)
73
- # folium.TileLayer('Stamen Water Color').add_to(my_map)
74
- # folium.TileLayer('cartodbpositron').add_to(my_map)
75
- # folium.TileLayer('cartodbdark_matter').add_to(my_map)
76
- # folium.LayerControl().add_to(my_map)
77
-
78
- # data_to_display = data_to_display[["city", "temp", "humidity",
79
- # "conditions", "aqi"]]
80
-
81
- # cities_coords = {("Sundsvall", "Sweden"): [62.390811, 17.306927],
82
- # ("Stockholm", "Sweden"): [59.334591, 18.063240],
83
- # ("Malmo", "Sweden"): [55.604981, 13.003822],
84
- # ("Kyiv", "Ukraine"): [50.450001, 30.523333]}
85
-
86
- # # if "Kyiv" in data_to_display["city"]:
87
- # # cities_coords[("Kyiv", "Ukraine")]: [50.450001, 30.523333]
88
- # # pass
89
-
90
- # data_to_display = data_to_display.set_index("city")
91
-
92
- # cols_names_dict = {"temp": "Temperature",
93
- # "humidity": "Humidity",
94
- # "conditions": "Conditions",
95
- # "aqi": "AQI"}
96
-
97
- # data_to_display = data_to_display.rename(columns=cols_names_dict)
98
-
99
- # cols_ = ["Temperature", "Humidity", "AQI"]
100
- # data_to_display[cols_] = data_to_display[cols_].apply(lambda x: round(x, 1))
101
 
102
- # for city, country in cities_coords:
103
- # text = f"""
104
- # <h4 style="color:green;">{city}</h4>
105
- # <h5 style="color":"green">
106
- # <table style="text-align: right;">
107
- # <tr>
108
- # <th>Country:</th>
109
- # <td><b>{country}</b></td>
110
- # </tr>
111
- # """
112
- # for column in data_to_display.columns:
113
- # text += f"""
114
- # <tr>
115
- # <th>{column}:</th>
116
- # <td>{data_to_display.loc[city][column]}</td>
117
- # </tr>"""
118
- # text += """</table>
119
- # </h5>"""
120
 
121
- # folium.Marker(
122
- # cities_coords[(city, country)], popup=text, tooltip=f"<strong>{city}</strong>"
123
- # ).add_to(my_map)
124
 
 
 
125
 
126
- # # call to render Folium map in Streamlit
127
- # folium_static(my_map)
128
- # progress_bar.progress(80)
129
- # st.sidebar.write("-" * 36)
130
 
 
 
131
 
132
- # model = get_model(project=project,
133
- # model_name="gradient_boost_model",
134
- # evaluation_metric="f1_score",
135
- # sort_metrics_by="max")
136
 
137
- # preds = model.predict(X)
 
138
 
139
- # cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
140
- # print("cities are %s" % cities)
 
141
 
142
- # next_day_date = datetime.today() + timedelta(days=1)
143
- # next_day = next_day_date.strftime ('%d/%m/%Y')
144
- # print("preds is %s" % preds)
145
- # df = pd.DataFrame(data=preds, index=cities, columns=[f"AQI Predictions for {next_day}"], dtype=int)
146
 
147
- # st.sidebar.write(df)
148
- # progress_bar.progress(100)
149
- # st.button("Re-run")
150
- # # hi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  st.write("Successfully connected!✔️")
36
  progress_bar.progress(20)
37
 
38
+ st.write(36 * "-")
39
+ fancy_header('\n☁️ Getting batch data from Feature Store...')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
+ start_date = datetime.now() - timedelta(days=1)
42
+ start_time = int(start_date.timestamp()) * 1000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ # X = feature_view.get_batch_data(start_time=start_time)
 
 
45
 
46
+ X = feature_view.get_batch_data(start_time=1673625600000)
47
+ progress_bar.progress(50)
48
 
49
+ print(X.date.values)
 
 
 
50
 
51
+ latest_date_unix = str(X.date.values[0])[:10]
52
+ latest_date = time.ctime(int(latest_date_unix))
53
 
54
+ st.write(f"⏱ Data for {latest_date}")
 
 
 
55
 
56
+ X = X.drop(columns=["date"]).fillna(0)
57
+ print("X is \n %s" % X)
58
 
59
+ data_to_display = decode_features(X, feature_view=feature_view)
60
+ data_to_display["city"] = "Oslo"
61
+ # print(data_to_display)
62
 
63
+ progress_bar.progress(60)
 
 
 
64
 
65
+ st.write(36 * "-")
66
+ fancy_header(f"🗺 Processing the map...")
67
+
68
+ fig = Figure(width=550,height=350)
69
+
70
+ my_map = folium.Map(location=[58, 20], zoom_start=3.71)
71
+ fig.add_child(my_map)
72
+ folium.TileLayer('Stamen Terrain').add_to(my_map)
73
+ folium.TileLayer('Stamen Toner').add_to(my_map)
74
+ folium.TileLayer('Stamen Water Color').add_to(my_map)
75
+ folium.TileLayer('cartodbpositron').add_to(my_map)
76
+ folium.TileLayer('cartodbdark_matter').add_to(my_map)
77
+ folium.LayerControl().add_to(my_map)
78
+
79
+ data_to_display = data_to_display[["city", "temp", "humidity",
80
+ "conditions", "aqi"]]
81
+
82
+ cities_coords = {("Oslo", "Norway"): [59.9139, 10.7522]}
83
+
84
+ data_to_display = data_to_display.set_index("city")
85
+
86
+ cols_names_dict = {"temp": "Temperature",
87
+ "humidity": "Humidity",
88
+ "conditions": "Conditions",
89
+ "aqi": "AQI"}
90
+
91
+ data_to_display = data_to_display.rename(columns=cols_names_dict)
92
+
93
+ cols_ = ["Temperature", "Humidity", "AQI"]
94
+ data_to_display[cols_] = data_to_display[cols_].apply(lambda x: round(x, 1))
95
+
96
+ for city, country in cities_coords:
97
+ text = f"""
98
+ <h4 style="color:green;">{city}</h4>
99
+ <h5 style="color":"green">
100
+ <table style="text-align: right;">
101
+ <tr>
102
+ <th>Country:</th>
103
+ <td><b>{country}</b></td>
104
+ </tr>
105
+ """
106
+ for column in data_to_display.columns:
107
+ text += f"""
108
+ <tr>
109
+ <th>{column}:</th>
110
+ <td>{data_to_display.loc[city][column]}</td>
111
+ </tr>"""
112
+ text += """</table>
113
+ </h5>"""
114
+
115
+ folium.Marker(
116
+ cities_coords[(city, country)], popup=text, tooltip=f"<strong>{city}</strong>"
117
+ ).add_to(my_map)
118
+
119
+
120
+ # call to render Folium map in Streamlit
121
+ folium_static(my_map)
122
+ progress_bar.progress(80)
123
+ st.sidebar.write("-" * 36)
124
+
125
+
126
+ model = get_model(project=project,
127
+ model_name="gradient_boost_model",
128
+ evaluation_metric="f1_score",
129
+ sort_metrics_by="max")
130
+
131
+ preds = model.predict(X)
132
+
133
+ cities = [city_tuple[0] for city_tuple in cities_coords.keys()]
134
+ print("cities are %s" % cities)
135
+
136
+ next_day_date = datetime.today() + timedelta(days=1)
137
+ next_day = next_day_date.strftime ('%d/%m/%Y')
138
+ print("preds is %s" % preds)
139
+ df = pd.DataFrame(data=preds, index=cities, columns=[f"AQI Predictions for {next_day}"], dtype=int)
140
+
141
+ st.sidebar.write(df)
142
+ progress_bar.progress(100)
143
+ st.button("Re-run")