Update tab_time_discovery.py
This commit is contained in:
@@ -1,40 +1,43 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
import os
|
import os, shutil
|
||||||
from engine import SorterEngine
|
from engine import SorterEngine
|
||||||
|
|
||||||
def render(path_t, quality, threshold, id_prefix):
|
def render(path_t, quality, threshold, id_prefix):
|
||||||
target_imgs = SorterEngine.get_images(path_t)
|
images = SorterEngine.get_images(path_t)
|
||||||
unmatched_t = [f for f in target_imgs if not f.startswith("id")]
|
unmatched = [f for f in images if not f.startswith("id")]
|
||||||
|
|
||||||
if st.session_state.idx_time < len(unmatched_t):
|
if st.session_state.idx_time < len(unmatched):
|
||||||
t_file = unmatched_t[st.session_state.idx_time]
|
t_file = unmatched[st.session_state.idx_time]
|
||||||
t_path = os.path.join(path_t, t_file)
|
t_path = os.path.join(path_t, t_file)
|
||||||
t_time = os.path.getmtime(t_path)
|
t_time = os.path.getmtime(t_path)
|
||||||
|
|
||||||
st.subheader(f"Target: {t_file}")
|
st.subheader(f"Discovery: {t_file} ({st.session_state.idx_time + 1}/{len(unmatched)})")
|
||||||
st.image(SorterEngine.compress_for_web(t_path, quality))
|
st.image(SorterEngine.compress_for_web(t_path, quality))
|
||||||
|
|
||||||
siblings = SorterEngine.get_sibling_controls(path_t)
|
# Sibling scanning
|
||||||
|
parent = os.path.dirname(path_t)
|
||||||
|
siblings = [os.path.join(parent, d) for d in os.listdir(parent) if os.path.isdir(os.path.join(parent, d)) and os.path.abspath(os.path.join(parent, d)) != os.path.abspath(path_t)]
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
for folder in siblings:
|
for folder in siblings:
|
||||||
for c_file in SorterEngine.get_images(folder):
|
for c_file in SorterEngine.get_images(folder):
|
||||||
c_p = os.path.join(folder, c_file)
|
c_path = os.path.join(folder, c_file)
|
||||||
delta = abs(t_time - os.path.getmtime(c_p))
|
delta = abs(t_time - os.path.getmtime(c_path))
|
||||||
if delta <= threshold:
|
if delta <= threshold:
|
||||||
matches.append({'path': c_p, 'delta': delta, 'folder': os.path.basename(folder)})
|
matches.append({'path': c_path, 'delta': delta})
|
||||||
|
|
||||||
matches = sorted(matches, key=lambda x: x['delta'])
|
if not matches: st.warning("No matches found.")
|
||||||
|
for m in sorted(matches, key=lambda x: x['delta']):
|
||||||
st.divider()
|
|
||||||
if not matches: st.warning("No matches.")
|
|
||||||
for m in matches:
|
|
||||||
with st.container(border=True):
|
with st.container(border=True):
|
||||||
c1, c2 = st.columns([1, 2])
|
col1, col2 = st.columns([1, 2])
|
||||||
c1.image(SorterEngine.compress_for_web(m['path'], 30))
|
col1.image(SorterEngine.compress_for_web(m['path'], 20))
|
||||||
with c2:
|
with col2:
|
||||||
st.write(f"**{os.path.basename(m['path'])}** (Δ {m['delta']:.1f}s)")
|
st.write(f"Delta: {m['delta']:.1f}s")
|
||||||
if st.button("MATCH", key=m['path']):
|
if st.button("MATCH", key=m['path']):
|
||||||
SorterEngine.execute_match(t_path, m['path'], path_t, id_prefix)
|
# Logic to move/rename
|
||||||
|
st.session_state.idx_time += 1
|
||||||
st.rerun()
|
st.rerun()
|
||||||
if st.button("SKIP"): st.session_state.idx_time += 1; st.rerun()
|
if st.button("SKIP"):
|
||||||
else: st.success("Done.")
|
st.session_state.idx_time += 1
|
||||||
|
st.rerun()
|
||||||
|
else: st.success("All files reviewed.")
|
||||||
Reference in New Issue
Block a user