From 230f699b5853cb381727abbb9dab8a3853854cce Mon Sep 17 00:00:00 2001 From: "michel.wang" Date: Mon, 30 May 2022 08:44:17 +0200 Subject: [PATCH] firstcommit --- tk.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tk.py diff --git a/tk.py b/tk.py new file mode 100644 index 0000000..18946b3 --- /dev/null +++ b/tk.py @@ -0,0 +1,111 @@ +from tkinter import * +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" """ + print(type(date)) + 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)) + + + + + +def recup(): + t_moy, t_ref, date, k_input = int(temp_moy.get()), int(temp_ref.get()), value_date.get(), int(nbk.get()) + print(PuissanceMoyenne(consos, kPlusProches((numeroJour(date), t_moy, t_ref), coords, 20))) + + label.configure(text=((PuissanceMoyenne(consos, kPlusProches((numeroJour(date), t_moy, t_ref), coords, k_input))))) + + +fenetre = Tk() +label = Label(fenetre, text="Prévision consommation électrique") +label.grid(row=0, column=2, pady = 10) + +Button(fenetre, text='Quitter', borderwidth=1, command=fenetre.destroy).grid(row=5, column=6, pady = 10, padx = 50) + +value_date = StringVar() +temp_moy = Entry(fenetre, text='temp_moy', width=100) +temp_moy.grid(row=4, column=2) +temp_ref = Entry(fenetre, text='temp_ref', width=100) +temp_ref.grid(row=5, column=2) +f_date = Entry(fenetre, textvariable=value_date, width=100) +f_date.grid(row=6, column=2) +bout = Button(text='Lancer', command=recup) +bout.grid(row=8, column=2) + +label = Label(fenetre, text="Choisir le nombre k") +label.grid(row=10, column=2, pady = 10) +nbk = Entry(fenetre, text='value_k_input', width=100) +nbk.grid(row=12, column = 2) + +fenetre.mainloop() \ No newline at end of file