in lab/03-Package-Deploy/greengrass-v2/artifacts/aws.samples.windturbine.detector/1.0.0/inference/windturbine.py [0:0]
def __detect_anomalies__(self, buffer):
"""
Process the data received from the turbine and reports the
anomalies detected via MQTT
"""
start_time = time.time()
# create a copy & prep the data
data = self.__data_prep__(np.array(buffer))
if not self.edge_agent.is_model_loaded(self.model_meta['model_name']):
model_label_data = {"model_label_status" : "Model not loaded"}
self.msg_client.publish_model_status(model_label_data)
return
x = self.__preprocess_data__(data)
# run the model
p = self.edge_agent.predict(self.model_meta['model_name'], x)
if p is not None:
values, anomalies = self.__calculate_anomalies__(x, p)
anomaly_result = {"values" : values.tolist(), "anomalies" : anomalies.tolist()}
self.msg_client.publish_anomalies(message=anomaly_result)
else:
logging.info(f"No anomalies detected")
elapsed_time = time.time() - start_time
time.sleep(0.5-elapsed_time)