import os from datetime import datetime, timedelta import sys import matplotlib.pyplot as plt import gc import codecs FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' def date(): return datetime.now().strftime("%d/%m/%Y %H:%M:%S") def write_log(mode="a", *args): message = ' '.join(map(str, args)) print(message) with codecs.open(FILELOG, mode, "utf8") as f: f.write(message + '\r\n') def process_file(file, file_type): FILE = os.path.join(AQU_FOLDER, file) if os.stat(FILE).st_size == 0: print(f'Le fichier {os.path.basename(FILE)} est vide') Error.append(os.path.basename(FILE) + ' est vide') return liste_value = [] liste_date = [] with open(FILE) as f: for line in f: try: Date, Station, Type, Valeur = line.strip().split(';') Date_format = Date.replace('-', '/', 2) Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") duree = today - timedelta(days=5) if Date_good_type > duree: liste_value.append(float(Valeur)) liste_date.append(Date_good_type) except ValueError as ve: print(f"Erreur de format de date pour le fichier {file}: {ve}") continue if liste_value: plt.figure(figsize=(6, 3)) plt.plot(liste_date, liste_value) plt.xticks(rotation=45) plt.title(Station) plt.tight_layout() plt.xlabel('Temps') ylabel = {'niv': 'Niveau (m)', 'deb': 'Debit (m3/s)', 'plu': 'Pluie (mm)'}.get(file_type) plt.ylabel(ylabel) file_name = f'{Station}_{ylabel.replace(" ", "_").replace("/", "_")}.png' plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{file_name}', bbox_inches="tight", dpi=30) plt.close() def process_files(file_list, file_type): total_files = len(file_list) print(f"\nTraitement des fichiers {file_type} ({total_files} fichiers)...") for i, file in enumerate(file_list): try: process_file(file, file_type) except Exception as e: print(f"Erreur lors du traitement du fichier {file}: {e}") Error.append(f"Erreur avec {file}: {e}") progress = int((i + 1) / total_files * 100) #print(f"Progression {file_type} : {progress}% ({i + 1}/{total_files})") #print(f"\nTraitement des fichiers {file_type} terminé.\n") return total_files def process_file_batches(file_list, file_type, batch_size, message): count = 0 if file_list: for batch_start in range(0, len(file_list), batch_size): batch_files = file_list[batch_start:batch_start + batch_size] count += process_files(batch_files, file_type) gc.collect() print(f'\n{message} traité. Mémoire libérée.\n') return count def process_all_files(): file_types = {'niv': AQU_FILES_NIV, 'deb': AQU_FILES_DEB, 'plu': AQU_FILES_PLU} counts = {} for file_type, file_list in file_types.items(): count = process_file_batches(file_list, file_type, batch_size, f'Batch de fichiers {file_type.upper()}') counts[file_type] = count print(f'\nNombre total de graphiques créés : NIV={counts["niv"]}, DEB={counts["deb"]}, PLU={counts["plu"]}\n') write_log("a", "Nombre total de graphiques créés NIV=", counts["niv"], "DEB=", counts["deb"], "PLU=", counts["plu"]) write_log("a", "\n") print("\nExecution du script " + sys.argv[0] + "\n") DATEDEB = date() write_log("w", "\n") write_log("a", "Execution du script ", sys.argv[0]) write_log("a", "\n") write_log("a", " ", DATEDEB) write_log("a", "\n") AQU_FILES_NIV = [f for f in os.listdir(AQU_FOLDER) if f.endswith('niv.aqu') and not f.endswith('piezo_niv.aqu')] AQU_FILES_DEB = [f for f in os.listdir(AQU_FOLDER) if f.endswith('deb.aqu')] AQU_FILES_PLU = [f for f in os.listdir(AQU_FOLDER) if f.endswith('plu.aqu') and not f.endswith('MF_plu.aqu')] print(f"Nombre de fichiers .aqu pour chaque type :") print(f" NIV: {len(AQU_FILES_NIV)}") print(f" DEB: {len(AQU_FILES_DEB)}") print(f" PLU: {len(AQU_FILES_PLU)}") batch_size = 50 Error = [] today = datetime.now() process_all_files() DATEFIN = date() write_log("a", "\n") write_log("a", " ", DATEFIN) write_log("a", "\n") write_log("a", "Fin du script") write_log("a", "\n") print('\nFin du script') ## v10 FONCTIONNE MAIS PEU ESTHETIQUE ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import gc ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ## ##def date(): ## return datetime.now().strftime("%d/%m/%Y %H:%M:%S") ## ##def write_log(mode="a", *args): ## message = ' '.join(map(str, args)) ## print(message) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(message + '\r\n') ## ##def process_file(file, file_type): ## FILE = os.path.join(AQU_FOLDER, file) ## if os.stat(FILE).st_size == 0: ## print(f'Le fichier {os.path.basename(FILE)} est vide') ## Error.append(os.path.basename(FILE) + ' est vide') ## return ## ## liste_value = [] ## liste_date = [] ## ## with open(FILE) as f: ## for line in f: ## try: ## Date, Station, Type, Valeur = line.strip().split(';') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## except ValueError as ve: ## print(f"Erreur de format de date pour le fichier {file}: {ve}") ## continue ## ## if liste_value: ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## ylabel = {'niv': 'Niveau (m)', 'deb': 'Debit (m3/s)', 'plu': 'Pluie (mm)'}.get(file_type) ## plt.ylabel(ylabel) ## file_name = f'{Station}_{ylabel.replace(" ", "_").replace("/", "_")}.png' ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{file_name}', bbox_inches="tight", dpi=30) ## plt.close() ## ##def process_files(file_list, file_type): ## total_files = len(file_list) ## print(f"\nTraitement des fichiers {file_type} ({total_files} fichiers)...") ## for i, file in enumerate(file_list): ## try: ## process_file(file, file_type) ## except Exception as e: ## print(f"Erreur lors du traitement du fichier {file}: {e}") ## Error.append(f"Erreur avec {file}: {e}") ## ## progress = int((i + 1) / total_files * 100) ## print(f"\rProgression {file_type} : {progress}% ({i + 1}/{total_files})", end='') ## ## print(f"\nTraitement des fichiers {file_type} terminé.\n") ## return total_files ## ##def process_file_batches(file_list, file_type, batch_size, message): ## count = 0 ## if file_list: ## for batch_start in range(0, len(file_list), batch_size): ## batch_files = file_list[batch_start:batch_start + batch_size] ## count += process_files(batch_files, file_type) ## gc.collect() ## print(f'\n{message} traité. Mémoire libérée.\n') ## return count ## ##def process_all_files(): ## file_types = {'niv': AQU_FILES_NIV, 'deb': AQU_FILES_DEB, 'plu': AQU_FILES_PLU} ## counts = {} ## for file_type, file_list in file_types.items(): ## count = process_file_batches(file_list, file_type, batch_size, f'Batch de fichiers {file_type.upper()}') ## counts[file_type] = count ## ## print(f'\nNombre total de graphiques créés : NIV={counts["niv"]}, DEB={counts["deb"]}, PLU={counts["plu"]}\n') ## write_log("a", "Nombre total de graphiques créés NIV=", counts["niv"], "DEB=", counts["deb"], "PLU=", counts["plu"]) ## write_log("a", "\n") ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FILES_NIV = [f for f in os.listdir(AQU_FOLDER) if f.endswith('niv.aqu')] # and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_DEB = [f for f in os.listdir(AQU_FOLDER) if f.endswith('deb.aqu')] # and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_PLU = [f for f in os.listdir(AQU_FOLDER) if f.endswith('plu.aqu') and not f.endswith('MF_plu.aqu')] # and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ##print(f"Nombre de fichiers .aqu pour chaque type :") ##print(f" NIV: {len(AQU_FILES_NIV)}") ##print(f" DEB: {len(AQU_FILES_DEB)}") ##print(f" PLU: {len(AQU_FILES_PLU)}") ## ##batch_size = 50 ##Error = [] ##today = datetime.now() ## ##process_all_files() ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "Fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## ## V9 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import gc ##import codecs ##import time ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## return now.strftime("%d/%m/%Y %H:%M:%S") ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##def process_files(file_list, file_type, type_count): ## count = 0 ## for file in file_list: ## FILE = os.path.join(AQU_FOLDER, file) ## try: ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print(f'Le fichier {os.path.basename(FILE)} est vide') ## Error.append(os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if file_type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## elif file_type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_debit.png', bbox_inches="tight", dpi=30) ## elif file_type == "plu": ## plt.ylabel('Pluie (mm)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=30) ## ## plt.close() ## count += 1 ## except Exception as e: ## print(f"Erreur lors du traitement du fichier {FILE}: {e}") ## Error.append(f"Erreur avec {FILE}: {e}") ## continue ## ## return count ## ##def print_progress(current, total, file_type): ## progress = (current / total) * 100 ## print(f"\rProgression {file_type}: [{current}/{total}] - {progress:.2f}%", end="") ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ## ### Créer des listes pour chaque type de fichier ##AQU_FILES_NIV = [f for f in os.listdir(AQU_FOLDER) if f.endswith('niv.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_DEB = [f for f in os.listdir(AQU_FOLDER) if f.endswith('deb.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_PLU = [f for f in os.listdir(AQU_FOLDER) if f.endswith('plu.aqu') and not f.endswith('MF_plu.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ##nombre_fichiers_AQU_NIV = len(AQU_FILES_NIV) ##nombre_fichiers_AQU_DEB = len(AQU_FILES_DEB) ##nombre_fichiers_AQU_PLU = len(AQU_FILES_PLU) ## ##print(f"Nombre de fichiers .aqu pour chaque type :") ##print(f" NIV: {nombre_fichiers_AQU_NIV}") ##print(f" DEB: {nombre_fichiers_AQU_DEB}") ##print(f" PLU: {nombre_fichiers_AQU_PLU}") ## ##today = datetime.today() ##Error = [] ## ### Traitement par lot ##batch_size = 50 # Nombre de fichiers à traiter par lot ## ## Traitement des fichiers NIV ##count_niv = 0 ##for batch_start in range(0, nombre_fichiers_AQU_NIV, batch_size): ## batch_files_niv = AQU_FILES_NIV[batch_start:batch_start + batch_size] ## count_niv += process_files(batch_files_niv, 'niv', nombre_fichiers_AQU_NIV) ## print_progress(batch_start + batch_size if batch_start + batch_size < nombre_fichiers_AQU_NIV else nombre_fichiers_AQU_NIV, nombre_fichiers_AQU_NIV, "NIV") ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers NIV traité. Mémoire libérée.\n') ##time.sleep(5) ### Traitement des fichiers DEB ##count_deb = 0 ##for batch_start in range(0, nombre_fichiers_AQU_DEB, batch_size): ## batch_files_deb = AQU_FILES_DEB[batch_start:batch_start + batch_size] ## count_deb += process_files(batch_files_deb, 'deb', nombre_fichiers_AQU_DEB) ## print_progress(batch_start + batch_size if batch_start + batch_size < nombre_fichiers_AQU_DEB else nombre_fichiers_AQU_DEB, nombre_fichiers_AQU_DEB, "DEB") ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers DEB traité. Mémoire libérée.\n') ##time.sleep(5) ## Traitement des fichiers PLU ##count_plu = 0 ##for batch_start in range(0, nombre_fichiers_AQU_PLU, batch_size): ## batch_files_plu = AQU_FILES_PLU[batch_start:batch_start + batch_size] ## count_plu += process_files(batch_files_plu, 'plu') ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers PLU traité. Mémoire libérée.\n') ##time.sleep(5) ##print(f'\nNombre total de graphiques créés : NIV={count_niv}, DEB={count_deb}, PLU={count_plu}\n') ##write_log("a", "Nombre total de graphiques créés : NIV=", count_niv, ", DEB=", count_deb, ", PLU=", count_plu) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('Problèmes dans les fichiers:') ## write_log("a", "\n") ## write_log("a", " Problèmes dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "Fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## ## V8 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import matplotlib.patches as patches ##import gc ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## return now.strftime("%d/%m/%Y %H:%M:%S") ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##def process_files(file_list, file_type, type_count): ## count = 0 ## for file in file_list: ## FILE = os.path.join(AQU_FOLDER, file) ## print(f"Traitement du fichier : {FILE}") ## try: ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print(f'Le fichier {os.path.basename(FILE)} est vide') ## Error.append(os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if file_type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## elif file_type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_debit.png', bbox_inches="tight", dpi=30) ## elif file_type == "plu": ## plt.ylabel('Pluie (mm)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=30) ## ## plt.close() ## count += 1 ## except Exception as e: ## print(f"Erreur lors du traitement du fichier {FILE}: {e}") ## Error.append(f"Erreur avec {FILE}: {e}") ## continue ## ## return count ## ##def plot_progress_bar(progress_dict): ## plt.figure(figsize=(10, 5)) ## types = progress_dict.keys() ## counts = progress_dict.values() ## plt.bar(types, counts, color=['blue', 'green', 'red']) ## plt.xlabel('Type de fichier') ## plt.ylabel('Nombre de fichiers traités') ## plt.title('État d\'avancement du traitement des fichiers') ## plt.ylim(0, max(counts) + 10) # Ajuster la limite supérieure pour plus de lisibilité ## plt.tight_layout() ## plt.savefig('C:/xampp/htdocs/dashboard/graph/progress_bar.png', bbox_inches='tight') ## plt.close() ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ## ### Créer des listes pour chaque type de fichier ##AQU_FILES_NIV = [f for f in os.listdir(AQU_FOLDER) if f.endswith('niv.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_DEB = [f for f in os.listdir(AQU_FOLDER) if f.endswith('deb.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_PLU = [f for f in os.listdir(AQU_FOLDER) if f.endswith('plu.aqu') and not f.endswith('MF_plu.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ##nombre_fichiers_AQU_NIV = len(AQU_FILES_NIV) ##nombre_fichiers_AQU_DEB = len(AQU_FILES_DEB) ##nombre_fichiers_AQU_PLU = len(AQU_FILES_PLU) ## ##print(f"Nombre de fichiers .aqu pour chaque type :") ##print(f" NIV: {nombre_fichiers_AQU_NIV}") ##print(f" DEB: {nombre_fichiers_AQU_DEB}") ##print(f" PLU: {nombre_fichiers_AQU_PLU}") ## ##today = datetime.today() ##Error = [] ## ### Traitement par lot ##batch_size = 50 # Nombre de fichiers à traiter par lot ## ### Traitement des fichiers NIV ##count_niv = 0 ##for batch_start in range(0, nombre_fichiers_AQU_NIV, batch_size): ## batch_files_niv = AQU_FILES_NIV[batch_start:batch_start + batch_size] ## count_niv += process_files(batch_files_niv, 'niv', nombre_fichiers_AQU_NIV) ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers NIV traité. Mémoire libérée.\n') ## ### Traitement des fichiers DEB ##count_deb = 0 ##for batch_start in range(0, nombre_fichiers_AQU_DEB, batch_size): ## batch_files_deb = AQU_FILES_DEB[batch_start:batch_start + batch_size] ## count_deb += process_files(batch_files_deb, 'deb', nombre_fichiers_AQU_DEB) ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers DEB traité. Mémoire libérée.\n') ## ### Traitement des fichiers PLU ##count_plu = 0 ##for batch_start in range(0, nombre_fichiers_AQU_PLU, batch_size): ## batch_files_plu = AQU_FILES_PLU[batch_start:batch_start + batch_size] ## count_plu += process_files(batch_files_plu, 'plu', nombre_fichiers_AQU_PLU) ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers PLU traité. Mémoire libérée.\n') ## ### Créer le bargraphe de l'état d'avancement ##progress_dict = { ## 'NIV': count_niv, ## 'DEB': count_deb, ## 'PLU': count_plu ##} ##plot_progress_bar(progress_dict) ## ##print(f'\nNombre total de graphiques créés : NIV={count_niv}, DEB={count_deb}, PLU={count_plu}\n') ##write_log("a", "Nombre total de graphiques créés : NIV=", count_niv, ", DEB=", count_deb, ", PLU=", count_plu) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('Problèmes dans les fichiers:') ## write_log("a", "\n") ## write_log("a", " Problèmes dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "Fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## ## ####import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import matplotlib.patches as patches ##import gc ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## return now.strftime("%d/%m/%Y %H:%M:%S") ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##def process_files(file_list, file_type, type_count): ## count = 0 ## for file in file_list: ## FILE = os.path.join(AQU_FOLDER, file) ## print(f"Traitement du fichier : {FILE}") ## try: ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print(f'Le fichier {os.path.basename(FILE)} est vide') ## Error.append(os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if file_type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## elif file_type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_debit.png', bbox_inches="tight", dpi=30) ## elif file_type == "plu": ## plt.ylabel('Pluie (mm)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=30) ## ## plt.close() ## count += 1 ## except Exception as e: ## print(f"Erreur lors du traitement du fichier {FILE}: {e}") ## Error.append(f"Erreur avec {FILE}: {e}") ## continue ## ## return count ## ##def plot_progress_bar(progress_dict): ## plt.figure(figsize=(10, 5)) ## types = progress_dict.keys() ## counts = progress_dict.values() ## plt.bar(types, counts, color=['blue', 'green', 'red']) ## plt.xlabel('Type de fichier') ## plt.ylabel('Nombre de fichiers traités') ## plt.title('État d\'avancement du traitement des fichiers') ## plt.ylim(0, max(counts) + 10) # Ajuster la limite supérieure pour plus de lisibilité ## plt.tight_layout() ## plt.savefig('C:/xampp/htdocs/dashboard/graph/progress_bar.png', bbox_inches='tight') ## plt.close() ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ## ### Créer des listes pour chaque type de fichier ##AQU_FILES_NIV = [f for f in os.listdir(AQU_FOLDER) if f.endswith('niv.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_DEB = [f for f in os.listdir(AQU_FOLDER) if f.endswith('deb.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##AQU_FILES_PLU = [f for f in os.listdir(AQU_FOLDER) if f.endswith('plu.aqu') and not f.endswith('MF_plu.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ##nombre_fichiers_AQU_NIV = len(AQU_FILES_NIV) ##nombre_fichiers_AQU_DEB = len(AQU_FILES_DEB) ##nombre_fichiers_AQU_PLU = len(AQU_FILES_PLU) ## ##print(f"Nombre de fichiers .aqu pour chaque type :") ##print(f" NIV: {nombre_fichiers_AQU_NIV}") ##print(f" DEB: {nombre_fichiers_AQU_DEB}") ##print(f" PLU: {nombre_fichiers_AQU_PLU}") ## ##today = datetime.today() ##Error = [] ## ### Traitement par lot ##batch_size = 50 # Nombre de fichiers à traiter par lot ## ### Traitement des fichiers NIV ##count_niv = 0 ##for batch_start in range(0, nombre_fichiers_AQU_NIV, batch_size): ## batch_files_niv = AQU_FILES_NIV[batch_start:batch_start + batch_size] ## count_niv += process_files(batch_files_niv, 'niv', nombre_fichiers_AQU_NIV) ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers NIV traité. Mémoire libérée.\n') ## ### Traitement des fichiers DEB ##count_deb = 0 ##for batch_start in range(0, nombre_fichiers_AQU_DEB, batch_size): ## batch_files_deb = AQU_FILES_DEB[batch_start:batch_start + batch_size] ## count_deb += process_files(batch_files_deb, 'deb', nombre_fichiers_AQU_DEB) ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers DEB traité. Mémoire libérée.\n') ## ### Traitement des fichiers PLU ##count_plu = 0 ##for batch_start in range(0, nombre_fichiers_AQU_PLU, batch_size): ## batch_files_plu = AQU_FILES_PLU[batch_start:batch_start + batch_size] ## count_plu += process_files(batch_files_plu, 'plu', nombre_fichiers_AQU_PLU) ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers PLU traité. Mémoire libérée.\n') ## ### Créer le bargraphe de l'état d'avancement ##progress_dict = { ## 'NIV': count_niv, ## 'DEB': count_deb, ## 'PLU': count_plu ##} ##plot_progress_bar(progress_dict) ## ##print(f'\nNombre total de graphiques créés : NIV={count_niv}, DEB={count_deb}, PLU={count_plu}\n') ##write_log("a", "Nombre total de graphiques créés : NIV=", count_niv, ", DEB=", count_deb, ", PLU=", count_plu) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('Problèmes dans les fichiers:') ## write_log("a", "\n") ## write_log("a", " Problèmes dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "Fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## V7 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import gc ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## return now.strftime("%d/%m/%Y %H:%M:%S") ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##def process_files(file_list, file_type): ## count = 0 ## for file in file_list: ## FILE = os.path.join(AQU_FOLDER, file) ## #print(f"Traitement du fichier : {FILE}") ## try: ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print(f'Le fichier {os.path.basename(FILE)} est vide') ## Error.append(os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if file_type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## #print(f'fichier {Station}_Niveau.png créé') ## elif file_type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_debit.png', bbox_inches="tight", dpi=30) ## #print(f'fichier {Station}_debit.png créé') ## elif file_type == "plu": ## plt.ylabel('Pluie (mm)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=30) ## #print(f'fichier {Station}_Pluie.png créé') ## ## plt.close() ## count += 1 ## except Exception as e: ## print(f"Erreur lors du traitement du fichier {FILE}: {e}") ## Error.append(f"Erreur avec {FILE}: {e}") ## continue ## ## print(f'\nNombre de graphiques créés pour les fichiers {file_type}.aqu = {count}\n') ## write_log("a", f"Nombre de graphiques créés pour les fichiers {file_type}.aqu ", count) ## write_log("a", "\n") ## ## # Nettoyer la mémoire après chaque liste traitée ## gc.collect() ## print('\nMémoire nettoyée.\n') ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ### Filtrer les fichiers avec extensions 'niv.aqu', 'plu.aqu', et 'deb.aqu' en excluant 'MF_plu.aqu' ##AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith(('niv.aqu', 'plu.aqu', 'deb.aqu')) and not f.endswith('MF_plu.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ### Séparer les fichiers en trois listes ## ##niv_files = [f for f in AQU_FILES if f.endswith('niv.aqu')] ##deb_files = [f for f in AQU_FILES if f.endswith('deb.aqu')] ##plu_files = [f for f in AQU_FILES if f.endswith('plu.aqu')] ## ##nombre_fichiers_AQU = len(AQU_FILES) ##print(f"Nombre total de fichiers .aqu filtrés : {nombre_fichiers_AQU}") ## ##today = datetime.today() ##Error = [] ## ### Traiter les fichiers par type ##print("\ntraitement des fichiers de niveau\n") ##process_files(niv_files, "niv") ## ##print("traitement des fichiers de debit\n") ##process_files(deb_files, "deb") ## ##print("traitement des fichiers de pluie\n") ##process_files(plu_files, "plu") ## ##if len(Error) > 0: ## print('Problèmes dans les fichiers:') ## write_log("a", "\n") ## write_log("a", " Problèmes dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "Fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## V6 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import gc ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## date_time = now.strftime("%d/%m/%Y %H:%M:%S") ## return date_time ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ### Filtrer les fichiers avec extensions 'niv.aqu', 'plu.aqu', et 'deb.aqu' ###AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith(('niv.aqu', 'plu.aqu', 'deb.aqu')) and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ## ##AQU_FILES = [f for f in os.listdir(AQU_FOLDER) ## if f.endswith(('niv.aqu', 'plu.aqu', 'deb.aqu')) ## and not f.endswith('MF_plu.aqu') ] # and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ## ##nombre_fichiers_AQU = len(AQU_FILES) ##print(f"Nombre de fichiers .aqu filtrés : {nombre_fichiers_AQU}") ## ##today = datetime.today() ##Error = [] ##count = 0 ##batch_size = 50 # Nombre de fichiers à traiter par lot ## ##for batch_start in range(0, nombre_fichiers_AQU, batch_size): ## batch_files = AQU_FILES[batch_start:batch_start + batch_size] ## ## for file in batch_files: ## print("\nfile =", file) ## FILE = os.path.join(AQU_FOLDER, file) ## #print(f"Traitement du fichier : {FILE}") ## try: ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print(f'Le fichier {os.path.basename(FILE)} est vide') ## Error.append(os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if Type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## print(f'{Station}_Niveau.png créé') ## elif Type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_debit.png', bbox_inches="tight", dpi=30) ## print(f'{Station}_debit.png créé') ## elif Type == "plu": ## plt.ylabel('Pluie (mm)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=30) ## print(f'{Station}_Pluie.png créé') ## ## plt.close() ## count += 1 ## except Exception as e: ## print(f"Erreur lors du traitement du fichier {FILE}: {e}") ## Error.append(f"Erreur avec {FILE}: {e}") ## continue ## ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers traité. Mémoire libérée.\n') ## ##print(f'\nNombre de graphiques créés = {count}\n') ##write_log("a", "Nombre de graphiques créés ", count) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('Problèmes dans les fichiers:') ## write_log("a", "\n") ## write_log("a", " Problèmes dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "Fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## ## ## V5 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import gc ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## date_time = now.strftime("%d/%m/%Y %H:%M:%S") ## return date_time ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ##AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith(('niv.aqu', 'plu.aqu', 'deb.aqu')) and os.path.isfile(os.path.join(AQU_FOLDER, f))] ## ####AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith('.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##nombre_fichiers_AQU = len(AQU_FILES) ##print(f"Nombre de fichiers .aqu : {nombre_fichiers_AQU}") ## ##today = datetime.today() ##Error = [] ##count = 0 ##batch_size = 50 # Nombre de fichiers à traiter par lot ## ##for batch_start in range(0, nombre_fichiers_AQU, batch_size): ## batch_files = AQU_FILES[batch_start:batch_start + batch_size] ## ## for file in batch_files: ## FILE = os.path.join(AQU_FOLDER, file) ## #print(f"Traitement du fichier : {FILE}") ## print(file) ## try: ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print(f'Le fichier {os.path.basename(FILE)} est vide') ## Error.append(os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if Type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## elif Type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_{Type}.png', bbox_inches="tight", dpi=30) ## elif Type == "plu": ## plt.ylabel('Pluie (mm)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=30) ## ## plt.close() ## count += 1 ## except Exception as e: ## print(f"Erreur lors du traitement du fichier {FILE}: {e}") ## Error.append(f"Erreur avec {FILE}: {e}") ## ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'Batch de {batch_size} fichiers traité. Mémoire libérée.') ## ##print(f'\nNombre de graphiques créés = {count}\n') ##write_log("a", "Nombre de graphiques créés ", count) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('Problèmes dans les fichiers:') ## write_log("a", "\n") ## write_log("a", " Problèmes dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "Fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## ##V4 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import gc ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## date_time = now.strftime("%d/%m/%Y %H:%M:%S") ## return date_time ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ##AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith('.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##nombre_fichiers_AQU = len(AQU_FILES) ##print(f"Nombre de fichiers .aqu : {nombre_fichiers_AQU}") ## ##today = datetime.today() ##Error = [] ##count = 0 ##batch_size = 50 # Nombre de fichiers à traiter par lot ## ##for batch_start in range(0, nombre_fichiers_AQU, batch_size): ## batch_files = AQU_FILES[batch_start:batch_start + batch_size] ## ## for file in batch_files: ## FILE = os.path.join(AQU_FOLDER, file) ## print(FILE) ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print('le Fichier ' + os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## plt.figure(figsize=(6, 3)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if Type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## elif Type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_{Type}.png', bbox_inches="tight", dpi=30) ## elif Type == "plu": ## plt.ylabel('Pluie (mm)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=30) ## ## plt.close() ## count += 1 ## ## gc.collect() # Forcer la libération de la mémoire après chaque lot ## print(f'\nBatch de {batch_size} fichiers traité. Mémoire libérée.\n') ## ##print(f'\nNombre de graphiques créés = {count}\n') ##write_log("a", "Nombre de graphiques créés ", count) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('problème dans les fichiers: ') ## write_log("a", "\n") ## write_log("a", " problème dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## ## ## ## ## V3 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import matplotlib.dates as md ##import numpy as np ##import pandas as pd ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## date_time = now.strftime("%d/%m/%Y %H:%M:%S") ## return date_time ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ##AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith('.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##nombre_fichiers_AQU = len(AQU_FILES) ##print(f"Nombre de fichiers .aqu : {nombre_fichiers_AQU}") ## ##today = datetime.today() ##Error = [] ##count = 0 ## ##for file in AQU_FILES: ## FILE = os.path.join(AQU_FOLDER, file) ## print(FILE) ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print('le Fichier ' + os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## # Ajuster la taille de la figure (figsize) et la résolution (dpi) ## plt.figure(figsize=(8, 4)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if Type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=30) ## plt.close() ## elif Type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_{Type}.png', bbox_inches="tight", dpi=30) ## plt.close() # Fermer le graphique pour libérer la mémoire ## ## elif Type == "plu": ## plt.figure(figsize=(8, 4)) ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.xlabel('Temps') ## plt.title(Station) ## plt.ylabel('Pluie (mm)') ## plt.tight_layout() ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=50) ## plt.close() ## ## count += 1 ## ##print(f'\nNombre de graphiques créés = {count}\n') ##write_log("a", "Nombre de graphiques créés ", count) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('problème dans les fichiers: ') ## write_log("a", "\n") ## write_log("a", " problème dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## V2 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import matplotlib.dates as md ##import numpy as np ##import pandas as pd ##import codecs ## ##FILELOG = 'C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now = datetime.now() ## date_time = now.strftime("%d/%m/%Y %H:%M:%S") ## return date_time ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB = date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " ", DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ##AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith('.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] ##nombre_fichiers_AQU = len(AQU_FILES) ##print(f"Nombre de fichiers .aqu : {nombre_fichiers_AQU}") ## ##today = datetime.today() ##Error = [] ##count = 0 ## ##for file in AQU_FILES: ## FILE = os.path.join(AQU_FOLDER, file) ## print(FILE) ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print('le Fichier ' + os.path.basename(FILE) + ' est vide') ## else: ## liste_value = [] ## liste_date = [] ## lines = f.readlines() ## ## for i in range(len(lines)): ## list_split = lines[i].split(';') ## Date = list_split[0] ## Station = list_split[1] ## Type = list_split[2] ## Valeur = list_split[3].strip('\n') ## Date_format = Date.replace('-', '/', 2) ## Date_good_type = datetime.strptime(Date_format, "%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days=5) ## ## if Date_good_type > duree: ## liste_value.append(float(Valeur)) ## liste_date.append(Date_good_type) ## ## if Type == 'niv' or Type == 'deb': ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if Type == "niv": ## plt.ylabel('Niveau (m)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Niveau.png', bbox_inches="tight", dpi=40) ## elif Type == 'deb': ## plt.ylabel('Débit (m3/s)') ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_{Type}.png', bbox_inches="tight", dpi=40) ## ## plt.close() # Fermer le graphique pour libérer la mémoire ## ## elif Type == "plu": ## plt.plot(liste_date, liste_value) ## plt.xticks(rotation=45) ## plt.xlabel('Temps') ## plt.title(Station) ## plt.ylabel('Pluie (mm)') ## plt.tight_layout() ## plt.savefig(f'C:/xampp/htdocs/dashboard/graph/{Station}_Pluie.png', bbox_inches="tight", dpi=80) ## plt.close() ## ## count += 1 ## ##print(f'\nNombre de graphiques créés = {count}\n') ##write_log("a", "Nombre de graphiques créés ", count) ##write_log("a", "\n") ## ##if len(Error) > 0: ## print('problème dans les fichiers: ') ## write_log("a", "\n") ## write_log("a", " problème dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN = date() ##write_log("a", "\n") ##write_log("a", " ", DATEFIN) ##write_log("a", "\n") ##write_log("a", "fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## V1 ##import os ##from datetime import datetime, timedelta ##import sys ##import matplotlib.pyplot as plt ##import matplotlib.dates as md ##import numpy as np ##import pandas as pd ##import codecs ## ##FILELOG ='C:/xampp/htdocs/dashboard/PYTHON/besoins_jaugeage/graphique_carte.txt' ## ##def date(): ## now= datetime.now() #now= str(datetime.datetime.now())[0:19] ## date_time=now.strftime("%d/%m/%Y %H:%M:%S") ## return date_time ## ##def write_log(mode="a", *args): ## print(' '.join([str(x) for x in list(args)])) ## with codecs.open(FILELOG, mode, "utf8") as f: ## f.write(' '.join([str(x) for x in list(args)]) + '\r\n') ## ###---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x ## ##print("\nExecution du script " + sys.argv[0] + "\n") ##DATEDEB=date() ##write_log("w", "\n") ##write_log("a", "Execution du script ", sys.argv[0]) ##write_log("a", "\n") ##write_log("a", " " , DATEDEB) ###print(DATEDEB) ##write_log("a", "\n") ## ##AQU_FOLDER = r'C:\xampp\htdocs\dashboard\Donnees' ##AQU_FILES = [f for f in os.listdir(AQU_FOLDER) if f.endswith('.aqu') and os.path.isfile(os.path.join(AQU_FOLDER, f))] # print(AQU_FILES) ##nombre_fichiers_AQU=len(AQU_FILES) ##print(f"Nombre de fichiers .aqu : {nombre_fichiers_AQU}") ## ## ##today = datetime.today() ##Error = [] ## ##for file in AQU_FILES: ## FILE = os.path.join(AQU_FOLDER,file) ## print(FILE) ## with open(FILE) as f: ## if os.stat(FILE).st_size == 0: ## print('le Fichier '+ os.path.basename(FILE)+ ' est vide') ## else: ## liste_value=[] ## liste_date=[] ## count=0 ## i=0 ## lines = f.readlines() ## #boucle qui atribut qui liste toutes les lignes du fichier ## while i < len(lines): ## list_split = lines[i].split(';') ## Date=list_split[0] ## Station=list_split[1] ## Type=list_split[2] ## Valeur=list_split[3] ## Valeur_sans_esp=Valeur.strip('\n') ## Date_format= Date.replace('-','/',2) ## Date_good_type = datetime.strptime(Date_format,"%Y/%m/%d %H:%M:%S") ## duree = today - timedelta(days = 5) ## #creations des valeurs des deux axes pour le graph ## if Date_good_type > duree: ## liste_value.append(float(Valeur_sans_esp)) ## liste_date.append(Date_good_type) ## count=count+1 ## i=i+1 ## ## #creation du graph debit et niveau ## if Type == 'niv' or Type == 'deb': ## plt.plot(liste_date,liste_value) ## plt.xticks(rotation=45) ## plt.title(Station) ## plt.tight_layout() ## plt.xlabel('Temps') ## ## if Type == "niv": ## plt.ylabel('Niveau( m )') ## plt.savefig('C:/xampp/htdocs/dashboard/graph/'+Station+'_Niveau.png',bbox_inches="tight") ## plt.close() ## #print('Creation du graphique du fichier '+donnees) ## elif Type == 'deb': ## plt.ylabel('Debit( m3/s )') ## plt.savefig('C:/xampp/htdocs/dashboard/graph/'+Station+'_'+Type+'.png',bbox_inches="tight") ## plt.close() ## #print('Creation du graphique du fichier '+donnees) ## ## #creation graph pluie ## elif Type == "plu": ## plt.plot(liste_date,liste_value) ## plt.xticks(rotation=45) ## plt.xlabel('Temps') ## plt.title(Station) ## plt.ylabel('pluie(mm)') ## plt.tight_layout() ## plt.savefig('C:/xampp/htdocs/dashboard/graph/'+Station+'_Pluie.png',bbox_inches="tight") ## plt.close() ## ## ## ##print('\nNombre de graphiques crées ='+ str(count) + "\n") ##write_log("a", "Nombre de graphiques crées " , count ) ##write_log("a", "\n") ##if len(Error) > 0: ## print('probleme dans les fichiers: ') ## write_log("a", "\n") ## write_log("a", " probleme dans les fichiers: ") ## print(Error) ## write_log("a", Error) ## ##DATEFIN=date() ##write_log("a", "\n") ##write_log("a", " " , DATEFIN) ##write_log("a", "\n") ##write_log("a", "fin du script") ##write_log("a", "\n") ## ##print('\nFin du script') ## ## ##