Ë
     kò  ã                   ó`   — d d gZ dZd„ Zd„ Zd„ Z	 	 	 	 dd„Z	 	 	 	 	 	 	 	 dd„Zd„ Zd	Zd
„ Zd„ Z	y)é    ©ÚslowÚtimedÚrapidc                 óÚ   — | €ddgS t        | «      dk7  rt        d«      ‚t        | d   xs d«      }t        | d   xs d«      }|dk  s|dk  rt        d«      ‚||kD  rt        d«      ‚||gS )z^
    Return a normalized [score, x_count] pair.

    None and empty values become [0, 0].
    r   é   z,A score value must contain [score, x_count].é   z%Score and X count cannot be negative.zX count cannot exceed score.)ÚlenÚ
ValueErrorÚint)ÚvalueÚscoreÚx_counts      úmodules/scoring/calculator.pyÚnormalize_score_pairr   
   s�   € ð €}Ø�1ˆvˆä
ˆ5ƒz�Q‚Üð ó
ð 	
ô
 ��a‘’˜AÓ€EÜ�%˜‘(’-˜aÓ €Gàˆq‚y�G˜a’KÜØ3ó
ð 	
ð �‚ÜØ*ó
ð 	
ð
 	Øðð ó    c                 ó   — | t         k7  S )z6
    Return True when a score pair is not [0, 0].
    )Ú
ZERO_SCORE)r   s    r   Ú	has_scorer   .   s   € ð ”JÑÐr   c                 óJ   — t        d„ | D «       «      t        d„ | D «       «      gS )z5
    Sum point and X-count values independently.
    c              3   ó&   K  — | ]	  }|d    –— Œ y­w)r   N© ©Ú.0r   s     r   ú	<genexpr>z"sum_score_pairs.<locals>.<genexpr>>   ó   è ø€ ò 
àð �!�Hñ
ùó   ‚c              3   ó&   K  — | ]	  }|d    –— Œ y­w)r	   Nr   r   s     r   r   z"sum_score_pairs.<locals>.<genexpr>B   r   r   )Úsum)Úscore_pairss    r   Úsum_score_pairsr!   7   s:   € ô 	ñ 
à$ô
ó 	
ô 	ñ 
à$ô
ó 	
ð	ð 	r   Nc           
      óŒ  — t        | «      t        |«      t        |«      dœ}t        |«      }t        d„ |j                  «       D «       «      }t        |«      }t	        |j                  «       «      }|dk(  rd}	|}
| xs ||k(  }n,|dk(  r	|rd}	|}
d}n|dk(  r|s	d}	ddg}
d}nd	}	|}
| xs ||k(  }|d
   |d   |d   |
|	||||dœ	S )aA  
    Normalize one Rimfire or Centerfire entry.

    States:

        complete
            All three stage scores are present. The total is
            calculated from those stages.

        totals_only
            No stage scores are present, but a supplied total
            is available.

        not_entered
            No stages and no supplied total are present.

        partial_with_total
            One or two stages are present and a supplied total
            is available. The supplied total is retained.

        partial_unresolved
            One or two stages are present and there is no
            supplied total. The total remains [0, 0].

    If all stages are complete and a supplied total is also
    provided, the calculated total remains authoritative. A
    mismatch is recorded in total_matches_stages.
    r   c              3   ó2   K  — | ]  }t        |«      –— Œ y ­w)N)r   r   s     r   r   z+normalize_firearm_scores.<locals>.<genexpr>}   s   è ø€ ò  àô 	�%×ñ ùs   ‚é   Úcompleter   Útotals_onlyNÚnot_enteredÚpartialr   r   r   )	r   r   r   ÚtotalÚstateÚpopulated_stage_countÚcalculated_totalÚsupplied_totalÚtotal_matches_stages)r   r   Úvaluesr   r!   )r   r   r   r-   ÚstagesÚnormalized_supplied_totalr+   Úhas_supplied_totalr,   r*   r)   r.   s               r   Únormalize_firearm_scoresr3   I   sZ  € ôF %Øó
ô &Øó
ô &Øó
ñ
€Fô 	Øó	
ð ô  ñ  à—]‘]“_ô ó Ðô
 #Ø!óÐô 'Ø�‰‹óÐð  Ò!ØˆØ ˆð #Ð"ò  Ø(Øñ ñ 	ð 	 Ò"ÙàˆØ)ˆØ#Ñð 	 Ò"Ù"àˆØ�A�ˆØ#Ñð ˆØ ˆð #Ð"ò  Ø(Øñ ð 	ð �v‘Ø˜‘Ø˜‘ØØà!ð ð &ð !ñ!ð r   c                 óÈ   — t        | |||¬«      }t        ||||¬«      }	t        |d   |	d   f«      }
|d   |d   |d   |d   |	d   |	d   |	d   |	d   |
|d   |	d   dœ||	dœdœS )	a�  
    Build one normalized VIPL scorecard.

    The Combined Total is calculated from the normalized
    Rimfire Total plus the normalized Centerfire Total.

    This supports:

        both firearm categories
        Rimfire only
        Centerfire only
        totals-only submissions
        one complete and one totals-only category
        partial entries with supplied totals
    )r   r   r   r-   r)   r   r   r   r*   )ÚrimfireÚ
centerfire)Úrf_slowÚrf_timedÚrf_rapidÚrf_totalÚcf_slowÚcf_timedÚcf_rapidÚcf_totalÚcombined_totalÚentry_statesÚdetails)r3   r!   )r7   r8   r9   r:   r;   r<   r=   r>   r5   r6   r?   s              r   Úbuild_scorecardrB   Ã   sÃ   € ô2 'ØØØØô	€Gô *ØØØØô	€Jô %à�GÑØ�wÑð	
ó€Nð ˜6‘?Ø˜GÑ$Ø˜GÑ$Ø˜GÑ$Ø˜fÑ%Ø˜wÑ'Ø˜wÑ'Ø˜wÑ'Ø(à˜wÑ'Ø$ WÑ-ñ
ð
 Ø$ñ
ñð r   c                 ó4   — dD �ci c]  }|| |   “Œ
 c}S c c}w )N©	r7   r8   r9   r:   r;   r<   r=   r>   r?   r   ©Úcalculated_scorecardÚstats     r   Úscorecard_values_onlyrH     s/   € ð


öàð 	Ð" 4Ñ(Ñ(òð ùò s   …rD   c                 óN   — t         D �ci c]  }|t        | |   «      “Œ c}S c c}w )zå
    Return only the nine score fields used by VIPL ranking,
    award, aggregation, and rendering code.

    Calculator metadata remains available in the original
    calculated scorecard but is not included in this result.
    )ÚSCORECARD_STATSÚlistrE   s     r   rH   rH   $  s:   € ô $ö	ð ð 	ŒdØ  Ñ&ó
ñ 	
òð ùò s   ‰"c                  ó.   — t        di | ¤Ž}t        |«      S )zm
    Build and normalize a scorecard, then return only the
    nine score fields used elsewhere in VIPL.
    r   )rB   rH   )Úscore_valuesrF   s     r   Úcalculate_scorecard_valuesrN   6  s)   € ô +ñ Ø
ñÐô !Øóð r   )NNNN)NNNNNNNN)
r   ÚFIREARM_STAGESr   r   r!   r3   rB   rH   rJ   rN   r   r   r   ú<module>rP      sq   ðØ�ˆV€
ð€ò!òHòð& 
Ø
Ø
Øó	wðv ØØØØØØØó@òDð$
€òó$r   