earlsab commited on
Commit
9ebd77d
·
1 Parent(s): 74509d6

fix sorting logic

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -401,22 +401,29 @@ def create_html_output(job_result: Dict, resume_results: List[Dict]) -> str:
401
  while i < len(sorted_resumes):
402
  current = sorted_resumes[i]
403
  similar_exp = [current]
 
404
  j = i + 1
405
 
406
  # Find all resumes with similar experience to the current one
407
  while j < len(sorted_resumes) and sorted_resumes[j]['match_count'] == current['match_count']:
408
  if abs(sorted_resumes[j]['total_experience'] - current['total_experience']) <= 1:
409
  similar_exp.append(sorted_resumes[j])
410
- sorted_resumes.pop(j)
411
- else:
412
- j += 1
413
 
414
  # Sort by quality score if there are resumes with similar experience
415
  if len(similar_exp) > 1:
416
  similar_exp.sort(key=lambda x: -x['quality_score'])
417
 
418
  final_sorted.extend(similar_exp)
419
- i = j if len(similar_exp) == 1 else i + 1
 
 
 
 
 
 
 
420
 
421
  # Add sorted rows to summary table
422
  for resume_data in final_sorted:
 
401
  while i < len(sorted_resumes):
402
  current = sorted_resumes[i]
403
  similar_exp = [current]
404
+ indices_to_remove = []
405
  j = i + 1
406
 
407
  # Find all resumes with similar experience to the current one
408
  while j < len(sorted_resumes) and sorted_resumes[j]['match_count'] == current['match_count']:
409
  if abs(sorted_resumes[j]['total_experience'] - current['total_experience']) <= 1:
410
  similar_exp.append(sorted_resumes[j])
411
+ indices_to_remove.append(j)
412
+ j += 1
 
413
 
414
  # Sort by quality score if there are resumes with similar experience
415
  if len(similar_exp) > 1:
416
  similar_exp.sort(key=lambda x: -x['quality_score'])
417
 
418
  final_sorted.extend(similar_exp)
419
+
420
+ # Create a new list without the removed indices
421
+ sorted_resumes = [r for idx, r in enumerate(sorted_resumes) if idx != i and idx not in indices_to_remove]
422
+
423
+ # We don't need to increment i since we've created a new list without the processed items
424
+ # but if the list is empty, we need to break out of the loop
425
+ if not sorted_resumes:
426
+ break
427
 
428
  # Add sorted rows to summary table
429
  for resume_data in final_sorted: