def application_Vacance(self, dataset): donnees_covid = dataset.donnees_covid.liste donnees_vacance = dataset.donnees_vacances indice_dep = donnees_covid[0].index("dep") indice_jour = donnees_covid[0].index("jour") indice_selection = donnees_covid[0].index(self.var_selection) new_dataset = Dataset( Covid(None, [ donnees_covid[0][indice_dep], donnees_covid[0][indice_jour], self.var_jointure, self.var_selection ]), donnees_vacance) endroit = None if self.var_jointure in donnees_vacance['Academie'][ 0] and self.var_jointure in donnees_vacance['Calendrier'][0]: endroit = 'Academie' elif self.var_jointure in donnees_vacance['Calendrier'][0]: endroit = 'Calendrier' elif self.var_jointure in donnees_vacance['Academie'][0]: endroit = 'Academie' else: print( "La variable recherchée n'est pas présente. Revoyez l'écriture ou les données" ) for i in range(1, len(donnees_covid)): pos = 0 if donnees_covid[i][indice_dep] == '2A': while not donnees_vacance['Academie'][pos][ "Code_Dpt"] == '2A' and pos < ( len(donnees_vacance['Academie']) - 1): pos += 1 elif donnees_covid[i][indice_dep] == '2B': while not donnees_vacance['Academie'][pos][ "Code_Dpt"] == '2B' and pos < ( len(donnees_vacance['Academie']) - 1): pos += 1 else: while not float(donnees_vacance['Academie'][pos]["Code_Dpt"] ) == donnees_covid[i][indice_dep] and pos < ( len(donnees_vacance['Academie']) - 1): pos += 1 new_dataset.ajout_donnees_covid([ donnees_covid[i][indice_dep], donnees_covid[i][indice_jour], donnees_vacance[endroit][pos][self.var_jointure], donnees_covid[i][indice_selection] ]) return (new_dataset.donnees_covid.liste)
def ecart_type(self,dataset): resu=[] var=self.variance(dataset).donnees_covid.liste for ligne in var: resu.append([ligne[0],ligne[1]**(0.5)]) return Dataset(Covid(None,resu),None)
def application_Covid(self, dataset): new_list = [] covid = dataset.donnees_covid.liste indice = covid[0].index(self.var_selection) for elt in covid: new_list.append([elt[indice]]) return (Dataset(Covid(None, new_list), dataset.donnees_vacances))
def application_Covid(self, dataset): list_covid = dataset.donnees_covid.liste indice_var = list_covid[0].index(self.var_selection) list_moyenne = [[self.var_selection]] for i in range(self.time, len(list_covid)): moyenne = 0 for x in list_covid[i - self.time + 1:i]: moyenne += x[indice_var] moyenne /= self.time list_moyenne.append([moyenne]) return Dataset(Covid(None, list_moyenne), dataset.donnees_vacances)
def application_Vacance(self, dataset): vacances = dataset.donnees_vacances new_list = [] if self.var_selection in vacances['Calendrier'][0]: for elt in vacances['Calendrier']: new_list.append(elt[self.var_selection]) else: for elt in vacances['Academie']: new_list.append(elt[self.var_selection]) new_list.insert(0, self.var_selection) return (Dataset(dataset.donnees_covid, new_list))
def moyenne(self,dataset): resu=[] largueur=len(dataset.donnees_covid.liste[0]) longueur = len(dataset.donnees_covid.liste)-1 for i in range(largueur): if type(dataset.donnees_covid.liste[1][i])==float: sum=0 for donnees in dataset.donnees_covid.liste[1:]: sum=sum +float(donnees[i]) resu.append(['{}'.format(dataset.donnees_covid.liste[0][i]),sum/longueur]) return Dataset(Covid(None,resu),dataset.donnees_vacances)
def variance(self,dataset): resu=[] largueur=len(dataset.donnees_covid.liste[0]) longueur = len(dataset.donnees_covid.liste)-1 for i in range(largueur): if type(dataset.donnees_covid.liste[1][i])==float: var=0 for j in range(len(self.moyenne(dataset).donnees_covid.liste)): if self.moyenne(dataset).donnees_covid.liste[j][0]==dataset.donnees_covid.liste[0][i]: indice= j moy=self.moyenne(dataset).donnees_covid.liste[indice][1] for donnees in dataset.donnees_covid.liste[1:]: var= var+(float(donnees[i])-moy)**2 resu.append(['{}'.format(dataset.donnees_covid.liste[0][i]),var/longueur]) return Dataset(Covid(None,resu),dataset.donnees_vacances)
def application_Vacance(self, dataset): vacances = dataset.donnees_vacances.dictionnaire debut = [int(x) for x in self.date_debut.split('-')] fin = [int(x) for x in self.date_fin.split('-')] def convient(date): if not(debut[0]<=date[0]<=fin[0]): return False elif ( debut[0] == date[0] and debut[1] > date[1] ) or (fin[0] == date[0] and fin[1] < date[1]): return False elif ( debut[0] == date[0] and debut[1] == date[1] and debut[2] > date[2]) or (fin[0] == date[0] and fin[1] == date[1] and fin[2] < date[2]): return False else : return True list_calendrier = [] for i in range(len(vacances['Calendrier'])): if (vacances['Calendrier'][i]['Debut'] != None ) and (vacances['Calendrier'][i]['Fin'] != None) : vac_debut = [int(x) for x in vacances['Calendrier'][i]['Debut'].split('-')] vac_fin = [int(x) for x in vacances['Calendrier'][i]['Fin'].split('-')] if convient(vac_debut) and convient(vac_fin): list_calendrier.append(vacances['Calendrier'][i]) return Dataset(dataset.donnees_covid,Vacance(None,{'Calendrier': list_calendrier, 'Academie': vacances['Academie']}))
def application_Covid(self, dataset): list_covid = dataset.donnees_covid.liste list_date = [] indice_date=list_covid[0].index('jour') for x in list_covid[1:] : list_date.append([int(y) for y in x[indice_date].split('-')]) debut = [int(x) for x in self.date_debut.split('-')] fin = [int(x) for x in self.date_fin.split('-')] def convient(date): if not(debut[0]<=date[0]<=fin[0]): return False elif ( debut[0] == date[0] and debut[1] > date[1] ) or (fin[0] == date[0] and fin[1] < date[1]): return False elif ( debut[0] == date[0] and debut[1] == date[1] and debut[2] > date[2]) or (fin[0] == date[0] and fin[1] == date[1] and fin[2] < date[2]): return False else : return True new_jeu_covid =[list_covid[0]] for i in range(len(list_covid)-1): date = list_date[i] if convient(date): new_jeu_covid.append(list_covid[i+1]) return Dataset(Covid(None,new_jeu_covid),dataset.donnees_vacances)
def application_Covid(self, dataset): donnees_covid = dataset.donnees_covid.liste donnees_covid2 = self.dataset2.donnees_covid.liste indice_jour = donnees_covid[0].index("jour") indice_jour2 = donnees_covid2[0].index("jour") indice_sexe = None if "reg" in donnees_covid[0]: indice_spatial = donnees_covid[0].index("reg") elif "dep" in donnees_covid[0]: indice_spatial = donnees_covid[0].index("dep") elif "numReg" in donnees_covid[0]: indice_spatial = donnees_covid[0].index("Numreg") if 'sexe' in donnees_covid[0]: indice_sexe = donnees_covid[0].index("sexe") if self.var_selection in donnees_covid[0]: indice1 = donnees_covid[0].index(self.var_selection) elif self.var_jointure in donnees_covid[0]: indice1 = donnees_covid[0].index(self.var_jointure) if self.var_selection in donnees_covid2[0]: indice2 = donnees_covid2[0].index(self.var_selection) elif self.var_jointure in donnees_covid2[0]: indice2 = donnees_covid2[0].index(self.var_jointure) new_dataset = Dataset( Covid(None, [[ donnees_covid[0][indice_spatial], donnees_covid2[0][indice_jour2], donnees_covid[0][indice1], donnees_covid2[0][indice2] ]]), dataset.donnees_vacances) new_dataset.donnees_covid.append() pos = 1 i = 1 if len(donnees_covid) >= len( donnees_covid2): #il y a plus de jours dans donnees_covid if indice_sexe == None: while i < len(donnees_covid) and pos < (len(donnees_covid2)): if donnees_covid[i][indice_jour] == donnees_covid2[pos][ indice_jour2]: new_dataset.ajout_donnees_covid([ donnees_covid[i][indice_spatial], donnees_covid2[pos][indice_jour2], donnees_covid[i][indice1], donnees_covid2[pos][indice2] ]) i += 1 pos += 1 else: i += 1 else: while i < len(donnees_covid) and pos < (len(donnees_covid2)): if donnees_covid[i][indice_jour] == donnees_covid2[pos][ indice_jour2]: new_dataset.ajout_donnees_covid([ donnees_covid[i][indice_spatial], donnees_covid2[pos][indice_jour2], donnees_covid[i][indice1], donnees_covid2[pos][indice2] ]) i += 3 pos += 1 else: i += 3 else: if indice_sexe == None: while i < len(donnees_covid2) and pos < (len(donnees_covid2)): if donnees_covid2[i][indice_jour2] == donnees_covid[pos][ indice_jour]: new_dataset.ajout_donnees_covid([ donnees_covid[pos][indice_spatial], donnees_covid[pos][indice_jour2], donnees_covid[pos][indice1], donnees_covid2[i][indice2] ]) i += 1 pos += 1 else: i += 1 else: while i < len(donnees_covid) and pos < (len(donnees_covid2)): if donnees_covid2[i][indice_jour2] == donnees_covid[pos][ indice_jour]: new_dataset.ajout_donnees_covid([ donnees_covid[pos][indice_spatial], donnees_covid[pos][indice_jour2], donnees_covid[pos][indice1], donnees_covid2[i][indice2] ]) i += 3 pos += 1 else: i += 3 return (new_dataset)
'./Donnees/Donnees_Covid/donnees-hospitalieres-nouveaux-covid19-2021-03-03-17h03.csv' ) #d=Covid('/Users/thomashilger/Desktop/projet_donnees/Donnees/Donnees_Covid/covid-hospit-incid-reg-2021-03-03-17h20.csv') #data=Dataset(d) #print(Moyenne_glissante('numReg', 'covid', 20).application(data).donnees_covid.liste) # unittest.main() #Sauvegarder(Normalisation('numReg','covid').application(data)).SauvegarderCSV('normal') #print(Fenetrage('numReg', 'covid', '2020-03-019', '2020-03-20').application(Dataset(d)).donnees_covid) #Sauvegarder(a.liste).SauvegarderCSV('test',sep=',') #print(EstimationDescriptive().ecart_type(data)) data = Dataset(a, b.dictionnaire) #print(Covid(None,[["Academie"],['France']])) #print((Jointure('incid_hosp','vacance',"Zone").application(data))) #print(Selection_Var('jour','Covid').application(data)) #print(data2) #Sauvegarder(Selection_Var('numReg','covid').application(data)).SauvegarderCSV('selection.csv') # print((Agregation_Spatiale("dc",'Covid',"region").application(data))) #chiffre eh dessous des offciciels ??? #Selection_Var('numReg','covid').application(data).donnees_covid #data=(Selection_Var('jour','Covid').application(data)) #print(Selection_Var('numReg','covid').application(data).donnees_covid)
def application_regionale(self, dataset): var_dataset = (Selection_Var( self.var_selection, 'covid').application(dataset)).donnees_covid.liste liste_region = self.reg() donnees_covid = dataset.donnees_covid.liste somme = 0 indice_jour = donnees_covid[0].index("jour") indice_dep = donnees_covid[0].index("dep") if 'sexe' in dataset.donnees_covid.liste[0]: indice0, indice1, indice2 = self.sexe(dataset) somme0 = 0 somme1 = 0 somme2 = 0 difference1 = indice1 - indice0 difference2 = indice2 - indice0 difference = indice2 - indice0 + 1 ind_bon_dep = None new_dataset = Dataset( Covid(None, [["Region", 'jour', "sexe", self.var_selection]]), dataset.donnees_vacances) new_jour = donnees_covid[1][indice_jour] for region in liste_region: pos0 = indice0 while pos0 < (len(var_dataset) - difference): jour = donnees_covid[pos0][indice_jour] while jour == new_jour and pos0 < (len(var_dataset) - difference): if donnees_covid[pos0][indice_dep] in region: somme0 += var_dataset[pos0][0] somme1 += var_dataset[pos0 + difference1][0] somme2 += var_dataset[pos0 + difference2][0] ind_bon_dep = pos0 pos0 += difference new_jour = donnees_covid[pos0][indice_jour] else: pos0 += difference new_jour = donnees_covid[pos0][indice_jour] if ind_bon_dep != None: new_dataset.ajout_donnees_covid([ region[0], donnees_covid[pos0][indice_jour], float(0), somme0 ]) new_dataset.ajout_donnees_covid([ region[0], donnees_covid[pos0 + difference1][indice_jour], float(1), somme1 ]) new_dataset.ajout_donnees_covid([ region[0], donnees_covid[pos0 + difference2][indice_jour], float(2), somme2 ]) ind_bon_dep = None somme0 = 0 somme1 = 0 somme2 = 0 pos0 += difference else: new_dataset = Dataset( Covid(None, [["Region", 'jour', self.var_selection]]), dataset.donnees_vacances) somme = 0 i = 1 new_jour = donnees_covid[i][indice_jour] ind_bon_dep = None for region in liste_region: i = 1 while i < len(var_dataset) - 1: jour = donnees_covid[i][indice_jour] while jour == new_jour and i < len(var_dataset) - 1: if donnees_covid[i][indice_dep] in region: somme += var_dataset[i][0] ind_bon_dep = i i += 1 new_jour = donnees_covid[i][indice_jour] else: i += 1 new_jour = donnees_covid[i][indice_jour] if ind_bon_dep != None: new_dataset.ajout_donnees_covid([ region[0], donnees_covid[ind_bon_dep][indice_jour], somme ]) ind_bon_dep = None somme = 0 i += 1 return (new_dataset.donnees_covid.liste)
def application_nationale(self, dataset): var_dataset = (Selection_Var( self.var_selection, 'covid').application(dataset)).donnees_covid.liste donnees_covid = dataset.donnees_covid.liste somme = 0 indice_jour = donnees_covid[0].index("jour") if "sexe" in donnees_covid[0]: indice0, indice1, indice2 = self.sexe(dataset) somme0 = var_dataset[indice0][0] somme1 = var_dataset[indice2][0] somme2 = var_dataset[indice2][0] difference1 = indice1 - indice0 difference2 = indice2 - indice0 difference = indice2 - indice0 + 1 pos0 = indice0 + difference new_dataset = Dataset( Covid(None, [["Nationale", 'jour', 'sexe', self.var_selection]]), dataset.donnees_vacances) while pos0 < len(var_dataset) - difference: if donnees_covid[pos0][indice_jour] == donnees_covid[ pos0 - difference][indice_jour]: somme0 += var_dataset[pos0][0] somme1 += var_dataset[pos0 + difference1][0] somme2 += var_dataset[pos0 + difference2][0] pos0 += difference else: new_dataset.ajout_donnees_covid([ "France", donnees_covid[pos0][indice_jour], float(0), somme0 ]) new_dataset.ajout_donnees_covid([ "France", donnees_covid[pos0 + difference1][indice_jour], float(1), somme1 ]) new_dataset.ajout_donnees_covid([ "France", donnees_covid[pos0 + difference2][indice_jour], float(2), somme2 ]) somme0 = var_dataset[pos0][0] somme1 = var_dataset[pos0 + difference1][0] somme2 = var_dataset[pos0 + difference2][0] pos0 += difference else: new_dataset = Dataset( Covid(None, [["Nationale", 'jour', self.var_selection]]), dataset.donnees_vacances) somme = var_dataset[1][0] i = 2 while i < len(var_dataset): if donnees_covid[i][indice_jour] == donnees_covid[ i - 1][indice_jour]: somme += var_dataset[i][0] i += 1 else: new_dataset.ajout_donnees_covid( ["France", donnees_covid[i][indice_jour], somme]) somme = var_dataset[i][0] i += 1 return (new_dataset.donnees_covid.liste)