-
Notifications
You must be signed in to change notification settings - Fork 1
/
frame_stats.py
executable file
·1282 lines (1082 loc) · 48.9 KB
/
frame_stats.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Carnet de vol parapente - Affichage des statistiques sur les vols
# Copyright (C) 2011 Pierre Knobel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# A faire :
# ajouter graphiques annuels (duree, duree moyenne, vitesse moyenne, nombre de vols, classement CFD)
import datetime
import os
import sys
from tkinter.tix import *
from tkinter import messagebox
from tkinter import filedialog
from divers import cumul, list_days_since_origin, days_since_origin, date_annotations
prog_path = os.path.dirname(sys.argv[0])
images_path = os.path.join(prog_path, "images")
bgc = "#e3e3fa"
# Marges en pixels autour des graphiques
m = 50
class FrameStats(Frame):
'''Statistiques extraites du carnet de vol
'''
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.db_connected = False
self.conn = None
self.cur = None
# Annee
self.annee = StringVar()
# Nombre de vol
self.nvols = StringVar()
# Temps de vol format HHhMM
self.tvol = StringVar()
# Temps moyen par vol (minutes)
self.tvol_moy = StringVar()
# Distance sur parcours declares
self.d_parcours = StringVar()
# Distance moyenne par vol
self.d_parcours_moy = StringVar()
# Vitesse moyenne sur parcours de cross
self.v_parcours = StringVar()
# Vitesse / sol moyenne
self.v_gps = StringVar()
# Vitesse moyenne sur parcours de cross
self.v_parcours = StringVar()
f0 = Frame(self, bd=3)
# Menu deroulant pour selection de l'annee
self.cb_annee = ComboBox(f0, label="Année", dropdown=1, editable=0,
bg="white", variable=self.annee, listwidth=30,
command=self.stats_vols)
self.cb_annee.entry.config(width=8, bg='white')
self.cb_annee.pack(side='top')
#self.cb_annee.grid(column=0, row=0, sticky="W")
# premiere frame a gauche spour l'affichage de statistiques
f1 = Frame(f0, bd=3, relief="groove", bg = bgc)
l = Label(f1, text="Nombre de vols :", bg = bgc)
l.grid(column=0, row=0, sticky="W")
Label(f1, textvariable=self.nvols, bg = bgc).grid(column=1, row=0,
sticky="W")
Label(f1, text="Temps de vol cumulé :", bg = bgc).grid(column=0,
row=2,
sticky="W")
Label(f1, textvariable=self.tvol, bg = bgc).grid(column=1,
row=2, sticky="W")
Label(f1, text="Durée moyenne :", bg = bgc).grid(column=0, row=3,
sticky="W")
Label(f1, textvariable=self.tvol_moy, bg = bgc).grid (column=1, row=3,
sticky="W")
Label(f1, text="Distance cross\ncumulée :", bg = bgc).grid(column=0,
row=4,
sticky="W")
Label(f1, textvariable=self.d_parcours, bg = bgc).grid(column=1, row=4,
sticky="W")
l = Label(f1, text="Distance moyenne\npar cross :", bg = bgc)
l.grid(column=0, row=5, sticky="W")
Label(f1, textvariable=self.d_parcours_moy, bg = bgc).grid(column=1,
row=5,
sticky="W")
l = Label(f1, text="Vitesse moyenne\n sur parcours :", bg = bgc)
l.grid(column=0, row=6, sticky="W")
Label(f1, textvariable=self.v_parcours, bg = bgc).grid(column=1,
row=6,
sticky="W")
l= Label(f1, text="Vitesse moyenne\nau GPS :", bg = bgc)
l.grid (column=0, row=7, sticky="W")
Label(f1, textvariable=self.v_gps, bg = bgc).grid(column=1, row=7,
sticky="W")
#f1.grid(column=0, row=1)
f1.pack(expand=1, fill=tkinter.tix.BOTH)
f1.columnconfigure(0, pad=10)
f1.columnconfigure(1, pad=10)
f1.rowconfigure(0, pad=20)
f1.rowconfigure(1, pad=20)
f1.rowconfigure(2, pad=20)
f1.rowconfigure(3, pad=20)
f1.rowconfigure(4, pad=20)
f1.rowconfigure(5, pad=20)
f1.rowconfigure(6, pad=20)
f1.rowconfigure(7, pad=20)
f0.pack(side="left", expand=0, fill=tkinter.tix.BOTH)
# deuxieme frame a gauche pour l'affichage de graphiques
f2 = Frame(self, bd=3, relief="groove")
self.type_graph = StringVar()
self.cb_graph = ComboBox(f2, label="Type de graphique", dropdown=1,
editable=0, bg="white", listwidth=250,
variable=self.type_graph,
command=self.affiche_graph)
self.cb_graph.slistbox.listbox.config(height=13)
self.cb_graph.entry.config(width=30)
self.cb_graph.pack(side="top")
self.cb_graph.insert('end', "Cumul de temps de vol")
self.cb_graph.insert('end', "Temps de vol")
self.cb_graph.insert('end', "Temps de vol par mois")
self.cb_graph.insert('end', "Temps de vol total annuel")
self.cb_graph.insert('end', "Temps de vol moyen et max annuel")
self.cb_graph.insert('end', "Cumul de distance")
self.cb_graph.insert('end', "Distance")
self.cb_graph.insert('end', "Distance moyenne et max annuelle")
self.cb_graph.insert('end', "Cumul du nombre de vols")
self.cb_graph.insert('end', "Nombre de vols par mois")
self.cb_graph.insert('end', "Nombre de vols par an")
self.cb_graph.insert('end', "Types de vols")
self.cb_graph.insert('end', "Types de vols par temps de vol")
self.cb_graph.insert('end', "Encadrement")
self.cb_graph.insert('end', "Encadrement par temps de vol")
h = len(self.cb_graph.slistbox.listbox.get(0, END))
self.cb_graph.slistbox.listbox.config(height=h)
self.canv = Canvas(f2, bg = bgc)
self.canv.pack(expand=1, fill=tkinter.tix.BOTH, side="bottom")
# Get canvas width and height
self.canv.bind("<Configure>", self.resize_graph)
self.w = self.canv.winfo_width()
self.h = self.canv.winfo_height()
f2.pack(expand=1, fill=tkinter.tix.BOTH, side="right")
self.columnconfigure(0, pad=4)
self.columnconfigure(1, pad=4, weight=2)
self.rowconfigure(0, pad=4)
self.rowconfigure(1, pad=4, weight=2)
def on_pilot_selection(self, conn):
'''Fonction executee lorsqu'un pilote est selectionne
Chargement des informations a partir de sa base de donnees'''
self.db_connected = True
self.conn = conn
self.cur = self.conn.cursor()
self.fill_cb_annees()
self.stats_vols()
def fill_cb_annees(self):
'''Recuperer les annees des vols et les ajouter a la liste deroulante
'''
if not self.db_connected:
return
self.cur.execute("SELECT DISTINCT annee FROM vols ORDER BY annee DESC")
liste_annees = [str(a[0]) for a in self.cur.fetchall()]
self.cb_annee.slistbox.listbox.delete(0, 'end')
for annee in liste_annees:
self.cb_annee.insert(tkinter.tix.END, annee)
self.cb_annee.insert(tkinter.tix.END, "Toutes")
self.annee.set("Toutes")
def stats_vols(self, *args):
'''calculer les statistiques de vol
'''
if not self.db_connected:
return
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
# Nombre vols
if not annee:
req = 'SELECT count(*) FROM vols WHERE NOT type_vol = "Gonflage"'
self.cur.execute(req)
else:
req = '''SELECT count(*) FROM vols
WHERE NOT type_vol = "Gonflage"
AND annee = ?'''
self.cur.execute(req, (annee, ))
self.nvols.set(str(self.cur.fetchall()[0][0]))
# Duree cumulee
if not annee:
req = 'SELECT SUM(duree) FROM vols WHERE NOT type_vol = "Gonflage"'
self.cur.execute(req)
else:
req = '''SELECT SUM(duree) FROM vols
WHERE NOT type_vol = "Gonflage"
AND annee = ?'''
self.cur.execute(req, (annee, ))
tvol_min = self.cur.fetchall()[0][0]
if tvol_min is not None:
tvol_str = "%02d h %02d min" % (tvol_min // 60, tvol_min % 60)
else:
tvol_str = ''
self.tvol.set(tvol_str)
# Duree moyenne
if not annee:
req = 'SELECT AVG(duree) FROM vols WHERE NOT type_vol = "Gonflage"'
self.cur.execute(req)
else:
req = '''SELECT AVG(duree) FROM vols
WHERE NOT type_vol = "Gonflage"
AND annee = ?'''
self.cur.execute(req, (annee, ))
tvol_moy = self.cur.fetchall()[0][0]
if tvol_moy is not None:
tvol_str = "%02d min" % (int(tvol_moy))
else:
tvol_str = ''
self.tvol_moy.set(tvol_str)
# Distance cross cumulee
if not annee:
req = '''SELECT SUM(distance_parcours) FROM vols
WHERE NOT distance_parcours = 0'''
self.cur.execute(req)
else:
req = '''SELECT SUM(distance_parcours) FROM vols
WHERE NOT distance_parcours = 0
AND annee = ?'''
self.cur.execute(req, (annee, ))
d_parcours = self.cur.fetchall()[0][0]
if d_parcours is not None:
dist_str = str(d_parcours) + " km"
else:
dist_str = ''
self.d_parcours.set(dist_str)
# Distance cross moyenne
if not annee:
req = '''SELECT AVG(distance_parcours) FROM vols
WHERE NOT distance_parcours = 0'''
self.cur.execute(req)
else:
req = '''SELECT AVG(distance_parcours) FROM vols
WHERE NOT distance_parcours = 0
AND annee = ?'''
self.cur.execute(req, (annee, ))
d_parcours_moy = self.cur.fetchall()[0][0]
if d_parcours_moy is not None:
dist_str = "%d km" % (d_parcours_moy)
else:
dist_str = ''
self.d_parcours_moy.set(dist_str)
# Vitesse cross moyenne
if not annee:
req = '''SELECT CAST(SUM(distance_parcours) as real) / SUM(duree) * 60
FROM vols
WHERE NOT distance_parcours = 0
AND NOT duree = 0'''
self.cur.execute(req)
else:
req = '''SELECT CAST(SUM(distance_parcours) as real) / SUM(duree) * 60
FROM vols
WHERE NOT distance_parcours = 0
AND NOT duree = 0
AND annee = ?'''
self.cur.execute(req, (annee, ))
v_parcours = self.cur.fetchall()[0][0]
if v_parcours is not None:
v_str = "%.2f km/h" % (v_parcours)
else:
v_str = ''
self.v_parcours.set(v_str)
# Vitesse gps moyenne
if not annee:
req = '''SELECT CAST(SUM(distance_totale) as real) / SUM(duree) * 60
FROM vols
WHERE NOT distance_totale = 0
AND NOT duree = 0'''
self.cur.execute(req)
else:
req = '''SELECT CAST(SUM(distance_totale) as real) / SUM(duree) * 60
FROM vols
WHERE NOT distance_totale = 0
AND NOT duree = 0
AND annee = ?'''
self.cur.execute(req, (annee, ))
v_gps = self.cur.fetchall()[0][0]
if v_gps is not None:
v_str = "%.2f km/h" % (v_gps)
else:
v_str = ''
self.v_gps.set(v_str)
# Remise a jour du graphique apres avoir change d'annee
self.affiche_graph()
def resize_graph(self, event):
'''Fonction executee lors du redimensionnement de la fenetre.
Mise a jour de la hauteur et largeur du canvas et de l'affichage.
'''
self.w = event.width
self.h = event.height
self.affiche_graph()
def affiche_graph(self, *args):
'''Fonction invoquee lors de la selection d'un type de graphique
ainsi que lors du redimensionnement de la fenetre.'''
if not self.db_connected:
return
if self.type_graph.get() == "Cumul de temps de vol":
self.affiche_cumul_tvol()
elif self.type_graph.get() == "Temps de vol":
self.affiche_tvol()
elif self.type_graph.get() == "Temps de vol par mois":
self.affiche_tvol_par_mois()
elif self.type_graph.get() == "Temps de vol total annuel":
self.affiche_duree_totale_annuelle()
elif self.type_graph.get() == "Temps de vol moyen et max annuel":
self.affiche_duree_max_moy_annuelle()
elif self.type_graph.get() == "Cumul de distance":
self.affiche_cumul_distance()
elif self.type_graph.get() == "Distance moyenne et max annuelle":
self.affiche_distance_annuelle()
elif self.type_graph.get() == "Distance":
self.affiche_distance()
elif self.type_graph.get() == "Cumul du nombre de vols":
self.affiche_cumul_nvols()
elif self.type_graph.get() == "Nombre de vols par mois":
self.affiche_nvols_par_mois()
elif self.type_graph.get() == "Nombre de vols par an":
self.affiche_nvols_annuel()
elif self.type_graph.get() == "Types de vols":
self.affiche_repartition_type_vol()
elif self.type_graph.get() == "Types de vols par temps de vol":
self.affiche_repartition_type_vol_temps()
elif self.type_graph.get() == "Encadrement":
self.affiche_repartition_encadrement()
elif self.type_graph.get() == "Encadrement par temps de vol":
self.affiche_repartition_encadrement_temps()
def affiche_cumul_tvol(self, *args):
'''Recupere les valeurs necessaires pour l'affichage de la courbe de
cumul de temps de vol puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT annee, mois, jour, duree FROM vols
WHERE NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour'''
self.cur.execute(req)
else:
req = '''SELECT annee, mois, jour, duree FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
l_dates = [datetime.date(v[0], v[1], v[2]) for v in l_vols]
min_date, max_date = (min(l_dates), max(l_dates))
l_jours = list_days_since_origin(l_dates, origin = min_date)
# annotation de l'axe des abscissses : 1er de chaque mois
# les annotations sont des chaines de caracteres stockees dans un dico
# indexe par la position en x
annot1_x, annot2_x = date_annotations(l_dates)
l_tvol = [v[3] for v in l_vols]
l_cumul_tvol = cumul(l_tvol)
self.affiche_cumul(l_jours, l_cumul_tvol, labels1_x = annot1_x,
labels2_x = annot2_x, xlegend = "Date",
ylegend = "Temps de vol (min)")
def affiche_tvol(self, *args):
'''Recupere les valeurs necessaires pour l'affichage de la courbe de
temps de vol puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT annee, mois, jour, duree FROM vols
WHERE NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour'''
self.cur.execute(req)
else:
req = '''SELECT annee, mois, jour, duree FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
l_dates = [datetime.date(v[0], v[1], v[2]) for v in l_vols]
l_jours = list_days_since_origin(l_dates)
annot1_x, annot2_x = date_annotations(l_dates)
l_tvol = [v[3] for v in l_vols]
self.affiche_points(l_jours, l_tvol, labels1_x = annot1_x,
labels2_x = annot2_x, xlegend = "Date",
ylegend = "Temps de vol (min)")
def affiche_cumul_distance(self, *args):
'''Recupere les valeurs necessaires pour l'affichage de la courbe de
cumul de distance en cross puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT annee, mois, jour, distance_parcours FROM vols
WHERE NOT distance_parcours = 0
ORDER BY annee, mois, jour'''
self.cur.execute(req)
else:
req = '''SELECT annee, mois, jour, distance_parcours FROM vols
WHERE annee = ?
AND NOT distance_parcours = 0
ORDER BY annee, mois, jour
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
l_dates = [datetime.date(v[0], v[1], v[2]) for v in l_vols]
l_jours = list_days_since_origin(l_dates)
annot1_x, annot2_x = date_annotations(l_dates)
l_dist = [v[3] for v in l_vols]
l_cumul_dist = cumul(l_dist)
self.affiche_cumul(l_jours, l_cumul_dist, labels1_x = annot1_x,
labels2_x = annot2_x , xlegend = "Date",
ylegend = "Distance (km)")
def affiche_distance(self, *args):
'''Recupere les valeurs necessaires pour l'affichage des distances
puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT annee, mois, jour, distance_parcours FROM vols
WHERE NOT distance_parcours = 0
ORDER BY annee, mois, jour'''
self.cur.execute(req)
else:
req = '''SELECT annee, mois, jour, distance_parcours FROM vols
WHERE annee = ?
AND NOT distance_parcours = 0
ORDER BY annee, mois, jour
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
l_dates = [datetime.date(v[0], v[1], v[2]) for v in l_vols]
l_jours = list_days_since_origin(l_dates)
annot1_x, annot2_x = date_annotations(l_dates)
l_dist = [v[3] for v in l_vols]
self.affiche_points(l_jours, l_dist, labels1_x = annot1_x,
labels2_x = annot2_x, xlegend = "Date",
ylegend = "Distance (km)")
def affiche_cumul_nvols(self, *args):
'''Recupere les valeurs necessaires pour l'affichage de la courbe de
cumul de temps de vol puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT annee, mois, jour FROM vols
WHERE NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour'''
self.cur.execute(req)
else:
req = '''SELECT annee, mois, jour FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
l_dates = [datetime.date(v[0], v[1], v[2]) for v in l_vols]
l_jours = list_days_since_origin(l_dates)
annot1_x, annot2_x = date_annotations(l_dates)
l_cumul_nvols = cumul([1 for v in l_vols])
self.affiche_cumul(l_jours, l_cumul_nvols, labels1_x = annot1_x,
labels2_x = annot2_x, xlegend = "Dates",
ylegend = "Nombre de vols")
def affiche_repartition_type_vol(self):
'''Recupere les valeurs necessaires pour l'affichage du camembert de
de repartition des types de vol puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT type_vol FROM vols'''
self.cur.execute(req)
else:
req = '''SELECT type_vol FROM vols
WHERE annee = ?
'''
self.cur.execute(req, (annee,))
l_vols = [v[0] for v in self.cur.fetchall()]
if len(l_vols) < 2:
self.canv.delete("all")
return
# types vol
liste_tv = ["Plouf", "Vol thermique sur site", "Cross", "Vol rando",
"Gonflage", "Soaring", "Rando & cross", "SIV", "Treuil",
"Voltige", "Vol à ski", "Speedriding", "Compétition"]
repartition_tv = {}
for v in l_vols:
for tv in liste_tv:
if v == tv:
if not v in repartition_tv:
repartition_tv[v] = 1
else:
repartition_tv[v] += 1
self.affiche_camembert(repartition_tv)
def affiche_repartition_type_vol_temps(self):
'''Recupere les valeurs necessaires pour l'affichage du camembert de
de repartition des types de vol par temps de vol puis appelle la
fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT type_vol, duree FROM vols'''
self.cur.execute(req)
else:
req = '''SELECT type_vol, duree FROM vols
WHERE annee = ?
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
# types vol
liste_tv = ["Plouf", "Vol thermique sur site", "Cross", "Vol rando",
"Gonflage", "Soaring", "Rando & cross", "SIV", "Treuil",
"Voltige", "Vol à ski", "Speedriding", "Compétition"]
repartition_tv = {}
for v in l_vols:
for tv in liste_tv:
if v[0] == tv:
if not tv in repartition_tv:
repartition_tv[tv] = v[1]
else:
repartition_tv[tv] += v[1]
self.affiche_camembert(repartition_tv)
def affiche_repartition_encadrement(self):
'''Recupere les valeurs necessaires pour l'affichage du camembert de
de repartition des types de vol puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT encadrement FROM vols'''
self.cur.execute(req)
else:
req = '''SELECT encadrement FROM vols
WHERE annee = ?
'''
self.cur.execute(req, (annee,))
l_vols = [v[0] for v in self.cur.fetchall()]
if len(l_vols) < 2:
self.canv.delete("all")
return
# encadrements
liste_encadrements = ['Autonome', 'Entre potes', 'Club', 'Ecole']
repartition_enc = {}
for v in l_vols:
for enc in liste_encadrements:
if v == enc:
if not enc in repartition_enc:
repartition_enc[enc] = 1
else:
repartition_enc[enc] += 1
self.affiche_camembert(repartition_enc)
def affiche_repartition_encadrement_temps(self):
'''Recupere les valeurs necessaires pour l'affichage du camembert de
de repartition des types de vol par temps de vol puis appelle la
fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT encadrement, duree FROM vols'''
self.cur.execute(req)
else:
req = '''SELECT encadrement, duree FROM vols
WHERE annee = ?
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
# encadrements
liste_encadrements = ['Autonome', 'Entre potes', 'Club', 'Ecole']
repartition_enc = {}
for v in l_vols:
for enc in liste_encadrements:
if v[0] == enc:
if not enc in repartition_enc:
repartition_enc[enc] = v[1]
else:
repartition_enc[enc] += v[1]
self.affiche_camembert(repartition_enc)
def affiche_nvols_par_mois(self):
'''Recupere les valeurs necessaires pour l'affichage de la courbe du
nombre de vols par mois puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT annee, mois, jour FROM vols
WHERE NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour'''
self.cur.execute(req)
else:
req = '''SELECT annee, mois, jour FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
l_dates = [datetime.date(v[0], v[1], v[2]) for v in l_vols]
min_date, max_date = (min(l_dates), max(l_dates))
n_mois = 0
n_annee = 0
l_mois = []
l_nvols_par_mois = []
l_dates = []
annot1_x = {}
annot2_x = {}
for y in range(min_date.year, max_date.year + 1):
annot2_x[n_mois] = "%d" % (y)
for m in range(1, 13):
if min_date <= datetime.date(y, m, 28) and\
datetime.date(y, m, 1) <= max_date:
req = '''SELECT COUNT(*) FROM vols
WHERE annee = ?
AND mois = ?'''
self.cur.execute(req, (y, m))
l_nvols_par_mois.append(self.cur.fetchall()[0][0])
l_mois.append(n_mois)
l_dates.append(datetime.date(y, m, 1))
annot1_x[n_mois] = "%d" % (m)
n_mois += 1
n_annee += 1
self.affiche_histogramme(l_mois, l_nvols_par_mois, labels1_x = annot1_x,
labels2_x = annot2_x, xlegend = "Mois",
ylegend = "Nombre de vols par mois")
def affiche_nvols_annuel(self):
'''Recupere les valeurs necessaires pour l'affichage de l'histogramme
du nombre de vols par an'''
req = '''SELECT DISTINCT annee FROM vols
WHERE NOT type_vol = "Gonflage"
ORDER BY annee'''
self.cur.execute(req)
l_annees = [item[0] for item in self.cur.fetchall()]
if len(l_annees) < 2:
self.canv.delete("all")
return
l_nvols_annee = []
annot1_x = {}
for annee in l_annees:
req = '''SELECT COUNT(*)
FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"'''
self.cur.execute(req, (annee, ))
nvols = self.cur.fetchall()
l_nvols_annee.append(nvols[0][0])
annot1_x[annee] = "%d" % (annee)
self.affiche_histogramme(l_annees, l_nvols_annee,
labels1_x = annot1_x, xlegend = "Années",
ylegend = "Nombre de vols par an")
def affiche_tvol_par_mois(self):
'''Recupere les valeurs necessaires pour l'affichage de la courbe du
temps de vol par mois puis appelle la fonction d'affichage'''
if self.annee.get() == "Toutes":
annee = 0
else:
annee = int(self.annee.get())
if not annee:
req = '''SELECT annee, mois, jour, duree FROM vols
WHERE NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour'''
self.cur.execute(req)
else:
req = '''SELECT annee, mois, jour, duree FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"
ORDER BY annee, mois, jour
'''
self.cur.execute(req, (annee,))
l_vols = self.cur.fetchall()
if len(l_vols) < 2:
self.canv.delete("all")
return
l_dates = [datetime.date(v[0], v[1], v[2]) for v in l_vols]
min_date, max_date = (min(l_dates), max(l_dates))
n_mois = 0
n_annee = 0
l_mois = []
l_tvol_par_mois = []
l_dates = []
annot1_x = {}
annot2_x = {}
for y in range(min_date.year, max_date.year + 1):
annot2_x[n_mois] = "%d" % (y)
for m in range(1, 13):
if min_date <= datetime.date(y, m, 28) and\
datetime.date(y, m, 1) <= max_date:
req = '''SELECT SUM(duree) FROM vols
WHERE annee = ?
AND mois = ?
AND NOT type_vol = "Gonflage"'''
self.cur.execute(req, (y, m))
t_vol = self.cur.fetchall()[0][0]
if t_vol is not None:
l_tvol_par_mois.append(t_vol)
else:
l_tvol_par_mois.append(0)
l_mois.append(n_mois)
l_dates.append(datetime.date(y, m, 1))
annot1_x[n_mois] = "%d" % (m)
n_mois += 1
n_annee += 1
self.affiche_histogramme(l_mois, l_tvol_par_mois, labels1_x = annot1_x,
labels2_x = annot2_x, xlegend = "Mois",
ylegend = "Temps de vol par mois (min)")
def affiche_distance_annuelle(self):
'''Recupere les valeurs necessaires pour l'affichage de l'histogramme
de la distance max et la distance moyenne annuelle'''
req = '''SELECT DISTINCT annee FROM vols
WHERE distance_parcours > 0
ORDER BY annee'''
self.cur.execute(req)
l_annees = [item[0] for item in self.cur.fetchall()]
if len(l_annees) < 2:
self.canv.delete("all")
return
l_dist_moy_annee = []
l_dist_max_annee = []
annot1_x = {}
for annee in l_annees:
req = '''SELECT MAX(distance_parcours), AVG(distance_parcours)
FROM vols
WHERE annee = ?
AND distance_parcours > 0'''
self.cur.execute(req, (annee, ))
distances = self.cur.fetchall()
l_dist_max_annee.append(distances[0][0])
l_dist_moy_annee.append(distances[0][1])
annot1_x[annee] = "%d" % (annee)
self.affiche_histogramme(l_annees, l_dist_max_annee,
list_y2 = l_dist_moy_annee,
labels1_x = annot1_x, xlegend = "Années",
ylegend = "Distance max et moyenne par année")
def affiche_duree_max_moy_annuelle(self):
'''Recupere les valeurs necessaires pour l'affichage de l'histogramme
de la durée max_ et la durée moyenne annuelle'''
req = '''SELECT DISTINCT annee FROM vols
WHERE duree > 0
AND NOT type_vol = "Gonflage"
ORDER BY annee'''
self.cur.execute(req)
l_annees = [item[0] for item in self.cur.fetchall()]
if len(l_annees) < 2:
self.canv.delete("all")
return
l_duree_moy_annee = []
l_duree_max_annee = []
annot1_x = {}
for annee in l_annees:
req = '''SELECT MAX(duree), AVG(duree)
FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"
AND duree > 0'''
self.cur.execute(req, (annee, ))
durees = self.cur.fetchall()
l_duree_max_annee.append(durees[0][0])
l_duree_moy_annee.append(durees[0][1])
annot1_x[annee] = "%d" % (annee)
self.affiche_histogramme(l_annees, l_duree_max_annee,
list_y2 = l_duree_moy_annee,
labels1_x = annot1_x, xlegend = "Années",
ylegend = "Temps de vol max et moyen annuel")
def affiche_duree_totale_annuelle(self):
'''Recupere les valeurs necessaires pour l'affichage de l'histogramme
du temps de vol cumulé annuel'''
req = '''SELECT DISTINCT annee FROM vols
WHERE duree > 0
AND NOT type_vol = "Gonflage"
ORDER BY annee'''
self.cur.execute(req)
l_annees = [item[0] for item in self.cur.fetchall()]
if len(l_annees) < 2:
self.canv.delete("all")
return
l_duree_tot_annee = []
annot1_x = {}
for annee in l_annees:
req = '''SELECT SUM(duree)
FROM vols
WHERE annee = ?
AND NOT type_vol = "Gonflage"
AND duree > 0'''
self.cur.execute(req, (annee, ))
durees = self.cur.fetchall()
l_duree_tot_annee.append(durees[0][0]/60)
annot1_x[annee] = "%d" % (annee)
self.affiche_histogramme(l_annees, l_duree_tot_annee,
labels1_x = annot1_x, xlegend = "Années",
ylegend = "Temps de vol total annuel (h)")
def affiche_cumul(self, list_x, list_y, labels1_x = None, labels2_x = None,
xlegend = '', ylegend = ''):
'''Affiche une courbe y = f(x) en escalier avec x dans list_x et y
dans list_y.
labels_x est un dictionnaire contenant des chaines de caracteres indexees
par la position sur l'axe