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,30 @@ from plotting import (
|
|
11 |
create_iv_plot_with_temperature_curves,
|
12 |
)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
# Filter the necessary columns
|
27 |
-
chunk = chunk[columns]
|
28 |
-
|
29 |
-
# Apply date range filtering if necessary
|
30 |
-
if start_date and end_date:
|
31 |
-
chunk = chunk[(chunk.index >= start_date) & (chunk.index <= end_date)]
|
32 |
-
|
33 |
-
chunks.append(chunk)
|
34 |
-
|
35 |
-
return pd.concat(chunks)
|
36 |
|
37 |
# Initialize Panel extension
|
38 |
pn.extension("plotly")
|
39 |
|
40 |
-
# Widgets for selecting columns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
inverter_ids = pn.widgets.MultiSelect(
|
42 |
name="Inverter IDs",
|
43 |
value=[list(INVERTER_ID_MAPPING.keys())[0]],
|
@@ -62,31 +59,21 @@ heatmap_temperature = pn.widgets.Checkbox(
|
|
62 |
# Create a loading spinner
|
63 |
loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50)
|
64 |
|
|
|
65 |
@pn.depends(
|
66 |
inverter_ids.param.value,
|
67 |
plot_power_curves.param.value,
|
68 |
plot_temperature_curves.param.value,
|
|
|
69 |
)
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves):
|
76 |
if not inverter_ids:
|
77 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
78 |
else:
|
79 |
-
selected_columns = []
|
80 |
-
if plot_power_curves:
|
81 |
-
selected_columns += [CURRENT, IRRADIANCE, VOLTAGE, POWER_DC, POWER_AC]
|
82 |
-
if plot_temperature_curves:
|
83 |
-
selected_columns += [T_AMBIENT, T_MODULE, T_HEATSINK, T_CPU, T_BOARD]
|
84 |
-
if not plot_power_curves and not plot_temperature_curves:
|
85 |
-
selected_columns += [CURRENT, IRRADIANCE, VOLTAGE]
|
86 |
-
|
87 |
-
timeseries_data = load_data_in_chunks('multi_index_timeseries_data.csv', selected_columns)
|
88 |
-
other_features_data = load_data_in_chunks('other_features_data.csv', TEMPERATURE_COLUMNS_TO_USE)
|
89 |
-
|
90 |
# Plot IV + Power + Temperature Curves
|
91 |
if plot_power_curves and plot_temperature_curves:
|
92 |
print("Plotting IV + Power + Temperature Curves")
|
@@ -108,6 +95,7 @@ def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves):
|
|
108 |
print("Plot only IV Curves")
|
109 |
return create_iv_plot(timeseries_data, inverter_ids)
|
110 |
|
|
|
111 |
@pn.depends(heatmap_pr.param.value)
|
112 |
def update_heatmap_pr(heatmap_pr):
|
113 |
if heatmap_pr:
|
@@ -117,6 +105,7 @@ def update_heatmap_pr(heatmap_pr):
|
|
117 |
return pn.Row(pr_heatmap)
|
118 |
return pn.pane.Markdown("")
|
119 |
|
|
|
120 |
@pn.depends(heatmap_sy.param.value)
|
121 |
def update_heatmap_sy(heatmap_sy):
|
122 |
if heatmap_sy:
|
@@ -126,6 +115,7 @@ def update_heatmap_sy(heatmap_sy):
|
|
126 |
return pn.Row(sy_heatmap)
|
127 |
return pn.pane.Markdown("")
|
128 |
|
|
|
129 |
@pn.depends(heatmap_current.param.value)
|
130 |
def update_heatmap_current(heatmap_current):
|
131 |
if heatmap_current:
|
@@ -135,6 +125,7 @@ def update_heatmap_current(heatmap_current):
|
|
135 |
return pn.Row(current_heatmap)
|
136 |
return pn.pane.Markdown("")
|
137 |
|
|
|
138 |
@pn.depends(heatmap_voltage.param.value)
|
139 |
def update_heatmap_voltage(heatmap_voltage):
|
140 |
if heatmap_voltage:
|
@@ -144,6 +135,7 @@ def update_heatmap_voltage(heatmap_voltage):
|
|
144 |
return pn.Row(voltage_heatmap)
|
145 |
return pn.pane.Markdown("")
|
146 |
|
|
|
147 |
@pn.depends(heatmap_power.param.value)
|
148 |
def update_heatmap_power(heatmap_power):
|
149 |
if heatmap_power:
|
@@ -153,6 +145,7 @@ def update_heatmap_power(heatmap_power):
|
|
153 |
return pn.Row(power_heatmap)
|
154 |
return pn.pane.Markdown("")
|
155 |
|
|
|
156 |
@pn.depends(heatmap_irradiance.param.value)
|
157 |
def update_heatmap_irradiance(heatmap_irradiance):
|
158 |
if heatmap_irradiance:
|
@@ -162,6 +155,7 @@ def update_heatmap_irradiance(heatmap_irradiance):
|
|
162 |
return pn.Row(irradiance_heatmap)
|
163 |
return pn.pane.Markdown("")
|
164 |
|
|
|
165 |
@pn.depends(heatmap_temperature.param.value)
|
166 |
def update_heatmap_temperature(heatmap_temperature):
|
167 |
if heatmap_temperature:
|
@@ -171,6 +165,7 @@ def update_heatmap_temperature(heatmap_temperature):
|
|
171 |
return pn.Row(temp_heatmap)
|
172 |
return pn.pane.Markdown("")
|
173 |
|
|
|
174 |
# Create dashboard layout
|
175 |
dashboard = pn.Column(
|
176 |
"# ENEL Dashboard",
|
|
|
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 |
create_iv_plot_with_temperature_curves,
|
12 |
)
|
13 |
|
14 |
+
# Function to load chunked data based on date range
|
15 |
+
def load_timeseries_data(start_date, end_date):
|
16 |
+
file_name = f"enel_timeseries_data_{start_date}_{end_date}.csv"
|
17 |
+
return pd.read_csv(file_name, index_col=0, header=[0, 1, 2], parse_dates=True)
|
18 |
+
|
19 |
+
def load_other_features_data(start_date, end_date):
|
20 |
+
file_name = f"enel_other_features_data_{start_date}_{end_date}.csv"
|
21 |
+
return pd.read_csv(file_name, index_col=0, header=0, parse_dates=True)
|
22 |
+
|
23 |
+
kpi_data = pd.read_csv(
|
24 |
+
r"kpi_data.csv", index_col=0, header=0, parse_dates=True
|
25 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Initialize Panel extension
|
28 |
pn.extension("plotly")
|
29 |
|
30 |
+
# Widgets for selecting date range and columns
|
31 |
+
date_range_picker = pn.widgets.DateRangePicker(
|
32 |
+
name='Date Range',
|
33 |
+
start=pd.Timestamp('2022-09-01'),
|
34 |
+
end=pd.Timestamp('2023-08-31'),
|
35 |
+
value=(start, end + pd.DateOffset(months=1))
|
36 |
+
)
|
37 |
+
|
38 |
inverter_ids = pn.widgets.MultiSelect(
|
39 |
name="Inverter IDs",
|
40 |
value=[list(INVERTER_ID_MAPPING.keys())[0]],
|
|
|
59 |
# Create a loading spinner
|
60 |
loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50)
|
61 |
|
62 |
+
# Panel interactive functions
|
63 |
@pn.depends(
|
64 |
inverter_ids.param.value,
|
65 |
plot_power_curves.param.value,
|
66 |
plot_temperature_curves.param.value,
|
67 |
+
date_range_picker.param.value
|
68 |
)
|
69 |
+
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves, date_range):
|
70 |
+
start_date, end_date = date_range
|
71 |
+
timeseries_data = load_timeseries_data(start_date, end_date)
|
72 |
+
other_features_data = load_other_features_data(start_date, end_date)
|
73 |
+
|
|
|
74 |
if not inverter_ids:
|
75 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
76 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Plot IV + Power + Temperature Curves
|
78 |
if plot_power_curves and plot_temperature_curves:
|
79 |
print("Plotting IV + Power + Temperature Curves")
|
|
|
95 |
print("Plot only IV Curves")
|
96 |
return create_iv_plot(timeseries_data, inverter_ids)
|
97 |
|
98 |
+
|
99 |
@pn.depends(heatmap_pr.param.value)
|
100 |
def update_heatmap_pr(heatmap_pr):
|
101 |
if heatmap_pr:
|
|
|
105 |
return pn.Row(pr_heatmap)
|
106 |
return pn.pane.Markdown("")
|
107 |
|
108 |
+
|
109 |
@pn.depends(heatmap_sy.param.value)
|
110 |
def update_heatmap_sy(heatmap_sy):
|
111 |
if heatmap_sy:
|
|
|
115 |
return pn.Row(sy_heatmap)
|
116 |
return pn.pane.Markdown("")
|
117 |
|
118 |
+
|
119 |
@pn.depends(heatmap_current.param.value)
|
120 |
def update_heatmap_current(heatmap_current):
|
121 |
if heatmap_current:
|
|
|
125 |
return pn.Row(current_heatmap)
|
126 |
return pn.pane.Markdown("")
|
127 |
|
128 |
+
|
129 |
@pn.depends(heatmap_voltage.param.value)
|
130 |
def update_heatmap_voltage(heatmap_voltage):
|
131 |
if heatmap_voltage:
|
|
|
135 |
return pn.Row(voltage_heatmap)
|
136 |
return pn.pane.Markdown("")
|
137 |
|
138 |
+
|
139 |
@pn.depends(heatmap_power.param.value)
|
140 |
def update_heatmap_power(heatmap_power):
|
141 |
if heatmap_power:
|
|
|
145 |
return pn.Row(power_heatmap)
|
146 |
return pn.pane.Markdown("")
|
147 |
|
148 |
+
|
149 |
@pn.depends(heatmap_irradiance.param.value)
|
150 |
def update_heatmap_irradiance(heatmap_irradiance):
|
151 |
if heatmap_irradiance:
|
|
|
155 |
return pn.Row(irradiance_heatmap)
|
156 |
return pn.pane.Markdown("")
|
157 |
|
158 |
+
|
159 |
@pn.depends(heatmap_temperature.param.value)
|
160 |
def update_heatmap_temperature(heatmap_temperature):
|
161 |
if heatmap_temperature:
|
|
|
165 |
return pn.Row(temp_heatmap)
|
166 |
return pn.pane.Markdown("")
|
167 |
|
168 |
+
|
169 |
# Create dashboard layout
|
170 |
dashboard = pn.Column(
|
171 |
"# ENEL Dashboard",
|