
    h                         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	Zded
ddefdZdedefdZded
edefdZdedefdZded
edefdZddZdej0                  defdZdedefdZy)    )schema)CommercialEquipmentCreate)NetworkPlanningCreate)CatchmentPotentialBaseTblCatchmentPotential)CustomerLocationBaseTblCustomerLocationNdatareturnc                 z    | j                   | j                  t        d      | j                   | j                  z  S )NQshopping_frequency_per_month and household_consumption_per_month must not be None)shopping_frequency_per_monthhousehold_consumption_per_month
ValueErrorr
   s    1/var/www/html/RetailAPI/app/utils/common_utils.py%calculate_total_household_consumptionr   
   s<    ((0D4X4X4`lmm,,t/S/SSS    existingr	   c                     | j                  d      xs |j                  }| j                  d      xs |j                  }||t        d      ||z  | d<   | S )zp
    Merge partial update data with existing DB values and calculate total_household_consumption_per_month.
    r   r   r   %total_household_consumption_per_month)getr   r   r   )r
   r   shopping_freqhousehold_conss       r   .fill_and_calculate_total_household_consumptionr      sd     HH;<e@e@eMXX?@lHDlDlN 6lmm4AN4RD	01Kr   c                     | j                   | j                  t        d      t        | j                   | j                  z        S )N?number_of_households and percentage_of_segment must not be None)number_of_householdspercentage_of_segmentr   intr   s    r   3calculate_potential_number_of_household_consumptionr!      sA      (D,F,F,NZ[[t((4+E+EEFFr   c                     | j                  d      xs |j                  }| j                  d      xs |j                  }||t        d      t	        ||z        | d<   | S )zi
    Merge partial update data with existing DB values and calculate potential_number_of_households.
    r   r   r   potential_number_of_households)r   r   r   r   r    )r
   r   r   r   s       r   'fill_and_calculate_potential_householdsr$   !   sn      88$:;\x?\?\ HH%<=_A_A_#'<'DZ[[-01EH]1]-^D	)*Kr   c                 8    t         fddD              rt        d       j                   j                  z    j                   j
                  z    j                   j                  z    j                   j                  z    j                   j                  z   dS )Nc              3   :   K   | ]  }t        |      d u   y wN)getattr).0fieldr
   s     r   	<genexpr>z/calculate_total_store_counts.<locals>.<genexpr>/   s)      
E 	e$
s   )
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,   r1   r-   r2   r.   r3   r/   r4   r0   r5   r   s   `r   calculate_total_store_countsr<   .   s    
 
  XYY !% 0 043C3C C $ 0 043C3C C $ 0 043C3C C $ 0 043C3C C $ 0 043C3C C r   c           	          i }t        dd      D ]Y  }d| }d| }d| }| j                  |t        ||d             }| j                  |t        ||d             }|O|R||z   ||<   [ |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_vals	            r   #calculate_total_store_counts_updaterK   @   s    FadV$dV$&tf- &'(FD"AB&'(FD"AB&"4#f_F6N  Mr   c                     t         j                  t         j                  z   dj                  fdt	        |       D              S )N c              3   H   K   | ]  }t        j                          y wr'   )secretschoice)r)   _alphabets     r   r+   z+generate_secure_password.<locals>.<genexpr>S   s     C]7>>(+]s   ")stringascii_lettersdigitsjoinrC   )lengthrR   s    @r   generate_secure_passwordrX   Q   s0    ##fmm3H77CU6]CCCr   requestc                 B    | j                         }|d   |d   z  |d<   |S Ncost_per_unitnumber_of_unitstotal
model_dumprY   r
   s     r   prepare_furniture_datarb   U   .    D)D1B,CCDMKr   c                 B    | j                         }|d   |d   z  |d<   |S r[   r_   ra   s     r   prepare_equipment_datare   Z   rc   r   )   )app.api.carpentryr   $app.api.commercial_equipment.schemasr   app.api.network.schemasr   #app.models.main.catchment_potentialr   r   !app.models.main.customer_locationr   r	   rO   rS   r    r   dictr   r!   r$   r<   objectrK   rX   CarpentryCreaterb   re    r   r   <module>rp      s    $ J 9 ] W  T0D T T
 I^ cg G>T GY\ G
$ BW \` '<  $d f  "DF$:$: t 
$= $ r   