You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
1.0 KiB

  1. # app/csv_config.py
  2. import csv
  3. from pathlib import Path
  4. from typing import List
  5. from dataclasses import dataclass
  6. # RIPRISTINATO IMPORT RELATIVO: Necessario per il Core Orchestrator
  7. from .normalize import norm_mac
  8. @dataclass
  9. class GatewayConfig:
  10. mac: str
  11. name: str = ""
  12. label: str = ""
  13. def load_gateway_features_csv(file_path: str, delimiter: str = ";") -> List[GatewayConfig]:
  14. """Carica l'anagrafica gateway per definire l'ordine delle feature del modello."""
  15. gws = []
  16. p = Path(file_path)
  17. if not p.exists():
  18. return gws
  19. try:
  20. with open(p, "r", encoding="utf-8") as f:
  21. reader = csv.DictReader(f, delimiter=delimiter)
  22. # Normalizzazione header
  23. reader.fieldnames = [fn.strip().lower() for fn in reader.fieldnames]
  24. for row in reader:
  25. raw_mac = row.get("mac", "").strip()
  26. if raw_mac:
  27. gws.append(GatewayConfig(mac=norm_mac(raw_mac)))
  28. except Exception:
  29. pass
  30. return gws