No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

49 líneas
1.7 KiB

  1. import streamlit as st
  2. import pandas as pd
  3. import os
  4. def show_gateway_manager(config):
  5. # Recupera il percorso dal config.yaml, con fallback
  6. # Nota: cerchiamo sia sotto 'infer' che 'collect_train' se necessario
  7. csv_path = config.get('infer', {}).get('gateways_csv', '/data/config/gateway.csv')
  8. st.subheader("🌐 Gestione Gateway (gateway.csv)")
  9. st.info(f"Percorso file: `{csv_path}`")
  10. if not os.path.exists(csv_path):
  11. st.error("Il file gateway.csv non è stato trovato al percorso specificato.")
  12. if st.button("Crea file vuoto"):
  13. df_new = pd.DataFrame(columns=["Position", "Floor", "RoomName", "X", "Y", "Z", "GatewayName", "MAC"])
  14. df_new.to_csv(csv_path, sep=';', index=False)
  15. st.rerun()
  16. return
  17. # Caricamento del CSV
  18. try:
  19. # Usiamo il separatore ';' come da tuo esempio
  20. df = pd.read_csv(csv_path, sep=';', dtype=str)
  21. except Exception as e:
  22. st.error(f"Errore nel caricamento del CSV: {e}")
  23. return
  24. # Interfaccia di editing
  25. st.write("Modifica i dati direttamente nella tabella qui sotto:")
  26. edited_df = st.data_editor(
  27. df,
  28. num_rows="dynamic",
  29. use_container_width=True,
  30. key="gateway_editor"
  31. )
  32. col1, col2 = st.columns([1, 5])
  33. with col1:
  34. if st.button("💾 Salva Gateway"):
  35. try:
  36. edited_df.to_csv(csv_path, sep=';', index=False)
  37. st.success("File gateway.csv salvato con successo!")
  38. except Exception as e:
  39. st.error(f"Errore durante il salvataggio: {e}")
  40. with col2:
  41. st.caption("Nota: L'aggiunta di righe avviene cliccando sull'ultima riga vuota della tabella.")