# -*- 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é
if donneemax>15:
return (5,1)
elif donneemax > 10:
- return (2,1)
+ return (1,0.5)
else:
return (1,0.2)
if typedonnees == "taille":
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
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