| 520 | |
| 521 | # Function to calculate statistics for a group of attempts |
| 522 | def calc_stats(attempts): |
| 523 | if not attempts: |
| 524 | return { |
| 525 | "count": 0, |
| 526 | "avg_thinking_tokens": 0, |
| 527 | "avg_thought_transitions": 0, |
| 528 | "transition_usage": {phrase: 0 for phrase in THOUGHT_TRANSITIONS}, |
| 529 | "has_think_tags_pct": 0 |
| 530 | } |
| 531 | |
| 532 | thinking_tokens = [a['thought_analysis']['thinking_tokens'] for a in attempts] |
| 533 | thought_transitions = [a['thought_analysis']['thought_transitions'] for a in attempts] |
| 534 | has_think_tags = sum(1 for a in attempts if a['thought_analysis']['has_think_tags']) |
| 535 | |
| 536 | # Count total transition usage |
| 537 | transition_usage = defaultdict(int) |
| 538 | for attempt in attempts: |
| 539 | for phrase, count in attempt['thought_analysis']['transition_counts'].items(): |
| 540 | transition_usage[phrase] += count |
| 541 | |
| 542 | return { |
| 543 | "count": len(attempts), |
| 544 | "avg_thinking_tokens": statistics.mean(thinking_tokens) if thinking_tokens else 0, |
| 545 | "median_thinking_tokens": statistics.median(thinking_tokens) if thinking_tokens else 0, |
| 546 | "min_thinking_tokens": min(thinking_tokens) if thinking_tokens else 0, |
| 547 | "max_thinking_tokens": max(thinking_tokens) if thinking_tokens else 0, |
| 548 | "avg_thought_transitions": statistics.mean(thought_transitions) if thought_transitions else 0, |
| 549 | "median_thought_transitions": statistics.median(thought_transitions) if thought_transitions else 0, |
| 550 | "transition_usage": dict(transition_usage), |
| 551 | "has_think_tags_pct": (has_think_tags / len(attempts)) * 100 if attempts else 0 |
| 552 | } |
| 553 | |
| 554 | # Calculate statistics |
| 555 | correct_stats = calc_stats(correct_attempts) |