
    soj                         d dl T d dlmZ d dlmZ d dlmZ d dlmZ  G d de          Z	e	
                                 dS )	    )*)	BaseModel)Crew)DavyBackFight)Userc                      e Zd ZU dZ eedd          Zeez  ed<    eed          Z	eez  ed<    ee
d          Ze
ez  ed<    ed	
          Zeez  ed<    ed          Zeez  ed<    G d d          Zedede
dd fd            Zd Zededed          fd            Zedede
defd            ZdefdZd ZdefdZdefdZdS )DavyBackFightParticipantz(
    DavyBackFightParticipant class
    davy_back_fight_participantsCASCADE)backref	on_deletedavy_back_fight)r   usercrewr   )defaultcontributionT)null
win_amountc                       e Zd ZdZdS )DavyBackFightParticipant.Metadavy_back_fight_participantN)__name__
__module____qualname__db_table     */app/src/model/DavyBackFightParticipant.pyMetar      s        0r   r   dbfreturnc                    t                                                               t           j        | k    t           j        |k    z                                t           j                                                                                  S )z
        Get the top player of a crew in a Davy Back Fight
        :param dbf: The Davy Back Fight object
        :param crew: The crew object
        :return: The DavyBackFightParticipant object
        )	r	   selectwherer   r   order_byr   descfirstr    r   s     r   get_top_playerz'DavyBackFightParticipant.get_top_player   sj     %++--U)9S@+0D8:  X.;@@BBCCUWW	
r   c                 .    ddl m}  || j                  S )z\
        Get the contribution formatted
        :return: The contribution formatted
        r   get_belly_formatted)src.service.bounty_servicer,   r   selfr,   s     r   get_contribution_formattedz3DavyBackFightParticipant.get_contribution_formatted+   s+     	CBBBBB""4#4555r   c                     t                                                               t           j        | k                                  t           j                                                  S )z
        Get the participants by contribution
        :param dbf: The Davy Back Fight object
        :return: The list of DavyBackFightParticipant objects
        )r	   r#   r$   r   r%   r   r&   )r    s    r    get_participants_by_contributionz9DavyBackFightParticipant.get_participants_by_contribution5   sK     %++--U+;sBCCX.;@@BBCC	
r   c                    t                               t                              t           j                                                t           j        | k    t           j        |k    z                                            S )z
        Get the total contributions of a crew in a Davy Back Fight
        :param dbf: The Davy Back Fight object
        :param crew: The crew object
        :return: The total contributions
        )	r	   r#   fnSUMr   r$   r   r   scalarr(   s     r   get_total_contributionsz0DavyBackFightParticipant.get_total_contributionsC   s_     %++BFF3K3X,Y,YZZU)9S@+0D8:  VXX	
r   c                 v    t                               | j        | j                  }|dk    r| j        |z  dz  ndS )zh
        Get the user contribution percentage
        :return: The user contribution percentage
        r   d   )r	   r7   r   r   r   )r/   totals     r   get_contribution_percentagez4DavyBackFightParticipant.get_contribution_percentageT   s@    
 )@@AUW[W`aa49AII!E)S001Dr   c                 F    | j                                         | j        k    S )z?
        Won the Davy Back Fight
        :return: None
        )r   get_winner_crewr   )r/   s    r   in_winner_crewz'DavyBackFightParticipant.in_winner_crew\   s      #3355BBr   c                     ddl m} |                                 }t           || j                            | j                  |                    S )zG
        Get the user win amount
        :return: The user win
        r   )get_value_from_percentage)src.utils.math_utilsr@   r;   intr   get_opponent_chest_amountr   )r/   r@   user_percentages      r   get_win_amountz'DavyBackFightParticipant.get_win_amountd   sb    
 	CBBBBB::<<%%$>>tyII? 
 
 	
r   c                 H    ddl m}  ||                                           S )z[
        Get the user win amount formatted
        :return: The user win formatted
        r   r+   )r-   r,   rE   r.   s     r   get_win_amount_formattedz1DavyBackFightParticipant.get_win_amount_formattedr   s4    
 	CBBBBB""4#6#6#8#8999r   N)r   r   r   __doc__ForeignKeyFieldr   r   __annotations__r   r   r   r   BigIntegerFieldr   rB   r   r   staticmethodr)   r0   listr2   r7   floatr;   r>   rE   strrG   r   r   r   r	   r	   	   s%          8G=8 8 8O]_4    $3?4A_#`#`#`D$
 ```#2?4A_#`#`#`D$
 ```*9/!*D*D*DL#'DDD(7T(B(B(BJo%BBB1 1 1 1 1 1 1 1 
M 
 
:T 
 
 
 \
"6 6 6 
m 
E_@` 
 
 
 \
 
] 
$ 
3 
 
 
 \
 EU E E E EC C C
 
 
 
 
:# : : : : : :r   r	   N)peeweesrc.model.BaseModelr   src.model.Crewr   src.model.DavyBackFightr   src.model.Userr   r	   create_tabler   r   r   <module>rV      s        ) ) ) ) ) )       1 1 1 1 1 1      p: p: p: p: p:y p: p: p:f  % % ' ' ' ' 'r   