SamanthaStorm commited on
Commit
4e77d52
·
verified ·
1 Parent(s): a2574c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -486,21 +486,27 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
486
  dates_used = [r[1] or "Undated" for r in results] # Store dates for future mapping
487
 
488
 
489
- # --- Composite Abuse Score with Aggression Weighting ---
490
  composite_abuse_scores = []
491
 
492
- for top_label, score_dict in results:
493
- pattern_scores = score_dict.get("pattern_scores", {})
494
  weighted_score = 0
 
495
 
496
- for label, score in pattern_scores.items():
497
- if label == "aggression":
498
- weighted_score += score * 1.5 # Boost aggression impact
499
- else:
500
- weighted_score += score
501
 
502
- composite_abuse_scores.append(weighted_score)
 
 
 
 
 
503
 
 
504
  # Average and scale to percentage
505
  composite_abuse = int(round(sum(composite_abuse_scores) / len(composite_abuse_scores) * 100))
506
 
 
486
  dates_used = [r[1] or "Undated" for r in results] # Store dates for future mapping
487
 
488
 
489
+ # --- Composite Abuse Score with Weighted Patterns ---
490
  composite_abuse_scores = []
491
 
492
+ for result, _ in results:
493
+ abuse_score, threshold_labels, top_patterns, _, _, _ = result
494
  weighted_score = 0
495
+ total_weight = 0
496
 
497
+ for label, score in top_patterns:
498
+ weight = PATTERN_WEIGHTS.get(label, 1.0)
499
+ weighted_score += score * weight
500
+ total_weight += weight
 
501
 
502
+ if total_weight > 0:
503
+ final_score = (weighted_score / total_weight) * 100
504
+ else:
505
+ final_score = 0
506
+
507
+ composite_abuse_scores.append(final_score)
508
 
509
+ composite_abuse = int(round(sum(composite_abuse_scores) / len(composite_abuse_scores)))
510
  # Average and scale to percentage
511
  composite_abuse = int(round(sum(composite_abuse_scores) / len(composite_abuse_scores) * 100))
512