Exemple #1
0
def get_sensor_names():
    """
    Returns a list of unique sensor names in the database
    """

    # each topic is sensors/<sensor_name>/.....
    # so to get the observed sensors, just look for unique <sensor_names> in the topic list
    sensor_names = []
    topics = database.get_topics()
    for topic in topics:
        parts = topic.split('/')
        if len(parts) <= 1:
            logging.error(
                "Unknown topic format in database, expected sensors/<sensor_name>/...: {}".format(topic))
            continue
        sensor_name = parts[1]
        if sensor_name not in sensor_names:
            sensor_names.append(sensor_name)
    return sensor_names
Exemple #2
0
def get_topics():
    return jsonify(database.get_topics())
Exemple #3
0
    args = argparser.parse_args()

    # make database instance
    db_path = args.db_path
    database_path = os.path.dirname(db_path)
    database_name = os.path.basename(db_path)
    if not os.path.exists(database_path):
        logging.info('Creating directory "{}"'.format(database_path))
        os.mkdir(database_path)

    db_path = os.path.join(database_path, database_name)
    logging.info("Connecting to database '{}'".format(db_path))
    database.open(db_path)

    # first off, get all existing data from the database
    topics = database.get_topics()
    for topic in topics:
        data = database.get_data(topic)

        # sensor type is the last part in the topic
        sensor_type_str, sensor_name_str = sensor_type_and_name_from_db_name(
            topic)

        with g_topic_data_lock:
            if sensor_type_str in g_topic_data:
                sensor_type: SensorType = g_topic_data[sensor_type_str]
                the_data = sensor_type.add_series(sensor_name_str)
            else:
                sensor_type = SensorType(sensor_type_str)
                the_data = sensor_type.add_series(sensor_name_str)
                g_topic_data[sensor_type_str] = sensor_type