2017-08-20 22:56:21 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Created on Thu Aug 17 22:25:52 2017
|
|
|
|
|
|
|
|
@author: arofarn
|
|
|
|
"""
|
|
|
|
|
|
|
|
###########
|
|
|
|
# IMPORTS #
|
|
|
|
###########
|
|
|
|
|
|
|
|
from cameteo import *
|
|
|
|
from flask import render_template
|
|
|
|
from flask_bootstrap import Bootstrap
|
|
|
|
from flask_nav import Nav
|
|
|
|
from flask_nav.elements import *
|
|
|
|
|
2017-10-01 09:07:48 +02:00
|
|
|
from bokeh.plotting import figure
|
|
|
|
from bokeh.embed import components
|
|
|
|
from bokeh.models import ColumnDataSource
|
|
|
|
from bokeh.resources import INLINE
|
|
|
|
|
2017-08-20 22:56:21 +02:00
|
|
|
########
|
|
|
|
# MAIN #
|
|
|
|
########
|
|
|
|
|
|
|
|
bootstrap = Bootstrap(app)
|
|
|
|
|
|
|
|
nav = Nav()
|
|
|
|
nav.init_app(app)
|
|
|
|
|
2017-10-01 09:23:50 +02:00
|
|
|
navbar = Navbar('Camétéo',
|
2017-08-20 22:56:21 +02:00
|
|
|
View('Accueil', 'index'),
|
2017-09-16 01:36:47 +02:00
|
|
|
View('Toutes les données', 'all_data'),
|
2017-08-20 22:56:21 +02:00
|
|
|
Subgroup('Par données',
|
2017-10-01 09:07:48 +02:00
|
|
|
View("Température de l'air", 'by_data_type', dt='AT'),
|
|
|
|
View("Humidité relative", 'by_data_type', dt='RH'),
|
|
|
|
View("Pression atmosphérique (locale)", 'by_data_type', dt='AP'),
|
|
|
|
View("Pression atmosphérique (mer)", 'by_data_type', dt='MSLP'),
|
|
|
|
View("Altitude", 'by_data_type', dt='ALTI'),
|
2017-08-20 22:56:21 +02:00
|
|
|
),
|
2017-10-01 09:23:50 +02:00
|
|
|
Subgroup('Par capteur',
|
2017-08-20 22:56:21 +02:00
|
|
|
View("Capteur BME280", 'by_sensor', sens = 'AdaBME280_1')
|
2017-09-16 01:36:47 +02:00
|
|
|
),
|
2017-10-01 09:07:48 +02:00
|
|
|
Subgroup('Photos',
|
|
|
|
View('Dernière Photo', 'picture', num=0),
|
|
|
|
View('Première Photo', 'picture', num=999999999),
|
|
|
|
),
|
2017-09-16 01:36:47 +02:00
|
|
|
View('Configuration', 'config_page')
|
2017-08-20 22:56:21 +02:00
|
|
|
)
|
2017-10-01 09:23:50 +02:00
|
|
|
|
2017-08-20 22:56:21 +02:00
|
|
|
nav.register_element('top', navbar)
|
|
|
|
|
2017-10-01 09:07:48 +02:00
|
|
|
js_resources = INLINE.render_js()
|
|
|
|
css_resources = INLINE.render_css()
|
|
|
|
|
2017-08-20 22:56:21 +02:00
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2017-10-01 09:23:50 +02:00
|
|
|
return render_template('index.html.j2')
|
2017-10-01 09:07:48 +02:00
|
|
|
|
|
|
|
@app.route('/picture=<num>')
|
|
|
|
def picture(num):
|
|
|
|
num=int(num)
|
|
|
|
if num < 0 :
|
|
|
|
num = 0
|
|
|
|
pictures = Photo.query.order_by(Photo.file_date.desc())
|
|
|
|
if num > pictures.count()-1:
|
|
|
|
num = pictures.count()-1
|
|
|
|
pict = pictures[num]
|
2017-10-01 09:23:50 +02:00
|
|
|
return render_template('photos.html.j2', picture_path = os.path.join("static/photos", pict.file_name), numero = num )
|
2017-09-16 01:36:47 +02:00
|
|
|
|
|
|
|
@app.route('/all_data')
|
|
|
|
def all_data():
|
|
|
|
date_deb = datetime.utcnow()-timedelta(seconds=3600)
|
2017-08-20 22:56:21 +02:00
|
|
|
res = Data.query.filter(Data.dbdate >= date_deb)
|
2017-10-01 09:23:50 +02:00
|
|
|
return render_template('data_viz.html.j2', dat=res.order_by(Data.dbdate.desc()).paginate(per_page=15))
|
|
|
|
|
2017-08-20 22:56:21 +02:00
|
|
|
@app.route('/type_id=<dt>')
|
|
|
|
def by_data_type(dt):
|
|
|
|
date_deb = datetime.utcnow()-timedelta(seconds=3600)
|
2017-10-01 09:07:48 +02:00
|
|
|
#Récupération des données à afficher
|
|
|
|
res = Data.query.filter(Data.type_id == dt).filter(Data.dbdate >= date_deb).order_by(Data.valdate)
|
2017-10-01 09:23:50 +02:00
|
|
|
|
2017-10-01 09:07:48 +02:00
|
|
|
plot_data = ColumnDataSource(data=dict(x = res.values('valdate'), y = res.values('value')))
|
2017-10-01 09:23:50 +02:00
|
|
|
|
|
|
|
#Préparation du graphique
|
2017-10-01 09:07:48 +02:00
|
|
|
data_plot = figure(tools = TOOLS,
|
|
|
|
title = dt,
|
|
|
|
x_axis_label = 'Date',
|
|
|
|
x_axis_type = 'datetime',
|
|
|
|
y_axis_label = dt,
|
|
|
|
plot_height = 400,
|
|
|
|
plot_width = 800,
|
|
|
|
)
|
|
|
|
data_plot.line('x', 'y', source=plot_data, line_width=2)
|
2017-10-01 09:23:50 +02:00
|
|
|
|
2017-10-01 09:07:48 +02:00
|
|
|
script, div = components(data_plot)
|
2017-10-01 09:23:50 +02:00
|
|
|
|
|
|
|
return render_template('data_graph.html.j2', dat=res.order_by(Data.dbdate.desc()).paginate(per_page=15),
|
|
|
|
plot_script=script,
|
2017-10-01 09:07:48 +02:00
|
|
|
plot_div=div,
|
|
|
|
js_resources=js_resources,
|
|
|
|
css_resources=css_resources,
|
|
|
|
)
|
2017-10-01 09:23:50 +02:00
|
|
|
|
2017-08-20 22:56:21 +02:00
|
|
|
@app.route('/sensor_id=<sens>')
|
|
|
|
def by_sensor(sens):
|
|
|
|
date_deb = datetime.utcnow()-timedelta(seconds=3600)
|
|
|
|
res = Data.query.filter(Data.sensor_id == sens).filter(Data.dbdate >= date_deb)
|
2017-10-01 09:23:50 +02:00
|
|
|
return render_template('data_viz.html.j2', dat=res.order_by(Data.dbdate.desc()).paginate(per_page=15))
|
|
|
|
|
2017-09-16 01:36:47 +02:00
|
|
|
@app.route('/configuration', methods=['GET', 'POST'])
|
|
|
|
def config_page():
|
2017-10-01 09:23:50 +02:00
|
|
|
|
2017-09-16 01:36:47 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
pass
|
2017-10-01 09:23:50 +02:00
|
|
|
|
|
|
|
return render_template('config_page.html.j2')
|
|
|
|
|
2017-08-20 22:56:21 +02:00
|
|
|
if __name__=="__main__":
|
2017-10-01 09:23:50 +02:00
|
|
|
app.run(host="0.0.0.0")
|