Before modifications
This commit is contained in:
@@ -203,6 +203,7 @@ async def send_discovery_messages(mqtt_client, device_names):
|
||||
await mqtt_client.publish(topic, json.dumps(msg).encode(), retain=True)
|
||||
|
||||
|
||||
|
||||
async def async_main(
|
||||
mqtt_info: MqttInfo,
|
||||
trackers: List[str],
|
||||
@@ -237,12 +238,12 @@ async def async_main(
|
||||
logging.debug(f"Got Measurement {measurement}")
|
||||
m = device_decoder(measurement)
|
||||
if m is not None:
|
||||
logging.debug(f"Decoded Measurement {m}")
|
||||
logging.info(f"Decoded Measurement {m}")
|
||||
training_data_logger.report_measure(m)
|
||||
feature_vec =feature_accumulator.add_measurement(m)
|
||||
if feature_vec:
|
||||
feature_str={tracker : value for tracker, value in zip(trackers, feature_vec)}
|
||||
logging.debug(f"Features: {feature_str}")
|
||||
logging.info(f"Features: {feature_str}")
|
||||
if feature_vec is not None and classifier is not None:
|
||||
room = classifier(m.device, feature_vec)
|
||||
if room != current_rooms[m.device]:
|
||||
@@ -250,6 +251,20 @@ async def async_main(
|
||||
current_rooms[m.device] = room
|
||||
await client.publish(f"my_btmonitor/ml/{m.device}", room.encode())
|
||||
|
||||
async def async_main_with_restart(
|
||||
mqtt_info: MqttInfo,
|
||||
trackers: List[str],
|
||||
devices: List[str],
|
||||
classifier,
|
||||
device_decoder: DeviceDecoder,
|
||||
training_data_logger: KnownRoomCsvLogger,
|
||||
):
|
||||
while True:
|
||||
try:
|
||||
await async_main(mqtt_info, trackers, devices, classifier, device_decoder, training_data_logger)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("restarting...")
|
||||
|
||||
def get_classification_func(training_df: pd.DataFrame, log_classifier_scores=True):
|
||||
devices_to_track = list(training_df["device"].unique())
|
||||
@@ -291,5 +306,4 @@ if __name__ == "__main__":
|
||||
device_decoder = DeviceDecoder(irk_to_devicename, address_to_name)
|
||||
trackers = list(training_df["tracker"].cat.categories)
|
||||
devices = list(training_df['device'].cat.categories)
|
||||
asyncio.run(async_main(mqtt_info, trackers, devices, classification_func, device_decoder, training_data_logger))
|
||||
|
||||
asyncio.run(async_main_with_restart(mqtt_info, trackers, devices, classification_func, device_decoder, training_data_logger))
|
||||
|
||||
Reference in New Issue
Block a user