marcopellegrino
commited on
Commit
•
de2cfd4
1
Parent(s):
78643cb
add webapp
Browse files- resources/.DS_Store +0 -0
- webapp.py +83 -0
resources/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
webapp.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import altair as alt
|
2 |
+
import pandas as pd
|
3 |
+
import streamlit as st
|
4 |
+
import hopsworks
|
5 |
+
|
6 |
+
# Connect to Hopsworks
|
7 |
+
project = hopsworks.login()
|
8 |
+
fs = project.get_feature_store()
|
9 |
+
dataset_api = project.get_dataset_api()
|
10 |
+
|
11 |
+
# download the forecast to the local environment
|
12 |
+
dataset_api.download('Resources/weather_forecast/forecast.csv', overwrite=True)
|
13 |
+
|
14 |
+
# Read CSV file without setting any column as the index
|
15 |
+
df = pd.read_csv('resources/forecast.csv', index_col=None)
|
16 |
+
|
17 |
+
#df_mapping = pd.read_csv('resources/weather_code_mapping.csv', index_col=None)
|
18 |
+
#df_mapping = df_mapping[['weather_code', 'weather_code_group']]
|
19 |
+
# Merge DataFrames on the 'weather_code' column
|
20 |
+
#df = pd.merge(df, df_mapping, left_on='weather_code_prediction', right_on='weather_code', how='left')
|
21 |
+
#df['weather_code_group_label'] = df['weather_code'].astype(str) + '-' + df['weather_code_group']
|
22 |
+
|
23 |
+
# Drop the index column if it exists
|
24 |
+
df = df.loc[:, ~df.columns.str.contains('^Unnamed')]
|
25 |
+
|
26 |
+
df_print = df[['date', 'temperature_min', 'precipitation_sum', 'wind_gusts_max', 'weather_code_prediction','weather_code_group']]
|
27 |
+
df_print.temperature_min = df_print.temperature_min.round()
|
28 |
+
df_print.precipitation_sum = df_print.precipitation_sum.round()
|
29 |
+
df_print.wind_gusts_max = df_print.wind_gusts_max.round()
|
30 |
+
df_print.rename(columns = {'date':'Day',
|
31 |
+
'temperature_min':'Temperature Min [°C]',
|
32 |
+
'precipitation_sum':'Precipitation Sum [mm]',
|
33 |
+
'wind_gusts_max':'Wind Gusts Max [km/h]',
|
34 |
+
'weather_code_prediction':'Weather code',
|
35 |
+
'weather_code_group':'Weather'
|
36 |
+
}, inplace = True)
|
37 |
+
|
38 |
+
|
39 |
+
st.title('Weather Code Forecast for Stockholm')
|
40 |
+
|
41 |
+
st.dataframe(df_print, hide_index=True,)
|
42 |
+
|
43 |
+
# Define the base time-series chart.
|
44 |
+
def get_chart(data):
|
45 |
+
hover = alt.selection_single(
|
46 |
+
fields=["date"],
|
47 |
+
nearest=True,
|
48 |
+
on="mouseover",
|
49 |
+
empty="none",
|
50 |
+
)
|
51 |
+
|
52 |
+
lines = (
|
53 |
+
alt.Chart(data, title="Evolution of Weather Code")
|
54 |
+
.mark_line()
|
55 |
+
.encode(
|
56 |
+
x=alt.X("date:T", title="Date", axis=alt.Axis(labelAngle=-60)), # Adjust labelAngle as needed
|
57 |
+
y=alt.Y("weather_code_prediction:Q", title="Weather Code", scale=alt.Scale(domain=[1, 13]))
|
58 |
+
)
|
59 |
+
)
|
60 |
+
|
61 |
+
# Draw points on the line, and highlight based on selection
|
62 |
+
points = lines.transform_filter(hover).mark_circle(size=65)
|
63 |
+
|
64 |
+
# Draw a rule at the location of the selection
|
65 |
+
tooltips = (
|
66 |
+
alt.Chart(data)
|
67 |
+
.mark_rule()
|
68 |
+
.encode(
|
69 |
+
x=alt.X("yearmonthdate(date):T", title="Date"),
|
70 |
+
y=alt.Y("weather_code_prediction:Q", title="Weather Code", scale=alt.Scale(domain=[1, 13])),
|
71 |
+
opacity=alt.condition(hover, alt.value(0.3), alt.value(0)),
|
72 |
+
tooltip=[
|
73 |
+
alt.Tooltip("date:T", title="Date"),
|
74 |
+
alt.Tooltip("weather_code_label", title="Weather code"),
|
75 |
+
alt.Tooltip("weather_code_prediction", title="Weather code level"),
|
76 |
+
],
|
77 |
+
)
|
78 |
+
.add_selection(hover)
|
79 |
+
)
|
80 |
+
return (lines + points + tooltips).interactive()
|
81 |
+
|
82 |
+
st.altair_chart(get_chart(df).interactive(),
|
83 |
+
use_container_width=True)
|