iyadsultan commited on
Commit
36b6039
·
1 Parent(s): dacb5f5

Refactor document index handling in evaluation process to use 1-based indexing. Update logging for document navigation actions and ensure proper session management. Adjust form action in evaluate.html for consistency.

Browse files
Files changed (2) hide show
  1. app.py +30 -23
  2. templates/evaluate.html +1 -1
app.py CHANGED
@@ -421,21 +421,25 @@ def evaluate():
421
  # Create sessions directory if it doesn't exist
422
  os.makedirs(os.path.join(DATA_DIR, 'sessions'), exist_ok=True)
423
 
 
 
 
 
424
  # Check for jump_to parameter to jump to a specific document number
425
  jump_to = request.args.get('jump_to', type=int)
426
  if jump_to is not None:
427
  # Ensure jump_to is within valid range
428
  documents = load_documents()
429
  if jump_to >= 1 and jump_to <= len(documents):
430
- session['current_document_index'] = jump_to - 1 # Convert to 0-based index
431
- log_error(f"Jumping to document number: {jump_to} (index: {jump_to - 1})")
432
  else:
433
  flash(f"Invalid document number. Please enter a number between 1 and {len(documents)}.")
434
  log_error(f"Invalid jump_to value: {jump_to}")
435
-
436
- # Initialize current document index if not set (start fresh each session)
437
- if 'current_document_index' not in session:
438
- session['current_document_index'] = 0
439
 
440
  # Generate session ID if not set
441
  if 'session_id' not in session:
@@ -458,10 +462,10 @@ def evaluate():
458
  if has_criteria_data and has_note_origin:
459
  # Get all documents
460
  all_documents = load_documents()
461
- current_index = session.get('current_document_index', 0)
462
 
463
- if current_index < len(all_documents):
464
- document = all_documents[current_index]
465
 
466
  # Prepare evaluation data
467
  evaluation_data = {
@@ -502,9 +506,11 @@ def evaluate():
502
 
503
  # Handle "Skip" action
504
  if action == 'skip':
505
- session['current_document_index'] = session.get('current_document_index', 0) + 1
 
 
506
  flash("Document skipped.")
507
- return redirect(url_for('evaluate'))
508
 
509
  # Handle regular evaluation submission
510
  # Get all documents
@@ -515,12 +521,12 @@ def evaluate():
515
  flash("No documents available for evaluation.")
516
  return redirect(url_for('index'))
517
 
518
- current_index = session.get('current_document_index', 0)
519
- if current_index >= len(all_documents):
520
  flash("All documents have been processed.")
521
  return redirect(url_for('results'))
522
 
523
- document = all_documents[current_index]
524
  log_error(f"Processing evaluation for document: {document.get('filename')}")
525
 
526
  # Prepare evaluation data
@@ -551,13 +557,14 @@ def evaluate():
551
 
552
  # Move to next document
553
  session['current_document_index'] = current_index + 1
 
554
 
555
  # Check if all documents have been processed
556
- if session['current_document_index'] >= len(all_documents):
557
  flash("All documents have been evaluated. Thank you!")
558
  return redirect(url_for('results'))
559
 
560
- # Redirect to next document
561
  return redirect(url_for('evaluate'))
562
  else:
563
  flash("Error saving evaluation. Please try again.")
@@ -579,21 +586,21 @@ def evaluate():
579
  log_error("No documents found, redirecting")
580
  return render_template('no_documents.html')
581
 
582
- # Get current document index
583
- current_index = session.get('current_document_index', 0)
584
 
585
  # Check if we've reached the end
586
- if current_index >= len(all_documents):
587
  flash("All documents have been processed in this session.")
588
  return redirect(url_for('results'))
589
 
590
  # Get the current document
591
- document = all_documents[current_index]
592
- log_error(f"Selected document at index {current_index} (note #{current_index + 1}): {document.get('filename')}")
593
 
594
  # Get current session progress (only for this session)
595
  total_docs = len(all_documents)
596
- current_progress = current_index
597
  progress = int((current_progress / total_docs) * 100) if total_docs > 0 else 0
598
 
599
  log_error(f"Session Progress: {current_progress}/{total_docs} documents ({progress}%)")
@@ -611,7 +618,7 @@ def evaluate():
611
  total_docs=total_docs,
612
  evaluated_docs=current_progress,
613
  progress=progress,
614
- current_note_number=current_index + 1)
615
 
616
  except Exception as e:
617
  log_error(f"Error in evaluate route: {str(e)}")
 
421
  # Create sessions directory if it doesn't exist
422
  os.makedirs(os.path.join(DATA_DIR, 'sessions'), exist_ok=True)
423
 
