{# Jinja2 template for pairwise summary only (no table) #}
{% if colordict %}
{% endif %}
{% if summary_data and wltdict %}
{% set candidate_list = wltdict.items() | list %}
{% if candidate_list %}
{% if is_copeland_tie %}
No Condorcet winner: Copeland tie between
{%- if copewinners and candnames -%}
{%- for winner_token in copewinners -%}
{{ candnames[winner_token] if winner_token in candnames else winner_token }}{% if not loop.last %}, {% endif %}
{%- endfor -%}
{%- else -%}
{{ copewinnerstring }}
{%- endif -%}
{% else %}
{% set winner_token = candidate_list[0][0] %}
{% set winner_record = candidate_list[0][1] %}
{% set winner_name = candnames[winner_token] if candnames and winner_token in candnames else winner_token %}
{% set winner_h2h_text = "" %}
{% if candidate_list | length > 1 %}
{% set runner_up_token = candidate_list[1][0] %}
{% set h2h_found = false %}
{% for victory in summary_data['victory_data'] %}
{% if not h2h_found and not victory.get('is_tie', False) %}
{% if (victory['winner'] == winner_token and victory['loser'] == runner_up_token) or
(victory['winner'] == runner_up_token and victory['loser'] == winner_token) %}
{% set margin = victory['winner_votes'] - victory['loser_votes'] %}
{% set winner_h2h_text = " (beats runner-up " + "{:,}".format(victory['winner_votes']) + "-" + "{:,}".format(victory['loser_votes']) + "; margin: " + "{:,}".format(margin) + ")" %}
{% set h2h_found = true %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
Winner: {{ winner_name }}{{ winner_h2h_text }}
{% endif %}
{% if candidate_list | length > 1 %}
{% set runner_up_token = candidate_list[1][0] %}
{% set runner_up_record = candidate_list[1][1] %}
{% set runner_up_name = candnames[runner_up_token] if candnames and runner_up_token in candnames else runner_up_token %}
{% if is_copeland_tie %}
Runner-up: {{ runner_up_name }} (beats all other candidates except the tied Condorcet winners)
{% else %}
Runner-up: {{ runner_up_name }} (beats all other candidates except {{ winner_name }})
{% endif %}
{% endif %}
{% set decisive_victories = [] %}
{% for victory in summary_data['victory_data'] %}
{% if not victory.get('is_tie', False) %}
{% set _ = decisive_victories.append(victory) %}
{% endif %}
{% endfor %}
{% if decisive_victories %}
{% set smallest_victory = decisive_victories | min(attribute='victory_size') %}
{% set largest_victory = decisive_victories | max(attribute='victory_size') %}
{% set method_label = "margin" if summary_data['victory_method'] == "margins" else "winning votes" %}
{% set smallest_winner_name = candnames[smallest_victory['winner']] if candnames and smallest_victory['winner'] in candnames else smallest_victory['winner'] %}
{% set smallest_loser_name = candnames[smallest_victory['loser']] if candnames and smallest_victory['loser'] in candnames else smallest_victory['loser'] %}
{% set smallest_margin = smallest_victory['winner_votes'] - smallest_victory['loser_votes'] %}
{% set largest_winner_name = candnames[largest_victory['winner']] if candnames and largest_victory['winner'] in candnames else largest_victory['winner'] %}
{% set largest_loser_name = candnames[largest_victory['loser']] if candnames and largest_victory['loser'] in candnames else largest_victory['loser'] %}
{% set largest_margin = largest_victory['winner_votes'] - largest_victory['loser_votes'] %}
Largest margin: {{ largest_winner_name }} over {{ largest_loser_name }} ({{ "{:,}".format(largest_victory['winner_votes']) }}-{{ "{:,}".format(largest_victory['loser_votes']) }}; margin: {{ "{:,}".format(largest_margin) }})
{% endif %}
{% set ties = [] %}
{% for victory in summary_data['victory_data'] %}
{% if victory.get('is_tie', False) %}
{% set _ = ties.append(victory) %}
{% endif %}
{% endfor %}
Pairwise ties: {% if ties %}{{ ties | length }}{% else %}none{% endif %}
{% if summary_data['total_ballots'] > 0 %}
Total ballots: {{ "{:,}".format(summary_data['total_ballots']) }}