From 3d5de873c649b5c23278f31f94d26046f606b4c6 Mon Sep 17 00:00:00 2001 From: CHATAIGNER Gabriel Date: Thu, 12 May 2022 09:52:38 +0200 Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20les=20fichiers=20vers=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knn.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/knn.py b/knn.py index 0c00383..6edadd5 100644 --- a/knn.py +++ b/knn.py @@ -1 +1,95 @@ -def \ No newline at end of file +def lecture(fichier): + temp_jour = [] + conso = [] + with open(fichier, "r") as menu: + menu.readline() + for ligne in menu: + ligne_net = ligne.strip() + lst_ligne = list(ligne_net.split(";")) + temp_jour.append(lst_ligne) + for i in range(len(temp_jour)): + temp_jour[i][1] = float(temp_jour[i][1]) + temp_jour[i][2] = float(temp_jour[i][2]) + temp_jour[i][3] = float(temp_jour[i][3]) + return temp_jour + + +def estBissextile(an): + """Fonction estBissextile qui prend en paramètre l’année à vérifier et qui renvoie True si elle est bissextile, False sinon""" + an_base = an + an = an//4 + if an*4 == an_base: + return True + else: + return False + +def numeroJour(date): + an_mois_jour = list(date.split("-")) + + + an = int(an_mois_jour[0]) + mois = int(an_mois_jour[1]) + jour = int(an_mois_jour[2]) + + + + if mois == 1: + j_en_plus = 0 + elif mois == 2: + j_en_plus = 31 + elif mois == 3: + j_en_plus = 59 + elif mois == 4: + j_en_plus = 90 + elif mois == 5: + j_en_plus = 120 + elif mois == 6: + j_en_plus = 151 + elif mois == 7: + j_en_plus = 181 + elif mois == 8: + j_en_plus = 212 + elif mois == 9: + j_en_plus = 243 + elif mois == 10: + j_en_plus = 273 + elif mois == 11: + j_en_plus = 304 + elif mois == 12: + j_en_plus = 334 + + if estBissextile(an) and mois > 2: + j_en_plus += 1 + + num_jour = j_en_plus + jour + if num_jour > 365: + num_jour = 365 + return num_jour + + +def moyenne_liste + temp_jour, = lecture("pic-journalier-consommation.csv") + temp_num_jour = [] + for i in range(365): + temp_jour[i][0] = numeroJour(temp_jour[i][0]) + for l in range(len(temp_jour)): + lst_conso = [] + lst_temp_moy = [] + lst_temp_ref = [] + moy_conso = 0 + moy_temp_moy = 0 + moy_temp_ref = 0 + for m in range(len(temp_jour)): + if temp_jour[l][0] == i+1: + lst_conso.append(temp_jour[l][1]) + lst_temp_moy.append(temp_jour[l][2]) + lst_temp_ref.append(temp_jour[l][3]) + for n in range(len(lst_conso)): + moy_conso += lst_conso[n] + moy_temp_moy += lst_temp_moy[n] + moy_temp_ref += lst_temp_ref[n] + moy_conso = moy_conso / len(lst_conso) + temp_num_jour + + +