Ë
     k‡  ã                   ó”   — d dl mZmZmZ d dlmZ d„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdeedœdeedœdeedœfZy)é    )ÚCENTERFIRE_TIEBREAK_ORDERÚOVERALL_TIEBREAK_ORDERÚRIMFIRE_TIEBREAK_ORDER)Úbuild_tiebreak_keyc                 ó"   — t        | t        «      S ©N)r   r   ©Ú	scorecards    úmodules/awards/vipl_awards.pyÚoverall_tiebreak_keyr      ó   € ÜØÜóð ó    c                 ó"   — t        | t        «      S r   )r   r   r	   s    r   Úcenterfire_tiebreak_keyr      s   € ÜØÜ!óð r   c                 ó"   — t        | t        «      S r   )r   r   r	   s    r   Úrimfire_tiebreak_keyr      r   r   c                 ó.   ‡ ‡— ‰ syt        ‰ ˆ ˆfd„¬«      S )z´
    Return the shooter with the strongest scorecard.

    candidates is expected to have this shape:

        {
            shooter_name: scorecard,
            ...
        }
    Nc                 ó   •—  ‰‰|    «      S r   © )ÚshooterÚ
candidatesÚkey_functions    €€r   ú<lambda>zselect_winner.<locals>.<lambda>0   s   ø€ ™LØ�wÑó
€ r   )Úkey)Úmax)r   r   s   ``r   Úselect_winnerr       s    ù€ ñ ØäØô
ôð r   c                 ó$   — | ||d   |d   |d   dœS )zJ
    Return useful award information without modifying the scorecard.
    Úcombined_totalÚcf_totalÚrf_total)Úawardr   r   r   r    r   )Ú
award_namer   r
   s      r   Úmake_award_resultr#   6   s-   € ð
 ØØ#Ð$4Ñ5Ø˜jÑ)Ø˜jÑ)ñð r   c           	      ó,  — t        | «      }g }g }t        D ]y  }|s ||fS t        ||d   |d   «      }|d   d   }||   }t        |«      }|j	                  |d   t        |«      |||dœ«       |j	                  t        |d   ||«      «       ||= Œ{ ||fS )zl
    Select VIPL award winners and return a complete audit trail.

    Returns:

        winners, audit
    r   Ú
stat_orderr   r   r!   )r!   Úcandidate_countÚranked_candidatesÚselected_winnerÚcomplete_first_place_ties)ÚdictÚAWARD_RULESÚrank_award_candidatesÚfind_complete_first_place_tiesÚappendÚlenr#   )	Úshooter_scorecardsÚ	remainingÚwinnersÚauditÚruler'   Úwinner_nameÚwinner_scorecardÚcomplete_tiess	            r   Úselect_award_winners_with_auditr8   C   sê   € ô Ð'Ó(€IØ€GØ€Eäò ##ˆÙØðF �Eˆ>ÐôC 2ØØ�Ñ Ø�Ñó
Ðð (¨Ñ*¨9Ñ5ˆØ$ [Ñ1Ðä6Øó
ˆð 	�‰à˜g™Ü#& y£>Ø%6Ø#.Ø-:ñô	
ð 	�‰ÜØ�W‘ØØ óô	
ð �kÑ"ðG##ðJ �Eˆ>Ðr   c                 ó"   — t        | «      \  }}|S )zE
    Preserve the original, simple API used by application code.
    )r8   )r0   r2   r3   s      r   Úselect_award_winnersr:   w   s   € ô 5Øó�N€GˆUð €Nr   c                 ór   — | i i}| |vr|S ||    j                  «       D ]  \  }}t        |«      ||    |<   Œ |S )zÉ
    Build league-wide awards for every available month.

    Output shape:

        awards[year][month] = [
            award_result,
            award_result,
            award_result,
        ]
    ©Úitemsr:   )ÚtheyearÚshooter_scoresÚawardsÚmonthr0   s        r   Úbuild_monthly_awardsrB   �   sf   € ð  	�ð€Fð �nÑ$Øˆð 	�wÑ×%Ñ%Ó'ò
