示例#1
0
def get_light_data(back_period="None"):
    # print "test:", back_period, type(back_period), repr(back_period)
    if back_period != "None":
        back_period = int(back_period)
    else:
        back_period = get_setting("ENVIRONMENT_BACK_PLOT_PERIOD", int).value

    node_1_ldr_light = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 15). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    # print "Sensor_data:", node_1_ldr_light
    scan_period = get_setting("ENVIRONMENT_SCAN_PERIOD", float)
    node_1_ldr_light_data = []
    timestamp = []
    # timestamp_str = node_1_ldr_light[0][0]
    for i in range(back_period):  # enumerate(node_1_dht_temp):

        try:
            node_1_ldr_light_data.append(node_1_ldr_light[i][1] if node_1_ldr_light[i][1] is not None else None)  # ????
        except IndexError:
            pass
        try:
            timestamp.append(time_since_epoch(node_1_ldr_light[i][0]) * 1000)
        except IndexError:
            pass
    # print node_1_ldr_light_data
    series = {"data": [
        {
            "name": "Node-1 LDR L [e]",
            "type": "line",
            "data": zip(timestamp, node_1_ldr_light_data)[::-1],
            "color": "orange",
            "tooltip": {
                "valueSuffix": ' e'
            }
        }
    ],
        "back_period": back_period,
        "node_ldr_last_light": node_1_ldr_light_data[0],
        "node_ldr_average_light": stats.mean(node_1_ldr_light_data),
        "scan_period": scan_period.value
    }
    # print series["data"]
    return jsonify(**series)
示例#2
0
def view_server():
    form = BackPeriodForm()
    back_period = None
    if form.validate_on_submit():
        print "Form OK 22"
        back_period = form.back_period.data
        print back_period

    table_data = read_temp_log(get_files(),
                               back_period=back_period if back_period is not None else
                               get_setting("SERVER_TEMP_PLOT_BACK_PERIOD", int).value)

    temperature_chart_data = [[], [], [], []]
    load_chart_data = [[], [], [], []]
    all_date_time = []
    for row in table_data:
        if row[0].startswith("Tim"):
            continue
        date_time = datetime.datetime.strptime(row[0], "%H:%M:%S %m/%d/%y")
        all_date_time.append(date_time)
        temperature_chart_data[0].append(float(row[1]))
        temperature_chart_data[1].append(float(row[2]))
        temperature_chart_data[2].append(float(row[3]))
        temperature_chart_data[3].append(float(row[4]))

        load_chart_data[0].append(float(row[5]))
        load_chart_data[1].append(float(row[6]))
        load_chart_data[2].append(float(row[7]))
        load_chart_data[3].append(float(row[8]))
    update_time = all_date_time[0]
    stat_data = [
        {
            "name": "Core 0",
            "temp_mean": stats.mean(temperature_chart_data[0]),
            "temp_st_dev": stats.st_dev(temperature_chart_data[0]),
            "load_mean": stats.mean(load_chart_data[0]),
            "load_st_dev": stats.st_dev(load_chart_data[0]),
            "temperature_last_reading": temperature_chart_data[0][0]
        },
        {
            "name": "Core 1",
            "temp_mean": stats.mean(temperature_chart_data[1]),
            "temp_st_dev": stats.st_dev(temperature_chart_data[1]),
            "load_mean": stats.mean(load_chart_data[1]),
            "load_st_dev": stats.st_dev(load_chart_data[1]),
            "temperature_last_reading": temperature_chart_data[1][0]
        },
        {
            "name": "Core 2",
            "temp_mean": stats.mean(temperature_chart_data[2]),
            "temp_st_dev": stats.st_dev(temperature_chart_data[2]),
            "load_mean": stats.mean(load_chart_data[2]),
            "load_st_dev": stats.st_dev(load_chart_data[2]),
            "temperature_last_reading": temperature_chart_data[2][0]
        },
        {
            "name": "Core 3",
            "temp_mean": stats.mean(temperature_chart_data[3]),
            "temp_st_dev": stats.st_dev(temperature_chart_data[3]),
            "load_mean": stats.mean(load_chart_data[3]),
            "load_st_dev": stats.st_dev(load_chart_data[3]),
            "temperature_last_reading": temperature_chart_data[3][0]
        },
    ]

    proc_max_temp = get_setting("PROC_MAX_TEMP_LIMIT", float).value
    limits = {"proc_max_temp": proc_max_temp}
    print "lesko", limits
    # pprint(stat_data)
    return render_template("view_server.html",
                           form=form,
                           back_period=back_period,
                           stat_data=stat_data,
                           limits=limits,
                           update_time=update_time,
                           page_loc="server")
