fix report

This commit is contained in:
VALLONGOL 2025-07-11 09:03:37 +02:00
parent b6e54a7331
commit db0c170f0b

View File

@ -19,6 +19,7 @@ import ctypes
import threading
import shutil
import time
from datetime import datetime
try:
import pandas as pd
except ImportError:
@ -324,19 +325,16 @@ class AppController:
def _create_and_save_summary(self, storyboard_df: "pd.DataFrame", output_dir: Path) -> "pd.DataFrame":
"""
Aggregates the full storyboard DataFrame into a human-readable summary.
Aggregates the full storyboard DataFrame, saves it in multiple formats, and returns it.
"""
df = storyboard_df.copy()
# Usa i nomi delle colonne unici che abbiamo creato
df['status'] = (
df['Mode'].astype(str) + '-' + df['Mode.2'].astype(str) + ' | ' +
df['Scal.2'].astype(str) + ' | ' + 'wf_' + df['WF'].astype(str) +
df['Mode'].astype(str) + '-' + df['Mode.3'].astype(str) + '_' +
df['Scal.2'].astype(str) + '_' + 'wf-' + df['WF'].astype(str) +
'-' + df['WF.2'].astype(str)
)
# ... (il resto della funzione _create_and_save_summary rimane identico) ...
df['status_changed'] = df['status'].ne(df['status'].shift())
change_indices = df[df['status_changed']].index.tolist()
@ -353,7 +351,8 @@ class AppController:
if segment.empty: continue
TICK_DURATION_S = 64e-9
# === MODIFICA CHIAVE QUI: Correzione della costante di tempo ===
TICK_DURATION_S = 64e-6 # 64 microsecondi, non nanosecondi
summary_records.append({
'Segment (Mode | Scale | WF)': segment['status'].iloc[0],
@ -368,7 +367,6 @@ class AppController:
summary_df = pd.DataFrame(summary_records)
# Salva il riassunto
csv_path = output_dir / "flight_summary.csv"
json_path = output_dir / "flight_summary.json"
log.info(f"Saving aggregated summary to {csv_path}")
@ -376,7 +374,71 @@ class AppController:
log.info(f"Saving aggregated summary to {json_path}")
summary_df.to_json(json_path, orient="records", indent=4)
self._save_text_report(summary_df, storyboard_df, output_dir)
return summary_df
def _save_text_report(self, summary_df: "pd.DataFrame", full_df: "pd.DataFrame", output_dir: Path):
"""Saves a human-readable, formatted text report of the flight analysis."""
report_path = output_dir / "flight_report.txt"
log.info(f"Saving formatted text report to {report_path}")
# === MODIFICA CHIAVE QUI: Correzione della costante di tempo anche qui ===
TICK_DURATION_S = 64e-6
total_duration = (full_df['TTAG'].iloc[-1] - full_df['TTAG'].iloc[0]) * TICK_DURATION_S
start_batch_total, end_batch_total = full_df['Batch'].iloc[0], full_df['Batch'].iloc[-1]
total_batches = end_batch_total - start_batch_total + 1
start_file_total, end_file_total = full_df['file'].iloc[0], full_df['file'].iloc[-1]
total_files = full_df['file'].nunique()
with open(report_path, 'w', encoding='utf-8') as f:
f.write("--- Radar Flight Analysis Report ---\n\n")
f.write(f"Flight Name: {self.view.analyzer_flight_name_var.get()}\n")
f.write(f"Analysis Date (UTC): {datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')}\n\n")
f.write("--- Flight Summary ---\n")
f.write(f"Total Duration: {total_duration:.2f} seconds\n")
f.write(f"Batch Range: {start_batch_total} to {end_batch_total} (Total: {total_batches})\n")
f.write(f"Source Files: {total_files} files (from {start_file_total} to {end_file_total})\n\n")
f.write("--- Flight Segments Storyboard ---\n")
# Determina larghezze colonne (aggiungendo Start/End File)
col_name = 'Segment (Mode | Scale | WF)'
cols = {
'Segment': max(summary_df[col_name].str.len().max(), len(col_name)),
'Start Batch': max(summary_df['Start Batch'].astype(str).str.len().max(), len('Start Batch')),
'# Batches': max(summary_df['Batch Count'].astype(str).str.len().max(), len('# Batches')),
'Duration (s)': len('Duration (s)'),
'Start File': max(summary_df['Start File'].str.len().max(), len('Start File')),
'End File': max(summary_df['End File'].str.len().max(), len('End File'))
}
# Scrive l'header della tabella
header = (
f"{col_name:<{cols['Segment']}} | "
f"{'Start Batch':>{cols['Start Batch']}} | "
f"{'# Batches':>{cols['# Batches']}} | "
f"{'Duration (s)':>{cols['Duration (s)']}} | "
f"{'Start File':<{cols['Start File']}} | "
f"{'End File':<{cols['End File']}}"
)
f.write(header + "\n")
f.write('-' * len(header) + "\n")
# Scrive le righe dei dati
for _, row in summary_df.iterrows():
line = (
f"{row[col_name]:<{cols['Segment']}} | "
f"{row['Start Batch']:>{cols['Start Batch']}} | "
f"{row['Batch Count']:>{cols['# Batches']}} | "
f"{row['Duration (s)']:>{cols['Duration (s)']:}.2f} | "
f"{row['Start File']:<{cols['Start File']}} | "
f"{row['End File']:<{cols['End File']}}"
)
f.write(line + "\n")
f.write("\n--- End of Report ---\n")
def _parse_summary_txt_to_dataframe(self, txt_path: Path) -> Optional["pd.DataFrame"]:
"""