def download(guid=None): form = DownloadForm() if request.method == 'POST' and form.validate(): s = hp.find_device(form.guid.data) if s is None: s = hp.find_sensor(form.guid.data) if s is None: flash("ID not found") else: try: df = s.get_data(head=pd.Timestamp(form.start.data), tail=pd.Timestamp(form.end.data), resample=form.resample.data) except: flash( "Error connecting to the data storage, please try again later" ) else: filename = '{}.csv'.format(s.key) filepath = safe_join(download_path, filename) df.to_csv(filepath, encoding='utf-8') del df gc.collect() return send_file(filepath, as_attachment=True) if guid is not None: form.guid.data = guid return render_template('download.html', form=form)
def download(guid=None): form = DownloadForm() if request.method == 'POST' and form.validate(): s = hp.find_device(form.guid.data) if s is None: s = hp.find_sensor(form.guid.data) if s is None: flash("ID not found") else: try: df = s.get_data( head=pd.Timestamp(form.start.data), tail=pd.Timestamp(form.end.data), resample=form.resample.data ) except: flash("Error connecting to the data storage, please try again later") else: filename = '{}.csv'.format(s.key) filepath = safe_join(download_path, filename) df.to_csv(filepath, encoding='utf-8') del df gc.collect() return send_file( filepath, as_attachment=True ) if guid is not None: form.guid.data = guid return render_template( 'download.html', form=form )
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)
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 )