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.
 
 
 
 

73 rivejä
2.4 KiB

  1. import streamlit as st
  2. import os
  3. import pandas as pd
  4. from pathlib import Path
  5. import time
  6. from datetime import datetime
  7. def show_training_data_manager(cfg):
  8. st.subheader("📂 Gestione Campioni Training")
  9. try:
  10. raw_path = cfg.get('collect_train', {}).get('samples_dir', '/data/train/samples')
  11. samples_dir = Path(raw_path)
  12. except Exception as e:
  13. st.error(f"Errore config: {e}")
  14. return
  15. # --- 1. RECUPERO E FILTRO DATI ---
  16. all_files = [f for f in os.listdir(samples_dir) if f.endswith('.csv')]
  17. files_data = []
  18. for file in all_files:
  19. path = samples_dir / file
  20. ts = os.path.getmtime(path)
  21. files_data.append({
  22. "File": file,
  23. "Data": datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M"),
  24. "ts": ts
  25. })
  26. df = pd.DataFrame(files_data).sort_values("ts", ascending=False)
  27. # Barra di ricerca
  28. search = st.text_input("🔍 Cerca coordinata:", "").strip().lower()
  29. if search:
  30. df = df[df['File'].str.lower().str.contains(search)]
  31. # --- 2. VISUALIZZAZIONE COMPATTA (SENZA TREMOLIO) ---
  32. # Usiamo le colonne per restringere la tabella al centro
  33. col_tab, col_empty = st.columns([3, 1])
  34. with col_tab:
  35. # st.table non ha scrollbar e non ha interazioni JS che causano tremolio
  36. st.table(df[["File", "Data"]].head(20))
  37. st.divider()
  38. # --- 3. AZIONI ---
  39. st.markdown("### 🛠️ Azioni")
  40. selected = st.selectbox("Seleziona file per operare:", df["File"].tolist())
  41. if selected:
  42. file_path = samples_dir / selected
  43. c1, c2, c3 = st.columns([1,1,1])
  44. with c1:
  45. if st.button("👁️ Dettagli", use_container_width=True):
  46. content = pd.read_csv(file_path, sep=";")
  47. st.markdown(f"**Dati di `{selected}`**")
  48. st.table(content.T.reset_index().rename(columns={'index': 'AP', 0: 'RSSI'}))
  49. with c2:
  50. with open(file_path, "rb") as f:
  51. st.download_button("📥 Scarica", f, file_name=selected, use_container_width=True)
  52. with c3:
  53. if st.button("🗑️ Elimina", use_container_width=True, type="primary"):
  54. os.remove(file_path)
  55. st.rerun()
  56. # Stats discrete in sidebar
  57. st.sidebar.caption(f"Totale campioni: {len(all_files)}")