Dodano algorytm ZDistA oraz możliwość przełączania algorytmów

- Dodano nowy plik distance_algorithm_zimba.py bazowany na ZDistA_komp.c
- Zaktualizowano tester.py z wyborem algorytmu (ALGORITHM = 1 lub 2)
- Pliki wynikowe zawierają nazwę algorytmu w nazwie

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 23:29:42 +01:00
parent 800c4937aa
commit 81c3b851d1
2 changed files with 445 additions and 7 deletions

View File

@@ -4,9 +4,32 @@ matplotlib.use('Agg') # Non-interactive backend for saving plots
import matplotlib.pyplot as plt
from comtrade import Comtrade
import math
from distance_algorithm import DistanceRelay
import sys
# ============================================================
# KONFIGURACJA - WYBIERZ ALGORYTM
# ============================================================
# Dostępne algorytmy:
# 1 - distance_algorithm (DistanceRelay) - podstawowy
# 2 - distance_algorithm_zimba (DistanceRelayZDistA) - bazowany na ZDistA_komp.c
ALGORITHM = 2 # <-- zmień tę wartość aby przełączyć algorytm
if ALGORITHM == 1:
from distance_algorithm import DistanceRelay
ALGORITHM_NAME = "distance_relay"
ALGORITHM_DESC = "DistanceRelay (podstawowy)"
elif ALGORITHM == 2:
from distance_algorithm_zimba import DistanceRelayZDistA
DistanceRelay = DistanceRelayZDistA
ALGORITHM_NAME = "zdistA"
ALGORITHM_DESC = "DistanceRelayZDistA (bazowany na ZDistA_komp.c)"
else:
raise ValueError(f"Nieznany algorytm: {ALGORITHM}")
print(f"=== Używany algorytm: {ALGORITHM_DESC} ===")
# ============================================================
# Obsluga argumentow wiersza polecen
if len(sys.argv) > 1:
base_name = sys.argv[1] # Nazwa pliku bez rozszerzenia
@@ -362,8 +385,8 @@ plt.legend()
plt.grid(True)
plt.tight_layout()
plt.savefig('test_result.png')
print("Wynik zapisany do test_result.png")
plt.savefig(f'test_result_{ALGORITHM_NAME}.png')
print(f"Wynik zapisany do test_result_{ALGORITHM_NAME}.png")
# Generowanie pliku rezultat.md
def detect_fault_and_generate_report(t, trip_history, z_r_history, z_x_history,
@@ -434,10 +457,10 @@ def detect_fault_and_generate_report(t, trip_history, z_r_history, z_x_history,
# Zapisz raport
report_content = "\n".join(report)
with open('rezultat.md', 'w', encoding='utf-8') as f:
with open(f'rezultat_{ALGORITHM_NAME}.md', 'w', encoding='utf-8') as f:
f.write(report_content)
print("Raport zapisany do rezultat.md")
print(f"Raport zapisany do rezultat_{ALGORITHM_NAME}.md")
return fault_idx is not None
# Generuj raport
@@ -535,7 +558,7 @@ result_md = generate_result_md(
Z_line_R, Z_line_X, relay
)
with open('rezultat.md', 'w', encoding='utf-8') as f:
with open(f'rezultat_{ALGORITHM_NAME}.md', 'w', encoding='utf-8') as f:
f.write(result_md)
print("Zapisano rezultat.md")
print(f"Zapisano rezultat_{ALGORITHM_NAME}.md")