示例#3
0
def get_server_data(back_period="None"):
    print "get_server_data"
    print back_period, type(back_period), repr(back_period)
    if back_period != "None":
        back_period = int(back_period)
    else:
        back_period = get_setting("SERVER_TEMP_PLOT_BACK_PERIOD", int).value
    table_data = read_temp_log(get_files(),
                               back_period=back_period)

    temperature_chart_data = [[], [], [], [], []]
    load_chart_data = [[], [], [], [], []]
    for row in table_data:
        if row[0].startswith("Tim"):
            continue
        # print row[0]
        date_time = datetime.datetime.strptime(row[0], "%H:%M:%S %m/%d/%y")
        temperature_chart_data[0].append(float(row[1]))
        temperature_chart_data[1].append(float(row[2]))
        temperature_chart_data[2].append(float(row[3]))
        temperature_chart_data[3].append(float(row[4]))
        temperature_chart_data[4].append(time_since_epoch(date_time) * 1000)

        load_chart_data[0].append(float(row[5]))
        load_chart_data[1].append(float(row[6]))
        load_chart_data[2].append(float(row[7]))
        load_chart_data[3].append(float(row[8]))
        load_chart_data[4].append(time_since_epoch(date_time) * 1000)

    # print temperature_chart_data[3]
    data = {
        "chart_real_time_temperature": {"data": [
            {
                "name": "Core 0",
                "data": zip(temperature_chart_data[4], temperature_chart_data[0])[::-1]
            },
            {
                "name": "Core 1",
                "data": zip(temperature_chart_data[4], temperature_chart_data[1])[::-1]
            },
            {
                "name": "Core 2",
                "data": zip(temperature_chart_data[4], temperature_chart_data[2])[::-1]
            },
            {
                "name": "Core 3",
                "data": zip(temperature_chart_data[4], temperature_chart_data[3])[::-1]
            }
        ]},

        "chart_real_time_load": {"data": [
            {
                "name": "Core 0",
                "data": zip(load_chart_data[4], load_chart_data[0])[::-1]
            },
            {
                "name": "Core 1",
                "data": zip(load_chart_data[4], load_chart_data[1])[::-1]
            },
            {
                "name": "Core 2",
                "data": zip(load_chart_data[4], load_chart_data[2])[::-1]
            },
            {
                "name": "Core 3",
                "data": zip(load_chart_data[4], load_chart_data[3])[::-1]
            }
        ]},

        "stat_data": {"data": [
            {
                "name": "Core 0",
                "temp_mean": stats.mean(temperature_chart_data[0]),
                "temp_st_dev": stats.st_dev(temperature_chart_data[0]),
                "load_mean": stats.mean(load_chart_data[0]),
                "load_st_dev": stats.st_dev(load_chart_data[0])
            },
            {
                "name": "Core 1",
                "temp_mean": stats.mean(temperature_chart_data[1]),
                "temp_st_dev": stats.st_dev(temperature_chart_data[1]),
                "load_mean": stats.mean(load_chart_data[1]),
                "load_st_dev": stats.st_dev(load_chart_data[1])
            },
            {
                "name": "Core 2",
                "temp_mean": stats.mean(temperature_chart_data[2]),
                "temp_st_dev": stats.st_dev(temperature_chart_data[2]),
                "load_mean": stats.mean(load_chart_data[2]),
                "load_st_dev": stats.st_dev(load_chart_data[2])
            },
            {
                "name": "Core 3",
                "temp_mean": stats.mean(temperature_chart_data[3]),
                "temp_st_dev": stats.st_dev(temperature_chart_data[3]),
                "load_mean": stats.mean(load_chart_data[3]),
                "load_st_dev": stats.st_dev(load_chart_data[3])
            },
        ]}
    }
    return jsonify(**data)
示例#4
0
def get_weather_arso_data(back_period="None"):
    if back_period != "None":
        back_period = int(back_period)
    else:
        back_period = get_setting("ENVIRONMENT_BACK_PLOT_PERIOD", int).value

    temp = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 44). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    sun_radiance = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 46). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    hum = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 45). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    # print "Sensor_data:", data
    scan_period = 30
    temperature_data = []
    sun_radiance_data = []
    humidity_data = []
    timestamp = []
    timestamp_str = temp[0][0]
    for i in range(back_period):  # enumerate(node_1_dht_temp):
        # Try - except every one because we don't know if all data is available for all sensors
        try:
            sun_radiance_data.append(
                    sun_radiance[i][1] if sun_radiance[i][1] is not None else None)  # ????
        except IndexError:
            pass

        try:
            humidity_data.append(hum[i][1] if hum[i][1] is not None else None)  # ????
        except IndexError:
            pass

        try:
            temperature_data.append(temp[i][1] if temp[i][1] is not None else None)  # ????
        except IndexError:
            pass

        try:
            timestamp.append(time_since_epoch(sun_radiance[i][0]) * 1000)
        except IndexError:
            pass
    series = {"data": [
        {
            "name": "Temperature [°C]",
            "type": "line",
            "data": zip(timestamp, temperature_data)[::-1],
            # "color": "green",
            "tooltip": {
                "valueSuffix": ' °C'
            }
        },
        {
            "name": "Humidity [%]",
            "type": "line",
            "yAxis": 1,
            "data": zip(timestamp, humidity_data)[::-1],
            "color": "blue",
            "tooltip": {
                "valueSuffix": ' %'
            }
        }
    ],
        "sun_radiance_data": [{
            "name": "Sun Radiance [W/m2]",
            "type": "line",
            "data": zip(timestamp, sun_radiance_data)[::-1],
            "color": "orange",
            "tooltip": {
                "valueSuffix": ' W/m2'
            }
        }],

        "back_period": back_period,

        "temperature_last_reading": temperature_data[0],
        "sun_radiance_last_reading": sun_radiance_data[0],
        "humidity_last_reading": humidity_data[0],

        "temperature_average": stats.mean(temperature_data),
        "sun_radiance_average": stats.mean(sun_radiance_data),
        "humidity_average": stats.mean(humidity_data),
        "last_update_time": datetime.datetime.strftime(timestamp_str, "%d.%m.%Y %H:%M:%S"),
        "scan_period": scan_period
    }
    # print series["data"]
    return jsonify(**series)
