pyCreateTh update

This commit is contained in:
Alex38Lyon committed 2026-11-19 18:51:48 +01:00
1 parent f900462feb
commit 98fb6dc75e
10 files changed
+2164 -2660

No files matched your search

+37 -106
View File
@@ -1,92 +1,35 @@
"""
!---------------------------------------------------------!
! !
! TroX to Therion !
! !
! Code to transform the .troX files !
! Visual Topo into files that can !
! be used by Therion !
! !
! Written by Alexandre Pont !
! !
!---------------------------------------------------------!
!---------------------------------------------------------!
! !
! 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
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).
TODOS : -....
Création Alex 2026 01 08
TODOS : -....
"""
import xml.etree.ElementTree as ET
import xml.etree.ElementTree as ET # noqa: I001
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.")
from Lib.general_fonctions import Colors
#################################################################################################
def analyse_xml_balises(xml_path):
"""
Analyse un fichier XML et affiche :
@@ -98,23 +41,15 @@ def analyse_xml_balises(xml_path):
xml_path = Path(xml_path)
if not xml_path.exists():
raise FileNotFoundError(
f"{Colors.ERROR}Fichier introuvable : {Colors.ENDC}{xml_path}"
)
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"
},
"Version": {"version", "header", "metadata"},
"Mesures": {"mesure", "measure", "value", "data", "record"},
"Param": {"param", "parameter", "config", "setting"},
}
DEFAULT_CATEGORY = "Autres"
@@ -159,26 +94,22 @@ def analyse_xml_balises(xml_path):
# ----------------------------
# Affichage
# ----------------------------
print("\n" + "=" * 80)
print(f"{Colors.INFO}" + "=" * 80)
print(f"{Colors.INFO}Analyse du fichier : {Colors.ENDC}{xml_path.name}")
print("=" * 80)
print(f"{Colors.INFO}" + "=" * 80)
for category in sorted(categorized_tags.keys()):
print(f"\n{Colors.YELLOW}## {category}{Colors.ENDC}")
print("-" * 60)
print(f"{Colors.YELLOW}## {category}{Colors.ENDC}")
print(f"{Colors.INFO}" + "-" * 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]}")
print(f"{Colors.BLUE}Balise <{Colors.ENDC}{tag}{Colors.BLUE}>\t{Colors.CYAN}Occurrences : {Colors.ENDC}{tag_counter[tag]}")
if attributes_counter[tag]:
print(f" {Colors.MAGENTA}Attributs :{Colors.ENDC}")
print(f"\t{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"\t\t{Colors.MAGENTA}- {Colors.ENDC}{attr}{Colors.MAGENTA} : {Colors.ENDC}{count}")
# else:
# print(f"\t{Colors.RED}Attributs : aucun{Colors.ENDC}")
print(f"\n{Colors.INFO}Analyse terminée.{Colors.ENDC}")
print(f"{Colors.INFO}Analyse terminée.{Colors.ENDC}")