Ñ!ˆÐ!ô !Ø"óð 	ˆw‰˜Òð
ð €Mr   c                 ó¸   — | i i}| |vr|S ||    j                  «       D ]9  \  }}i ||    |<   |j                  «       D ]  \  }}t        |«      ||    |   |<   Œ Œ; |S )zÑ
    Build awards for every club in every available month.

    Output shape:

        awards[year][month][club] = [
            award_result,
            award_result,
            award_result,
        ]
    r<   )r>   Úvipl_scoresr@   rA   Úmonth_scoresÚclubr0   s          r   Úbuild_club_awardsrG   £   sš   € ð  	�ð€Fð �kÑ!Øˆð 	�GÑ×"Ñ"Ó$òÑˆˆ|ð "$ˆˆw‰˜Ñð ×ÑÓ ò	Ñ$ˆDÐ$ô %Ø&óð �7‰O˜EÑ" 4Ò(ñ	ðð €Mr   c                 óB   — | j                  dd«      j                  «       S )NÚ_ú )ÚreplaceÚtitle)Ústats    r   Úformat_stat_namerN   É   s   € Ø�<‰<˜˜SÓ!×'Ñ'Ó)Ð)r   c                 óL   — |D �cg c]  }|| |   d   | |   d   dœ‘Œ c}S c c}w )z9
    Return a readable version of the tie-break key.
    r   é   )rM   ÚscoreÚx_countr   )r
   r%   rM   s      r   Úbuild_tiebreak_detailsrS   Ì   sC   € ð öð ð	 Ø˜t‘_ QÑ'Ø  ‘ qÑ)ó	
òð ùò s   …!c                 óÄ   ‡— t        | j                  «       ˆfd„d¬«      }t        |d¬«      D ���cg c]  \  }\  }}|| ‰|«      t        ||«      dœ‘Œ! c}}}S c c}}}w )zü
    Rank the current candidate pool for audit purposes.

    Sorting is descending because higher scores and X counts win.
    Python's sort is stable, so an exact tie through the entire
    chain retains the candidates' existing insertion order.
    c                 ó   •—  ‰| d   «      S )NrP   r   )Úitemr   s    €r   r   z'rank_award_candidates.<locals>.<lambda>è   s   ø€ ™ d¨1¡gÓ.€ r   T)r   ÚreverserP   )Ústart)Úpositionr   r   Údetails)Úsortedr=   Ú	enumeraterS   )r   r   r%   r'   rY   r   r
   s    `     r   r,   r,   Ú   s}   ø€ ô Ø×ÑÓÛ.ØôÐô" ØØô
÷ð ñ +ˆHÑ*�w 	ð !ØÙ 	Ó*Ü-ØØóó		
ôð ùô s   ²$Ac                 óZ   — | sg S | d   d   }| D �cg c]  }|d   |k(  r|d   ‘Œ c}S c c}w )zr
    Return all candidates whose complete comparison key is
    identical to the first-place candidate's key.
    r   r   r   r   )r'   Úwinning_keyÚ	candidates      r   r-   r-   þ   sO   € ñ
 Øˆ	à# AÑ& uÑ-€Kð +öàØ�UÑ˜{Ò*ð 	�)Óòð ùò s   ‘(zHighest Overall)r!   r   r%   zHighest CenterfirezHighest RimfireN)Úmodules.constantsr   r   r   Úmodules.scoring.tiebreaksr   r   r   r   r   r#   r8   r:   rB   rG   rN   rS   r,   r-   r+   r   r   r   ú<module>rb      s�   ð÷ñ õ
ò
òòòò,
ò1òhòòD$òL*òò!òHð$ #Ø,Ø,ñð &Ø/Ø/ñð #Ø,Ø,ñð�r   