Graphe fonctionnel avec bokeh pour les données par type (à améliorer, mais ça marche)
This commit is contained in:
parent
daf1053f7d
commit
b5c32cfc15
@ -14,5 +14,5 @@
|
||||
{% block body %}
|
||||
{{super()}}
|
||||
|
||||
<div class="footer">-- by arofarn --</div>
|
||||
<div class="footer">-- by arofarn with the help of Flask --</div>
|
||||
{% endblock %}
|
@ -3,16 +3,18 @@
|
||||
|
||||
{% block styles %}
|
||||
{{super()}}
|
||||
{{ css_ressources }}
|
||||
{{ js_ressources }}
|
||||
{{ css_resources|safe }}
|
||||
{{ js_resources|safe }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% from "bootstrap/pagination.html" import render_pagination %}
|
||||
<div class="container">
|
||||
|
||||
{{ plot_div|safe }}
|
||||
<div id="graph"></div>
|
||||
|
||||
{{ render_pagination(dat) }}
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead class="thead-inverse">
|
||||
@ -41,6 +43,7 @@
|
||||
{{ render_pagination(dat) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ plot_script|safe }}
|
||||
|
||||
{% endblock %}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Aug 17 22:25:52 2017
|
||||
@ -14,7 +15,7 @@ from flask import render_template
|
||||
from flask_bootstrap import Bootstrap
|
||||
from flask_nav import Nav
|
||||
from flask_nav.elements import *
|
||||
|
||||
import pandas as pd
|
||||
from bokeh.plotting import figure
|
||||
from bokeh.embed import components
|
||||
from bokeh.models import ColumnDataSource
|
||||
@ -77,26 +78,27 @@ def all_data():
|
||||
|
||||
@app.route('/type_id=<dt>')
|
||||
def by_data_type(dt):
|
||||
date_deb = datetime.utcnow()-timedelta(seconds=3600)
|
||||
date_deb = datetime.now()-timedelta(hours=1)
|
||||
#Récupération des données à afficher
|
||||
res = 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)
|
||||
res = pd.read_sql(q.selectable, db.engine)
|
||||
|
||||
plot_data = ColumnDataSource(data=dict(x = res.values('valdate'), y = res.values('value')))
|
||||
plot_data = ColumnDataSource(data=dict(x = res['data_valdate'], y = res['data_value']))
|
||||
|
||||
#Préparation du graphique
|
||||
data_plot = figure(tools = TOOLS,
|
||||
data_plot = figure(tools = "hover,pan,reset,save,wheel_zoom",
|
||||
title = dt,
|
||||
x_axis_label = 'Date',
|
||||
x_axis_type = 'datetime',
|
||||
y_axis_label = dt,
|
||||
plot_height = 400,
|
||||
plot_width = 800,
|
||||
plot_width = 1140,
|
||||
)
|
||||
data_plot.line('x', 'y', source=plot_data, line_width=2)
|
||||
|
||||
script, div = components(data_plot)
|
||||
|
||||
return render_template('data_graph.html.j2', dat=res.order_by(Data.dbdate.desc()).paginate(per_page=15),
|
||||
return render_template('data_graph.html.j2', dat=q.order_by(Data.dbdate.desc()).paginate(per_page=15),
|
||||
plot_script=script,
|
||||
plot_div=div,
|
||||
js_resources=js_resources,
|
||||
|
Loading…
Reference in New Issue
Block a user