duongthienz commited on
Commit
b4222d5
·
verified ·
1 Parent(s): a504eda

Cont fixing proportion plot

Browse files
Files changed (1) hide show
  1. utils.py +8 -4
utils.py CHANGED
@@ -491,12 +491,15 @@ def build_multifile_category_df(validNames, results, summaries, categories, cate
491
  df6_dict.setdefault(category, [])
492
 
493
  # Second pass: compute proportions per file
494
- for fn in validNames:
495
  currAnnotation, totalSeconds = results[fn]
496
  safe_total = max(totalSeconds, 1)
497
  prefix = fn + ": "
498
  renames = speakerRenames.get(fn, {})
499
 
 
 
 
500
  # For each role: union all assigned speakers into one subset, then sum.
501
  # su.sumTimes uses get_timeline(False).duration() which merges overlaps.
502
  for i, category in enumerate(categories):
@@ -505,13 +508,13 @@ def build_multifile_category_df(validNames, results, summaries, categories, cate
505
  for t in categorySelect[i]
506
  if t.startswith(prefix)
507
  ] if i < len(categorySelect) else []
508
- # Filter to speakers that actually exist in this annotation
509
  valid_sps = [sp for sp in assigned_sps if sp in currAnnotation.labels()]
510
  if valid_sps:
511
  val = su.sumTimes(currAnnotation.subset(valid_sps)) / safe_total
512
  else:
513
  val = 0.0
514
  df6_dict[category].append(min(val, 1.0))
 
515
 
516
  # For unassigned speakers: each gets their own column
517
  assigned_all = {
@@ -525,10 +528,11 @@ def build_multifile_category_df(validNames, results, summaries, categories, cate
525
  display = renames.get(sp, sp)
526
  val = su.sumTimes(currAnnotation.subset([sp])) / safe_total
527
  df6_dict[display].append(min(val, 1.0))
 
528
 
529
- # Fill 0 for any extra columns this file doesn't have
530
  for category in allCategories:
531
- if len(df6_dict[category]) < len(df6_dict["files"]):
532
  df6_dict[category].append(0)
533
 
534
  return pd.DataFrame(df6_dict), allCategories
 
491
  df6_dict.setdefault(category, [])
492
 
493
  # Second pass: compute proportions per file
494
+ for row_idx, fn in enumerate(validNames):
495
  currAnnotation, totalSeconds = results[fn]
496
  safe_total = max(totalSeconds, 1)
497
  prefix = fn + ": "
498
  renames = speakerRenames.get(fn, {})
499
 
500
+ # Track which allCategories columns get a value this row
501
+ filled = set()
502
+
503
  # For each role: union all assigned speakers into one subset, then sum.
504
  # su.sumTimes uses get_timeline(False).duration() which merges overlaps.
505
  for i, category in enumerate(categories):
 
508
  for t in categorySelect[i]
509
  if t.startswith(prefix)
510
  ] if i < len(categorySelect) else []
 
511
  valid_sps = [sp for sp in assigned_sps if sp in currAnnotation.labels()]
512
  if valid_sps:
513
  val = su.sumTimes(currAnnotation.subset(valid_sps)) / safe_total
514
  else:
515
  val = 0.0
516
  df6_dict[category].append(min(val, 1.0))
517
+ filled.add(category)
518
 
519
  # For unassigned speakers: each gets their own column
520
  assigned_all = {
 
528
  display = renames.get(sp, sp)
529
  val = su.sumTimes(currAnnotation.subset([sp])) / safe_total
530
  df6_dict[display].append(min(val, 1.0))
531
+ filled.add(display)
532
 
533
+ # Fill 0 for every allCategories column not touched this row
534
  for category in allCategories:
535
+ if category not in filled:
536
  df6_dict[category].append(0)
537
 
538
  return pd.DataFrame(df6_dict), allCategories