示例#1
0
def slack():
    raw = request.form
    try:
        payload = raw['payload']  # it is a button callback
    except BadRequestKeyError:
        payload = raw.to_dict(flat=True)  # it is a command
    else:
        payload = json.loads(payload)

    verification_token = c.get('slack', 'verification_token')
    message_token = payload.get('token', '')
    if not verification_token == message_token:
        return Response(status=401)

    message = {
        "attachments": [
                {
                    "fallback": "OpenGrid.be callback",
                    "pretext": "Hello! This is OpenGrid.be speaking. Somebody has sent me this message but I don't know what to do with it",
                    "text": "```{}```".format(json.dumps(payload, indent=2)),
                    "mrkdwn_in": ["text"],
                }
            ]
        }
    slackbot.post_json(message)

    return Response(status=200)
示例#2
0
def slack():
    raw = request.form
    try:
        payload = raw['payload']  # it is a button callback
    except BadRequestKeyError:
        payload = raw.to_dict(flat=True)  # it is a command
    else:
        payload = json.loads(payload)

    verification_token = c.get('slack', 'verification_token')
    message_token = payload.get('token', '')
    if not verification_token == message_token:
        return Response(status=401)

    message = {
        "attachments": [{
            "fallback":
            "OpenGrid.be callback",
            "pretext":
            "Hello! This is OpenGrid.be speaking. Somebody has sent me this message but I don't know what to do with it",
            "text":
            "```{}```".format(json.dumps(payload, indent=2)),
            "mrkdwn_in": ["text"],
        }]
    }
    slackbot.post_json(message)

    return Response(status=200)
示例#3
0
def figure_exists(filename):
    path = c.get('backend', 'figures')
    file_path = safe_join(path, filename)

    return os.path.exists(file_path)
示例#4
0
def figure(filename):
    path = c.get('backend', 'figures')
    file_path = safe_join(path, filename)

    return send_file(file_path)
示例#5
0
def sensor(sensorid):
    s = hp.find_sensor(sensorid)

    if s is None:
        abort(404)

    path = c.get('backend', 'figures')

    analyses = []
    units = dict(electricity="Watt", gas="Watt", water="liter/min")

    # create timeseries plot
    filename = 'TimeSeries_{}.html'.format(s.key)
    analyses.append(
        plot.Html(
            title='Timeseries',
            content=safe_join(path, filename),
            description=
            u"This interactive graph  shows the measurement of {sensordescription} over the last 7 days.\
                                 The unit of the data is {unit}, and the graph contains minute values.\
                                 The graph is interactive: use the bottom ruler to zoom in/out and to change the period. \
                                 The graph is in local time (for Belgium).".
            format(sensordescription=s.description, unit=units.get(s.type))))

    if s.type == 'electricity' and not s.system == 'solar':
        # create standby horizontal
        filename = 'standby_horizontal_{}.png'.format(s.key)
        analyses.append(
            plot.Figure(
                title='Standby 10 days',
                content=filename,
                description=
                u"This figure shows the electric standby power of {sensordescription} (in {unit}). \
                             The left plot shows your standby power over the last 10 days (red diamonds). The distribution\
                             of the standby power of other opengrid families is shown as a boxplot. The red line is the median,\
                             the box limits are the 25th and 75th percentiles. By comparing your standby power to this box,\
                             you get an idea of your position in the opengrid community.\
                             The right plot shows your measured power consumption of {sensordescription} for the last night.\
                             This may give you an idea of what's going on in the night. Try to switch something off tonight and\
                             come back tomorrow to this graph to see the effect!"
                .format(sensordescription=s.description,
                        unit=units.get(s.type))))
        # create standby vertical
        filename = 'standby_vertical_{}.png'.format(s.key)
        analyses.append(
            plot.Figure(
                title='Standby 40 days',
                content=filename,
                description=
                u"This figure also shows the electric standby power of {sensordescription} (in {unit}). \
                             The left plot shows your standby power over the last 40 days (red diamonds).\
                             The standby power of other opengrid families is indicated by the 10th, 50th and 90th percentile.\
                             Again, this allows you to get an idea of your standby power in comparison to the opengrid community.\
                             The right plot shows your measured power consumption of {sensordescription} for the last night.\
                             This may give you an idea of what's going on in the night. Try to switch something off tonight and\
                             come back tomorrow to this graph to see the effect!<br><br>\
                             Which of these two graphs do you prefer? Let us know in the\
                             <a href=\"https://groups.google.com/d/forum/opengrid-private\">forum</a>."
                .format(sensordescription=s.description,
                        unit=units.get(s.type))))

    # create carpet plot
    filename = 'carpet_{}_{}.png'.format(s.type, s.key)
    analyses.append(
        plot.Figure(
            title='Carpet plot',
            content=filename,
            description=
            u"This plot shows the measurement of {sensordescription} over the last 3 weeks in a 'raster'. \
                         Each day is a single row in the 'raster', the horizontal axis is time (0-24h).\
                         The intensity of the measurement is plotted as a color: blue is low, red is high.  <br><br> \
                         The plot shows when the consumption typically takes place. \
                         This is useful discover trends or patterns over a day or week.\
                         This allows to check if systems are correctly scheduled (night set-back for heating, clock for\
                         an electrical boiler, etc. )<br><br>\
                         Do you think this is useful? Let us know in the\
                         <a href=\"https://groups.google.com/d/forum/opengrid-private\">forum</a>."
            .format(sensordescription=s.description)))

    analyses = [analysis for analysis in analyses if analysis.has_content()]

    return render_template('sensor.html', sensor=s, analyses=analyses)
