diff options
Diffstat (limited to 'trace_courbe.py')
-rw-r--r-- | trace_courbe.py | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/trace_courbe.py b/trace_courbe.py index 2139d39..a967916 100644 --- a/trace_courbe.py +++ b/trace_courbe.py | |||
@@ -3,13 +3,14 @@ | |||
3 | from configuration import CONFIG | 3 | from configuration import CONFIG |
4 | from gestionOMS import * | 4 | from gestionOMS import * |
5 | from gestion_unites import * | 5 | from gestion_unites import * |
6 | from gestion_donnees import calcule_max_graphique | ||
6 | 7 | ||
7 | import matplotlib.pyplot as plt | 8 | import matplotlib.pyplot as plt |
8 | 9 | ||
9 | # Essentiellement, la fonction qui trace la courbe | 10 | # Essentiellement, la fonction qui trace la courbe |
10 | 11 | ||
11 | 12 | ||
12 | def cree_figure(conf,l_jours,l_poids,liste_err): | 13 | def cree_figure(conf,l_jours,l_poids,typedonnee,liste_err): |
13 | debug("debut de cree_figure",liste_err) | 14 | debug("debut de cree_figure",liste_err) |
14 | try: | 15 | try: |
15 | liste_data_labels_p,liste_data_labels_z = renvoie_liste_labels(conf,CONFIG["liste_data_choisie_p"],CONFIG["liste_data_choisie_z"],liste_err) | 16 | liste_data_labels_p,liste_data_labels_z = renvoie_liste_labels(conf,CONFIG["liste_data_choisie_p"],CONFIG["liste_data_choisie_z"],liste_err) |
@@ -17,12 +18,16 @@ def cree_figure(conf,l_jours,l_poids,liste_err): | |||
17 | erreur("bug avec liste data labels",liste_err) | 18 | erreur("bug avec liste data labels",liste_err) |
18 | return "" | 19 | return "" |
19 | 20 | ||
21 | # maxi saisi par l'utilisateur ? | ||
20 | if conf["maxi"] ==0: | 22 | if conf["maxi"] ==0: |
21 | if l_jours != []: | 23 | # Est-ce qu'on a donné un maxi quand même (car même échelle) ? |
22 | jour_maxi = max(l_jours)# pas la peine d'aller très au delà du jour max | 24 | print(conf) |
23 | jour_maxi = int(jour_maxi* 1.1)+3 # on rajoute un peu | 25 | print(conf["non_sauve"]) |
26 | if conf["non_sauve"].get("maxi",0) == 0: | ||
27 | print("bla") | ||
28 | jour_maxi = calcule_max_graphique(l_jours) | ||
24 | else: | 29 | else: |
25 | jour_maxi = CONFIG["jours_defaut_donneesvides"] # si pas de données, arbitrairement on met ça | 30 | jour_maxi = conf["non_sauve"]["maxi"]+1 |
26 | else: | 31 | else: |
27 | jour_maxi = conf["maxi"]+1 | 32 | jour_maxi = conf["maxi"]+1 |
28 | 33 | ||
@@ -31,39 +36,45 @@ def cree_figure(conf,l_jours,l_poids,liste_err): | |||
31 | jour_maxi = max(CONFIG["jours_mini_courbe"],min(jour_maxi,CONFIG["jours_maxi_courbe"])) | 36 | jour_maxi = max(CONFIG["jours_mini_courbe"],min(jour_maxi,CONFIG["jours_maxi_courbe"])) |
32 | debug("cree_figure : gestion du jour max ok : "+str(jour_maxi),liste_err) | 37 | debug("cree_figure : gestion du jour max ok : "+str(jour_maxi),liste_err) |
33 | 38 | ||
34 | if conf["unite"] == "": | 39 | # si l'unité n'est pas précisée, ni en "non sauvé" ni par l'utilisateur |
35 | conf["unite"] = choix_unite(jour_maxi) | 40 | if conf["unite"] == "" and conf["non_sauve"].get("unite","") == "": |
36 | 41 | unite = choix_unite(jour_maxi) | |
37 | l_jours_conv = convertit_tableau(l_jours,conf["unite"],liste_err) | 42 | debug("Unité non précisée, on choisit "+unite,liste_err) |
43 | elif conf["unite"] != "": | ||
44 | unite = conf["unite"] | ||
45 | else: | ||
46 | unite = conf["non_sauve"]["unite"] | ||
47 | |||
48 | l_jours_conv = convertit_tableau(l_jours,unite,liste_err) | ||
38 | # Attention, comme les jours commencent à partir de 0, faut enlever 1 pour avoir la borne... | 49 | # Attention, comme les jours commencent à partir de 0, faut enlever 1 pour avoir la borne... |
39 | age_maxi = convertitunite(jour_maxi-1,conf["unite"],liste_err) | 50 | age_maxi = convertitunite(jour_maxi-1,unite,liste_err) |
40 | 51 | ||
41 | debug("cree_figure : conversion des unités ok",liste_err) | 52 | debug("cree_figure : conversion des unités ok",liste_err) |
42 | 53 | ||
43 | titre = "Courbe de poids OMS" | 54 | titre = "Courbe de "+typedonnee+" OMS" |
44 | 55 | ||
45 | if conf["typecourbe"] == "P": | 56 | if conf["typecourbe"] == "P": |
46 | # percentiles | 57 | # percentiles |
47 | liste_data_labels = liste_data_labels_p | 58 | liste_data_labels = liste_data_labels_p |
48 | if conf["sexe"] == "M": | 59 | if conf["sexe"] == "M": |
49 | fichier_oms = CONFIG["fichiersOMS"]["perc_garcon"]#f_poids_perc_garcon | 60 | fichier_oms = CONFIG["fichiersOMS"][typedonnee]["perc_garcon"]#f_poids_perc_garcon |
50 | titre += " (percentiles, garçon)" | 61 | titre += " (percentiles, garçon)" |
51 | elif conf["sexe"] == "F": | 62 | elif conf["sexe"] == "F": |
52 | fichier_oms = CONFIG["fichiersOMS"]["perc_fille"] | 63 | fichier_oms = CONFIG["fichiersOMS"][typedonnee]["perc_fille"] |
53 | titre += " (percentiles, fille)" | 64 | titre += " (percentiles, fille)" |
54 | else: | 65 | else: |
55 | fichier_oms = CONFIG["fichiersOMS"]["perc_mixte"] | 66 | fichier_oms = CONFIG["fichiersOMS"][typedonnee]["perc_mixte"] |
56 | titre += " (percentiles)" | 67 | titre += " (percentiles)" |
57 | elif conf["typecourbe"] == "Z": | 68 | elif conf["typecourbe"] == "Z": |
58 | liste_data_labels = liste_data_labels_z | 69 | liste_data_labels = liste_data_labels_z |
59 | if conf["sexe"] == "M": | 70 | if conf["sexe"] == "M": |
60 | fichier_oms = CONFIG["fichiersOMS"]["z_garcon"] | 71 | fichier_oms = CONFIG["fichiersOMS"][typedonnee]["z_garcon"] |
61 | titre += " (moyenne et écarts-types, garçon)" | 72 | titre += " (moyenne et écarts-types, garçon)" |
62 | elif conf["sexe"] == "F": | 73 | elif conf["sexe"] == "F": |
63 | fichier_oms = CONFIG["fichiersOMS"]["z_fille"] | 74 | fichier_oms = CONFIG["fichiersOMS"][typedonnee]["z_fille"] |
64 | titre += " (moyenne et écarts-types, fille)" | 75 | titre += " (moyenne et écarts-types, fille)" |
65 | else: | 76 | else: |
66 | fichier_oms = CONFIG["fichiersOMS"]["z_mixte"] | 77 | fichier_oms = CONFIG["fichiersOMS"][typedonnee]["z_mixte"] |
67 | titre += " (moyenne et écarts-types)" | 78 | titre += " (moyenne et écarts-types)" |
68 | else: | 79 | else: |
69 | erreur("Type de courbe invalide"+conf["typecourbe"],liste_err) | 80 | erreur("Type de courbe invalide"+conf["typecourbe"],liste_err) |
@@ -88,7 +99,7 @@ def cree_figure(conf,l_jours,l_poids,liste_err): | |||
88 | 99 | ||
89 | debug("cree_figure : on va convertir données OMS à la bonne unité",liste_err) | 100 | debug("cree_figure : on va convertir données OMS à la bonne unité",liste_err) |
90 | try: | 101 | try: |
91 | coljour = convertit_tableau(extraire_colonne(t,0,jour_maxi),conf["unite"],liste_err) | 102 | coljour = convertit_tableau(extraire_colonne(t,0,jour_maxi),unite,liste_err) |
92 | except: | 103 | except: |
93 | erreur("Problème à la conversion du tableau OMS. jour_maxi = "+str(jour_maxi)+" unite = "+unite,liste_err) | 104 | erreur("Problème à la conversion du tableau OMS. jour_maxi = "+str(jour_maxi)+" unite = "+unite,liste_err) |
94 | return "" | 105 | return "" |
@@ -133,8 +144,8 @@ def cree_figure(conf,l_jours,l_poids,liste_err): | |||
133 | if l_jours != []: | 144 | if l_jours != []: |
134 | plt.plot(l_jours_conv,l_poids,label=conf["nom"],color=conf["couleurs"]["cadretxt"],marker='o') | 145 | plt.plot(l_jours_conv,l_poids,label=conf["nom"],color=conf["couleurs"]["cadretxt"],marker='o') |
135 | 146 | ||
136 | plt.xlabel("Âge en "+conf["unite"],color=conf["couleurs"]["cadretxt"]) | 147 | plt.xlabel("Âge en "+unite,color=conf["couleurs"]["cadretxt"]) |
137 | plt.ylabel("Poids en kg",color=conf["couleurs"]["cadretxt"]) | 148 | plt.ylabel(typedonnee.capitalize()+" en "+CONFIG["unites_typedonnees"][typedonnee],color=conf["couleurs"]["cadretxt"]) |
138 | plt.title(titre,color=conf["couleurs"]["cadretxt"]) | 149 | plt.title(titre,color=conf["couleurs"]["cadretxt"]) |
139 | plt.axis([0,age_maxi,poids_min,poids_max]) | 150 | plt.axis([0,age_maxi,poids_min,poids_max]) |
140 | 151 | ||