a
    I!fd                     @   s.   d dl mZmZ ddlmZ G dd dZdS )    )ceilfloor   )ContentEvaluatorc                   @   sv   e Zd ZdZejZdZdZdZ	e
dddZe
dd	d
Ze
dddZe
ee	fddZe
dd Ze
dd ZdS )DynamicRewardServiceiL  d   g      ?      ?Fc                 C   sP   |dkrt dtj| |tj|||d}tj| |tj|||d}t|t|fS )Nr   z%Multiplier cannot be greater than 1.0)
multiplierignore_reach)
ValueErrorr   %calculate_dynamic_compensation_amountMIN_CONTENT_SCOREMAX_CONTENT_SCOREr   r   )min_compensationmax_compensationreachr	   r
   Ztailored_min_compensationZtailored_max_compensation r   G/var/www/html/python-backend/backend/services/dynamic_reward_service.py&calculate_tailored_compensation_bounds   s
    z;DynamicRewardService.calculate_tailored_compensation_boundsNc                 C   sN   |d u rd}t | |||||}t|d d }| r@t|S t|dS d S )Nr      )r   r   round
is_integerint)r   r   content_scorer   r	   r
   compensation_amountr   r   r   -calculate_rounded_dynamic_compensation_amount   s    zBDynamicRewardService.calculate_rounded_dynamic_compensation_amountc           
      C   s^   t |}t |}|s$t ||nt j||ddd}||  | |  }	|	|9 }	t| t|	|S )a   Calculates the compensation amount based on the content score and reach. The compensation amount is a number between min_compensation and max_compensation.
                Args:
                    min_compensation (float): The minimum compensation amount.
                    max_compensation (float): The maximum compensation amount.
                    content_score (float): The content score of the user.
                    reach (int): The reach of the user.
                    multiplier (float): The multiplier to apply to the compensation amount.
                    ignore_reach (bool): Whether or not to ignore the reach in the calculation. Used for UGC content where reach is not applicable.
                Returns:
                    float: The compensation amount.
        r   r   )reach_weightcontent_score_weight)r   normalize_content_scorenormalize_reachcalculate_combined_range_factormaxmin)
r   r   r   r   r	   r
   Znormalized_content_scorenormalized_reachZcombined_range_factorr   r   r   r   r   /   s    

"z:DynamicRewardService.calculate_dynamic_compensation_amountc                 C   s   || | |  d S Nr   r   )r   r#   r   r   r   r   r   r    L   s    z4DynamicRewardService.calculate_combined_range_factorc                 C   s   t | tj d dS r$   )r"   r   MAX_REACH_THRESHOLD)r   r   r   r   r   Q   s    z$DynamicRewardService.normalize_reachc                 C   s    t | tj d tjtj  dS )Nr   r   )r!   r   r   r   )r   r   r   r   r   V   s    z,DynamicRewardService.normalize_content_score)r   F)NF)r   F)__name__
__module____qualname__r%   r   MINIMUM_SCORE_THRESHOLDr   r   ZREACH_WEIGHTZCONTENT_SCORE_WEIGHTstaticmethodr   r   r   r    r   r   r   r   r   r   r      s"   
r   N)mathr   r   content_evaluatorr   r   r   r   r   r   <module>   s   