def GetColumn(ligne, colnumber): myarray = ligne.split("\t") return str(myarray[colnumber]) def GetDateFromDateTime (datetime): return datetime[:10] def DoTempMatch (temp1, temp2, temp3, temp4, tolerence): tmin = abs(temp1) - tolerence tmax = abs(temp1) + tolerence if (abs(temp2) > tmax or abs(temp2) < tmin): return False if (abs(temp3) > tmax or abs(temp3) < tmin): return False if (abs(temp4) > tmax or abs(temp4) < tmin): return False return True # Automatisation de fichiers de donnees brutes # # Recherche du point a partir duquel la temperature ne varie plus # Recuperation des donnees # Fichier avec incrementation de profondeurs tous les 5cm fichierBase = 'D:\data\myfile\raw_corrected.txt' fichierBaseDestination = 'D:\data\myfile\Results.txt' # Marge acceptable de variation de temperatures pour chaque jour tolerance = input('Entrez la tolerance en degres Celsius: ') tolerance = float(tolerance) # Transformation de la tolerance en nombre a virgule flottante nomIsothermeFinal = 'Fichier_final.txt' # Ouverture lecture fermeture du fichier (source) fichierIsotherme = open(fichierBase) lignes = fichierIsotherme.readlines() fichierIsotherme.close() enteteProfondeur = lignes[1] lignesdonnees = lignes[2:] print ("Nombre de lignes totales", len(lignesdonnees)) #verification des donnees index = 0; while (1): myDateTime1 = GetDateFromDateTime( GetColumn(lignesdonnees[index],1)) myDateTime2 = GetDateFromDateTime( GetColumn(lignesdonnees[index+1],1)) myDateTime3 = GetDateFromDateTime( GetColumn(lignesdonnees[index+2],1)) myDateTime4 = GetDateFromDateTime( GetColumn(lignesdonnees[index+3],1)) if (myDateTime1 != myDateTime2 or myDateTime1 != myDateTime3 or myDateTime1 != myDateTime4): print ("Erreur avec les dates... Tabouret verifie ton fichier!!!! a la ligne {} date: {}".format(index, myDateTime1)) break index = index + 4 if (index + 3 >= len(lignesdonnees)): break if ((len(lignesdonnees) % 4) != 0 ): print ("Erreur nombre de lignes pas divisible par 4") exit() # processing nombretours = len(lignesdonnees) / 4 print ("Nombre de jours:", nombretours) # Ouverture du fichier (destination) fichierDestination = open(fichierBaseDestination, 'w') fichierDestination.write ('Fichier genere par search_point.py pour trouver le point isotherme\n') fichierDestination.write ('INDEX\tDATE\tCOLONNE\tPROFONDEUR\tTEMPERATURE\n') index = 0 YoupiTrouve = 0 BouhPasTrouve = 0 while ( index < len(lignesdonnees)): # recuperer nombre de colonnes nbcol = len(lignesdonnees[index].split("\t")) if (index == 0): print ("nombre de colonnes:", nbcol) colindex = 2 trouvetempmatch = False while (colindex < nbcol): myCol1 = float(GetColumn(lignesdonnees[index], colindex)) myCol2 = float(GetColumn(lignesdonnees[index+1], colindex)) myCol3 = float(GetColumn(lignesdonnees[index+2], colindex)) myCol4 = float(GetColumn(lignesdonnees[index+3], colindex)) colindex = colindex + 1 if (DoTempMatch(myCol1, myCol2, myCol3, myCol4, tolerance) == True and myCol1 < 30): #print ("Youpi...{} temperature match at column {}, profondeur: {}, temperature: {}".format(index,colindex, GetColumn(enteteProfondeur, colindex), myCol1)) fichierDestination.write ("{}\t{}\t{}\t{}\t{}\n".format(index, GetDateFromDateTime( GetColumn(lignesdonnees[index],1)), colindex, GetColumn(enteteProfondeur, colindex), myCol1)) YoupiTrouve = YoupiTrouve + 1 trouvetempmatch = True break if (trouvetempmatch == False): #print ("Bouhhh... pas trouve snif snif") fichierDestination.write ("{}\t{}\n".format(index, GetDateFromDateTime( GetColumn(lignesdonnees[index],1)))) BouhPasTrouve = BouhPasTrouve + 1 index = index + 4 fichierDestination.close() #isothermeFinal = open(nomIsothermeFinal, 'w') #isothermeFinal.write ('Fichier genere par search_point.py pour trouver le point isotherme') print ("{} Temperatures trouvees, {} Temperatures non trouvees".format(YoupiTrouve, BouhPasTrouve)) #print (len(lignesdonnees) % 4) # Calcul du point isotherme par jour # Recherche de la profondeur a laquelle la temperature ne varie plus (+- la tolerance) #for index in range(len(lignesdonnees) / 4): # if (index == 1): # print (ligne) #for day in ligne.readlines(0,4): # print day #day.close() # while ligne < 5: # ligne = ligne + 1 # if (ligne[0] == ligne[1] +- tolerance): # print (index[profondeurs]) # print ('la profondeur charniere est', ) # isothermeFinal.write(','.join(profondeurs) + ',') #isothermeFinal.close()