示例#1
0
 def __init__(self, mqtt_handler, sensor_type, sensor_to_shop_dict):
     assert isinstance(mqtt_handler, MqttHandler)
     self.mqtt_handler = mqtt_handler
     self.sensor_to_shop_dict = sensor_to_shop_dict
     self.sensor_type = sensor_type
     input_topic_list = get_sensor_topic(None, self.sensor_type, '+', 'list')
     mqtt_handler.register_handler(input_topic_list, self._map_message_list)
     input_topic_count = get_sensor_topic(None, self.sensor_type, '+', 'count')
     mqtt_handler.register_handler(input_topic_count, self._map_message_count)
     logging.info("Created shop mapper for %s", sensor_type)
示例#2
0
 def aggregate_values(self, shop_id, values):
     result_dup = []
     for value in values.values():
         result_dup = result_dup + value
     result = list(set(result_dup))
     count_topic = get_sensor_topic(shop_id, self.sensor_type, None,
                                    'count')
     count_result = MqttHandler.MqttMessage(
         count_topic, self.generate_payload(shop_id,
                                            {'count': len(result)}))
     list_topic = get_sensor_topic(shop_id, self.sensor_type, None, 'list')
     list_result = MqttHandler.MqttMessage(
         list_topic, self.generate_payload(shop_id, {'clients': result}))
     return [count_result, list_result]
示例#3
0
 def aggregate_values(self, shop_id, values):
     result_transposed = {}
     for value in values.values():
         value_transposed = {value: key for key, value in value.items()}
         result_transposed.update(value_transposed)
     result = {value: key for key, value in result_transposed.items()}
     count_topic = get_sensor_topic(shop_id, self.sensor_type, None,
                                    'count')
     count_result = MqttHandler.MqttMessage(
         count_topic, self.generate_payload(shop_id,
                                            {'count': len(result)}))
     list_topic = get_sensor_topic(shop_id, self.sensor_type, None, 'list')
     list_result = MqttHandler.MqttMessage(
         list_topic, self.generate_payload(shop_id, {'clients': result}))
     return [count_result, list_result]
示例#4
0
 def __init__(self, mqtt_handler, shops_max_people_dict):
     assert isinstance(mqtt_handler, MqttHandler)
     self.mqtt_handler = mqtt_handler
     self.shops_max_people_dict = shops_max_people_dict
     input_topic = get_sensor_topic('+', 'people', None, 'count', use_type_subtopic=False)
     mqtt_handler.register_handler(input_topic, self._process)
     logging.info("Created DisplayActorController")
示例#5
0
 def __init__(self, mqtt_handler):
     super().__init__(
         mqtt_handler, get_sensor_topic('+',
                                        'ble',
                                        '+',
                                        'list',
                                        is_raw=True), 'ble')
示例#6
0
 def aggregate_values(self, shop_id, values):
     result = 0
     for value in values.values():
         result += value
     count_topic = get_sensor_topic(shop_id, self.sensor_type, None,
                                    'count')
     count_result = MqttHandler.MqttMessage(
         count_topic, self.generate_payload(shop_id, {'count': result}))
     return count_result
示例#7
0
 def _map_message(self, suffix, message):
     if 'sensor_id' not in message:
         logging.warning("Can not map %s sensor message to shop: sensor_id attribute missing", self.sensor_type)
         return
     sensor_id = message['sensor_id']
     if sensor_id not in self.sensor_to_shop_dict:
         logging.warning("No shop found for sensor from type %s with id: %s", self.sensor_type, sensor_id)
         return
     shop = self.sensor_to_shop_dict[sensor_id]
     logging.debug("Mapped sensor %s %s to shop %s", self.sensor_type, sensor_id, shop)
     message.update({'shop_id': shop, 'sensor_type': self.sensor_type})
     return MqttHandler.MqttMessage(get_sensor_topic(shop, self.sensor_type, sensor_id, suffix, is_raw=True),
                                    message)
示例#8
0
 def _process(self, topic, message):
     assert isinstance(message, dict)
     if 'shop_id' not in message or 'count' not in message:
         logging.warning("Can not process people count message: shop_id or count attribute missing, topic: %s", topic)
         return
     shop_id = message['shop_id']
     people_count = message['count']
     if shop_id not in self.shops_max_people_dict:
         logging.warning("Shop not found in max_people dict: %s", shop_id)
         return
     max_peoples = self.shops_max_people_dict[shop_id]
     utilization = translate(people_count,0, max_peoples, 0,100)
     action = self._utilization_action(utilization)
     message = {"shop_id": shop_id, "actor_type":"display", "action": action}
     logging.debug("Action message for shop %s with utilization %s: %s", shop_id, utilization, action['message'])
     return MqttHandler.MqttMessage(get_sensor_topic(shop_id, 'display', None, 'action', use_type_subtopic='actuators'),
                                    message)
示例#9
0
 def aggregate_values(self, shop_id, values):
     import statistics
     counts = [value['count'] for value in values.values()]
     aggregated_sensors = [
         value['aggregated_sensors'] for value in values.values()
     ]
     result = ceil(statistics.median(counts))
     total_aggregated_sensors = sum(aggregated_sensors)
     count_topic = get_sensor_topic(shop_id,
                                    'people',
                                    None,
                                    'count',
                                    use_type_subtopic=False)
     count_result = MqttHandler.MqttMessage(
         count_topic,
         self.generate_payload(
             shop_id, {
                 'count': result,
                 'aggregated_sensors': total_aggregated_sensors,
                 'aggregated_sensor_types': list(values.keys())
             }))
     return count_result
示例#10
0
 def __init__(self, mqtt_handler):
     super().__init__(mqtt_handler,
                      get_sensor_topic('+', '+', None, 'count'), 'people')
示例#11
0
 def __init__(self, mqtt_handler):
     super().__init__(
         mqtt_handler,
         get_sensor_topic('+', 'cam', '+', 'count', is_raw=True), 'cam')