
    	,hu                        d Z ddlZddlmZmZ ddlmZmZm	Z	m
Z
mZ 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 d
dlmZmZmZmZmZmZmZ  e       ZejA                  dd      dedee ee      f   dee ee      f   fd       Z!ejE                  de       ee       ee      fde#dedefd       Z$ejE                  ded       ee       ee      fde#dedefd       Z%ejM                  dd       ee       ee      fdededefd       Z'ejE                  de(e   d       ee       ee      fde#dedefd       Z)ejU                  dd       ee       ee      fde#dedefd        Z+ejA                  d!       e	d"       ee      fd#edefd$       Z,ejE                  d%ee          ee      fd&e-defd'       Z.y)(z
Catchment.    N)	AnnotatedList)	APIRouterDependsFileHTTPException
UploadFile)Session)service)get_db)JWTPayloadSchemaget_current_student)TblMainData   )GetPotentialResponseMainDataCreateMainDataResponseTotalPotentialResponseUpdatePotentialcatchmentPotentialCreatcatchmentPotentialResponsez/catchment_creatT)response_model_exclude_nonerequestdbtokenc                 h   K   t        j                  ||      j                  |        d {   S 7 wN)r   Catchment_Potentialcreate_catchment_potentialr   r   r   s      =/var/www/html/RetailAPI/app/api/catchment_potential/router.pycreate_catchmentr"      s+     ,,R7RRSZ[[[[   )202z//catchment_potential/{group_id}/total_potential)response_modelgroup_idc                 h   K   t        j                  ||      j                  |        d {   S 7 wr   )r   r   get_total_consumption_by_groupr%   r   r   s      r!   r'   r'      s+     ,,R7VVW_````r#   z/catchment/{catch_id})r$   r   catch_idc                 h   K   t        j                  ||      j                  |        d {   S 7 wr   )r   r   get_catchmentr)   r   r   s      r!   get_simulationr-      s*     ,,R7EEhOOOOr#   z/catchment/updatec                 h   K   t        j                  ||      j                  |        d {   S 7 wr   )r   r   update_catchmentr    s      r!   update_segmentr0      s*     ,,R6GGPPPPr#   z%/catchment_potential/group/{group_id}c                 h   K   t        j                  ||      j                  |        d {   S 7 wr   )r   r    get_catchment_poteneial_by_groupr(   s      r!   get_customer_locations_by_groupr3      s+     ,,R7XXYabbbbr#   z/catchment/delete/{catch_id}c                 h   K   t        j                  ||      j                  |        d {   S 7 wr   )r   r   delete_catchmentr,   s      r!   r5   r5   #   s*     ,,R7HHRRRRr#   z/upload-main-data/.filec                 d  K   t        j                  | j                        }|j                  D cg c]P  }|j	                         j                         j                  dd      j                  dd      j                  dd      R c}|_        d+d}g }|j                         D ]   \  }}t        d,i d ||dd      d ||dd      d	 ||d	d      d
 ||d
      d ||dd      d ||d      d ||d      d ||d      d ||d      d ||d      d ||d      d ||d      d ||d      d ||d      d ||d      d ||d      d  ||d!      d" ||d#      d$ ||d%      d& ||d&      d' ||d'      d( ||d(      }|j                  |        |j                  t              j                          |j                          |D ],  }	t        d,i |	j                         }
|j                  |
       . |j                          d)t!        |       d*iS c c}w w)-N _/-c                 b    || v r*t        j                  | |         s| j                  ||      S |S r   )pdisnullget)rowkeydefaults      r!   safe_getzupload_excel.<locals>.safe_get/   s.    (+s
299SX;NswwsG$[T[[    category_identifier format_typereference_retailerno_of_storesdescription!indicative_categories_descriptionno_of_cats_lno_of_cats_mno_of_cats_hindicative_sizeindicative_size_square_feetcapital_available)indicative_capital_available_rs_in_croresapprox_investment+approx_investment_per_store_in_rupees_lakhscomp_intensity_lcompetition_intensity_lcomp_intensity_mcompetition_intensity_mcomp_intensity_hcompetition_intensity_h
tech_inv_h#technology_investment_in_rs_lakhs_h
tech_inv_m#technology_investment_in_rs_lakhs_m
tech_inv_l#technology_investment_in_rs_lakhs_l
spillage_hspillage_factor_h
spillage_lspillage_factor_l
services_h
services_m
services_lmessagez records replaced successfullyr    )r=   
read_excelr6   columnsstriplowerreplaceiterrowsr   appendqueryr   deletecommitdictaddlen)r6   r   dfcolrC   main_data_listr9   r@   itemdatarecords              r!   upload_excelr}   '   s    	tyy	!B hjgqgqrgq`c#))+##%--c37??SIQQRUWZ[gqrBJ\ N++-3 
 (.CR H
 mR8
  (-A2F
 "#~6	

 !&I2N
 "#~6
 "#~6
 "#~6
 %S*GH
 's,WX
 's,YZ
 &c+DE
 &c+DE
 &c+DE
  %JK
   %JK!
"  %JK#
$  %89%
&  %89'
(  \2)
*  \2+
,  \2-
0 	d#3  8 HH[  "IIK +tyy{+
v  IIK#n-..LMNN] ss   .H0AH+F+H0z/main-data/rG   c                     |j                  t              j                  t        j                  | k(        j	                         }|st        dd      |S )Ni  z"No data found for this format type)status_codedetail)rq   r   filterrG   allr   )rG   r   resultss      r!   get_main_data_by_format_typer   \   sG    
 hh{#**;+B+Bk+QRVVXG4XYYNrD   )/__doc__pandasr=   typingr   r   fastapir   r   r   r   r	   sqlalchemy.ormr
   app.api.catchment_potentialr   app.database.main.mysqlr   app.dependency.authanticationr   r   app.models.main.main_datar   schemasr   r   r   r   r   r   r   catchment_potential_routerpostr"   r?   intr'   r-   putr0   listr3   rr   r5   r}   strr   ri   rD   r!   <module>r      s     " G G " / * O 1 j  j  j&[   !3QU V\$; \	'SZ[aSbJb@c \kt  vF  HO  Qd  He  ve  lf \ W\  QbxyELV_ov  xK  pL a3 a7 a\l a za  7H\z~6=foahi|a} P3 PG PN^ P @P  3QUVAHkr  tG  lH Q/ Qw QXh Q WQ  GW[\vWw  UY  ZFMfopw  yL  qM cC cG c]m c Zc ""#A^b"c7>vahi|a} SS SW SN^ S dS   !56*.s)76? 2OZ 2O 2O 72Oh dCS>TU &/ VrD   