mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-06-01 22:00:53 +00:00
Synthèse 2025
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,11 @@
|
||||
"""
|
||||
#############################################################################################
|
||||
general_fonctions.py for pyCreateTh.py
|
||||
# #
|
||||
# general_fonctions.py for pyCreateTh.py #
|
||||
# #
|
||||
#############################################################################################
|
||||
|
||||
Alex 2025 06 09
|
||||
"""
|
||||
import os, logging, sys, re, configparser, unicodedata, shutil
|
||||
from pathlib import Path
|
||||
@@ -191,11 +195,12 @@ def select_file_tk_window():
|
||||
file_path = filedialog.askopenfilename(
|
||||
title="Select your file",
|
||||
filetypes=[
|
||||
("Compatibles files", "*.th *.mak *.dat *.tro"),
|
||||
("Compatibles files", "*.th *.mak *.dat *.tro *.trox"),
|
||||
("MAK files", "*.mak"),
|
||||
("TH files", "*.th"),
|
||||
("DAT files", "*.dat"),
|
||||
("TRO files", "*.tro"),
|
||||
("TROX files", "*.trox"),
|
||||
("All files", "*.*")]
|
||||
)
|
||||
|
||||
@@ -450,3 +455,55 @@ def update_template_files(template_path, variables, output_path):
|
||||
log.error(f"An error occurred (update_template_files : {Colors.ENDC}{os.path.basename(template_path)}{Colors.ERROR}) : {Colors.ENDC}{e}")
|
||||
global_Data.error_count += 1
|
||||
|
||||
|
||||
#################################################################################################
|
||||
def load_text_file_utf8(filepath, short_filename):
|
||||
"""Loads a text file with various encodings and converts it to UTF-8.
|
||||
|
||||
Args:
|
||||
filepath (str): The path to the file to be loaded.
|
||||
short_filename (str): The name of the file (for logging purposes).
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the file content, a log message, and the encoding used.
|
||||
"""
|
||||
|
||||
encodings_to_try = [
|
||||
'utf-8-sig', # UTF-8 avec BOM
|
||||
'utf-8', # UTF-8 standard
|
||||
'windows-1252', # ANSI Windows Europe de l’Ouest
|
||||
'iso-8859-15', # ISO-8859-15 (latin9), remplace iso-8859-1 (latin1)
|
||||
'iso-8859-1',
|
||||
]
|
||||
|
||||
for enc in encodings_to_try:
|
||||
try:
|
||||
with open(filepath, 'r', encoding=enc) as f:
|
||||
content = f.read()
|
||||
log.info(f"Open source file: {Colors.ENDC}{short_filename}{Colors.GREEN}, with encoding: {Colors.ENDC}{enc}{Colors.GREEN} and conversion to {Colors.ENDC}utf-8")
|
||||
message_log = f"* Source file: {short_filename}, encoding: {enc}, conversion to utf-8\n"
|
||||
return content, message_log, enc
|
||||
|
||||
except UnicodeDecodeError as e:
|
||||
log.debug(f"Failed {Colors.ENDC}{enc}{Colors.DEBUG} for {Colors.ENDC}{short_filename}{Colors.DEBUG}: {Colors.ENDC}{e}")
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
log.critical(f"Unexpected error while reading {Colors.ENDC}{short_filename}{Colors.CRITICAL}: {e}")
|
||||
exit(0)
|
||||
return None, "", None
|
||||
|
||||
# Dernier recours : lecture binaire + forçage
|
||||
try:
|
||||
with open(filepath, 'rb') as f:
|
||||
raw = f.read()
|
||||
content = raw.decode('windows-1252', errors='replace')
|
||||
log.warning(f"Force-reading {Colors.ENDC}{short_filename}{Colors.WARNING} with character replacement (windows-1252)")
|
||||
message = f"* Force-reading source file: {short_filename} with character replacement (windows-1252)\n"
|
||||
return content, message, 'windows-1252'
|
||||
|
||||
except Exception as e:
|
||||
log.critical(f"Failed to read file {Colors.ENDC}{short_filename}{Colors.CRITICAL}: {Colors.ENDC}{e}")
|
||||
exit(0)
|
||||
return None, "", None
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ global_data.py for pyCreateTh.py
|
||||
#############################################################################################
|
||||
"""
|
||||
|
||||
Version = "2026.01.07"
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -182,7 +182,7 @@ fr_lengthre = re.compile(r".*Longueur totale de la topographie = \s*(\S+)m")
|
||||
fr_depthre = re.compile(r".*Longueur totale verticale =\s*(\S+)m")
|
||||
|
||||
en_lengthre = re.compile(r".*Total length of survey legs = \s*(\S+)m")
|
||||
en_depthre = re.compile(r".*Total vertical length of survey legs =\s*(\S+)m")
|
||||
en_depthre = re.compile(r".*Vertical range =\s*(\S+)m")
|
||||
|
||||
def get_stats_from_log(log):
|
||||
lenmatch = fr_lengthre.findall(log)
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
"""
|
||||
!---------------------------------------------------------!
|
||||
! !
|
||||
! TroX to Therion !
|
||||
! !
|
||||
! Code to transform the .troX files !
|
||||
! Visual Topo into files that can !
|
||||
! be used by Therion !
|
||||
! !
|
||||
! Written by Alexandre Pont !
|
||||
! !
|
||||
!---------------------------------------------------------!
|
||||
|
||||
ENGLISH :
|
||||
This code is to transform the .trox file from Visualtopo (http://vtopo.free.fr/)
|
||||
into files that can be read by Therion (http://therion.speleo.sk/).
|
||||
It reads .tro file and produce one .th file (file with survey data),
|
||||
and one thconfig file (file that is used to compile and build the survey with Therion).
|
||||
|
||||
Création Alex 2026 01 08
|
||||
|
||||
|
||||
TODOS : -....
|
||||
"""
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
from collections import defaultdict, Counter
|
||||
from pathlib import Path
|
||||
from Lib.general_fonctions import Colors, safe_relpath
|
||||
import Lib.global_data as global_data
|
||||
|
||||
|
||||
def analyse_xml_balises_old(xml_path):
|
||||
"""
|
||||
Analyse un fichier XML et affiche :
|
||||
- le nombre d'occurrences de chaque balise
|
||||
- pour chaque balise, les attributs rencontrés et leurs occurrences
|
||||
|
||||
Parameters
|
||||
----------
|
||||
xml_path : str | Path
|
||||
Chemin vers le fichier XML
|
||||
"""
|
||||
|
||||
xml_path = Path(xml_path)
|
||||
|
||||
if not xml_path.exists():
|
||||
raise FileNotFoundError(f"{Colors.ERROR}Fichier introuvable : {Colors.ENDC}{xml_path}")
|
||||
|
||||
# Chargement XML
|
||||
tree = ET.parse(xml_path)
|
||||
root = tree.getroot()
|
||||
|
||||
# Comptage des balises
|
||||
tag_counter = Counter()
|
||||
|
||||
# Dictionnaire :
|
||||
# { tag_name : Counter({attr_name: nb_occurrences}) }
|
||||
attributes_counter = defaultdict(Counter)
|
||||
|
||||
# Parcours de tous les éléments
|
||||
for elem in root.iter():
|
||||
tag_counter[elem.tag] += 1
|
||||
|
||||
for attr_name in elem.attrib.keys():
|
||||
attributes_counter[elem.tag][attr_name] += 1
|
||||
|
||||
# Affichage
|
||||
print("\n")
|
||||
print("=" * 80)
|
||||
print(f"{Colors.INFO}Analyse du fichier : {Colors.ENDC}{xml_path.name}")
|
||||
print("=" * 80)
|
||||
|
||||
for tag in sorted(tag_counter.keys()):
|
||||
print(f"\n{Colors.BLUE}Balise <{Colors.ENDC}{tag}{Colors.BLUE}>")
|
||||
print(f" {Colors.CYAN}Occurrences : {Colors.ENDC}{tag_counter[tag]}")
|
||||
|
||||
if attributes_counter[tag]:
|
||||
print(f" {Colors.MAGENTA}Attributs :")
|
||||
for attr, count in attributes_counter[tag].most_common():
|
||||
print(f" {Colors.MAGENTA}- {Colors.ENDC}{attr}{Colors.MAGENTA} : {Colors.ENDC}{count}")
|
||||
else:
|
||||
print(f" {Colors.RED}Attributs : aucun")
|
||||
|
||||
print(f"\n{Colors.INFO}Analyse terminée.")
|
||||
|
||||
|
||||
|
||||
|
||||
def analyse_xml_balises(xml_path):
|
||||
"""
|
||||
Analyse un fichier XML et affiche :
|
||||
- le nombre d'occurrences de chaque balise
|
||||
- pour chaque balise, les attributs rencontrés et leurs occurrences
|
||||
- le tout classé par type logique (Version, Mesures, Param, ...)
|
||||
"""
|
||||
|
||||
xml_path = Path(xml_path)
|
||||
|
||||
if not xml_path.exists():
|
||||
raise FileNotFoundError(
|
||||
f"{Colors.ERROR}Fichier introuvable : {Colors.ENDC}{xml_path}"
|
||||
)
|
||||
|
||||
# ----------------------------
|
||||
# Définition des catégories
|
||||
# ----------------------------
|
||||
TAG_CATEGORIES = {
|
||||
"Version": {
|
||||
"version", "header", "metadata"
|
||||
},
|
||||
"Mesures": {
|
||||
"mesure", "measure", "value", "data", "record"
|
||||
},
|
||||
"Param": {
|
||||
"param", "parameter", "config", "setting"
|
||||
},
|
||||
}
|
||||
|
||||
DEFAULT_CATEGORY = "Autres"
|
||||
|
||||
# Inverse la table pour lookup rapide
|
||||
tag_to_category = {}
|
||||
for category, tags in TAG_CATEGORIES.items():
|
||||
for tag in tags:
|
||||
tag_to_category[tag] = category
|
||||
|
||||
# ----------------------------
|
||||
# Chargement XML
|
||||
# ----------------------------
|
||||
tree = ET.parse(xml_path)
|
||||
root = tree.getroot()
|
||||
|
||||
tag_counter = Counter()
|
||||
attributes_counter = defaultdict(Counter)
|
||||
|
||||
# ----------------------------
|
||||
# Parcours XML
|
||||
# ----------------------------
|
||||
for elem in root.iter():
|
||||
tag = elem.tag
|
||||
tag_counter[tag] += 1
|
||||
|
||||
for attr_name in elem.attrib:
|
||||
attributes_counter[tag][attr_name] += 1
|
||||
|
||||
# ----------------------------
|
||||
# Regroupement par catégorie
|
||||
# ----------------------------
|
||||
categorized_tags = defaultdict(list)
|
||||
|
||||
for tag in tag_counter:
|
||||
# Nettoyage éventuel namespace XML
|
||||
clean_tag = tag.split("}")[-1]
|
||||
|
||||
category = tag_to_category.get(clean_tag, DEFAULT_CATEGORY)
|
||||
categorized_tags[category].append(tag)
|
||||
|
||||
# ----------------------------
|
||||
# Affichage
|
||||
# ----------------------------
|
||||
print("\n" + "=" * 80)
|
||||
print(f"{Colors.INFO}Analyse du fichier : {Colors.ENDC}{xml_path.name}")
|
||||
print("=" * 80)
|
||||
|
||||
for category in sorted(categorized_tags.keys()):
|
||||
print(f"\n{Colors.YELLOW}## {category}{Colors.ENDC}")
|
||||
print("-" * 60)
|
||||
|
||||
for tag in sorted(categorized_tags[category]):
|
||||
print(f"\n {Colors.BLUE}Balise <{Colors.ENDC}{tag}{Colors.BLUE}>")
|
||||
print(f" {Colors.CYAN}Occurrences : {Colors.ENDC}{tag_counter[tag]}")
|
||||
|
||||
if attributes_counter[tag]:
|
||||
print(f" {Colors.MAGENTA}Attributs :{Colors.ENDC}")
|
||||
for attr, count in attributes_counter[tag].most_common():
|
||||
print(
|
||||
f" {Colors.MAGENTA}- {Colors.ENDC}{attr}"
|
||||
f"{Colors.MAGENTA} : {Colors.ENDC}{count}"
|
||||
)
|
||||
else:
|
||||
print(f" {Colors.RED}Attributs : aucun{Colors.ENDC}")
|
||||
|
||||
print(f"\n{Colors.INFO}Analyse terminée.{Colors.ENDC}")
|
||||
Reference in New Issue
Block a user