From cf0d4c8c36224ca7059e99d03c25abaf694011d7 Mon Sep 17 00:00:00 2001 From: Denise sur Lya Date: Thu, 18 Feb 2021 20:05:29 +0100 Subject: =?UTF-8?q?extrapolation=20des=20courbes=20et=20calculs=20associ?= =?UTF-8?q?=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion_unites.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'gestion_unites.py') diff --git a/gestion_unites.py b/gestion_unites.py index d4089bd..f4cc38e 100644 --- a/gestion_unites.py +++ b/gestion_unites.py @@ -3,6 +3,7 @@ from configuration import CONFIG from gestion_erreurs import warning +from math import log ##################### outils pour affichage et choix de l'unité @@ -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 -- cgit v1.2.3