From 1831df8918286e726563043c86051894daebd13e Mon Sep 17 00:00:00 2001 From: SERNY Sacha Date: Mon, 30 May 2022 08:47:17 +0200 Subject: [PATCH] Delete 'py_main.py' --- py_main.py | 94 ------------------------------------------------------ 1 file changed, 94 deletions(-) delete mode 100644 py_main.py diff --git a/py_main.py b/py_main.py deleted file mode 100644 index 1b6db17..0000000 --- a/py_main.py +++ /dev/null @@ -1,94 +0,0 @@ -import numpy as np - -def lecture(name): - lst_date = [] - lst_conso = [] - lst_t_moy = [] - lst_t_ref = [] - with open(name) as fic: - fic.readline() - for ligne in fic: - date,conso, t_moy, t_ref = ligne.split(';') - lst_date.append(date) - lst_conso.append(float(conso)) - lst_t_moy.append(float(t_moy)) - lst_t_ref.append(float(t_ref)) - return(np.array(lst_date), np.array(lst_conso), np.array(lst_t_moy), np.array(lst_t_ref)) - -def estBissextile(a): - """regarde si l'année correspond à une année bissextile""" - return (a%4==0 and a%100!=0) or a%400==0 - -def distance (pos1, pos2): - - """fonction distance qui prend en paramètre 2 tuples (Numéro du jour, Température moyenne, température de référence) et qui renvoie un nombre réel représentant la distance euclidienne""" - x1, y1, z1 = pos1 - x2, y2, z2 = pos2 - diff_njour1, diff_njour2 = x1-x2, x2-x1 - if (x1-x2) <= (x2-x1): - diff = x1-x2 - else: - diff = x2-x1 - - return np.sqrt((diff)**2)+((y1-y2)**2)+((z1-z2)**2) - -def kPlusProches(echantillon, donnees, k): - """ à reprendre -> !! TOTAL CHAOS !! U_u 0w0 *_* """ - voisins = [] - for i in range(len(donnees)): - date, t_moy, t_ref, conso = donnees[i] - d = distance(echantillon, (date, t_moy, t_ref)) - voisins.append((d, i)) - voisins = sorted(voisins) - return [voisins[i][1] for i in range(k)] - -def numeroJour(date): - """renvoie le numéro du jour dans l'année de la date "2442-04-24" """ - - date = date.split('-') - a, m, j = date - a, m, j = int(a), int(m), int(j) - if (estBissextile(int(a))): - mois = (0,31,60,91,121,152,182,213,244,274,305,335,366) - else: - mois = (0,31,59,90,120,151,181,212,243,273,304,334,365) - - return int(mois[m-1] + j) - - -def PuissanceMoyenne(consos, i_voisins): - """renvoie la puissance moyenne, prend en entrée une liste triée en fonction de la distance""" - res = 0 - for el in i_voisins: - - res += consos[el] - return res/(len(i_voisins)) - - -def triAvecIndices(lst): - """J'sais même pas ce que je fais""" - - tab_i= [] - tab = [] - for i in range(len(lst)): - tab_i.append(i) - tab = list(zip(lst, tab_i)) - return tab -num_jour = [] - - -dates, consos, t_pics, t_refs = lecture("pic-journalier-consommation.csv") -for date in dates: - num_jour.append(numeroJour(date)) -coords = list(zip(num_jour, t_pics, t_refs, consos)) - -#print(kPlusProches((80, 14, 9), coords, 20) -print(PuissanceMoyenne(consos, kPlusProches((numeroJour("2011-06-24"), 15, 20), coords, 20))) - - -#application du jeu de test -tab = [] -test_dates, test_consos, test_pic, test_ref = lecture("jeuTests.csv") -for i in range (len(test_dates)): - tab.append(PuissanceMoyenne(consos, kPlusProches((numeroJour(test_dates[i]), test_pic[i], test_ref[i]), coords, 20))) -print(tab)