o
    Uh-                     @   s   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZ d dlZd dlZde
defd	d
ZdedddefddZdedefddZdededefddZdedefddZdededefddZdddZdedefddZdedefddZdS )     )CarpentryFurnitureCreate)CommercialEquipmentCreate)NetworkPlanningCreate)CatchmentPotentialBaseTblCatchmentPotential)CustomerLocationBaseTblCustomerLocationNdatareturnc                 C   s(   | j d u s
| jd u rtd| j | j S )NQshopping_frequency_per_month and household_consumption_per_month must not be None)shopping_frequency_per_monthhousehold_consumption_per_month
ValueErrorr	    r   1/var/www/html/RetailAPI/app/utils/common_utils.py%calculate_total_household_consumption	   s   r   existingr   c                 C   sH   |  dp|j}|  dp|j}|du s|du rtd|| | d< | S )zp
    Merge partial update data with existing DB values and calculate total_household_consumption_per_month.
    r   r   Nr   %total_household_consumption_per_month)getr   r   r   )r	   r   shopping_freqhousehold_consr   r   r   .fill_and_calculate_total_household_consumption   s   r   c                 C   s,   | j d u s
| jd u rtdt| j | j S )N?number_of_households and percentage_of_segment must not be None)number_of_householdspercentage_of_segmentr   intr   r   r   r   3calculate_potential_number_of_household_consumption   s   r   c                 C   sL   |  dp|j}|  dp|j}|du s|du rtdt|| | d< | S )zi
    Merge partial update data with existing DB values and calculate potential_number_of_households.
    r   r   Nr   potential_number_of_households)r   r   r   r   r   )r	   r   r   r   r   r   r   'fill_and_calculate_potential_households    s   r   c                    sV   t  fdddD rtd j j  j j  j j  j j	  j
 j dS )Nc                 3   s    | ]
}t  |d u V  qd S N)getattr).0fieldr   r   r   	<genexpr>.   s
    
z/calculate_total_store_counts.<locals>.<genexpr>)
format_a_y1format_a_y2format_a_y3format_a_y4format_a_y5format_b_y1format_b_y2format_b_y3format_b_y4format_b_y5u=   All format_a and format_b fields for Y1–Y5 must be provided)total_store_count_y1total_store_count_y2total_store_count_y3total_store_count_y4total_store_count_y5)anyr   r%   r*   r&   r+   r'   r,   r(   r-   r)   r.   r   r   r   r   calculate_total_store_counts-   s   




r5   c           	      C   sz   i }t ddD ]3}d| }d| }d| }| |t||d }| |t||d }|d ur:|d ur:|| ||< q|S )N      
format_a_y
format_b_ytotal_store_count_y)ranger   r!   )	r	   r   totalsyearfa_keyfb_keyts_keyfa_valfb_valr   r   r   #calculate_total_store_counts_update?   s   


rC      c                    s(   t jt j  d fddt| D S )N c                 3   s    | ]}t  V  qd S r    )secretschoice)r"   _alphabetr   r   r$   R   s    z+generate_secure_password.<locals>.<genexpr>)stringascii_lettersdigitsjoinr;   )lengthr   rI   r   generate_secure_passwordP   s   rP   requestc                 C       |   }|d |d  |d< |S Ncost_per_unitnumber_of_unitstotal
model_dumprQ   r	   r   r   r   prepare_furniture_dataT      rZ   c                 C   rR   rS   rW   rY   r   r   r   prepare_equipment_dataY   r[   r\   )rD   )app.api.carpentry.schemasr   $app.api.commercial_equipment.schemasr   app.api.network.schemasr   #app.models.main.catchment_potentialr   r   !app.models.main.customer_locationr   r   rF   rK   r   r   dictr   r   r   r5   objectrC   rP   rZ   r\   r   r   r   r   <module>   s     