示例#5
0
def get_environment_data(back_period="None"):
    # print "test:", back_period, type(back_period), repr(back_period)
    if back_period != "None":
        back_period = int(back_period)
    else:
        back_period = get_setting("ENVIRONMENT_BACK_PLOT_PERIOD", int).value

    ds_temp = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 1). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    node_1_ds_temp = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 12). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    node_1_dht_temp = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 13). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    node_1_dht_hum = db.session.query(SensorData.date_time, SensorData.value).join(Sensors). \
        filter(Sensors.id == SensorData.sensor_id).filter(Sensors.id == 14). \
        order_by(SensorData.date_time.desc()).limit(back_period).all()

    # print "Sensor_data:", data
    scan_period = get_setting("ENVIRONMENT_SCAN_PERIOD", float)
    temperature_ds_data = []
    node_1_temperature_ds_data = []
    node_1_temperature_dht_data = []
    node_1_humidity_dht_data = []
    timestamp = []
    timestamp_ds = []
    node_timestamp_str = node_1_dht_temp[0][0]
    timestamp_str = ds_temp[0][0]
    for i in range(back_period):  # enumerate(node_1_dht_temp):
        # Try - except every one because we don't know if all data is available for all sensors
        try:
            node_1_temperature_ds_data.append(
                    node_1_ds_temp[i][1] if node_1_ds_temp[i][1] is not None else None)  # ????
        except IndexError:
            pass

        try:
            node_1_temperature_dht_data.append(
                    node_1_dht_temp[i][1] if node_1_dht_temp[i][1] is not None else None)  # ????
        except IndexError:
            pass

        try:
            node_1_humidity_dht_data.append(node_1_dht_hum[i][1] if node_1_dht_hum[i][1] is not None else None)  # ????
        except IndexError:
            pass

        try:
            temperature_ds_data.append(ds_temp[i][1] if ds_temp[i][1] is not None else None)  # ????
        except IndexError:
            pass

        try:
            timestamp_ds.append(time_since_epoch(ds_temp[i][0]) * 1000)
        except IndexError:
            pass

        try:
            timestamp.append(time_since_epoch(node_1_ds_temp[i][0]) * 1000)
        except IndexError:
            pass
    series = {"data": [
        {
            "name": "DS18B20 T [°C]",
            "type": "line",
            "data": zip(timestamp_ds, temperature_ds_data)[::-1],
            # "color": "green",
            "tooltip": {
                "valueSuffix": ' °C'
            }
        },
        {
            "name": "Node-1 DS18B20 T [°C]",
            "type": "line",
            "data": zip(timestamp, node_1_temperature_ds_data)[::-1],
            # "color": "green",
            "tooltip": {
                "valueSuffix": ' °C'
            }
        },
        {
            "name": "Node-1 DHT22 T [°C]",
            "type": "line",
            "data": zip(timestamp, node_1_temperature_dht_data)[::-1],
            # "color": "yellow",
            "tooltip": {
                "valueSuffix": ' °C'
            }
        },
        {
            "name": "Node-1 DHT22 H [%]",
            "type": "line",
            "yAxis": 1,
            "data": zip(timestamp, node_1_humidity_dht_data)[::-1],
            "color": "blue",
            "tooltip": {
                "valueSuffix": ' %'
            }
        }
    ],
        "back_period": back_period,

        "ds_last_reading": temperature_ds_data[0],
        "node_ds_last_reading": node_1_temperature_ds_data[0],
        "node_dht_temp_last_reading": node_1_temperature_dht_data[0],
        "node_dht_hum_last_reading": node_1_humidity_dht_data[0],

        "ds_average": stats.mean(temperature_ds_data),
        "node_ds_average": stats.mean(node_1_temperature_ds_data),
        "node_dht_temp_average": stats.mean(node_1_temperature_dht_data),
        "node_dht_hum_average": stats.mean(node_1_humidity_dht_data),

        "node_last_update_time": datetime.datetime.strftime(node_timestamp_str, "%d.%m.%Y %H:%M:%S"),
        "ds_last_update_time": datetime.datetime.strftime(timestamp_str, "%d.%m.%Y %H:%M:%S"),
        "scan_period": scan_period.value
    }
    # print series["data"]
    return jsonify(**series)