jerin
lstm_2_rtu_model
be37c76
raw
history blame
1.37 kB
import json
from rtu.RTUAnomalizer import RTUAnomalizer
from rtu.RTUPipeline import RTUPipeline
import paho.mqtt.client as mqtt
def main():
rtu_data_pipeline = RTUPipeline(scaler_path="src/rtu/models/scaler_1.pkl")
print(rtu_data_pipeline.scaler)
rtu_anomalizer = RTUAnomalizer(
prediction_model_path="src/rtu/models/lstm_4rtu_smooth_02.keras",
clustering_model_paths=[
"src/rtu/models/kmeans_model1.pkl",
"src/rtu/models/kmeans_model2.pkl",
"src/rtu/models/kmeans_model3.pkl",
"src/rtu/models/kmeans_model4.pkl",
],
num_inputs=rtu_data_pipeline.num_inputs,
num_outputs=rtu_data_pipeline.num_outputs,
)
def on_message(client, userdata, message):
# print(json.loads(message.payload.decode()))
df_new, df_trans = rtu_data_pipeline.fit(message)
if not df_new is None and not df_trans is None:
out1,out2,out3,out4 = rtu_anomalizer.pipeline(df_new, df_trans, rtu_data_pipeline.scaler)
print(out3)
broker_address = "localhost"
broker_port = 1883
topic = "sensor_data"
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
client.on_message = on_message
client.connect(broker_address, broker_port)
client.subscribe(topic)
client.loop_forever()
if __name__ == "__main__":
main()