File Reference Appmain
File Reference App_main
Path: App/main.py
1. Purpose
هذا الملف جزء من نواة HDDS ويخدم طبقة وظيفية محددة داخل منظومة Radar/Audio/GUI orchestration.
2. Responsibilities
- احتواء منطق المجال الخاص بهذا الملف.
- توفير API داخلي لباقي الوحدات.
- تنفيذ جزء من Runtime pipeline.
3. Imports Analysis
- 3:from future import annotations
- 5:import os
- 6:import threading
- 7:import time
- 8:import tkinter as tk
- 9:from dataclasses import dataclass
- 10:from pathlib import Path
- 11:from tkinter import filedialog, messagebox, scrolledtext, ttk
- 20:import cv2
- 21:from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
- 22:from matplotlib.figure import Figure
- 23:import numpy as np
- 24:import torch
- 49:from audio.logging_utils import write_run_log as write_audio_log
- 50:from audio.preprocess import TARGET_SR as AUDIO_TARGET_SR
- 51:from audio.video_test import run_audio_file_inference, run_video_inference
- 52:from audio.report import build_text_report
- 53:from audio.schemas import AudioSegmentPrediction
- 54:from radar_sim.constants import AppConfig, ScenarioConfig, Target, load_app_config
- 55:from radar_sim.geometry import bistatic_range_to_delay_s, velocity_mps_to_doppler_hz
- 56:from radar_sim.plotting import build_processing_figure
- 57:from radar_sim.runner import default_config_path, execute_scenario, format_report
- 58:from radar_sim.scenarios import get_scenario, list_scenarios
- 59:from radar_sim.logging_utils import write_run_log as write_radar_log
4. Main Classes
- 103:class VisionFrameSummary:
- 113:class VisionLabResult:
- 126:class HybridSnapshot:
- 236:class ModernWorkbenchApp:
5. Main Functions
- 84:def _first_existing_path(*candidates: Path) -> Path:
- 136:def build_audio_probability_figure(
- 164:def encode_frame_for_tk(frame_bgr: np.ndarray) -> tk.PhotoImage:
- 173:def draw_boxes_on_frame(
- 193:def build_vision_report(result: VisionLabResult) -> str:
- 215:def build_audio_report_text(
- 1782:def launch_gui(initial_tab: str | None = None) -> None:
- 1800:def main() -> None:
تحليل الدوال (منهج عام):
- input: معاملات runtime/config/data structures.
- output: dataclasses/arrays/reports/state updates.
- algorithm: يعتمد على نوع الملف (DSP/ML/GUI/control flow).
- side effects: I/O، logging، GUI updates، أو model loading.
- runtime behavior: دوال critical قد تنفذ per-frame أو per-window.
6. Internal Workflow
- تهيئة البيانات أو الإعدادات.
- تطبيق المعالجة الأساسية.
- إعادة النتائج أو تحديث state خارجي.
7. Data Flow
- inbound: من ملفات config أو callers أعلى.
- processing: transformations حسب domain.
- outbound: structures تستخدمها ملفات أخرى أو GUI.
8. Mathematical Concepts
إذا كان الملف Radar/Audio DSP فإنه يستخدم مفاهيم مثل FFT, Doppler Shift, log-Mel, thresholding حسب السياق.
9. Important Variables
- 62:BG = "#07111f"
- 63:SURFACE = "#0f1b2d"
- 64:SURFACE_2 = "#14243a"
- 65:SURFACE_3 = "#1a2d46"
- 66:BORDER = "#27405d"
- 67:TEXT = "#e8edf4"
- 68:MUTED = "#9eb0c4"
- 69:GREEN = "#1fd18a"
- 70:AMBER = "#f6b73c"
- 71:RED = "#ff6b6b"
- 72:BLUE = "#50b9ff"
- 74:AUDIO_FILETYPES = [
- 78:VIDEO_FILETYPES = [
- 92:YOLO_DIR = _first_existing_path(
- 96:YOLO_WEIGHTS = _first_existing_path(
10. Integration Points
- Used By: يعتمد على استدعاءات بقية النظام لهذا الملف.
- Calls: وحدات داخلية وخارجية (NumPy/TensorFlow/PyTorch/OpenCV).
11. Runtime Sequence
ينفذ هذا الملف ضمن التسلسل العام الموضح في Runtime Execution Flow.
12. Error Handling
- يعتمد على
raise/exceptions المحلية في الملف. - في GUI يتم غالبًا احتواء الخطأ عبر dialogs أو status messages.
13. Performance Notes
- الملفات التشغيلية per-frame/per-window حساسة للأداء.
- عمليات ML inference وFFT هي الأعلى كلفة عادة.
14. Future Improvements
- إضافة profiling موحد.
- توحيد metrics logging.
- تقليل التكرار بين و عند الإمكان.
15. Related Notes
Metadata
- Source path: App/main.py
- Lines: 1806