示例#6
0
def figure_exists(filename):
    path = c.get('backend', 'figures')
    file_path = safe_join(path, filename)

    return os.path.exists(file_path)
示例#7
0
def figure(filename):
    path = c.get('backend', 'figures')
    file_path = safe_join(path, filename)

    return send_file(file_path)
示例#8
0
def sensor(sensorid):
    s = hp.find_sensor(sensorid)

    if s is None:
        abort(404)

    form = Recalculate()
    if request.method == 'POST' and form.validate():
        try:
            mvreg_sensor.compute(s, pd.Timestamp(form.start.data), pd.Timestamp(form.end.data))
            flash("Succes")
        except Exception as e:
            print(e)
            flash(str(e))
    else:
        flash("Form not validated")

    path = c.get('backend', 'figures')

    analyses = []
    units = dict(electricity="Watt",
                 gas="Watt",
                 water="liter/min")

    # create timeseries plot
    filename = 'TimeSeries_{}.html'.format(s.key)
    analyses.append(
        plot.Html(
            title='Timeseries',
            content=safe_join(path, filename),
            description=u"This interactive graph  shows the measurement of {sensordescription} over the last 7 days.\
                                 The unit of the data is {unit}, and the graph contains minute values.\
                                 The graph is interactive: use the bottom ruler to zoom in/out and to change the period. \
                                 The graph is in local time (for Belgium).".format(sensordescription=s.description,
                                                                                   unit=units.get(s.type))
        )
    )

    if s.type == 'electricity' and not s.system == 'solar':
        # create standby horizontal
        filename = 'standby_horizontal_{}.png'.format(s.key)
        analyses.append(
            plot.Figure(
                title='Standby 10 days',
                content=filename,
                description=u"This figure shows the electric standby power of {sensordescription} (in {unit}). \
                             The left plot shows your standby power over the last 10 days (red diamonds). The distribution\
                             of the standby power of other opengrid families is shown as a boxplot. The red line is the median,\
                             the box limits are the 25th and 75th percentiles. By comparing your standby power to this box,\
                             you get an idea of your position in the opengrid community.\
                             The right plot shows your measured power consumption of {sensordescription} for the last night.\
                             This may give you an idea of what's going on in the night. Try to switch something off tonight and\
                             come back tomorrow to this graph to see the effect!".format(
                    sensordescription=s.description,
                    unit=units.get(s.type))
            )
        )
        # create standby vertical
        filename = 'standby_vertical_{}.png'.format(s.key)
        analyses.append(
            plot.Figure(
                title='Standby 40 days',
                content=filename,
                description=u"This figure also shows the electric standby power of {sensordescription} (in {unit}). \
                             The left plot shows your standby power over the last 40 days (red diamonds).\
                             The standby power of other opengrid families is indicated by the 10th, 50th and 90th percentile.\
                             Again, this allows you to get an idea of your standby power in comparison to the opengrid community.\
                             The right plot shows your measured power consumption of {sensordescription} for the last night.\
                             This may give you an idea of what's going on in the night. Try to switch something off tonight and\
                             come back tomorrow to this graph to see the effect!<br><br>\
                             Which of these two graphs do you prefer? Let us know in the\
                             <a href=\"https://groups.google.com/d/forum/opengrid-private\">forum</a>.".format(
                    sensordescription=s.description,
                    unit=units.get(s.type))
            )
        )

    # create carpet plot
    filename = 'carpet_{}_{}.png'.format(s.type, s.key)
    analyses.append(
        plot.Figure(
            title='Carpet plot',
            content=filename,
            description=u"This plot shows the measurement of {sensordescription} over the last 3 weeks in a 'raster'. \
                         Each day is a single row in the 'raster', the horizontal axis is time (0-24h).\
                         The intensity of the measurement is plotted as a color: blue is low, red is high.  <br><br> \
                         The plot shows when the consumption typically takes place. \
                         This is useful discover trends or patterns over a day or week.\
                         This allows to check if systems are correctly scheduled (night set-back for heating, clock for\
                         an electrical boiler, etc. )<br><br>\
                         Do you think this is useful? Let us know in the\
                         <a href=\"https://groups.google.com/d/forum/opengrid-private\">forum</a>.".format(
                sensordescription=s.description)
        )
    )

    # create multivariable regression plots
    filename = 'multivar_results_{}.png'.format(s.key)
    analyses.append(
        plot.Figure(
            title='Monthly model and predictions',
            content=filename,
            description=u"This plot shows the monthly data and the model for your {sensordescription} <br><br>\
                             Do you think this is useful? Let us know in the\
                             <a href=\"https://groups.google.com/d/forum/opengrid-private\">forum</a>.".format(
                sensordescription=s.description)
        )
    )
    filename = 'multivar_prediction_weekly_{}.png'.format(s.key)
    analyses.append(
        plot.Figure(
            title='Weekly predictions and measurements',
            content=filename,
            description=u"This plot shows the weekly expected value and the measured value for your {sensordescription} <br><br>\
                                 Do you think this is useful? Let us know in the\
                                 <a href=\"https://groups.google.com/d/forum/opengrid-private\">forum</a>.".format(
                sensordescription=s.description)
        )
    )
    filename = 'multivar_model_{}.png'.format(s.key)
    analyses.append(
        plot.Figure(
            title='Monthly model',
            content=filename,
            description=u"This plot shows the monthly data and the model for your {sensordescription} <br><br>\
                                 Do you think this is useful? Let us know in the\
                                 <a href=\"https://groups.google.com/d/forum/opengrid-private\">forum</a>.".format(
                sensordescription=s.description)
        )
    )

    found_analyses = []
    for analysis in analyses:
        if analysis.has_content():
            if type(analysis) == plot.Figure:
                if figure_exists(analysis._content):
                    found_analyses.append(analysis)
            else:
                found_analyses.append(analysis)

    return render_template(
        'sensor.html',
        sensor=s,
        analyses=found_analyses,
        form=form
    )