Spaces:
Running
Running
Resume Feature Implementation
Browse files
components/review_dashboard_page.py
CHANGED
@@ -362,20 +362,18 @@ class ReviewDashboardPage:
|
|
362 |
Annotation.annotator_id == target_annotator_obj.id
|
363 |
).count()
|
364 |
|
365 |
-
# Calculate
|
366 |
-
INITIAL_BATCH_SIZE =
|
367 |
-
|
368 |
-
|
369 |
-
items_to_load = max(INITIAL_BATCH_SIZE, resume_index + 1)
|
370 |
-
# Cap it to avoid loading too many items at once
|
371 |
-
items_to_load = min(items_to_load, 20)
|
372 |
-
else:
|
373 |
-
# No unreviewed items found, load standard batch from the end
|
374 |
-
items_to_load = INITIAL_BATCH_SIZE
|
375 |
|
376 |
-
# Load items based on resume logic
|
377 |
if resume_index >= 0:
|
378 |
-
# Load
|
|
|
|
|
|
|
|
|
|
|
379 |
query = db.query(
|
380 |
Annotation,
|
381 |
TTSData.filename,
|
@@ -384,9 +382,12 @@ class ReviewDashboardPage:
|
|
384 |
TTSData, Annotation.tts_data_id == TTSData.id
|
385 |
).filter(
|
386 |
Annotation.annotator_id == target_annotator_obj.id
|
387 |
-
).order_by(Annotation.id).limit(items_to_load)
|
|
|
|
|
388 |
else:
|
389 |
-
#
|
|
|
390 |
query = db.query(
|
391 |
Annotation,
|
392 |
TTSData.filename,
|
@@ -395,14 +396,12 @@ class ReviewDashboardPage:
|
|
395 |
TTSData, Annotation.tts_data_id == TTSData.id
|
396 |
).filter(
|
397 |
Annotation.annotator_id == target_annotator_obj.id
|
398 |
-
).order_by(Annotation.id.
|
|
|
|
|
399 |
|
400 |
results = query.all()
|
401 |
|
402 |
-
# If we loaded from the end (all reviewed), reverse the results to maintain chronological order
|
403 |
-
if resume_index < 0:
|
404 |
-
results = list(reversed(results))
|
405 |
-
|
406 |
log.info(f"Loaded {len(results)} annotations out of {total_count} total for target annotator ID {target_annotator_obj.id}")
|
407 |
|
408 |
# Process items with minimal data - validation status will be loaded on-demand
|
@@ -427,15 +426,22 @@ class ReviewDashboardPage:
|
|
427 |
# --- Calculate initial index based on resume logic ---
|
428 |
initial_idx = 0
|
429 |
if items:
|
430 |
-
if resume_index >= 0
|
431 |
-
#
|
432 |
-
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
else:
|
435 |
-
# All items reviewed
|
436 |
initial_idx = len(items) - 1 if items else 0
|
437 |
if items:
|
438 |
-
log.info(f"User '{username}' has all
|
439 |
else:
|
440 |
log.info(f"User '{username}' has no items assigned, starting at index 0.")
|
441 |
|
|
|
362 |
Annotation.annotator_id == target_annotator_obj.id
|
363 |
).count()
|
364 |
|
365 |
+
# Calculate loading strategy based on resume logic
|
366 |
+
INITIAL_BATCH_SIZE = 10 # Standard batch size
|
367 |
+
CONTEXT_ITEMS = 1 # Number of reviewed items to include for context
|
368 |
+
load_offset = 0 # Initialize load_offset
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
|
|
|
370 |
if resume_index >= 0:
|
371 |
+
# Load items starting from around the first unreviewed annotation
|
372 |
+
# Include some context (already reviewed items) before the unreviewed one
|
373 |
+
load_offset = max(0, resume_index - CONTEXT_ITEMS)
|
374 |
+
items_to_load = INITIAL_BATCH_SIZE
|
375 |
+
|
376 |
+
# Load items starting from the calculated offset
|
377 |
query = db.query(
|
378 |
Annotation,
|
379 |
TTSData.filename,
|
|
|
382 |
TTSData, Annotation.tts_data_id == TTSData.id
|
383 |
).filter(
|
384 |
Annotation.annotator_id == target_annotator_obj.id
|
385 |
+
).order_by(Annotation.id).offset(load_offset).limit(items_to_load)
|
386 |
+
|
387 |
+
log.info(f"Resume mode: Loading {items_to_load} items starting from offset {load_offset} (first unreviewed at global index {resume_index})")
|
388 |
else:
|
389 |
+
# No unreviewed items found, load standard batch from the end
|
390 |
+
load_offset = max(0, total_count - INITIAL_BATCH_SIZE)
|
391 |
query = db.query(
|
392 |
Annotation,
|
393 |
TTSData.filename,
|
|
|
396 |
TTSData, Annotation.tts_data_id == TTSData.id
|
397 |
).filter(
|
398 |
Annotation.annotator_id == target_annotator_obj.id
|
399 |
+
).order_by(Annotation.id).offset(load_offset).limit(INITIAL_BATCH_SIZE)
|
400 |
+
|
401 |
+
log.info(f"All reviewed mode: Loading {INITIAL_BATCH_SIZE} items from offset {load_offset}")
|
402 |
|
403 |
results = query.all()
|
404 |
|
|
|
|
|
|
|
|
|
405 |
log.info(f"Loaded {len(results)} annotations out of {total_count} total for target annotator ID {target_annotator_obj.id}")
|
406 |
|
407 |
# Process items with minimal data - validation status will be loaded on-demand
|
|
|
426 |
# --- Calculate initial index based on resume logic ---
|
427 |
initial_idx = 0
|
428 |
if items:
|
429 |
+
if resume_index >= 0:
|
430 |
+
# Calculate the local index within loaded items
|
431 |
+
# The first unreviewed annotation should be at: resume_index - load_offset
|
432 |
+
local_resume_index = resume_index - load_offset
|
433 |
+
if 0 <= local_resume_index < len(items):
|
434 |
+
initial_idx = local_resume_index
|
435 |
+
log.info(f"User '{username}' resuming at first unreviewed item, local index: {initial_idx} (global index: {resume_index}, annotation ID: {items[initial_idx]['annotation_id']})")
|
436 |
+
else:
|
437 |
+
# Fallback to first item if calculation is off
|
438 |
+
initial_idx = 0
|
439 |
+
log.warning(f"Resume index calculation off, starting at first loaded item. Local index: {local_resume_index}, loaded items: {len(items)}")
|
440 |
else:
|
441 |
+
# All items reviewed, start from the last item
|
442 |
initial_idx = len(items) - 1 if items else 0
|
443 |
if items:
|
444 |
+
log.info(f"User '{username}' has all items reviewed, starting at last item index: {initial_idx} (annotation ID: {items[initial_idx]['annotation_id']})")
|
445 |
else:
|
446 |
log.info(f"User '{username}' has no items assigned, starting at index 0.")
|
447 |
|