Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import panel as pn
|
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
|
5 |
-
from consts import INVERTER_ID_MAPPING, TEMPERATURE_COLUMNS_TO_USE
|
6 |
from plotting import (
|
7 |
create_heatmap,
|
8 |
create_iv_plot_with_power_curves,
|
@@ -11,33 +11,32 @@ from plotting import (
|
|
11 |
create_iv_plot_with_temperature_curves,
|
12 |
)
|
13 |
|
14 |
-
# Function to load chunked data based on
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
file_name = f"enel_timeseries_data_{
|
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
|
24 |
-
|
25 |
-
|
26 |
-
file_name = f"enel_other_features_data_{
|
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
|
32 |
-
|
33 |
-
end_date = pd.Timestamp('2023-08-31').date()
|
34 |
|
35 |
kpi_data = pd.read_csv(
|
36 |
-
|
37 |
)
|
38 |
|
39 |
daily_timeseries_data = pd.read_csv(
|
40 |
-
|
41 |
index_col=0,
|
42 |
header=0,
|
43 |
parse_dates=True,
|
@@ -46,12 +45,10 @@ daily_timeseries_data = pd.read_csv(
|
|
46 |
# Initialize Panel extension
|
47 |
pn.extension("plotly")
|
48 |
|
49 |
-
# Widgets for selecting
|
50 |
-
|
51 |
-
name='
|
52 |
-
|
53 |
-
end=end_date,
|
54 |
-
value=(start_date, (start_date + pd.DateOffset(months=1)).date())
|
55 |
)
|
56 |
|
57 |
inverter_ids = pn.widgets.MultiSelect(
|
@@ -78,23 +75,28 @@ heatmap_temperature = pn.widgets.Checkbox(
|
|
78 |
# Create a loading spinner
|
79 |
loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50)
|
80 |
|
|
|
|
|
|
|
|
|
81 |
# Panel interactive functions
|
82 |
@pn.depends(
|
83 |
inverter_ids.param.value,
|
84 |
plot_power_curves.param.value,
|
85 |
plot_temperature_curves.param.value,
|
86 |
-
|
87 |
)
|
88 |
-
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves,
|
89 |
-
|
90 |
-
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
if
|
97 |
-
return pn.pane.Markdown("No data available for the selected
|
98 |
|
99 |
if not inverter_ids:
|
100 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
@@ -102,19 +104,19 @@ def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves, dat
|
|
102 |
# Plot IV + Power + Temperature Curves
|
103 |
if plot_power_curves and plot_temperature_curves:
|
104 |
return create_iv_plot_with_power_and_temperature_curves(
|
105 |
-
|
106 |
)
|
107 |
# Plot IV + Temperature Curves
|
108 |
elif (not plot_power_curves) and plot_temperature_curves:
|
109 |
return create_iv_plot_with_temperature_curves(
|
110 |
-
|
111 |
)
|
112 |
# Plot IV + Power Curves
|
113 |
elif plot_power_curves and (not plot_temperature_curves):
|
114 |
-
return create_iv_plot_with_power_curves(
|
115 |
# Plot only IV Curves
|
116 |
else:
|
117 |
-
return create_iv_plot(
|
118 |
|
119 |
|
120 |
@pn.depends(heatmap_pr.param.value)
|
@@ -190,7 +192,7 @@ def update_heatmap_temperature(heatmap_temperature):
|
|
190 |
# Create dashboard layout
|
191 |
dashboard = pn.Column(
|
192 |
"# ENEL Dashboard",
|
193 |
-
|
194 |
# IV Plots
|
195 |
pn.Row(
|
196 |
pn.Column(inverter_ids, plot_power_curves, plot_temperature_curves),
|
|
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
|
5 |
+
from consts import INVERTER_ID_MAPPING, TEMPERATURE_COLUMNS_TO_USE, CURRENT, IRRADIANCE, VOLTAGE, POWER_DC, POWER_AC, T_AMBIENT, T_MODULE, T_HEATSINK, T_CPU, T_BOARD
|
6 |
from plotting import (
|
7 |
create_heatmap,
|
8 |
create_iv_plot_with_power_curves,
|
|
|
11 |
create_iv_plot_with_temperature_curves,
|
12 |
)
|
13 |
|
14 |
+
# Function to load chunked data based on month selection
|
15 |
+
def load_timeseries_data_for_month(month):
|
16 |
+
start_date = pd.to_datetime(month).strftime('%Y-%m-01')
|
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()
|
|
|
33 |
|
34 |
kpi_data = pd.read_csv(
|
35 |
+
"kpi_data.csv", index_col=0, header=0, parse_dates=True
|
36 |
)
|
37 |
|
38 |
daily_timeseries_data = pd.read_csv(
|
39 |
+
"daily_aggregated_timeseries_data.csv",
|
40 |
index_col=0,
|
41 |
header=0,
|
42 |
parse_dates=True,
|
|
|
45 |
# Initialize Panel extension
|
46 |
pn.extension("plotly")
|
47 |
|
48 |
+
# Widgets for selecting month and columns
|
49 |
+
month_selector = pn.widgets.Select(
|
50 |
+
name='Choose a Month',
|
51 |
+
options=months,
|
|
|
|
|
52 |
)
|
53 |
|
54 |
inverter_ids = pn.widgets.MultiSelect(
|
|
|
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 |
+
|
82 |
# Panel interactive functions
|
83 |
@pn.depends(
|
84 |
inverter_ids.param.value,
|
85 |
plot_power_curves.param.value,
|
86 |
plot_temperature_curves.param.value,
|
87 |
+
month_selector.param.value
|
88 |
)
|
89 |
+
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves, selected_month):
|
90 |
+
global loaded_timeseries_data, loaded_other_features_data
|
91 |
+
if not selected_month:
|
92 |
+
return pn.pane.Markdown("Please select a month to load data.")
|
93 |
|
94 |
+
if loaded_timeseries_data is None or loaded_other_features_data is None:
|
95 |
+
loaded_timeseries_data = load_timeseries_data_for_month(selected_month)
|
96 |
+
loaded_other_features_data = load_other_features_data_for_month(selected_month)
|
97 |
+
|
98 |
+
if loaded_timeseries_data is None or loaded_other_features_data is None:
|
99 |
+
return pn.pane.Markdown("No data available for the selected month.")
|
100 |
|
101 |
if not inverter_ids:
|
102 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
|
|
104 |
# Plot IV + Power + Temperature Curves
|
105 |
if plot_power_curves and plot_temperature_curves:
|
106 |
return create_iv_plot_with_power_and_temperature_curves(
|
107 |
+
loaded_timeseries_data, loaded_other_features_data, inverter_ids
|
108 |
)
|
109 |
# Plot IV + Temperature Curves
|
110 |
elif (not plot_power_curves) and plot_temperature_curves:
|
111 |
return create_iv_plot_with_temperature_curves(
|
112 |
+
loaded_timeseries_data, loaded_other_features_data, inverter_ids
|
113 |
)
|
114 |
# Plot IV + Power Curves
|
115 |
elif plot_power_curves and (not plot_temperature_curves):
|
116 |
+
return create_iv_plot_with_power_curves(loaded_timeseries_data, inverter_ids)
|
117 |
# Plot only IV Curves
|
118 |
else:
|
119 |
+
return create_iv_plot(loaded_timeseries_data, inverter_ids)
|
120 |
|
121 |
|
122 |
@pn.depends(heatmap_pr.param.value)
|
|
|
192 |
# Create dashboard layout
|
193 |
dashboard = pn.Column(
|
194 |
"# ENEL Dashboard",
|
195 |
+
month_selector,
|
196 |
# IV Plots
|
197 |
pn.Row(
|
198 |
pn.Column(inverter_ids, plot_power_curves, plot_temperature_curves),
|