|
|
@ -1,9 +1,13 @@ |
|
|
|
from tkinter import * |
|
|
|
|
|
|
|
def lancer(): |
|
|
|
lecture("pic-journalier-consommation.csv") |
|
|
|
kPlusProches(value1, donnees_point,temp_jour) |
|
|
|
estBissextile(an) |
|
|
|
def lancer(k, date, temp_moy, temp_ref, donnees): |
|
|
|
donnees, lst_conso = moyenne_liste() |
|
|
|
donnees_point = [date, temp_moy, temp_ref] |
|
|
|
print(k) |
|
|
|
print(donnees_point) |
|
|
|
print(donnees) |
|
|
|
lst_k_plus_proches = kPlusProches(k, donnees_point, donnees) |
|
|
|
PuissanceMoyenne(lst_k_plus_proches) |
|
|
|
|
|
|
|
def lecture(fichier): |
|
|
|
temp_jour = [] |
|
|
@ -21,27 +25,20 @@ def lecture(fichier): |
|
|
|
|
|
|
|
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_jour): |
|
|
|
return an % 4 == 0 |
|
|
|
|
|
|
|
def kPlusProches(k,donnees_point,donnees): |
|
|
|
"""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.""" |
|
|
|
voisins = [] |
|
|
|
if k > len(temp_jour[0]): |
|
|
|
k = len(temp_jour[0]) |
|
|
|
energy = temp_jour.pop() |
|
|
|
energy.sort |
|
|
|
for i in range(len(temp_jour[0])): |
|
|
|
d = distance(temp_jour[i],donnees_point) |
|
|
|
voisins.append((d, i)) |
|
|
|
voisins.sort() |
|
|
|
return [voisins[i][1] for i in range(k)] |
|
|
|
if k > len(donnees): #par sécurité on réduit k |
|
|
|
k = len(donnees) |
|
|
|
voisin=[] |
|
|
|
for i in range(len(donnees)): |
|
|
|
voisin.append(distance(donnees, donnees_point, i)) |
|
|
|
voisin.sort() |
|
|
|
return [voisin[i] for i in range(k)] |
|
|
|
|
|
|
|
|
|
|
|
def numeroJour(date): |
|
|
|
an_mois_jour = list(date.split("-")) |
|
|
@ -84,92 +81,74 @@ def numeroJour(date): |
|
|
|
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)): |
|
|
|
temp_jour = lecture("pic-journalier-consommation.csv") |
|
|
|
donnees= [] |
|
|
|
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) |
|
|
|
moy_temp_moy = moy_temp_moy / len(lst_temp_moy) |
|
|
|
moy_temp_ref = moy_temp_ref / len(lst_temp_ref) |
|
|
|
temp_num_jour.append([i, moy_conso, moy_temp_moy, moy_temp_ref]) |
|
|
|
|
|
|
|
def distance(temp_jour, donneespoint): |
|
|
|
for i in range(len(temp_jour)): |
|
|
|
temp_jour[i][0] = numeroJour(temp_jour[i][0]) |
|
|
|
donnees.append([temp_jour[i][0], temp_jour[i][2], temp_jour[i][3]]) |
|
|
|
lst_conso.append(temp_jour[i][1]) |
|
|
|
return donnees, lst_conso |
|
|
|
|
|
|
|
def distance(donnees, donneespoint, i): |
|
|
|
"""Fonction qui dit qu'en prenant des points et ben on peut trouver une distance entre 2 point""" |
|
|
|
x1 = temp_jour[0] |
|
|
|
x1 = donnees[i][0] |
|
|
|
x2 = donneespoint[0] |
|
|
|
y1 = temp_jour[1] |
|
|
|
d1 = x1-x2 |
|
|
|
d2 = 365 - d1 |
|
|
|
d_final = d1 |
|
|
|
if d1 > d2: |
|
|
|
d_final = d2 |
|
|
|
y1 = donnees[i][1] |
|
|
|
y2 = donneespoint[1] |
|
|
|
z1 = temp_jour[2] |
|
|
|
z1 = donnees[i][2] |
|
|
|
z2 = donneespoint[2] |
|
|
|
dist = ((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2) |
|
|
|
return dist |
|
|
|
return ((d_final)**2)+((y1-y2)**2)+((z1-z2)**2) |
|
|
|
|
|
|
|
def PuissanceMoyenne(lst,distance): |
|
|
|
"""Fonction qui calcule la moyenne de distances entre les points """ |
|
|
|
def PuissanceMoyenne(lst_k_plus_proches): |
|
|
|
"""Calcule la moyenne de distances entre les points """ |
|
|
|
lecture("pic-journalier-consommation.csv") |
|
|
|
moy = sum() / len() |
|
|
|
conso_moy =0 # sum() / len(lst_k_plus_proches) |
|
|
|
return conso_moy |
|
|
|
|
|
|
|
def recup1(): |
|
|
|
voisins = value1.get() |
|
|
|
label5.configure(text=voisins) |
|
|
|
k = 5 #value1.get() |
|
|
|
return k |
|
|
|
|
|
|
|
def recup2(): |
|
|
|
date = value2.get() |
|
|
|
label6.configure(text=date) |
|
|
|
return date |
|
|
|
|
|
|
|
def recup3(): |
|
|
|
temp_moy = value3.get() |
|
|
|
label6.configure(text=temp_moy) |
|
|
|
return temp_moy |
|
|
|
|
|
|
|
def recup4(): |
|
|
|
temp_ref = value4.get() |
|
|
|
label6.configure(text=temp_ref) |
|
|
|
return temp_ref |
|
|
|
|
|
|
|
#def calc_conso(): |
|
|
|
# Conso = |
|
|
|
# label8.configure(text=Conso) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fenetre = Tk() |
|
|
|
txt_design = font = ('Helvetica', 12, 'bold', 'underline','italic') |
|
|
|
canvas1 = Canvas(fenetre) |
|
|
|
|
|
|
|
label1 = Label(fenetre, text="Choisissez le nombre de voisins (k) :",font = |
|
|
|
txt_design,bg ='#005dff',foreground="#ff5733") |
|
|
|
canvas1 = Canvas(fenetre) |
|
|
|
label1 = Label(fenetre, text="Choisissez le nombre de voisins (k) :") |
|
|
|
value1 = IntVar() |
|
|
|
entree1 = Entry(fenetre, textvariable=value1) |
|
|
|
entree1 = Entry(fenetre, textvariable=value1, width=45) |
|
|
|
|
|
|
|
label2 = Label(fenetre, text="Veuillez entrez la date (format 'aaaa-mm-jj'):",font = |
|
|
|
txt_design,bg ='#005dff',foreground="#ff5733") |
|
|
|
label2 = Label(fenetre, text="Veuillez entrez la date (format 'aaaa-mm-jj'):", width=45) |
|
|
|
value2 = IntVar() |
|
|
|
entree2 = Entry(fenetre, textvariable=value2) |
|
|
|
entree2 = Entry(fenetre, textvariable=value2, width=45) |
|
|
|
|
|
|
|
label3 = Label(fenetre, text="Veuillez entrez la température moyenne (en °C):",font = |
|
|
|
txt_design,bg ='#005dff',foreground="#ff5733") |
|
|
|
label3 = Label(fenetre, text="Veuillez entrez la température moyenne (en °C):", width=45) |
|
|
|
value3 = IntVar() |
|
|
|
entree3 = Entry(fenetre, textvariable=value3) |
|
|
|
entree3 = Entry(fenetre, textvariable=value3, width=45) |
|
|
|
|
|
|
|
label4 = Label(fenetre, text="Veuillez entrez la température de référence (en °C) :",font = |
|
|
|
txt_design,bg ='#005dff',foreground="#FF5733") |
|
|
|
label4 = Label(fenetre, text="Veuillez entrez la température de référence (en °C) :", width=45) |
|
|
|
value4 = IntVar() |
|
|
|
entree4 = Entry(fenetre, textvariable=value4) |
|
|
|
entree4 = Entry(fenetre, textvariable=value4, width=45) |
|
|
|
|
|
|
|
label1.grid(pady=10) |
|
|
|
entree1.grid() |
|
|
@ -183,16 +162,14 @@ entree3.grid() |
|
|
|
label4.grid(pady=10) |
|
|
|
entree4.grid() |
|
|
|
|
|
|
|
label9= Label(fenetre,width=8, text="Conso", bg="#b054da",fg='#fbff7a',font =('calibri',9,'bold') ,relief ='groove') |
|
|
|
label9 = Label(fenetre, text="Conso", bg="yellow") |
|
|
|
|
|
|
|
bouton1 = Button(canvas1, text="Tester", command=fenetre.destroy,height=2,width=8 ,bg="#e7374c",fg='#fbff7a', font = |
|
|
|
('colibri',13,'bold')).grid() |
|
|
|
bouton1 = Button(canvas1, text="Tester", command=lancer(recup1(), recup2(), recup3(), recup4(), moyenne_liste()), width=15, height=2, bg="cyan").grid(pady=10) |
|
|
|
|
|
|
|
canvas1.grid(pady = 15) |
|
|
|
label9.grid() |
|
|
|
canvas1.grid() |
|
|
|
label9.grid(pady=10) |
|
|
|
|
|
|
|
fenetre.title("IHM KNN") |
|
|
|
fenetre.iconbitmap('icon.ico') |
|
|
|
fenetre['bg'] = '#005dff' |
|
|
|
fenetre.geometry('400x360') |
|
|
|
fenetre.mainloop() |
|
|
|
|
|
|
|