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:
parent
b5c32cfc15
commit
9aa4f8084d
@ -77,8 +77,11 @@ class DataType(db.Model):
|
||||
__tablename__ = 'data_type'
|
||||
|
||||
type_id = db.Column(db.String(4), primary_key=True)
|
||||
name = db.Column(db.String(20), nullable=False)
|
||||
description = db.Column(db.String(1000))
|
||||
name = db.Column(db.String(20), nullable=False) #Short name
|
||||
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):
|
||||
return "<DataType(name='%s', ID='%s', description='%s')>" % (self.name, self.type_id, self.description)
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% extends "base.html.j2" %}
|
||||
{% block title %}Camétéo{% endblock %}
|
||||
{% block title %}Camétéo - {{ data_type }}{% endblock %}
|
||||
|
||||
{% block styles %}
|
||||
{{super()}}
|
||||
@ -13,6 +13,10 @@
|
||||
|
||||
{{ 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) }}
|
||||
|
||||
<div class="table-responsive">
|
||||
|
@ -81,9 +81,10 @@ def 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)
|
||||
|
||||
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
|
||||
data_plot = figure(tools = "hover,pan,reset,save,wheel_zoom",
|
||||
@ -94,11 +95,13 @@ def by_data_type(dt):
|
||||
plot_height = 400,
|
||||
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)
|
||||
|
||||
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',
|
||||
data_type = dt,
|
||||
dat=q.order_by(Data.dbdate.desc()).paginate(per_page=15),
|
||||
plot_script=script,
|
||||
plot_div=div,
|
||||
js_resources=js_resources,
|
||||
@ -121,5 +124,15 @@ def config_page():
|
||||
|
||||
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__":
|
||||
app.run(host="0.0.0.0")
|
||||
|
Loading…
Reference in New Issue
Block a user