jerin
r "Revert "lstm pipeline""
3b66598
raw
history blame
1.26 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="rtu/models/scaler_1.pkl")
rtu_anomalizer = RTUAnomalizer(
prediction_model_path="rtu/models/lstm_4rtu_smooth_02.keras",
clustering_model_paths=[
"rtu/models/kmeans_model1.pkl",
"rtu/models/kmeans_model2.pkl",
"rtu/models/kmeans_model3.pkl",
"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)
out = rtu_anomalizer.predict(df_new, df_trans, rtu_data_pipeline.scaler)
print(out)
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()