from collections import deque
from src.energy_prediction.EnergyPredictionModel import EnergyPredictionModel
from src.energy_prediction.EnergyPredictionPipeline import EnergyPredictionPipeline
from src.vav.VAVAnomalizer import VAVAnomalizer
from src.vav.VAVPipeline import VAVPipeline
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import mqtt_client
import time
from src.rtu.RTUPipeline import RTUPipeline
from src.rtu.RTUAnomalizer1 import RTUAnomalizer1
from src.rtu.RTUAnomalizer2 import RTUAnomalizer2
import plotly.express as px
rtu_data_pipeline = RTUPipeline(
scaler1_path="src/rtu/models/scaler_rtu_1_2.pkl",
scaler2_path="src/rtu/models/scaler_rtu_3_4.pkl",
)
rtu_anomalizers = []
rtu_anomalizers.append(
RTUAnomalizer1(
prediction_model_path="src/rtu/models/lstm_2rtu_smooth_04.keras",
clustering_model_paths=[
"src/rtu/models/kmeans_rtu_1.pkl",
"src/rtu/models/kmeans_rtu_2.pkl",
],
pca_model_paths=[
"src/rtu/models/pca_rtu_1.pkl",
"src/rtu/models/pca_rtu_2.pkl",
],
num_inputs=rtu_data_pipeline.num_inputs,
num_outputs=rtu_data_pipeline.num_outputs,
)
)
rtu_anomalizers.append(
RTUAnomalizer2(
prediction_model_path="src/rtu/models/lstm_2rtu_smooth_03.keras",
clustering_model_paths=[
"src/rtu/models/kmeans_rtu_3.pkl",
"src/rtu/models/kmeans_rtu_4.pkl",
],
pca_model_paths=[
"src/rtu/models/pca_rtu_3.pkl",
"src/rtu/models/pca_rtu_4.pkl",
],
num_inputs=rtu_data_pipeline.num_inputs,
num_outputs=rtu_data_pipeline.num_outputs,
)
)
vav_pipelines = []
vav_anomalizers = []
for i in range(1, 5):
vav_pipelines.append(
VAVPipeline(rtu_id=i, scaler_path=f"src/vav/models/scaler_vav_{i}.pkl")
)
for i in range(1, 5):
vav_anomalizers.append(
VAVAnomalizer(
rtu_id=i,
prediction_model_path=f"src/vav/models/lstm_vav_0{i}.keras",
clustering_model_path=f"src/vav/models/kmeans_vav_{i}.pkl",
pca_model_path=f"src/vav/models/pca_vav_{i}.pkl",
num_inputs=vav_pipelines[i - 1].num_inputs,
num_outputs=vav_pipelines[i - 1].num_outputs,
)
)
all_data = pd.read_csv("bootstrap_data.csv")
df_faults = pd.DataFrame(columns=["_______Time_______", "__________Issue__________"])
current_stat = [False, False, False, False]
energy_pipeline_north = EnergyPredictionPipeline(
scaler_path="src/energy_prediction/models/scalerNorth.pkl",
wing="north",
bootstrap_data=all_data,
)
energy_pipeline_south = EnergyPredictionPipeline(
scaler_path="src/energy_prediction/models/scalerSouth.pkl",
wing="south",
bootstrap_data=all_data,
)
energy_prediction_model_north = EnergyPredictionModel(
model_path=r"src/energy_prediction/models/lstm_energy_north_01.keras"
)
energy_prediction_model_south = EnergyPredictionModel(
model_path=r"src/energy_prediction/models/lstm_energy_south_01.keras"
)
# Set the layout of the page to 'wide'
st.set_page_config(layout="wide")
# Energy data generating used in Energy Usage Over Time plot ---- REPLACE WITH ACTUAL DATA ----
def generate_energy_data():
times = pd.date_range("2021-01-01", periods=200, freq="1min")
energy = np.random.randn(200).cumsum()
return pd.DataFrame({"Time": times, "Energy": energy})
# Create three columns for the header
header_row1_col1, header_row1_col2, header_row1_col3 = st.columns([0.8, 3, 1])
# Add logo to the first column of the header
with header_row1_col1:
st.image("logo.png")
# Add title to the second column of the header
with header_row1_col2:
st.markdown(
"
Building 59 - HVAC Dashboard
",
unsafe_allow_html=True,
)
# Add Time and Date to the third column of the header
mqtt_client.start_mqtt_client()
placeholder_header_time = header_row1_col3.empty()
# Create three columns for the first row
row1_col1, row1_col2, row1_col3 = st.columns([1.1, 1, 0.75])
# Use a container for RTU Status
rtu_status_container = row1_col1.container()
rtu_status_container.markdown(
"""
RTU Status
""",
unsafe_allow_html=True,
)
rtu_placeholders = []
rtu_columns = rtu_status_container.columns(4)
# Initial placeholder, does not update with streaming
for i in range(4):
with rtu_columns[i]:
placeholder = {"box": st.empty(), "sa_temp": st.empty(), "ra_temp": st.empty()}
rtu_placeholders.append(placeholder)
placeholder["box"].markdown(
f"""
RTU{i+1}
""",
unsafe_allow_html=True,
)
placeholder["sa_temp"].markdown("**SA temp:** -- °F")
placeholder["ra_temp"].markdown("**RA temp:** -- °F")
# Temperatures streaming and updates
def update_status_boxes(df, fault):
for i in range(4):
sa_temp = df[f"rtu_00{i+1}_sa_temp"].iloc[-1]
ra_temp = df[f"rtu_00{i+1}_ra_temp"].iloc[-1]
rtu_placeholders[i]["sa_temp"].markdown(f"**SA temp:** {sa_temp} °F")
rtu_placeholders[i]["ra_temp"].markdown(f"**RA temp:** {ra_temp} °F")
if fault[i] == 1:
rtu_placeholders[i]["box"].markdown(
f"""