Spaces:
Running
Running
start on adding energy prediction to main.py
Browse files
.gitignore
CHANGED
@@ -4,4 +4,5 @@ venv
|
|
4 |
__pycache__/
|
5 |
*.tf
|
6 |
data
|
7 |
-
*.csv
|
|
|
|
4 |
__pycache__/
|
5 |
*.tf
|
6 |
data
|
7 |
+
*.csv
|
8 |
+
src/test_main.py
|
src/energy_prediction/EnergyPredictionNorth.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
|
5 |
+
class EnergyPredictionNorth:
|
6 |
+
"""
|
7 |
+
Class for predicting energy consumption in the north wing of the building.
|
8 |
+
"""
|
9 |
+
|
10 |
+
def __init__(self,
|
11 |
+
model_path=None):
|
12 |
+
"""
|
13 |
+
Initialize the EnergyPredictionNorth object.
|
14 |
+
|
15 |
+
Args:
|
16 |
+
model_path (str): Path to the prediction model file.
|
17 |
+
"""
|
18 |
+
if model_path is not None:
|
19 |
+
self.load_model(model_path)
|
20 |
+
|
21 |
+
def load_model(self, model_path):
|
22 |
+
"""
|
23 |
+
Load the prediction model.
|
24 |
+
|
25 |
+
Args:
|
26 |
+
model_path (str): Path to the prediction model file.
|
27 |
+
"""
|
28 |
+
self.model = load_model(model_path)
|
29 |
+
|
30 |
+
def predict(self, data):
|
31 |
+
"""
|
32 |
+
Predict energy consumption based on the input data.
|
33 |
+
|
34 |
+
Args:
|
35 |
+
data (pd.DataFrame): Input data for prediction.
|
36 |
+
|
37 |
+
Returns:
|
38 |
+
np.ndarray: Predicted energy consumption values.
|
39 |
+
"""
|
40 |
+
return self.model.predict(data, verbose=0)
|
41 |
+
|
42 |
+
def inverse_transform(self, scaler, pred, df_trans):
|
43 |
+
"""
|
44 |
+
Inverse transform the predicted and actual values.
|
45 |
+
|
46 |
+
Args:
|
47 |
+
scaler (object): Scaler object for inverse transformation.
|
48 |
+
pred (array): Predicted values.
|
49 |
+
df_trans (DataFrame): Transformed input data.
|
50 |
+
|
51 |
+
Returns:
|
52 |
+
tuple: A tuple containing the actual and predicted values after inverse transformation.
|
53 |
+
"""
|
54 |
+
mean = scaler.mean_[0]
|
55 |
+
std = scaler.scale_[0]
|
56 |
+
|
57 |
+
pred = pred * std + mean
|
58 |
+
actual = df_trans[:,0] * std + mean
|
59 |
+
return actual, pred
|
src/energy_prediction/EnergyPredictionPipeline.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
|
3 |
+
class EnergyPredictionPipeline:
|
4 |
+
def __init__(self, model_path_north, model_path_south):
|
5 |
+
self.model_north = EnergyPredictionNorth(model_path_north)
|
6 |
+
self.model_south = EnergyPredictionSouth(model_path_south)
|
7 |
+
|
8 |
+
def predict(self, data):
|
9 |
+
north_data = data[data["wing"] == "north"]
|
10 |
+
south_data = data[data["wing"] == "south"]
|
11 |
+
|
12 |
+
north_prediction = self.model_north.predict(north_data)
|
13 |
+
south_prediction = self.model_south.predict(south_data)
|
14 |
+
|
15 |
+
return pd.concat([north_prediction, south_prediction])
|
src/energy_prediction/EnergyPredictionSouth.py
ADDED
File without changes
|
src/main.py
CHANGED
@@ -4,6 +4,7 @@ from rtu.RTUAnomalizer2 import RTUAnomalizer2
|
|
4 |
from rtu.RTUPipeline import RTUPipeline
|
5 |
from vav.VAVPipeline import VAVPipeline
|
6 |
from vav.VAVAnomalizer import VAVAnomalizer
|
|
|
7 |
import paho.mqtt.client as mqtt
|
8 |
|
9 |
|
@@ -43,6 +44,9 @@ def main():
|
|
43 |
|
44 |
# print(len(vav_pipeline.output_col_names))
|
45 |
|
|
|
|
|
|
|
46 |
def on_message(client, userdata, message):
|
47 |
df_new_vav, df_trans_vav = vav_pipeline.fit(message)
|
48 |
vav_anomalizer.num_inputs = vav_pipeline.num_inputs
|
|
|
4 |
from rtu.RTUPipeline import RTUPipeline
|
5 |
from vav.VAVPipeline import VAVPipeline
|
6 |
from vav.VAVAnomalizer import VAVAnomalizer
|
7 |
+
from energy_prediction.EnergyPredictionNorth import EnergyPredictionNorth
|
8 |
import paho.mqtt.client as mqtt
|
9 |
|
10 |
|
|
|
44 |
|
45 |
# print(len(vav_pipeline.output_col_names))
|
46 |
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
def on_message(client, userdata, message):
|
51 |
df_new_vav, df_trans_vav = vav_pipeline.fit(message)
|
52 |
vav_anomalizer.num_inputs = vav_pipeline.num_inputs
|