Browse Source
| Column 1 | Column 2 | Column 3 | | -------- | -------- | -------- | | Text | Textghxmaster
DAUDET Paul
3 years ago
1 changed files with 230 additions and 0 deletions
@ -0,0 +1,230 @@ |
|||
from tkinter import * |
|||
|
|||
fenetre = Tk() |
|||
txt_design = font = ('Helvetica', 12, 'bold', 'underline','italic') |
|||
canvas1 = Canvas(fenetre) |
|||
|
|||
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) |
|||
conso_moy = PuissanceMoyenne(lst_k_plus_proches) |
|||
label9.configure(text=conso_moy) |
|||
|
|||
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""" |
|||
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.""" |
|||
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("-")) |
|||
|
|||
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") |
|||
donnees= [] |
|||
lst_conso = [] |
|||
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 = donnees[i][0] |
|||
x2 = donneespoint[0] |
|||
d1 = x1-x2 |
|||
d2 = 365 - d1 |
|||
d_final = d1 |
|||
if d1 > d2: |
|||
d_final = d2 |
|||
y1 = donnees[i][1] |
|||
y2 = donneespoint[1] |
|||
z1 = donnees[i][2] |
|||
z2 = donneespoint[2] |
|||
return ((d_final)**2)+((y1-y2)**2)+((z1-z2)**2) |
|||
|
|||
def PuissanceMoyenne(lst_k_plus_proches): |
|||
"""Calcule la moyenne de distances entre les points """ |
|||
lecture("pic-journalier-consommation.csv") |
|||
conso_moy = 10 # sum() / len(lst_k_plus_proches) |
|||
return conso_moy |
|||
|
|||
|
|||
global count |
|||
colour = "" |
|||
|
|||
count = 0 |
|||
|
|||
def start(parent): |
|||
Tk.after(parent, 100, change) |
|||
|
|||
def change(): |
|||
|
|||
global count |
|||
if (count == 1): |
|||
fenetre.configure(bg = '#c0392b') |
|||
if (count == 2): |
|||
fenetre.configure(bg = '#e74c3c') |
|||
if (count == 3): |
|||
fenetre.configure(bg = '#9b59b6') |
|||
if (count == 4): |
|||
fenetre.configure(bg = '#8e44ad') |
|||
if (count == 5): |
|||
fenetre.configure(bg = '#2980b9') |
|||
if (count == 6): |
|||
fenetre.configure(bg = '#3498db') |
|||
if (count == 7): |
|||
fenetre.configure(bg = '#1abc9c') |
|||
if (count == 8): |
|||
fenetre.configure(bg = '#16a085') |
|||
if (count == 9): |
|||
fenetre.configure(bg = '#2ecc71') |
|||
if (count == 10): |
|||
fenetre.configure(bg = '#f1c40f') |
|||
if (count == 11): |
|||
fenetre.configure(bg = '#f39c12') |
|||
if (count == 12): |
|||
fenetre.configure(bg = '#e67e22') |
|||
if (count == 13): |
|||
fenetre.configure(bg = '#d35400') |
|||
if (count == 14): |
|||
fenetre.configure(bg = '#2c3e50') |
|||
start(fenetre) |
|||
for i in range (1): |
|||
count = count + 1 |
|||
if count == 15: |
|||
count = 1 |
|||
change() |
|||
|
|||
def recup1(): |
|||
k = 5 |
|||
return k |
|||
|
|||
def recup2(): |
|||
date = 2016 |
|||
return date |
|||
|
|||
def recup3(): |
|||
temp_moy = 34 |
|||
return temp_moy |
|||
|
|||
def recup4(): |
|||
temp_ref = 41 |
|||
return temp_ref |
|||
|
|||
def calc_conso(): |
|||
conso_moy = PuissanceMoyenne(lst_k_plus_proches) |
|||
label9.configure(text=conso_moy) |
|||
|
|||
label1 = Label(fenetre, text="Choisissez le nombre de voisins (k) :", font = |
|||
txt_design, bg ='#005dff', foreground="#ff5733") |
|||
value1 = IntVar() |
|||
entree1 = Entry(fenetre, textvariable=value1) |
|||
|
|||
label2 = Label(fenetre, text="Veuillez entrez la date (format 'aaaa-mm-jj'):", font = |
|||
txt_design, bg ='#005dff', foreground="#ff5733") |
|||
value2 = IntVar() |
|||
entree2 = Entry(fenetre, textvariable=value2) |
|||
|
|||
label3 = Label(fenetre, text="Veuillez entrez la température moyenne (en °C):", font = |
|||
txt_design, bg ='#005dff', foreground="#ff5733") |
|||
value3 = IntVar() |
|||
entree3 = Entry(fenetre, textvariable=value3) |
|||
|
|||
label4 = Label(fenetre, text="Veuillez entrez la température de référence (en °C) :", font = |
|||
txt_design, bg ='#005dff', foreground="#FF5733") |
|||
value4 = IntVar() |
|||
entree4 = Entry(fenetre, textvariable=value4) |
|||
|
|||
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,width=8, text="Conso", bg="#b054da", fg='#fbff7a', font =('calibri',9,'bold') , relief ='groove') |
|||
|
|||
bouton1 = Button(canvas1, text="Tester", command=lancer(recup1(), recup2(), recup3(), recup4(), moyenne_liste()), height=2,width=8 , bg="#e7374c", fg='#fbff7a', font = |
|||
('colibri',13,'bold')).grid() |
|||
|
|||
canvas1.grid(pady = 15) |
|||
label9.grid() |
|||
|
|||
fenetre.title("IHM KNN") |
|||
fenetre.iconbitmap('icon.ico') |
|||
fenetre['bg'] = 'blue' |
|||
fenetre.geometry('400x360') |
|||
fenetre.mainloop() |
Loading…
Reference in new issue