424
+ # Initialize current document index if not set (start fresh each session, 1-based)
425
+ if 'current_document_index' not in session:
426
+ session['current_document_index'] = 1
427
+
428
  # Check for jump_to parameter to jump to a specific document number
429
  jump_to = request.args.get('jump_to', type=int)
430
  if jump_to is not None:
431
  # Ensure jump_to is within valid range
432
  documents = load_documents()
433
  if jump_to >= 1 and jump_to <= len(documents):
434
+ session['current_document_index'] = jump_to # Store as 1-based index
435
+ log_error(f"JUMP: Setting document index to {jump_to} (document #{jump_to})")
436
  else:
437
  flash(f"Invalid document number. Please enter a number between 1 and {len(documents)}.")
438
  log_error(f"Invalid jump_to value: {jump_to}")
439
+ else:
440
+ # Log current position when not jumping
441
+ current_idx = session.get('current_document_index', 1)
442
+ log_error(f"CONTINUE: Current document index is {current_idx} (document #{current_idx})")
443
 
444
  # Generate session ID if not set
445
  if 'session_id' not in session:
 
462
  if has_criteria_data and has_note_origin:
463
  # Get all documents
464
  all_documents = load_documents()
465
+ current_index = session.get('current_document_index', 1)
466
 
467
+ if current_index <= len(all_documents):
468
+ document = all_documents[current_index - 1] # Convert to 0-based for array access
469
 
470
  # Prepare evaluation data
471
  evaluation_data = {
 
506
 
507
  # Handle "Skip" action
508
  if action == 'skip':
509
+ old_index = session.get('current_document_index', 1)
510
+ session['current_document_index'] = old_index + 1
511
+ log_error(f"SKIP: Moving from document {old_index} to document {session['current_document_index']}")
512
  flash("Document skipped.")
513
+ return redirect(url_for('evaluate')) # No jump_to parameter, continue from current position
514
 
515
  # Handle regular evaluation submission
516
  # Get all documents
 
521
  flash("No documents available for evaluation.")
522
  return redirect(url_for('index'))
523
 
524
+ current_index = session.get('current_document_index', 1)
525
+ if current_index > len(all_documents):
526
  flash("All documents have been processed.")
527
  return redirect(url_for('results'))
528
 
529
+ document = all_documents[current_index - 1] # Convert to 0-based for array access
530
  log_error(f"Processing evaluation for document: {document.get('filename')}")
531
 
532
  # Prepare evaluation data
 
557
 
558
  # Move to next document
559
  session['current_document_index'] = current_index + 1
560
+ log_error(f"SUBMIT: Moving from document {current_index} to document {session['current_document_index']}")
561
 
562
  # Check if all documents have been processed
563
+ if session['current_document_index'] > len(all_documents):
564
  flash("All documents have been evaluated. Thank you!")
565
  return redirect(url_for('results'))
566
 
567
+ # Redirect to next document (no jump_to parameter, continue from current position)
568
  return redirect(url_for('evaluate'))
569
  else:
570
  flash("Error saving evaluation. Please try again.")
 
586
  log_error("No documents found, redirecting")
587
  return render_template('no_documents.html')
588
 
589
+ # Get current document index (1-based)
590
+ current_index = session.get('current_document_index', 1)
591
 
592
  # Check if we've reached the end
593
+ if current_index > len(all_documents):
594
  flash("All documents have been processed in this session.")
595
  return redirect(url_for('results'))
596
 
597
  # Get the current document
598
+ document = all_documents[current_index - 1] # Convert to 0-based for array access
599
+ log_error(f"Selected document at index {current_index - 1} (note #{current_index}): {document.get('filename')}")
600
 
601
  # Get current session progress (only for this session)
602
  total_docs = len(all_documents)
603
+ current_progress = current_index - 1 # Convert to 0-based for progress calculation
604
  progress = int((current_progress / total_docs) * 100) if total_docs > 0 else 0
605
 
606
  log_error(f"Session Progress: {current_progress}/{total_docs} documents ({progress}%)")
 
618
  total_docs=total_docs,
619
  evaluated_docs=current_progress,
620
  progress=progress,
621
+ current_note_number=current_index)
622
 
623
  except Exception as e:
624
  log_error(f"Error in evaluate route: {str(e)}")
templates/evaluate.html CHANGED
@@ -77,7 +77,7 @@
77
  </div>
78
  </div>
79
 
80
- <form method="POST">
81
  <div class="criteria-container">
82
  {% for i in range(criteria|length) %}
83
  <div class="criteria-group">
 
77
  </div>
78
  </div>
79
 
80
+ <form method="POST" action="{{ url_for('evaluate') }}">
81
  <div class="criteria-container">
82
  {% for i in range(criteria|length) %}
83
  <div class="criteria-group">