]> git.immae.eu Git - perso/Denise/oms.git/blobdiff - gestion_unites.py
bug corrigé sur les prémas, à vérifier
[perso/Denise/oms.git] / gestion_unites.py
index b97d90b58ed6cfcfd44b77c8a854ab16d6a5d195..f4cc38ece48032755dca6bc34c9cec7318672e9b 100644 (file)
@@ -2,7 +2,8 @@
 # -*- coding: utf-8 -*-
 
 from configuration import CONFIG
-from gestion_erreurs import * 
+from gestion_erreurs import warning
+from math import log
 
 ##################### outils pour affichage et choix de l'unité
 
@@ -31,7 +32,7 @@ def choix_echelle_data(typedonnees, donneemax):
         if donneemax>15:
             return (5,1)
         elif donneemax > 10:
-            return (2,1)
+            return (1,0.5)
         else:
             return (1,0.2)
     if typedonnees == "taille":
@@ -53,25 +54,25 @@ def choix_echelle_temps(unite, tempsmaxi):
     if unite=="jours":
         if tempsmaxi > 60:  # pourquoi mettre en jours ?
             return (30,1)
-        elif tempsmaxi >20:
+        elif tempsmaxi >15:
             return (7,1)
         else:
             return (1,0)
     if unite=="semaines":
         if tempsmaxi >50:
             return (5,1)
-        elif tempsmaxi > 15:
+        elif tempsmaxi > 10:
             return (2,1)
         else:
             return (1,1/7) # On met en jours
     
     if unite=="mois":
-        if tempsmaxi > 30:
-            return (2,1)
+        if tempsmaxi > 24:
+            return (12,1)
         elif tempsmaxi > 10:
             return (1,0)
         else:
-            return (1,0.25) # on met en semaines
+            return (1,0.25) # on met en semaines à peu près (quart de mois)
         
     if unite=="années":
         return (1,1/12) # années / mois
@@ -94,4 +95,18 @@ def convertitunite(jours,unite,liste_err):
 def convertit_tableau(tableau,unite,liste_err):
     """ convertit un tableau de jours en une autre unité.
     Renvoie le nouveau tableau"""
-    return [convertitunite(elt,unite,liste_err) for elt in tableau]
\ No newline at end of file
+    return [convertitunite(elt,unite,liste_err) for elt in tableau]
+
+def arrondit_donnee(donnee, typed, arrondi=0):
+    """ on arrondit la donnée de type typed (à voir dans CONFIG)
+    à arrondit près. SI y'a 0 on va voir dans la config.
+    Pour l'arrondit on met par ex 1 pour arrondir à 1 pr_s, 0.1 pour arrondir
+    au dixième etc"""
+    if arrondi==0:
+        arrondi = CONFIG["arrondis_typedonnees"][typed]
+    if arrondi==0:
+        print("Euuuh ça va merder, y'a une div par 0 dans arrondit_donnees !")
+    
+    d_arr = round(donnee/arrondi)*arrondi
+    nbchiffresvoulus = int(log(1/arrondi, 10))+1 # max sur le nombre de chiffres après la virgule qu'on doit avoir
+    return round(d_arr, nbchiffresvoulus)
\ No newline at end of file