Compare commits

...

6 Commits

Author SHA1 Message Date
x12sa
36548544fb removed linear progress bar
All checks were successful
CI for csaxs_bec / test (push) Successful in 1m54s
2026-03-28 12:42:12 +01:00
x12sa
556afec35d http error message cooldown to 10 mins
All checks were successful
CI for csaxs_bec / test (push) Successful in 2m0s
2026-03-28 12:20:01 +01:00
x12sa
4b312f72c7 error message cooldown
All checks were successful
CI for csaxs_bec / test (push) Successful in 1m55s
2026-03-28 10:51:54 +01:00
x12sa
e003f6cf03 change url and fix in https certificate ignore
Some checks failed
CI for csaxs_bec / test (push) Has been cancelled
2026-03-28 10:50:36 +01:00
x12sa
5e57042e9c https without certificate possible 2026-03-28 10:35:31 +01:00
x12sa
187964078e mod audio gen 2026-03-28 10:31:23 +01:00
2 changed files with 89 additions and 96 deletions

View File

@@ -1317,7 +1317,8 @@ class Flomni(
self._webpage_gen = FlomniWebpageGenerator(
bec_client=client,
output_dir="~/data/raw/webpage/",
upload_url="http://s1090968537.online.de/upload.php", # optional
#upload_url="http://s1090968537.online.de/upload.php", # optional
upload_url="https://v1p0zyg2w9n2k9c1.myfritz.net/upload.php",
)
self._webpage_gen.start()

View File

@@ -235,6 +235,16 @@ class HttpUploader:
self._uploaded: dict[str, float] = {} # abs path -> mtime at last upload
self._lock = threading.Lock()
self._busy = False # True while an upload thread is running
self._warn_at: dict[str, float] = {} # key -> epoch of last warning
_WARN_COOLDOWN_S = 600 # only repeat the same warning once per minute
def _warn(self, key: str, msg: str) -> None:
"""Log a warning at most once per _WARN_COOLDOWN_S for a given key."""
now = _epoch()
if now - self._warn_at.get(key, 0) >= self._WARN_COOLDOWN_S:
self._warn_at[key] = now
logger.warning(msg)
# ── Public API ──────────────────────────────────────────────────────────
@@ -294,8 +304,10 @@ class HttpUploader:
def _upload_files(self, files: list, force: bool = False) -> None:
try:
import requests as _requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
except ImportError:
logger.warning("HttpUploader: 'requests' library not installed")
self._warn("no_requests", "HttpUploader: 'requests' library not installed")
return
for path in files:
@@ -312,21 +324,26 @@ class HttpUploader:
self._url,
files={"file": (path.name, f)},
timeout=self._timeout,
verify=False, # accept self-signed / untrusted certs
)
if r.status_code == 200:
self._uploaded[str(path)] = mtime
self._warn_at.pop(f"upload_{path.name}", None) # clear on success
logger.debug(f"HttpUploader: OK {path.name}")
else:
logger.warning(
self._warn(
f"upload_{path.name}",
f"HttpUploader: {path.name} -> HTTP {r.status_code}: "
f"{r.text[:120]}"
)
except Exception as exc:
logger.warning(f"HttpUploader: {path.name} failed: {exc}")
self._warn(f"upload_{path.name}", f"HttpUploader: {path.name} failed: {exc}")
def _do_cleanup(self) -> None:
try:
import requests as _requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
except ImportError:
return
try:
@@ -334,15 +351,17 @@ class HttpUploader:
self._url,
data={"action": "cleanup"},
timeout=self._timeout,
verify=False, # accept self-signed / untrusted certs
)
logger.info(f"HttpUploader cleanup: {r.text[:120]}")
self._warn_at.pop("cleanup", None) # clear on success
# Forget mtime records for ptycho files so they get re-uploaded
with self._lock:
to_remove = [k for k in self._uploaded if "/S" in k or "\\S" in k]
for k in to_remove:
self._uploaded.pop(k, None)
except Exception as exc:
logger.warning(f"HttpUploader cleanup failed: {exc}")
self._warn("cleanup", f"HttpUploader cleanup failed: {exc}")
# ---------------------------------------------------------------------------
@@ -1245,21 +1264,6 @@ def _render_html(phone_numbers: list) -> str:
}}
.info-item .value {{ font-size: 0.9rem; font-weight: 600; color: var(--text); }}
.bar-wrap {{ grid-column: 1 / -1; display: flex; flex-direction: column; gap: 0.35rem; }}
.bar-label {{
display: flex; justify-content: space-between;
font-family: var(--mono); font-size: 0.6rem; color: var(--text-dim);
letter-spacing: 0.06em; text-transform: uppercase;
}}
.bar-track {{ height: 5px; background: var(--surface2); border-radius: 99px; overflow: hidden; }}
.bar-fill {{
height: 100%;
background: var(--ring-blend);
background: color-mix(in srgb, var(--status-color) 65%, var(--surface2));
border-radius: 99px;
transition: width 0.8s cubic-bezier(.4,0,.2,1), background 0.6s;
}}
/* ── Recon card ── */
.recon-stats {{ display: flex; gap: 2rem; flex-wrap: wrap; }}
.recon-stat {{ display: flex; flex-direction: column; gap: 0.15rem; }}
@@ -1502,10 +1506,7 @@ def _render_html(phone_numbers: list) -> str:
<div class="info-item"><span class="label">ETA</span><span class="value" id="pi-eta">-</span></div>
<div class="info-item"><span class="label">Started</span><span class="value" id="pi-start">-</span></div>
</div>
<div class="bar-wrap">
<div class="bar-label"><span>Sub-tomo progress</span><span id="bar-sub-label">-</span></div>
<div class="bar-track"><div class="bar-fill" id="bar-sub-fill" style="width:0%"></div></div>
</div>
</div>
@@ -1667,90 +1668,80 @@ function initDrag() {{
}}
initDrag();
// ── Audio ─────────────────────────────────────────────────────────────────
// iOS (all browsers on iPhone use WebKit) requires:
// 1. AudioContext created inside a user gesture.
// 2. A real (even silent) BufferSource started synchronously in the gesture.
// 3. ctx.resume() awaited before scheduling audible nodes.
// We combine all three: silent unlock buffer + resume promise + .then(beeps).
// iOS (all browsers on iPhone use WebKit) strict rules:
// 1. AudioContext must be created inside a user gesture handler.
// 2. A real BufferSource must be started SYNCHRONOUSLY in the gesture
// .then() / microtasks run outside the gesture and are rejected.
// 3. ctx.resume() is called fire-and-forget; beeps are delayed 80ms by
// setTimeout so the engine has time to start before nodes are scheduled.
//
// unlockAudio() handles all of this and must be called at the TOP of any
// onclick handler that wants audio — before any other logic.
let audioCtx = null, audioEnabled = false;
let audioArmed = false, warningActive = false, warningTimer = null, lastStatus = null;
let staleActive = false, staleTimer = null, staleConfirmed = false;
let audioCtx=null, audioEnabled=false;
let audioArmed=false, warningActive=false, warningTimer=null, lastStatus=null;
let staleActive=false, staleTimer=null, staleConfirmed=false;
function getCtx() {{
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
function getCtx(){{
if(!audioCtx) audioCtx=new(window.AudioContext||window.webkitAudioContext)();
return audioCtx;
}}
function unlockAudio() {{
// Must be called synchronously inside a user gesture handler.
// Plays a 1-sample silent buffer — the most reliable iOS unlock method.
const ctx = getCtx();
const buf = ctx.createBuffer(1, 1, ctx.sampleRate);
const src = ctx.createBufferSource();
src.buffer = buf;
src.connect(ctx.destination);
src.start(0);
// resume() is async; return the promise so callers can chain.
return ctx.state === 'suspended' ? ctx.resume() : Promise.resolve();
function unlockAudio(){{
// Synchronous silent 1-sample buffer — the only reliable iOS unlock.
// Must be called synchronously at the start of a user gesture handler.
const ctx=getCtx();
const buf=ctx.createBuffer(1,1,ctx.sampleRate);
const src=ctx.createBufferSource();
src.buffer=buf; src.connect(ctx.destination); src.start(0);
if(ctx.state==='suspended') ctx.resume(); // fire-and-forget
}}
function beep(freq, dur, vol) {{
try {{
const ctx = getCtx();
const o = ctx.createOscillator();
const g = ctx.createGain();
function beep(freq,dur,vol){{
try{{
const ctx=getCtx(),o=ctx.createOscillator(),g=ctx.createGain();
o.connect(g); g.connect(ctx.destination);
o.type = 'sine';
o.frequency.setValueAtTime(freq, ctx.currentTime);
g.gain.setValueAtTime(vol, ctx.currentTime);
g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + dur);
o.start(); o.stop(ctx.currentTime + dur);
}} catch(e) {{ console.warn('Audio beep:', e); }}
o.type='sine'; o.frequency.setValueAtTime(freq,ctx.currentTime);
g.gain.setValueAtTime(vol,ctx.currentTime);
g.gain.exponentialRampToValueAtTime(0.001,ctx.currentTime+dur);
o.start(); o.stop(ctx.currentTime+dur);
}}catch(e){{console.warn('Audio:',e);}}
}}
function warningChime() {{
beep(660, 0.3, 0.4);
setTimeout(() => beep(440, 0.5, 0.4), 350);
function warningChime(){{
beep(660,0.3,0.4); setTimeout(()=>beep(440,0.5,0.4),350);
}}
function staleChime(){{
beep(1200,0.12,0.35);
setTimeout(()=>beep(1200,0.12,0.35),180);
setTimeout(()=>beep(1200,0.25,0.35),360);
}}
function staleChime() {{
beep(1200, 0.12, 0.35);
setTimeout(() => beep(1200, 0.12, 0.35), 180);
setTimeout(() => beep(1200, 0.25, 0.35), 360);
function testSound(){{
// Gesture handler — unlock first, then delay beeps 80ms for resume().
unlockAudio();
setTimeout(()=>beep(880, 0.15,0.4), 80);
setTimeout(()=>beep(1100,0.15,0.4),260);
setTimeout(()=>beep(880, 0.3, 0.4),440);
}}
function testSound() {{
// Called directly from onclick — gesture is active here.
unlockAudio().then(() => {{
beep(880, 0.15, 0.4);
setTimeout(() => beep(1100, 0.15, 0.4), 180);
setTimeout(() => beep(880, 0.3, 0.4), 360);
}});
function toggleAudio(){{
// Gesture handler — unlock first (synchronous), then do logic.
unlockAudio();
audioEnabled=!audioEnabled;
localStorage.setItem('audioEnabled',audioEnabled);
if(!audioEnabled){{
stopWarning(); audioArmed=false; warningActive=false;
document.getElementById('btn-confirm').style.display='none';
stopStaleWarning(); staleActive=false; staleConfirmed=false;
document.getElementById('btn-confirm-stale').style.display='none';
}} else {{
if(lastStatus==='scanning' && !audioArmed) audioArmed=true;
}}
updateAudioUI();
}}
function toggleAudio() {{
// Called directly from onclick — gesture is active here.
unlockAudio().then(() => {{
audioEnabled = !audioEnabled;
localStorage.setItem('audioEnabled', audioEnabled);
if (!audioEnabled) {{
stopWarning();
audioArmed = false; warningActive = false;
document.getElementById('btn-confirm').style.display = 'none';
stopStaleWarning();
staleActive = false; staleConfirmed = false;
document.getElementById('btn-confirm-stale').style.display = 'none';
}} else {{
if (lastStatus === 'scanning' && !audioArmed) audioArmed = true;
}}
updateAudioUI();
}});
}}
function confirmWarning(){{
stopWarning();
warningActive=false;
@@ -1759,9 +1750,10 @@ function confirmWarning(){{
}}
function startWarning(){{
// Not a gesture handler — context already unlocked by Enable button click.
if(warningActive) return;
warningActive=true;
if(audioEnabled) warningChime(); // returns promise; chime plays after unlock
if(audioEnabled) warningChime();
warningTimer=setInterval(()=>{{ if(audioEnabled) warningChime(); }},30000);
document.getElementById('btn-confirm').style.display='inline-block';
updateAudioUI();
@@ -1780,9 +1772,10 @@ function confirmStale(){{
}}
function startStaleWarning(){{
// Not a gesture handler — context already unlocked by Enable button click.
if(staleActive || staleConfirmed) return;
staleActive=true;
if(audioEnabled) staleChime(); // returns promise; chime plays after unlock
if(audioEnabled) staleChime();
staleTimer=setInterval(()=>{{ if(audioEnabled) staleChime(); }},30000);
document.getElementById('btn-confirm-stale').style.display='inline-block';
updateAudioUI();
@@ -1964,8 +1957,7 @@ function render(d){{
document.getElementById('pi-type').textContent=p.tomo_type||'-';
document.getElementById('pi-eta').textContent=p.estimated_remaining_human||'-';
document.getElementById('pi-start').textContent=fmtTime(p.tomo_start_time);
document.getElementById('bar-sub-label').textContent=(p.subtomo_projection||0)+' / '+(p.subtomo_total_projections||0);
document.getElementById('bar-sub-fill').style.width=(sPct*100).toFixed(1)+'%';
if(d.recon){{
document.getElementById('recon-waiting').textContent=d.recon.waiting;
const fv=document.getElementById('recon-failed');
@@ -2011,4 +2003,4 @@ poll();
</script>
</body>
</html>
"""
"""