Update tab_id_review.py

This commit is contained in:
2026-01-17 12:57:06 +01:00
parent cf6dec7b90
commit 5265451556

View File

@@ -1,38 +1,34 @@
import streamlit as st
import os
import os, shutil
from engine import SorterEngine
import tab_id_review, tab_time_discovery
st.set_page_config(layout="wide", page_title="Turbo Sorter Pro")
def render(path_t, path_c, quality):
map_t = SorterEngine.get_id_mapping(path_t)
map_c = SorterEngine.get_id_mapping(path_c)
common_ids = sorted(list(set(map_t.keys()) & set(map_c.keys())))
# --- Session State ---
if 'history' not in st.session_state: st.session_state.history = []
if 'idx_time' not in st.session_state: st.session_state.idx_time = 0
if common_ids:
curr_id = common_ids[0]
t_f, c_f = map_t[curr_id], map_c[curr_id]
t_p, c_p = os.path.join(path_t, t_f), os.path.join(path_c, c_f)
# --- Status Bar ---
matches_this_session = len([h for h in st.session_state.history if 'link' in h['type']])
moves_to_unused = len([h for h in st.session_state.history if h['type'] == 'unused'])
st.subheader(f"Reviewing ID: {curr_id}")
col1, col2 = st.columns(2)
st.info(f"📊 **Session Stats:** {matches_this_session} Matches Created | {moves_to_unused} Sent to Unused")
img1 = SorterEngine.compress_for_web(t_p, quality)
img2 = SorterEngine.compress_for_web(c_p, quality)
# --- Sidebar ---
BASE_PATH = "/storage"
favs = SorterEngine.load_favorites()
selected_fav = st.sidebar.selectbox("⭐ Favorites", ["None"] + list(favs.keys()))
if img1: col1.image(img1, caption=t_f)
if img2: col2.image(img2, caption=c_f)
path_t = st.sidebar.text_input("Path 1 (Target)", value=favs[selected_fav]['target'] if selected_fav != "None" else BASE_PATH)
path_c = st.sidebar.text_input("Path 2 (Control)", value=favs[selected_fav]['control'] if selected_fav != "None" else BASE_PATH)
quality = st.sidebar.slider("Bandwidth Compression", 5, 100, 40)
threshold = st.sidebar.number_input("Time Threshold (s)", value=50)
next_id_val = st.sidebar.number_input("Next ID Number", value=SorterEngine.get_max_id_number(path_t) + 1)
id_prefix = f"id{next_id_val:03d}_"
if st.sidebar.button("↶ UNDO", use_container_width=True, disabled=not st.session_state.history):
SorterEngine.revert_action(st.session_state.history.pop())
st.rerun()
# --- Tabs ---
t1, t2 = st.tabs(["🆔 ID Match Review", "🕒 Time Discovery"])
with t1: tab_id_review.render(path_t, path_c, quality)
with t2: tab_time_discovery.render(path_t, path_c, quality, threshold, id_prefix)
if st.button("❌ Move Pair to Unused", use_container_width=True):
t_un = os.path.join(path_t, "unused", t_f)
c_un = os.path.join(path_c, "unused", c_f)
os.makedirs(os.path.dirname(t_un), exist_ok=True)
os.makedirs(os.path.dirname(c_un), exist_ok=True)
shutil.move(t_p, t_un)
shutil.move(c_p, c_un)
st.session_state.history.append({'type': 'unused', 't_src': t_p, 't_dst': t_un, 'c_src': c_p, 'c_dst': c_un})
st.rerun()
else:
st.info("No existing ID matches found.")