|
|
|
from tkinter import *
|
|
|
|
|
|
|
|
def lancer(k, date, temp_moy, temp_ref, temp_num_jour):
|
|
|
|
moyenne_liste()
|
|
|
|
donnees_point = [date, temp_moy, temp_ref]
|
|
|
|
print(k)
|
|
|
|
print(donnees_point)
|
|
|
|
#print(temp_num_jour)
|
|
|
|
kPlusProches(k, donnees_point, temp_num_jour)
|
|
|
|
#estBissextile(an)
|
|
|
|
|
|
|
|
def lecture(fichier):
|
|
|
|
temp_jour = []
|
|
|
|
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 kPlusProches(k,donnees_point,temp_num_jour):
|
|
|
|
"""Fonction qui prend en paramètre un tuple correspondant au point à vérifier,
|
|
|
|
une liste du jeu de données et la conso électrique. Renvoie une liste triée
|
|
|
|
en fonction de la distance dont les éléments sont des tuples."""
|
|
|
|
|
|
|
|
if k > len(temp_num_jour):
|
|
|
|
k = len(temp_num_jour)
|
|
|
|
voisin=[]
|
|
|
|
for j in range(k):
|
|
|
|
voisin.append([None])
|
|
|
|
|
|
|
|
for i in range(len(temp_num_jour)):
|
|
|
|
MN = distance(temp_num_jour[i],donnees_point)
|
|
|
|
for l in range(k):
|
|
|
|
if voisin[l][1] == None or MN<voisin[l][4]:
|
|
|
|
# print(voisin)
|
|
|
|
# for m in range(k-l):
|
|
|
|
# print(voisin)
|
|
|
|
# a_placer = voisin[l]
|
|
|
|
# print(voisin)
|
|
|
|
# voisin[m][1] = [temp_num_jour[i][0], temp_num_jour[i][1], temp_num_jour[i][2], temp_num_jour[i][4], MN]
|
|
|
|
# print(voisin)
|
|
|
|
# voisin[m+1][1]= a_placer
|
|
|
|
# return voisin
|
|
|
|
|
|
|
|
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(len(temp_jour)):
|
|
|
|
temp_jour[i][0] = numeroJour(temp_jour[i][0])
|
|
|
|
lst_conso = []
|
|
|
|
lst_temp_moy = []
|
|
|
|
lst_temp_ref = []
|
|
|
|
moy_conso = 0
|
|
|
|
moy_temp_moy = 0
|
|
|
|
moy_temp_ref = 0
|
|
|
|
for l in range(1,366):
|
|
|
|
for m in range(len(temp_jour)):
|
|
|
|
if temp_jour[m][0] == l:
|
|
|
|
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)
|
|
|
|
moy_temp_moy = moy_temp_moy / len(lst_temp_moy)
|
|
|
|
moy_temp_ref = moy_temp_ref / len(lst_temp_ref)
|
|
|
|
temp_num_jour.append([temp_jour[l-1][0], moy_conso, moy_temp_moy, moy_temp_ref])
|
|
|
|
return temp_num_jour
|
|
|
|
|
|
|
|
def distance(temp_num_jour, donneespoint):
|
|
|
|
"""Fonction qui dit qu'en prenant des points et ben on peut trouver une distance entre 2 point"""
|
|
|
|
x1 = temp_num_jour[0]
|
|
|
|
x2 = donneespoint[0]
|
|
|
|
y1 = temp_num_jour[2]
|
|
|
|
y2 = donneespoint[1]
|
|
|
|
z1 = temp_num_jour[3]
|
|
|
|
z2 = donneespoint[2]
|
|
|
|
MN = ((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2)
|
|
|
|
return MN
|
|
|
|
|
|
|
|
def PuissanceMoyenne(lst,distance):
|
|
|
|
"""Calcule la moyenne de distances entre les points """
|
|
|
|
lecture("pic-journalier-consommation.csv")
|
|
|
|
moy = sum() / len()
|
|
|
|
|
|
|
|
def recup1():
|
|
|
|
k = 5 #value1.get()
|
|
|
|
return k
|
|
|
|
|
|
|
|
def recup2():
|
|
|
|
date = value2.get()
|
|
|
|
return date
|
|
|
|
|
|
|
|
def recup3():
|
|
|
|
temp_moy = value3.get()
|
|
|
|
return temp_moy
|
|
|
|
|
|
|
|
def recup4():
|
|
|
|
temp_ref = value4.get()
|
|
|
|
return temp_ref
|
|
|
|
|
|
|
|
#def calc_conso():
|
|
|
|
# Conso =
|
|
|
|
# label8.configure(text=Conso)
|
|
|
|
|
|
|
|
fenetre = Tk()
|
|
|
|
|
|
|
|
canvas1 = Canvas(fenetre)
|
|
|
|
|
|
|
|
label1 = Label(fenetre, text="Choisissez le nombre de voisins (k) :")
|
|
|
|
value1 = IntVar()
|
|
|
|
entree1 = Entry(fenetre, textvariable=value1, width=45)
|
|
|
|
|
|
|
|
label2 = Label(fenetre, text="Veuillez entrez la date (format 'aaaa-mm-jj'):", width=45)
|
|
|
|
value2 = IntVar()
|
|
|
|
entree2 = Entry(fenetre, textvariable=value2, width=45)
|
|
|
|
|
|
|
|
label3 = Label(fenetre, text="Veuillez entrez la température moyenne (en °C):", width=45)
|
|
|
|
value3 = IntVar()
|
|
|
|
entree3 = Entry(fenetre, textvariable=value3, width=45)
|
|
|
|
|
|
|
|
label4 = Label(fenetre, text="Veuillez entrez la température de référence (en °C) :", width=45)
|
|
|
|
value4 = IntVar()
|
|
|
|
entree4 = Entry(fenetre, textvariable=value4, width=45)
|
|
|
|
|
|
|
|
label1.grid(pady=10)
|
|
|
|
entree1.grid()
|
|
|
|
|
|
|
|
label2.grid(pady=10)
|
|
|
|
entree2.grid()
|
|
|
|
|
|
|
|
label3.grid(pady=10)
|
|
|
|
entree3.grid()
|
|
|
|
|
|
|
|
label4.grid(pady=10)
|
|
|
|
entree4.grid()
|
|
|
|
|
|
|
|
label9 = Label(fenetre, text="Conso", bg="yellow")
|
|
|
|
|
|
|
|
bouton1 = Button(canvas1, text="Tester", command=lancer(recup1(), recup2(), recup3(), recup4(), moyenne_liste()), width=15, height=2, bg="cyan").grid(pady=10)
|
|
|
|
|
|
|
|
canvas1.grid()
|
|
|
|
label9.grid(pady=10)
|
|
|
|
|
|
|
|
fenetre.title("IHM KNN")
|
|
|
|
fenetre.iconbitmap('icon.ico')
|
|
|
|
fenetre.mainloop()
|