HASH 26ea907a7b6b
DATE 2025-08-29
SUBJECT web: improve team identification algo
FILES 2 CHANGED
HASH 26ea907a7b6b
DATE 2025-08-29
SUBJECT web: improve team identification algo
FILES 2 CHANGED
┌─ nix/apps/team-leaderboard-generator.nix ──────────────────────────────────┐│ diff --git a/nix/apps/team-leaderboard-generator.nix b/nix/apps/team-leaderboard-g ││ enerator.nix ││ index 5de1d01..e508ef3 100644 ││ --- a/nix/apps/team-leaderboard-generator.nix ││ +++ b/nix/apps/team-leaderboard-generator.nix ││ @@ -231,7 +231,35 @@ ││ "all_runs": sorted(all_runs, key=lambda x: x["duration"]) ││ } ││ ││ - deduplicated.append(merged_team) ││ + # Validate that merged core players appear in most of their bes ││ t runs ││ + core_participation_count = 0 ││ + total_best_runs = len(best_team_runs) ││ + failed_runs = [] ││ + ││ + for dungeon_slug, run_data in best_team_runs.items(): ││ + # Find actual run to check core participation ││ + run_found = False ││ + for team in similar_teams: ││ + for run in team["all_runs"]: ││ + if run["duration"] == run_data["duration"] and run[ ││ "completed_timestamp"] == run_data["completed_timestamp"]: ││ + # Count how many core members participated in t ││ his run ││ + core_in_run = sum(1 for core_id in merged_core_ ││ ids if core_id in run["member_ids"]) ││ + if core_in_run >= 2: # At least 2 of 3 core me ││ mbers ││ + core_participation_count += 1 ││ + else: ││ + failed_runs.append(f"{dungeon_slug}: {core_ ││ in_run}/3 core members") ││ + run_found = True ││ + break ││ + if run_found: ││ + break ││ + ││ + core_participation_rate = core_participation_count / total_best ││ _runs if total_best_runs > 0 else 0 ││ + if core_participation_rate >= 0.85 and len(failed_runs) <= 1: ││ # Allow max 1 failed run ││ + deduplicated.append(merged_team) ││ + else: ││ + print(f"Warning: Rejecting merged team {merged_sig} - core ││ players only appear in {core_participation_rate:.1%} of best runs. Failed runs: {f ││ ailed_runs}") ││ + # Add individual teams instead of the problematic merged te ││ am ││ + deduplicated.extend(similar_teams) ││ ││ return deduplicated ││ ││ @@ -320,15 +348,18 @@ ││ } ││ ││ # Track extended rosters - players who run together consistentl ││ y ││ - # Group runs by overlapping player combinations to identify ext ││ ended teams ││ + # Use stricter criteria to prevent artificial team merging ││ found_roster = None ││ current_players = set(member_ids) ││ ││ # Check if this run matches any existing extended roster ││ for roster_sig, roster_players in extended_rosters.items(): ││ - # If 3+ players overlap, consider this part of the same ext ││ ended roster ││ overlap = len(current_players.intersection(roster_players)) ││ - if overlap >= 3: ││ + overlap_percentage = overlap / len(current_players.union(ro ││ ster_players)) ││ + ││ + # More balanced criteria: Allow extended rosters but preven ││ t mega-merging ││ + # Require 3+ overlap but with minimum 35% similarity to pre ││ vent distant connections ││ + if overlap >= 3 and overlap_percentage >= 0.35: ││ found_roster = roster_sig ││ # Add new players to the extended roster ││ extended_rosters[roster_sig].update(current_players) │└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ...eam-leaderboard-generator.nix ───┐│ diff --git a/nix/apps/team-leaderboard-gener ││ ator.nix b/nix/apps/team-leaderboard-generat ││ or.nix ││ index 5de1d01..e508ef3 100644 ││ --- a/nix/apps/team-leaderboard-generator.ni ││ x ││ +++ b/nix/apps/team-leaderboard-generator.ni ││ x ││ @@ -231,7 +231,35 @@ ││ "all_runs": sorted(al ││ l_runs, key=lambda x: x["duration"]) ││ } ││ ││ - deduplicated.append(merge ││ d_team) ││ + # Validate that merged co ││ re players appear in most of their best runs ││ + core_participation_count ││ = 0 ││ + total_best_runs = len(bes ││ t_team_runs) ││ + failed_runs = [] ││ + ││ + for dungeon_slug, run_dat ││ a in best_team_runs.items(): ││ + # Find actual run to ││ check core participation ││ + run_found = False ││ + for team in similar_t ││ eams: ││ + for run in team[" ││ all_runs"]: ││ + if run["durat ││ ion"] == run_data["duration"] and run["compl ││ eted_timestamp"] == run_data["completed_time ││ stamp"]: ││ + # Count h ││ ow many core members participated in this ru ││ n ││ + core_in_r ││ un = sum(1 for core_id in merged_core_ids if ││ core_id in run["member_ids"]) ││ + if core_i ││ n_run >= 2: # At least 2 of 3 core members ││ + core_ ││ participation_count += 1 ││ + else: ││ + faile ││ d_runs.append(f"{dungeon_slug}: {core_in_run ││ }/3 core members") ││ + run_found ││ = True ││ + break ││ + if run_found: ││ + break ││ + ││ + core_participation_rate = ││ core_participation_count / total_best_runs ││ if total_best_runs > 0 else 0 ││ + if core_participation_rat ││ e >= 0.85 and len(failed_runs) <= 1: # Allo ││ w max 1 failed run ││ + deduplicated.append(m ││ erged_team) ││ + else: ││ + print(f"Warning: Reje ││ cting merged team {merged_sig} - core player ││ s only appear in {core_participation_rate:.1 ││ %} of best runs. Failed runs: {failed_runs}" ││ ) ││ + # Add individual team ││ s instead of the problematic merged team ││ + deduplicated.extend(s ││ imilar_teams) ││ ││ return deduplicated ││ ││ @@ -320,15 +348,18 @@ ││ } ││ ││ # Track extended rosters ││ - players who run together consistently ││ - # Group runs by overlappi ││ ng player combinations to identify extended ││ teams ││ + # Use stricter criteria t ││ o prevent artificial team merging ││ found_roster = None ││ current_players = set(mem ││ ber_ids) ││ ││ # Check if this run match ││ es any existing extended roster ││ for roster_sig, roster_pl ││ ayers in extended_rosters.items(): ││ - # If 3+ players overl ││ ap, consider this part of the same extended ││ roster ││ overlap = len(current ││ _players.intersection(roster_players)) ││ - if overlap >= 3: ││ + overlap_percentage = ││ overlap / len(current_players.union(roster_p ││ layers)) ││ + ││ + # More balanced crite ││ ria: Allow extended rosters but prevent mega ││ -merging ││ + # Require 3+ overlap ││ but with minimum 35% similarity to prevent d ││ istant connections ││ + if overlap >= 3 and o ││ verlap_percentage >= 0.35: ││ found_roster = ro ││ ster_sig ││ # Add new players ││ to the extended roster ││ extended_rosters[ ││ roster_sig].update(current_players) │└──────────────────────────────────────────────┘