Petites améliorations du graphe + préparation d'autre amélioration

Ajout téléchargement des données en JSON
This commit is contained in:
Pierrick C 2017-10-02 00:33:03 +02:00
parent b5c32cfc15
commit 9aa4f8084d
3 changed files with 48 additions and 28 deletions

View File

@ -77,8 +77,11 @@ class DataType(db.Model):
__tablename__ = 'data_type' __tablename__ = 'data_type'
type_id = db.Column(db.String(4), primary_key=True) type_id = db.Column(db.String(4), primary_key=True)
name = db.Column(db.String(20), nullable=False) name = db.Column(db.String(20), nullable=False) #Short name
description = db.Column(db.String(1000)) plot_mini = db.Column(db.Float, nullable=True) #y minimum for plotting
plot_maxi = db.Column(db.Float, nullable=True) #y maximum for plotting
unit_si = db.Column(db.String(10), nullable=True) #Unit in SI
description = db.Column(db.String(1000)) #Long description
def __repr__(self): def __repr__(self):
return "<DataType(name='%s', ID='%s', description='%s')>" % (self.name, self.type_id, self.description) return "<DataType(name='%s', ID='%s', description='%s')>" % (self.name, self.type_id, self.description)

View File

@ -1,5 +1,5 @@
{% extends "base.html.j2" %} {% extends "base.html.j2" %}
{% block title %}Camétéo{% endblock %} {% block title %}Camétéo - {{ data_type }}{% endblock %}
{% block styles %} {% block styles %}
{{super()}} {{super()}}
@ -13,6 +13,10 @@
{{ plot_div|safe }} {{ plot_div|safe }}
<div id="json">
<a href="/json_type_id={{ data_type }}">Télécharger les données (JSON)</a>
</div>
{{ render_pagination(dat) }} {{ render_pagination(dat) }}
<div class="table-responsive"> <div class="table-responsive">

View File

@ -81,9 +81,10 @@ def by_data_type(dt):
date_deb = datetime.now()-timedelta(hours=1) date_deb = datetime.now()-timedelta(hours=1)
#Récupération des données à afficher #Récupération des données à afficher
q = Data.query.filter(Data.type_id == dt).filter(Data.dbdate >= date_deb).order_by(Data.valdate) q = Data.query.filter(Data.type_id == dt).filter(Data.dbdate >= date_deb).order_by(Data.valdate)
#q = Data.query.filter(Data.type_id == dt).order_by(Data.valdate)
res = pd.read_sql(q.selectable, db.engine) res = pd.read_sql(q.selectable, db.engine)
plot_data = ColumnDataSource(data=dict(x = res['data_valdate'], y = res['data_value'])) plot_data = ColumnDataSource(data=dict(dates = res['data_valdate'], values = res['data_value']))
#Préparation du graphique #Préparation du graphique
data_plot = figure(tools = "hover,pan,reset,save,wheel_zoom", data_plot = figure(tools = "hover,pan,reset,save,wheel_zoom",
@ -94,15 +95,17 @@ def by_data_type(dt):
plot_height = 400, plot_height = 400,
plot_width = 1140, plot_width = 1140,
) )
data_plot.line('x', 'y', source=plot_data, line_width=2) data_plot.line('dates', 'values', source=plot_data, line_width=2)
script, div = components(data_plot) script, div = components(data_plot)
return render_template('data_graph.html.j2', dat=q.order_by(Data.dbdate.desc()).paginate(per_page=15), return render_template('data_graph.html.j2',
plot_script=script, data_type = dt,
plot_div=div, dat=q.order_by(Data.dbdate.desc()).paginate(per_page=15),
js_resources=js_resources, plot_script=script,
css_resources=css_resources, plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
) )
@app.route('/sensor_id=<sens>') @app.route('/sensor_id=<sens>')
@ -121,5 +124,15 @@ def config_page():
return render_template('config_page.html.j2') return render_template('config_page.html.j2')
@app.route('/json_type_id=<dt>')
def json_by_data_type(dt):
date_deb = datetime.now()-timedelta(hours=1)
#Récupération des données à afficher
q = Data.query.filter(Data.type_id == dt).filter(Data.dbdate >= date_deb).order_by(Data.valdate)
#q = Data.query.filter(Data.type_id == dt).order_by(Data.valdate)
res = pd.read_sql(q.selectable, db.engine)
return res.to_json()
if __name__=="__main__": if __name__=="__main__":
app.run(host="0.0.0.0") app.run(host="0.0.0.0")