Update app.py
Browse files
app.py
CHANGED
@@ -17,16 +17,16 @@ def load_timeseries_data_for_month(month):
|
|
17 |
end_date = (pd.to_datetime(month) + pd.offsets.MonthEnd()).strftime('%Y-%m-%d')
|
18 |
file_name = f"enel_timeseries_data_{start_date}_{end_date}.csv"
|
19 |
if not os.path.exists(file_name):
|
20 |
-
return None
|
21 |
-
return pd.read_csv(file_name, index_col=0, header=[0, 1, 2], parse_dates=True)
|
22 |
|
23 |
def load_other_features_data_for_month(month):
|
24 |
start_date = pd.to_datetime(month).strftime('%Y-%m-01')
|
25 |
end_date = (pd.to_datetime(month) + pd.offsets.MonthEnd()).strftime('%Y-%m-%d')
|
26 |
file_name = f"enel_other_features_data_{start_date}_{end_date}.csv"
|
27 |
if not os.path.exists(file_name):
|
28 |
-
return None
|
29 |
-
return pd.read_csv(file_name, index_col=0, header=0, parse_dates=True)
|
30 |
|
31 |
# Define the available months
|
32 |
months = pd.date_range(start='2022-09-01', end='2023-08-31', freq='MS').strftime('%Y-%m').tolist()
|
@@ -53,13 +53,14 @@ month_selector = pn.widgets.Select(
|
|
53 |
|
54 |
inverter_ids = pn.widgets.MultiSelect(
|
55 |
name="Inverter IDs",
|
56 |
-
value=[list(INVERTER_ID_MAPPING.keys())[0]],
|
57 |
options=list(INVERTER_ID_MAPPING.keys()),
|
58 |
size=8,
|
|
|
59 |
)
|
|
|
60 |
# Line Plots
|
61 |
-
plot_power_curves = pn.widgets.Checkbox(name="Plot P-dc and P-ac", value=False)
|
62 |
-
plot_temperature_curves = pn.widgets.Checkbox(name="Plot Temperatures", value=False)
|
63 |
|
64 |
# Heatmaps
|
65 |
heatmap_pr = pn.widgets.Checkbox(name="Heat Map PR", value=False)
|
@@ -68,37 +69,46 @@ heatmap_current = pn.widgets.Checkbox(name="Heat Map - Current", value=False)
|
|
68 |
heatmap_voltage = pn.widgets.Checkbox(name="Heat Map - Voltage", value=False)
|
69 |
heatmap_power = pn.widgets.Checkbox(name="Heat Map - Power", value=False)
|
70 |
heatmap_irradiance = pn.widgets.Checkbox(name="Heat Map - Irradiance", value=False)
|
71 |
-
heatmap_temperature = pn.widgets.Checkbox(
|
72 |
-
name="Heat Map - Temperature Heatsink", value=False
|
73 |
-
)
|
74 |
|
75 |
# Create a loading spinner
|
76 |
-
loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50)
|
77 |
|
78 |
# Global variables to store loaded data
|
79 |
loaded_timeseries_data = None
|
80 |
loaded_other_features_data = None
|
81 |
loaded_month = None
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# Panel interactive functions
|
84 |
@pn.depends(
|
85 |
-
month_selector.param.value,
|
86 |
inverter_ids.param.value,
|
87 |
plot_power_curves.param.value,
|
88 |
plot_temperature_curves.param.value
|
89 |
)
|
90 |
-
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves
|
91 |
-
|
92 |
-
|
93 |
-
return pn.pane.Markdown("Please select a month to load data.")
|
94 |
-
|
95 |
-
if loaded_month != selected_month:
|
96 |
-
loaded_timeseries_data = load_timeseries_data_for_month(selected_month)
|
97 |
-
loaded_other_features_data = load_other_features_data_for_month(selected_month)
|
98 |
-
loaded_month = selected_month
|
99 |
-
|
100 |
-
if loaded_timeseries_data is None or loaded_other_features_data is None:
|
101 |
-
return pn.pane.Markdown("No data available for the selected month.")
|
102 |
|
103 |
if not inverter_ids:
|
104 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
@@ -195,6 +205,8 @@ def update_heatmap_temperature(heatmap_temperature):
|
|
195 |
dashboard = pn.Column(
|
196 |
"# ENEL Dashboard",
|
197 |
month_selector,
|
|
|
|
|
198 |
# IV Plots
|
199 |
pn.Row(
|
200 |
pn.Column(inverter_ids, plot_power_curves, plot_temperature_curves),
|
|
|
17 |
end_date = (pd.to_datetime(month) + pd.offsets.MonthEnd()).strftime('%Y-%m-%d')
|
18 |
file_name = f"enel_timeseries_data_{start_date}_{end_date}.csv"
|
19 |
if not os.path.exists(file_name):
|
20 |
+
return None, file_name
|
21 |
+
return pd.read_csv(file_name, index_col=0, header=[0, 1, 2], parse_dates=True), file_name
|
22 |
|
23 |
def load_other_features_data_for_month(month):
|
24 |
start_date = pd.to_datetime(month).strftime('%Y-%m-01')
|
25 |
end_date = (pd.to_datetime(month) + pd.offsets.MonthEnd()).strftime('%Y-%m-%d')
|
26 |
file_name = f"enel_other_features_data_{start_date}_{end_date}.csv"
|
27 |
if not os.path.exists(file_name):
|
28 |
+
return None, file_name
|
29 |
+
return pd.read_csv(file_name, index_col=0, header=0, parse_dates=True), file_name
|
30 |
|
31 |
# Define the available months
|
32 |
months = pd.date_range(start='2022-09-01', end='2023-08-31', freq='MS').strftime('%Y-%m').tolist()
|
|
|
53 |
|
54 |
inverter_ids = pn.widgets.MultiSelect(
|
55 |
name="Inverter IDs",
|
|
|
56 |
options=list(INVERTER_ID_MAPPING.keys()),
|
57 |
size=8,
|
58 |
+
disabled=True,
|
59 |
)
|
60 |
+
|
61 |
# Line Plots
|
62 |
+
plot_power_curves = pn.widgets.Checkbox(name="Plot P-dc and P-ac", value=False, disabled=True)
|
63 |
+
plot_temperature_curves = pn.widgets.Checkbox(name="Plot Temperatures", value=False, disabled=True)
|
64 |
|
65 |
# Heatmaps
|
66 |
heatmap_pr = pn.widgets.Checkbox(name="Heat Map PR", value=False)
|
|
|
69 |
heatmap_voltage = pn.widgets.Checkbox(name="Heat Map - Voltage", value=False)
|
70 |
heatmap_power = pn.widgets.Checkbox(name="Heat Map - Power", value=False)
|
71 |
heatmap_irradiance = pn.widgets.Checkbox(name="Heat Map - Irradiance", value=False)
|
72 |
+
heatmap_temperature = pn.widgets.Checkbox(name="Heat Map - Temperature Heatsink", value=False)
|
|
|
|
|
73 |
|
74 |
# Create a loading spinner
|
75 |
+
loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50, visible=False)
|
76 |
|
77 |
# Global variables to store loaded data
|
78 |
loaded_timeseries_data = None
|
79 |
loaded_other_features_data = None
|
80 |
loaded_month = None
|
81 |
|
82 |
+
# Function to load data based on selected month
|
83 |
+
@pn.depends(month_selector.param.value, watch=True)
|
84 |
+
def load_data(selected_month):
|
85 |
+
global loaded_timeseries_data, loaded_other_features_data, loaded_month
|
86 |
+
if not selected_month:
|
87 |
+
return
|
88 |
+
loading_spinner.visible = True
|
89 |
+
timeseries_data, timeseries_file = load_timeseries_data_for_month(selected_month)
|
90 |
+
other_features_data, other_features_file = load_other_features_data_for_month(selected_month)
|
91 |
+
if timeseries_data is None or other_features_data is None:
|
92 |
+
loading_spinner.visible = False
|
93 |
+
return pn.pane.Markdown(f"Files not found: {timeseries_file if timeseries_data is None else ''} {other_features_file if other_features_data is None else ''}")
|
94 |
+
loaded_timeseries_data = timeseries_data
|
95 |
+
loaded_other_features_data = other_features_data
|
96 |
+
loaded_month = selected_month
|
97 |
+
loading_spinner.visible = False
|
98 |
+
inverter_ids.disabled = False
|
99 |
+
plot_power_curves.disabled = False
|
100 |
+
plot_temperature_curves.disabled = False
|
101 |
+
return pn.pane.Markdown(f"Data loaded for month: {selected_month}")
|
102 |
+
|
103 |
# Panel interactive functions
|
104 |
@pn.depends(
|
|
|
105 |
inverter_ids.param.value,
|
106 |
plot_power_curves.param.value,
|
107 |
plot_temperature_curves.param.value
|
108 |
)
|
109 |
+
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves):
|
110 |
+
if not loaded_timeseries_data or not loaded_other_features_data:
|
111 |
+
return pn.pane.Markdown("No data loaded.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
if not inverter_ids:
|
114 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
|
|
205 |
dashboard = pn.Column(
|
206 |
"# ENEL Dashboard",
|
207 |
month_selector,
|
208 |
+
loading_spinner,
|
209 |
+
pn.panel(load_data),
|
210 |
# IV Plots
|
211 |
pn.Row(
|
212 |
pn.Column(inverter_ids, plot_power_curves, plot_temperature_curves),
|