forked from OpenShiftDemos/os-sample-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarche.py
84 lines (62 loc) · 2.75 KB
/
marche.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.dates import DateFormatter
from matplotlib.dates import HourLocator
import io
import base64
# import mpld3
from definitions import *
def tableau_de_marche(horaire, titre):
legende = []
plt.close()
axes = plt.subplot()
nTrains = len(horaire['train'])
nNavettes = len(horaire['navette'])
for train in horaire['train']:
xTrain = [arret['heure'] for arret in horaire['train'][train]]
yTrain = [Ligne[iArret[arret['lieu']]]['position'] for arret in horaire['train'][train]]
plt.plot(xTrain, yTrain)
for xy in zip(xTrain, yTrain):
axes.annotate('%s' % xy[0].strftime('%M'), xy=xy, textcoords='data')
legende.append('T' + str(train))
# Graphique navettes
if nNavettes > 0:
for navette in horaire['navette']:
xNavette = [arret['heure'] for arret in horaire['navette'][navette]]
yNavette = [Ligne[iArret[arret['lieu']]]['position'] for arret in horaire['navette'][navette]]
plt.plot(xNavette, yNavette)
# for xy in zip(xNavette, yNavette):
# axes.annotate('%s' % xy[0].strftime('%M'), xy=xy, textcoords='data')
legende.append('Navette T' + str(navette))
# Formatage général du tableau de marche
figure = plt.gcf()
figure.set_size_inches(11.69, 8.27) # mise au format A4
figure.canvas.set_window_title('Tableau de marche CFC - ' + titre)
axes.xaxis.set_major_locator(HourLocator())
axes.xaxis.set_major_formatter(DateFormatter('%H:%M'))
axes.tick_params(labelbottom='on', labeltop='on')
# plt.yticks(list(yGare.values()), list(yGare.keys()))
plt.yticks([arret['position'] for arret in Ligne if arret['gare']], [arret['nom'] for arret in Ligne if arret['gare']])
axes.set_yticks([Ligne[iArret['Dépôt']]['position']], minor=True)
axes.yaxis.set_minor_formatter(ticker.FixedFormatter(['Dépôt']))
plt.grid(which='major')
plt.grid(which='minor', linestyle='--')
if nTrains > 1 or nNavettes > 0:
plt.legend(legende, loc='upper left')
# with PdfPages('horaire.pdf') as pdf:
# pdf.savefig()
figure.suptitle('Chemin de Fer des Chanteraines', fontsize=24, fontweight='bold')
img = io.BytesIO()
plt.savefig(img, format='png')
img.seek(0)
graph_url = base64.b64encode(img.getvalue()).decode()
pdf = io.BytesIO()
plt.savefig(pdf, format='pdf')
pdf.seek(0)
pdf_url = base64.b64encode(pdf.getvalue()).decode()
# plt.show()
# mpld3.show()
# print(temps_demitourEpinay)
# print(temps_demitourGennevilliers)
plt.close()
return 'data:image/png;base64,{}'.format(graph_url), 'data:application/pdf;base64,{}'.format(pdf_url)