Пример #1
0
    def save_message(self, message):

        message_uuid = uuid.UUID(message.id)
        timestamp = date_time_utils.unix_timestamp_to_datetime(message.timestamp)
        received = date_time_utils.unix_timestamp_to_datetime(message.received_timestamp)

        values = {
            "message_uuid" : message_uuid.bytes,
            "message_uuid_text" : message.id,
            "message_source" : message.source,
            "message_type" : message.type,
            "message_json" : json.dumps(message.data),
            "message_timestamp" : timestamp,
            "message_received" : received
        }

        self.__execute_insert(INSERT_MESSAGE_SQL, values)
Пример #2
0
    def save_reading(self, message):

        message_uuid = uuid.UUID(message.id)
        timestamp = date_time_utils.unix_timestamp_to_datetime(message.timestamp)

        data = message.data
        reading_value = data["value"]
        raw_value = data.get("raw", None)
        units = data.get("units", None)
        sensor_id = data.get("sesnor_id", message.source)
        reading_type = message.type[len("event.device.sensor.reading."):]

        values = {
            "message_uuid" : message_uuid.bytes,
            "device_id" : message.source,
            "sensor_id" : sensor_id,
            "reading_type" : reading_type,
            "reading_value" : reading_value,
            "raw_value" : raw_value,
            "reading_units" : units,
            "reading_timestamp" : timestamp
        }

        self.__execute_insert(INSERT_READING_SQL, values)