diff --git a/py_main.py b/py_main.py index d305b2f..3e14ede 100644 --- a/py_main.py +++ b/py_main.py @@ -1,4 +1,7 @@ +%matplotlib inline import numpy as np +import matplotlib.pyplot as plt + def lecture(name): lst_date = [] lst_conso = [] @@ -13,5 +16,30 @@ def lecture(name): 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 \ No newline at end of file + +def numero_jour (date): + return date.split("-")[2] + +def distance (pos1, pos2): + x1, y1, z1 = pos1 + x2, y2, z2 = pos2 + return np.sqrt(((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2)) + +def kPlusProches(echantillon, donnees, k): + voisins = [] + for i in range(len(donnees)): + date, conso, t_moy = donnees[i] + print(donnees[i]) + d = distance(echantillon, (date, conso, t_moy)) + voisins.append((d, i)) + return [voisins[i][1] for i in range(k)] + +num_jour = [] + + +dates, consos, t_moys, t_refs = lecture("pic-journalier-consommation.csv") +for date in dates: + num_jour.append(numero_jour(date)) +coords = list(zip(num_jour, t_moys, t_refs)) +kPlusProches((13, 21.0, 20.6), coords, 4) +