Skip to content

Commit

Permalink
Show side bias on standings for Single-sided swiss rounds. (#339)
Browse files Browse the repository at this point in the history
* Show side bias on standings for Single-sided swiss rounds.

* Remove errant text change.

* Rename player meeting render function.

* Set nil side_bias for player meeting.
  • Loading branch information
plural authored Sep 17, 2024
1 parent d1065ff commit a62065a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
10 changes: 6 additions & 4 deletions app/controllers/players_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def render_standings_for_stage(stage)
end

# No standings during player meeting or first round, so list players
render_player_list_for_standings stage
render_player_list_for_player_meeting stage
end

def compute_and_render_cut_standings(stage)
Expand All @@ -184,12 +184,13 @@ def render_completed_standings(stage)
extended_sos: row.extended_sos,
corp_points: row.corp_points || 0,
runner_points: row.runner_points || 0,
manual_seed: row.manual_seed
manual_seed: row.manual_seed,
side_bias: stage.format == 'single_sided_swiss' ? row.player.side_bias : nil
}
end
end

def render_player_list_for_standings(stage)
def render_player_list_for_player_meeting(stage)
stage.players.sort.each_with_index.map do |player, i|
{
player: standings_player(player, show_ids: false),
Expand All @@ -200,7 +201,8 @@ def render_player_list_for_standings(stage)
extended_sos: 0,
corp_points: 0,
runner_points: 0,
manual_seed: player.manual_seed
manual_seed: player.manual_seed,
side_bias: nil
}
end
end
Expand Down
1 change: 1 addition & 0 deletions app/frontend/standings/StandingsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type SwissStanding = {
corp_points: number;
runner_points: number;
manual_seed: number | null;
side_bias: number | null;
}

export type CutStanding = {
Expand Down
20 changes: 18 additions & 2 deletions app/frontend/standings/SwissStandings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
export let stage: SwissStage;
export let manual_seed: boolean;
function printSideBias(sideBias: number) {
if (sideBias === 0) {
return 'Balanced';
} else if (sideBias > 0) {
return `Corp +${sideBias}`;
} else {
return `Runner +${-sideBias}`;
}
}
function printSOS(sos: string) {
return parseFloat(sos).toLocaleString(undefined, {
minimumFractionDigits: 4,
Expand All @@ -29,8 +39,11 @@
{#if manual_seed}
<th>Seed</th>
{/if}
<th>SOS</th>
<th>Extended SOS</th>
<th>SoS</th>
<th>ESoS</th>
{#if stage.format == 'single_sided_swiss' }
<th>Side Bias</th>
{/if}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -62,6 +75,9 @@
{/if}
<td>{printSOS(standing.sos)}</td>
<td>{printSOS(standing.extended_sos)}</td>
{#if stage.format == 'single_sided_swiss' }
<td>{printSideBias(standing.side_bias)}</td>
{/if}
</tr>
{/each}
</tbody>
Expand Down
6 changes: 4 additions & 2 deletions spec/requests/players_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ def standing_with_no_score(position, player)
'extended_sos' => 0,
'runner_points' => 0,
'corp_points' => 0,
'manual_seed' => nil
'manual_seed' => nil,
'side_bias' => nil
}
end

Expand All @@ -577,7 +578,8 @@ def standing_with_custom_score(position, points:, sos:, extended_sos:, player:)
'extended_sos' => extended_sos,
'runner_points' => 0,
'corp_points' => 0,
'manual_seed' => nil
'manual_seed' => nil,
'side_bias' => nil
}
end

Expand Down

0 comments on commit a62065a

Please sign in to comment.