Ejemplo n.º 1
0
def station(station_id):
    stations = tahmo.get_stations()
    station = tahmo.get_station(station_id)
    if bool(station['timeseries']):
        timeseries = station['timeseries']
        sortedTimeSeries = sorted(timeseries["temperature"].keys())
        date = datetime.datetime.strptime(sortedTimeSeries[0],
                                          '%Y-%m-%dT%H:%M')
        startTime = calendar.timegm(date.utctimetuple()) * 1000
        lasttimeMeasured = sortedTimeSeries[-1]
        if "temperature" in timeseries:
            lastMeasuredTemp = timeseries["temperature"][sorted(
                timeseries["temperature"].keys())[-1]]
        else:
            lastMeasuredTemp = "No record"
        if "precipitation" in timeseries:
            lastMeasuredPrecip = timeseries["precipitation"][sorted(
                timeseries["precipitation"].keys())[-1]]
        else:
            lastMeasuredPrecip = "No record"
        if "windspeed" in timeseries:
            lastMeasuredWindSpeed = timeseries["windspeed"][sorted(
                timeseries["windspeed"].keys())[-1]]
        else:
            lastMeasuredWindSpeed = "No record"
        if "winddirection" in timeseries:
            lastMeasuredWindDirection = timeseries["winddirection"][sorted(
                timeseries["winddirection"].keys())[-1]]
        else:
            lastMeasuredWindDirection = "No record"
        if "atmosphericpressure" in timeseries:
            lastMeasuredPressure = timeseries["atmosphericpressure"][sorted(
                timeseries["atmosphericpressure"].keys())[-1]]
        else:
            lastMeasuredPressure = "No record"
        if "relativehumidity" in timeseries:
            lastMeasuredHumidity = timeseries["relativehumidity"][sorted(
                timeseries["relativehumidity"].keys())[-1]]
        else:
            lastMeasuredHumidity = "No record"
        winddirectionClass = windArrow(lastMeasuredWindDirection)
        return render_template(
            "station.html",
            startTime=startTime,
            stations=stations,
            station=station["station"],
            timeseries=timeseries,
            lastMeasuredTemp=lastMeasuredTemp,
            lastMeasuredPrecip=lastMeasuredPrecip,
            lastMeasuredWindSpeed=lastMeasuredWindSpeed,
            lastMeasuredWindDirection=lastMeasuredWindDirection,
            lastMeasuredPressure=lastMeasuredPressure,
            lastMeasuredHumidity=lastMeasuredHumidity,
            sortedTimeSeries=sortedTimeSeries,
            winddirectionClass=winddirectionClass)
    else:
        station = station['station']
        message = "Station " + station["name"] + " has no recorded timeseries"
        return render_template('404.html', message=message,
                               stations=stations), 404
Ejemplo n.º 2
0
def stations():
    stations = tahmo.get_stations()
    marker = []
    for station in stations:
        station["location"]["infobox"] = "<a href=/station/" + station[
            "id"] + ">" + station["name"] + "</a>"
        marker.append(station["location"])
    print marker
    stationsMap = Map(identifier="section-map",
                      lat=-6.3690,
                      lng=38.8888,
                      zoom=7,
                      style="width:100%; height: 500px",
                      markers=marker)
    return render_template("stations.html",
                           stations=stations,
                           stationsMap=stationsMap)
Ejemplo n.º 3
0
def page_not_found(e):
    stations = tahmo.get_stations()
    message = "Internal Error"
    return render_template('404.html', message=message, stations=stations), 501
Ejemplo n.º 4
0
def page_not_found(e):
    stations = tahmo.get_stations()
    message = "Page is gone"
    return render_template('404.html', message=message, stations=stations), 410
Ejemplo n.º 5
0
def index():
    # AQsensors
    # nodes = cft.get_stations()mValues
    node = json.loads(cft.get_station(os.getenv("DEFAULT_NODE")))
    pmValues = node['sensors'][0]['sensordatas'][0]['sensordatavalues']

    dhtValues = node['sensors'][1]['sensordatas'][1]['sensordatavalues']

    p2 = pmValues[0]['value']
    p1 = pmValues[1]['value']

    cft_lastMeasuredTemp = dhtValues[1]['value']
    cft_lastMeasuredHumidity = dhtValues[0]['value']

    #choosen default station for home, BRT
    stations = tahmo.get_stations()
    station = tahmo.get_station(os.getenv("DEFAULT_STATION"))
    if bool(station['timeseries']):
        timeseries = station['timeseries']
        sortedTimeSeries = sorted(timeseries["temperature"].keys())
        date = datetime.datetime.strptime(sortedTimeSeries[0],
                                          '%Y-%m-%dT%H:%M')
        startTime = calendar.timegm(date.utctimetuple()) * 1000
        lasttimeMeasured = sortedTimeSeries[-1]
        if "temperature" in timeseries:
            lastMeasuredTemp = timeseries["temperature"][sorted(
                timeseries["temperature"].keys())[-1]]
        else:
            lastMeasuredTemp = "No record"
        if "precipitation" in timeseries:
            lastMeasuredPrecip = timeseries["precipitation"][sorted(
                timeseries["precipitation"].keys())[-1]]
        else:
            lastMeasuredPrecip = "No record"
        if "windspeed" in timeseries:
            lastMeasuredWindSpeed = timeseries["windspeed"][sorted(
                timeseries["windspeed"].keys())[-1]]
        else:
            lastMeasuredWindSpeed = "No record"
        if "winddirection" in timeseries:
            lastMeasuredWindDirection = timeseries["winddirection"][sorted(
                timeseries["winddirection"].keys())[-1]]
        else:
            lastMeasuredWindDirection = "No record"
        if "atmosphericpressure" in timeseries:
            lastMeasuredPressure = timeseries["atmosphericpressure"][sorted(
                timeseries["atmosphericpressure"].keys())[-1]]
        else:
            lastMeasuredPressure = "No record"
        if "relativehumidity" in timeseries:
            lastMeasuredHumidity = timeseries["relativehumidity"][sorted(
                timeseries["relativehumidity"].keys())[-1]]
        else:
            lastMeasuredHumidity = "No record"
        winddirectionClass = windArrow(lastMeasuredWindDirection)
        return render_template(
            "index.html",
            startTime=startTime,
            stations=stations,
            station=station["station"],
            timeseries=timeseries,
            lastMeasuredTemp=lastMeasuredTemp,
            lastMeasuredPrecip=lastMeasuredPrecip,
            lastMeasuredWindSpeed=lastMeasuredWindSpeed,
            lastMeasuredWindDirection=lastMeasuredWindDirection,
            lastMeasuredPressure=lastMeasuredPressure,
            lastMeasuredHumidity=lastMeasuredHumidity,
            sortedTimeSeries=sortedTimeSeries,
            p1=p1,
            p2=p2,
            cft_lastMeasuredHumidity=cft_lastMeasuredHumidity,
            cft_lastMeasuredTemp=cft_lastMeasuredTemp,
            winddirectionClass=winddirectionClass)
    else:
        station = station['station']
        message = "Station " + station["name"] + " has no recorded timeseries"
        return render_template('404.html', message=message,
                               stations=stations), 404