diff options
Diffstat (limited to 'app.py')
-rw-r--r-- | app.py | 76 |
1 files changed, 76 insertions, 0 deletions
@@ -0,0 +1,76 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # -*- coding: utf-8 -*- | ||
3 | |||
4 | import flask | ||
5 | import io | ||
6 | from configuration import * | ||
7 | from gestion_erreurs import * | ||
8 | from gestion_donnees import * | ||
9 | from gestion_unites import * | ||
10 | from trace_courbe import * | ||
11 | import matplotlib.pyplot as plt | ||
12 | |||
13 | import base64 | ||
14 | |||
15 | from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas | ||
16 | |||
17 | app = flask.Flask(__name__) | ||
18 | |||
19 | @app.route('/',methods=['POST','GET']) | ||
20 | def index(): | ||
21 | liste_err = initialise_erreurs() | ||
22 | val_form = config_init() | ||
23 | if flask.request.method=="POST": | ||
24 | if 'fichier_donnees' in flask.request.files: | ||
25 | ## charger les donneés dans le formulaire | ||
26 | fichier = flask.request.files['fichier_donnees'] | ||
27 | |||
28 | val_form = fichier_texte_vers_configdonnees(fichier,liste_err) | ||
29 | |||
30 | return flask.render_template("index.html",err=liste_err[1],valform=val_form) | ||
31 | |||
32 | @app.route('/apropos') | ||
33 | def apropos(): | ||
34 | |||
35 | return flask.render_template("apropos.html",err=[]) | ||
36 | |||
37 | |||
38 | @app.route("/courbe/<ext>", methods=['POST']) | ||
39 | def courbe_image(ext): | ||
40 | liste_err = initialise_erreurs() | ||
41 | data = flask.request.form | ||
42 | |||
43 | config = gere_configuration(data,liste_err) | ||
44 | |||
45 | l_jours,l_poids = gere_donneespoids(data,config["naissance"],liste_err) | ||
46 | fig = cree_figure(config,l_jours,l_poids,liste_err) | ||
47 | |||
48 | output = io.BytesIO() | ||
49 | FigureCanvas(fig).print_png(output) | ||
50 | |||
51 | plt.close(fig) | ||
52 | if ext == "b64": | ||
53 | return flask.Response(base64.b64encode(output.getvalue()), mimetype='text/plain') | ||
54 | elif ext == "png": | ||
55 | return flask.Response(output.getvalue(), mimetype='image/png') | ||
56 | else: | ||
57 | return flask.render_template("erreur_fatale.html",erreur="Le type d'image demandé n'est pas reconnu") | ||
58 | |||
59 | #return flask.Response(base64.b64encode(output.getvalue()), mimetype='text/plain') | ||
60 | |||
61 | @app.route("/export_donnees",methods=['POST']) | ||
62 | def export_donnees(): | ||
63 | # exporte les données au format texte | ||
64 | liste_err = initialise_erreurs() | ||
65 | data = flask.request.form | ||
66 | |||
67 | config = gere_configuration(data,liste_err) | ||
68 | l_jours,l_poids = gere_donneespoids(data,config["naissance"],liste_err) | ||
69 | |||
70 | texte = configuration_vers_texte(config) | ||
71 | texte += donnees_poids_vers_texte(l_jours,l_poids) | ||
72 | |||
73 | return flask.Response(texte,mimetype="text/plain") | ||
74 | |||
75 | if __name__ == "__main__": | ||
76 | app.run(host='0.0.0.0',debug=True) \ No newline at end of file | ||