Update tab_id_review.py
This commit is contained in:
@@ -1,38 +1,34 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
import os
|
import os, shutil
|
||||||
from engine import SorterEngine
|
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 common_ids:
|
||||||
if 'history' not in st.session_state: st.session_state.history = []
|
curr_id = common_ids[0]
|
||||||
if 'idx_time' not in st.session_state: st.session_state.idx_time = 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 ---
|
st.subheader(f"Reviewing ID: {curr_id}")
|
||||||
matches_this_session = len([h for h in st.session_state.history if 'link' in h['type']])
|
col1, col2 = st.columns(2)
|
||||||
moves_to_unused = len([h for h in st.session_state.history if h['type'] == 'unused'])
|
|
||||||
|
|
||||||
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 ---
|
if img1: col1.image(img1, caption=t_f)
|
||||||
BASE_PATH = "/storage"
|
if img2: col2.image(img2, caption=c_f)
|
||||||
favs = SorterEngine.load_favorites()
|
|
||||||
selected_fav = st.sidebar.selectbox("⭐ Favorites", ["None"] + list(favs.keys()))
|
|
||||||
|
|
||||||
path_t = st.sidebar.text_input("Path 1 (Target)", value=favs[selected_fav]['target'] if selected_fav != "None" else BASE_PATH)
|
if st.button("❌ Move Pair to Unused", use_container_width=True):
|
||||||
path_c = st.sidebar.text_input("Path 2 (Control)", value=favs[selected_fav]['control'] if selected_fav != "None" else BASE_PATH)
|
t_un = os.path.join(path_t, "unused", t_f)
|
||||||
|
c_un = os.path.join(path_c, "unused", c_f)
|
||||||
quality = st.sidebar.slider("Bandwidth Compression", 5, 100, 40)
|
os.makedirs(os.path.dirname(t_un), exist_ok=True)
|
||||||
threshold = st.sidebar.number_input("Time Threshold (s)", value=50)
|
os.makedirs(os.path.dirname(c_un), exist_ok=True)
|
||||||
next_id_val = st.sidebar.number_input("Next ID Number", value=SorterEngine.get_max_id_number(path_t) + 1)
|
shutil.move(t_p, t_un)
|
||||||
id_prefix = f"id{next_id_val:03d}_"
|
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})
|
||||||
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()
|
st.rerun()
|
||||||
|
else:
|
||||||
# --- Tabs ---
|
st.info("No existing ID matches found.")
|
||||||
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)
|
|
||||||
Reference in New Issue
Block a user