|
|
|
def lecture(fichier):
|
|
|
|
temp_jour = []
|
|
|
|
conso = []
|
|
|
|
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 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(365):
|
|
|
|
temp_jour[i][0] = numeroJour(temp_jour[i][0])
|
|
|
|
for l in range(len(temp_jour)):
|
|
|
|
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)
|
|
|
|
temp_num_jour
|
|
|
|
|
|
|
|
|
|
|
|
|