Spaces:
Sleeping
Sleeping
File size: 1,263 Bytes
3b66598 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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()
|