265 lines
8.1 KiB
Python
265 lines
8.1 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Test-Skript für das Trimble Geodesy Tool
|
||
Testet alle Module mit der Beispieldatei Baumschulenstr_93.jxl
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
||
from modules.jxl_parser import JXLParser
|
||
from modules.cor_generator import CORGenerator
|
||
from modules.network_adjustment import NetworkAdjustment
|
||
|
||
def test_jxl_parser():
|
||
"""Test des JXL-Parsers"""
|
||
print("=" * 80)
|
||
print("TEST 1: JXL-Parser")
|
||
print("=" * 80)
|
||
|
||
parser = JXLParser()
|
||
success = parser.parse("test_data/Baumschulenstr_93.jxl")
|
||
|
||
if not success:
|
||
print("❌ FEHLER: Datei konnte nicht geladen werden!")
|
||
return None
|
||
|
||
print(f"✓ Datei erfolgreich geladen: {parser.job_name}")
|
||
print(f"✓ Koordinatensystem: {parser.coordinate_system}")
|
||
print(f"✓ Winkeleinheit: {parser.angle_units}")
|
||
print()
|
||
|
||
# Stationen
|
||
print(f"Stationen: {len(parser.stations)}")
|
||
for sid, station in sorted(parser.stations.items(), key=lambda x: x[1].timestamp):
|
||
print(f" - {station.name}: {station.station_type}")
|
||
if station.east is not None:
|
||
print(f" Koordinaten: E={station.east:.4f}, N={station.north:.4f}, H={station.elevation or 0:.4f}")
|
||
print()
|
||
|
||
# Targets/Prismenkonstanten
|
||
print(f"Prismenkonstanten (eindeutige):")
|
||
seen = set()
|
||
for tid, target in parser.targets.items():
|
||
key = (target.prism_type, target.prism_constant)
|
||
if key not in seen:
|
||
seen.add(key)
|
||
print(f" - {target.prism_type}: {target.prism_constant*1000:+.1f} mm")
|
||
print()
|
||
|
||
# Punkte
|
||
active = parser.get_active_points()
|
||
print(f"Aktive Punkte: {len(active)}")
|
||
print()
|
||
|
||
# Referenzpunkte (Festpunkte)
|
||
ref_points = parser.get_reference_points()
|
||
print(f"Referenzpunkte (Passpunkte): {ref_points}")
|
||
|
||
# Standpunkte
|
||
station_points = parser.get_station_points()
|
||
print(f"Standpunkte: {station_points}")
|
||
|
||
# Messpunkte
|
||
meas_points = parser.get_measurement_points()
|
||
print(f"Messpunkte (erste 10): {meas_points[:10]}...")
|
||
print()
|
||
|
||
# Messungen für erste Station
|
||
first_station_id = list(parser.stations.keys())[0]
|
||
first_station = parser.stations[first_station_id]
|
||
measurements = parser.get_detailed_measurements_from_station(first_station_id)
|
||
|
||
print(f"Messungen von Station {first_station.name}:")
|
||
backsight = [m for m in measurements if m.classification == 'BackSight' and not m.deleted]
|
||
normal = [m for m in measurements if m.classification != 'BackSight' and not m.deleted]
|
||
|
||
print(f" Anschlussmessungen: {len(backsight)}")
|
||
for m in backsight:
|
||
print(f" - {m.point_name}: Hz={m.horizontal_circle:.6f}, V={m.vertical_circle:.6f}, D={m.edm_distance:.4f}")
|
||
|
||
print(f" Normale Messungen: {len(normal)}")
|
||
for m in normal[:5]: # Nur erste 5
|
||
print(f" - {m.point_name}: Hz={m.horizontal_circle:.6f}, V={m.vertical_circle:.6f}, D={m.edm_distance:.4f}")
|
||
|
||
print()
|
||
return parser
|
||
|
||
|
||
def test_cor_generator(parser):
|
||
"""Test des COR-Generators"""
|
||
print("=" * 80)
|
||
print("TEST 2: COR-Generator")
|
||
print("=" * 80)
|
||
|
||
generator = CORGenerator(parser)
|
||
points = generator.generate_from_computed_grid()
|
||
|
||
print(f"✓ {len(points)} Punkte generiert")
|
||
print()
|
||
|
||
# Vergleich mit Referenz-COR
|
||
print("Vergleich mit Baumschulenstr_93.cor:")
|
||
|
||
# Lade Referenz
|
||
ref_points = {}
|
||
with open("test_data/Baumschulenstr_93.cor", 'r') as f:
|
||
for line in f:
|
||
line = line.strip()
|
||
if not line or line.startswith('|--'):
|
||
continue
|
||
parts = line.replace('|', ',').split(',')
|
||
parts = [p.strip() for p in parts if p.strip()]
|
||
if len(parts) >= 4:
|
||
name = parts[0]
|
||
try:
|
||
x = float(parts[1])
|
||
y = float(parts[2])
|
||
z = float(parts[3])
|
||
ref_points[name] = (x, y, z)
|
||
except:
|
||
continue
|
||
|
||
# Vergleiche
|
||
matches = 0
|
||
mismatches = []
|
||
for p in points:
|
||
if p.name in ref_points:
|
||
ref_x, ref_y, ref_z = ref_points[p.name]
|
||
dx = abs(p.x - ref_x)
|
||
dy = abs(p.y - ref_y)
|
||
dz = abs(p.z - ref_z)
|
||
|
||
if dx < 0.01 and dy < 0.01 and dz < 0.01:
|
||
matches += 1
|
||
else:
|
||
mismatches.append((p.name, dx, dy, dz))
|
||
|
||
print(f" Übereinstimmungen: {matches}")
|
||
print(f" Abweichungen: {len(mismatches)}")
|
||
if mismatches[:5]:
|
||
print(f" Erste Abweichungen:")
|
||
for name, dx, dy, dz in mismatches[:5]:
|
||
print(f" - {name}: ΔX={dx:.3f}, ΔY={dy:.3f}, ΔZ={dz:.3f}")
|
||
print()
|
||
|
||
return generator
|
||
|
||
|
||
def test_calculation_protocol(parser):
|
||
"""Test des Berechnungsprotokolls"""
|
||
print("=" * 80)
|
||
print("TEST 3: Berechnungsprotokoll")
|
||
print("=" * 80)
|
||
|
||
protocol = parser.get_calculation_protocol()
|
||
lines = protocol.split('\n')
|
||
|
||
print(f"✓ Protokoll generiert ({len(lines)} Zeilen)")
|
||
print()
|
||
|
||
# Zeige Auszug
|
||
print("Auszug:")
|
||
for line in lines[:30]:
|
||
print(f" {line}")
|
||
print(" ...")
|
||
print()
|
||
|
||
# Speichere Protokoll
|
||
with open("test_data/berechnungsprotokoll_test.txt", 'w') as f:
|
||
f.write(protocol)
|
||
print("✓ Protokoll gespeichert: test_data/berechnungsprotokoll_test.txt")
|
||
print()
|
||
|
||
|
||
def test_network_adjustment(parser):
|
||
"""Test der Netzausgleichung"""
|
||
print("=" * 80)
|
||
print("TEST 4: Netzausgleichung (KORREKTES KONZEPT)")
|
||
print("=" * 80)
|
||
|
||
adjustment = NetworkAdjustment(parser)
|
||
|
||
# Beobachtungen extrahieren
|
||
obs = adjustment.extract_observations()
|
||
print(f"✓ {len(obs)} Beobachtungen extrahiert")
|
||
|
||
# Punkte initialisieren
|
||
adjustment.initialize_points()
|
||
print(f"✓ {len(adjustment.points)} Punkte initialisiert")
|
||
|
||
# KORREKTES KONZEPT: Nur Passpunkte als Festpunkte
|
||
ref_points = parser.get_reference_points()
|
||
print(f"\nFestpunkte (Passpunkte): {ref_points}")
|
||
|
||
for name in ref_points:
|
||
if name in adjustment.points:
|
||
adjustment.set_fixed_point(name)
|
||
|
||
print(f"✓ {len(adjustment.fixed_points)} Festpunkte gesetzt")
|
||
|
||
# Neupunkte (Standpunkte) - eindeutige Namen
|
||
station_points = list(set(s.name for s in parser.stations.values()))
|
||
new_points = [p for p in station_points if p not in adjustment.fixed_points]
|
||
print(f"Neupunkte (Standpunkte): {new_points}")
|
||
|
||
# Messpunkte
|
||
meas_points = [p for p in adjustment.points.keys()
|
||
if p not in adjustment.fixed_points and p not in station_points]
|
||
print(f"Messpunkte: {len(meas_points)}")
|
||
|
||
try:
|
||
result = adjustment.adjust()
|
||
print()
|
||
print(f"✓ Ausgleichung abgeschlossen:")
|
||
print(f" Iterationen: {result.iterations}")
|
||
print(f" Konvergiert: {result.converged}")
|
||
print(f" Sigma-0: {result.sigma_0_posteriori:.4f}")
|
||
print(f" Redundanz: {result.redundancy}")
|
||
print()
|
||
|
||
# Ausgeglichene Standpunkte
|
||
print("Ausgeglichene Standpunkte:")
|
||
for name in new_points:
|
||
if name in adjustment.points:
|
||
p = adjustment.points[name]
|
||
print(f" {name}: X={p.x:.4f}, Y={p.y:.4f}, Z={p.z:.4f}, σPos={p.std_position*1000:.1f}mm")
|
||
|
||
return adjustment
|
||
|
||
except Exception as e:
|
||
print(f"❌ FEHLER bei Ausgleichung: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
return None
|
||
|
||
|
||
def main():
|
||
print("\n" + "=" * 80)
|
||
print("TRIMBLE GEODESY TOOL - UMFANGREICHE TESTS")
|
||
print("Testdatei: Baumschulenstr_93.jxl")
|
||
print("=" * 80 + "\n")
|
||
|
||
# Test 1: Parser
|
||
parser = test_jxl_parser()
|
||
if not parser:
|
||
return
|
||
|
||
# Test 2: COR-Generator
|
||
test_cor_generator(parser)
|
||
|
||
# Test 3: Berechnungsprotokoll
|
||
test_calculation_protocol(parser)
|
||
|
||
# Test 4: Netzausgleichung
|
||
test_network_adjustment(parser)
|
||
|
||
print("\n" + "=" * 80)
|
||
print("TESTS ABGESCHLOSSEN")
|
||
print("=" * 80 + "\n")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|