Updated app.py with chunking of data based on selection of date range. Optimized the data flow.
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import panel as pn
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
from consts import INVERTER_ID_MAPPING, TEMPERATURE_COLUMNS_TO_USE
|
5 |
from plotting import (
|
@@ -10,26 +11,14 @@ from plotting import (
|
|
10 |
create_iv_plot_with_temperature_curves,
|
11 |
)
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
)
|
20 |
-
|
21 |
-
r"other_features_data.csv", index_col=0, header=0, parse_dates=True
|
22 |
-
)
|
23 |
-
other_features_data = other_features_data[TEMPERATURE_COLUMNS_TO_USE]
|
24 |
-
kpi_data = pd.read_csv(
|
25 |
-
r"kpi_data.csv", index_col=0, header=0, parse_dates=True
|
26 |
-
)
|
27 |
-
daily_timeseries_data = pd.read_csv(
|
28 |
-
r"daily_aggregated_timeseries_data.csv",
|
29 |
-
index_col=0,
|
30 |
-
header=0,
|
31 |
-
parse_dates=True,
|
32 |
-
)
|
33 |
|
34 |
# Initialize Panel extension
|
35 |
pn.extension("plotly")
|
@@ -59,7 +48,6 @@ heatmap_temperature = pn.widgets.Checkbox(
|
|
59 |
# Create a loading spinner
|
60 |
loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50)
|
61 |
|
62 |
-
|
63 |
# Panel interactive functions
|
64 |
@pn.depends(
|
65 |
inverter_ids.param.value,
|
@@ -70,27 +58,37 @@ def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves):
|
|
70 |
if not inverter_ids:
|
71 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
72 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
# Plot IV + Power + Temperature Curves
|
74 |
if plot_power_curves and plot_temperature_curves:
|
75 |
print("Plotting IV + Power + Temperature Curves")
|
76 |
return create_iv_plot_with_power_and_temperature_curves(
|
77 |
-
|
78 |
)
|
79 |
# Plot IV + Temperature Curves
|
80 |
elif (not plot_power_curves) and plot_temperature_curves:
|
81 |
print("Plot IV + Temperature Curves")
|
82 |
return create_iv_plot_with_temperature_curves(
|
83 |
-
|
84 |
)
|
85 |
# Plot IV + Power Curves
|
86 |
elif plot_power_curves and (not plot_temperature_curves):
|
87 |
print("Plot IV + Power Curves")
|
88 |
-
return create_iv_plot_with_power_curves(
|
89 |
# Plot only IV Curves
|
90 |
else:
|
91 |
print("Plot only IV Curves")
|
92 |
-
return create_iv_plot(
|
93 |
-
|
94 |
|
95 |
@pn.depends(heatmap_pr.param.value)
|
96 |
def update_heatmap_pr(heatmap_pr):
|
@@ -101,7 +99,6 @@ def update_heatmap_pr(heatmap_pr):
|
|
101 |
return pn.Row(pr_heatmap)
|
102 |
return pn.pane.Markdown("")
|
103 |
|
104 |
-
|
105 |
@pn.depends(heatmap_sy.param.value)
|
106 |
def update_heatmap_sy(heatmap_sy):
|
107 |
if heatmap_sy:
|
@@ -111,7 +108,6 @@ def update_heatmap_sy(heatmap_sy):
|
|
111 |
return pn.Row(sy_heatmap)
|
112 |
return pn.pane.Markdown("")
|
113 |
|
114 |
-
|
115 |
@pn.depends(heatmap_current.param.value)
|
116 |
def update_heatmap_current(heatmap_current):
|
117 |
if heatmap_current:
|
@@ -121,7 +117,6 @@ def update_heatmap_current(heatmap_current):
|
|
121 |
return pn.Row(current_heatmap)
|
122 |
return pn.pane.Markdown("")
|
123 |
|
124 |
-
|
125 |
@pn.depends(heatmap_voltage.param.value)
|
126 |
def update_heatmap_voltage(heatmap_voltage):
|
127 |
if heatmap_voltage:
|
@@ -131,7 +126,6 @@ def update_heatmap_voltage(heatmap_voltage):
|
|
131 |
return pn.Row(voltage_heatmap)
|
132 |
return pn.pane.Markdown("")
|
133 |
|
134 |
-
|
135 |
@pn.depends(heatmap_power.param.value)
|
136 |
def update_heatmap_power(heatmap_power):
|
137 |
if heatmap_power:
|
@@ -141,7 +135,6 @@ def update_heatmap_power(heatmap_power):
|
|
141 |
return pn.Row(power_heatmap)
|
142 |
return pn.pane.Markdown("")
|
143 |
|
144 |
-
|
145 |
@pn.depends(heatmap_irradiance.param.value)
|
146 |
def update_heatmap_irradiance(heatmap_irradiance):
|
147 |
if heatmap_irradiance:
|
@@ -151,7 +144,6 @@ def update_heatmap_irradiance(heatmap_irradiance):
|
|
151 |
return pn.Row(irradiance_heatmap)
|
152 |
return pn.pane.Markdown("")
|
153 |
|
154 |
-
|
155 |
@pn.depends(heatmap_temperature.param.value)
|
156 |
def update_heatmap_temperature(heatmap_temperature):
|
157 |
if heatmap_temperature:
|
@@ -161,7 +153,6 @@ def update_heatmap_temperature(heatmap_temperature):
|
|
161 |
return pn.Row(temp_heatmap)
|
162 |
return pn.pane.Markdown("")
|
163 |
|
164 |
-
|
165 |
# Create dashboard layout
|
166 |
dashboard = pn.Column(
|
167 |
"# ENEL Dashboard",
|
|
|
1 |
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 (
|
|
|
11 |
create_iv_plot_with_temperature_curves,
|
12 |
)
|
13 |
|
14 |
+
# Function to load data in chunks
|
15 |
+
def load_data_in_chunks(file_path, columns, start_date=None, end_date=None, chunksize=10000):
|
16 |
+
chunks = []
|
17 |
+
for chunk in pd.read_csv(file_path, usecols=['datetime'] + columns, chunksize=chunksize, parse_dates=['datetime']):
|
18 |
+
if start_date and end_date:
|
19 |
+
chunk = chunk[(chunk['datetime'] >= start_date) & (chunk['datetime'] <= end_date)]
|
20 |
+
chunks.append(chunk)
|
21 |
+
return pd.concat(chunks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Initialize Panel extension
|
24 |
pn.extension("plotly")
|
|
|
48 |
# Create a loading spinner
|
49 |
loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50)
|
50 |
|
|
|
51 |
# Panel interactive functions
|
52 |
@pn.depends(
|
53 |
inverter_ids.param.value,
|
|
|
58 |
if not inverter_ids:
|
59 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
60 |
else:
|
61 |
+
columns = []
|
62 |
+
if plot_power_curves:
|
63 |
+
columns += [CURRENT, IRRADIANCE, VOLTAGE, POWER_DC, POWER_AC]
|
64 |
+
if plot_temperature_curves:
|
65 |
+
columns += [T_AMBIENT, T_MODULE, T_HEATSINK, T_CPU, T_BOARD]
|
66 |
+
if not plot_power_curves and not plot_temperature_curves:
|
67 |
+
columns += [CURRENT, IRRADIANCE, VOLTAGE]
|
68 |
+
|
69 |
+
data = load_data_in_chunks('multi_index_timeseries_data.csv', columns)
|
70 |
+
other_data = load_data_in_chunks('other_features_data.csv', TEMPERATURE_COLUMNS_TO_USE)
|
71 |
+
|
72 |
# Plot IV + Power + Temperature Curves
|
73 |
if plot_power_curves and plot_temperature_curves:
|
74 |
print("Plotting IV + Power + Temperature Curves")
|
75 |
return create_iv_plot_with_power_and_temperature_curves(
|
76 |
+
data, other_data, inverter_ids
|
77 |
)
|
78 |
# Plot IV + Temperature Curves
|
79 |
elif (not plot_power_curves) and plot_temperature_curves:
|
80 |
print("Plot IV + Temperature Curves")
|
81 |
return create_iv_plot_with_temperature_curves(
|
82 |
+
data, other_data, inverter_ids
|
83 |
)
|
84 |
# Plot IV + Power Curves
|
85 |
elif plot_power_curves and (not plot_temperature_curves):
|
86 |
print("Plot IV + Power Curves")
|
87 |
+
return create_iv_plot_with_power_curves(data, inverter_ids)
|
88 |
# Plot only IV Curves
|
89 |
else:
|
90 |
print("Plot only IV Curves")
|
91 |
+
return create_iv_plot(data, inverter_ids)
|
|
|
92 |
|
93 |
@pn.depends(heatmap_pr.param.value)
|
94 |
def update_heatmap_pr(heatmap_pr):
|
|
|
99 |
return pn.Row(pr_heatmap)
|
100 |
return pn.pane.Markdown("")
|
101 |
|
|
|
102 |
@pn.depends(heatmap_sy.param.value)
|
103 |
def update_heatmap_sy(heatmap_sy):
|
104 |
if heatmap_sy:
|
|
|
108 |
return pn.Row(sy_heatmap)
|
109 |
return pn.pane.Markdown("")
|
110 |
|
|
|
111 |
@pn.depends(heatmap_current.param.value)
|
112 |
def update_heatmap_current(heatmap_current):
|
113 |
if heatmap_current:
|
|
|
117 |
return pn.Row(current_heatmap)
|
118 |
return pn.pane.Markdown("")
|
119 |
|
|
|
120 |
@pn.depends(heatmap_voltage.param.value)
|
121 |
def update_heatmap_voltage(heatmap_voltage):
|
122 |
if heatmap_voltage:
|
|
|
126 |
return pn.Row(voltage_heatmap)
|
127 |
return pn.pane.Markdown("")
|
128 |
|
|
|
129 |
@pn.depends(heatmap_power.param.value)
|
130 |
def update_heatmap_power(heatmap_power):
|
131 |
if heatmap_power:
|
|
|
135 |
return pn.Row(power_heatmap)
|
136 |
return pn.pane.Markdown("")
|
137 |
|
|
|
138 |
@pn.depends(heatmap_irradiance.param.value)
|
139 |
def update_heatmap_irradiance(heatmap_irradiance):
|
140 |
if heatmap_irradiance:
|
|
|
144 |
return pn.Row(irradiance_heatmap)
|
145 |
return pn.pane.Markdown("")
|
146 |
|
|
|
147 |
@pn.depends(heatmap_temperature.param.value)
|
148 |
def update_heatmap_temperature(heatmap_temperature):
|
149 |
if heatmap_temperature:
|
|
|
153 |
return pn.Row(temp_heatmap)
|
154 |
return pn.pane.Markdown("")
|
155 |
|
|
|
156 |
# Create dashboard layout
|
157 |
dashboard = pn.Column(
|
158 |
"# ENEL Dashboard",
|