a
    f{                     @   s4   d dl T dd Zdd Zdd Zdd	 Zd
d ZdS )   )*c                 C   sv   dd l }dd l}dd l}dd l}| }z0|td d d }|td d d }W n   d}d}Y n0 ||gS )N    datalatitude	longitudegfAL@gR<W;@)http.clienturllib.parsejsontimeloadsr   )addresshttpurllibr	   r
   str   r    r   -/var/www/html/django/DPS/gardens/functions.pyfindCoordinates   s    
r   c                 C   sH   | j dkr"tt| j t| jS | j dkrDtt| j t| jS d S )Nr      )meteoservice_idprintWeather_WunderGroundservice_uriWeather_Awekas)Zmeteostationr   r   r   get_weather_data#   s    


r   c                 C   s   dd l }ddlm} | }|| }|d d d }|d d d d }|d d d d }|d d d }|d d d d	 }	||d d d
 }
|||||	|
dS )Nr   parserZobservationsneighborhoodmetrictemp	windSpeedZwinddir
precipRateZobsTimeLocallocationtemperatureZ
wind_speedZwind_degZprecip_rater
   )requestsdateutilr   getr	   parse)r   r$   r   urlresponser"   r#   r   windDegr    r
   r   r   r   r   ,   s"    r   c                 C   s   dd l }ddlm} ddlm} | }|| }d}|d d }|d d }|d d }	|d d	 }
||d d
 }||||	|
|dS )Nr   )datetimer   u   Rēzeknecurrentr#   Z	windspeedZwinddirectionZprecipitationZdatatimestampr!   )r$   r+   r%   r   r&   r	   fromtimestamp)r   r$   r+   r   r(   r)   r"   r#   r   r*   r    r
   r   r   r   r   B   s$    r   c                 C   s  dd l }dd l}tjj| jd  tjj| j	d}|j
}| j}|d d }|d }|d }|d |d  }|d |d  }	||	g}
|j||j}t|| }||d  }|	|d  }tjj|d |d |j|j|j| j|jj| jd tjj|d |d |j|j|j| j|jj| jd td|d D ]X}|d ||  |d ||  g}tjj|d |d |j|j|j| j|jj| jd q*d S )Nr   )row_id)pkgeometrycoordinatesr   )r   r   widthheightbreedblock_idcultivares_idr.   )r	   geopy.distanceTreesobjectsfilteriddeleteEnterpriseSpecificBreedsr&   tree_breed_idplanting_distancer1   distancegeodesicmintcreater2   r3   titler5   cultivarrange)treeRowr	   geopyZ	Treebreedr@   r1   Zcoords_1Zcoords_2ZdifXZdifYZ	difCoordsZ
lengthLineZ
treeOnLineZ
interval_XZ
interval_Yicoordr   r   r   TreeRowGetTreesY   s`    
 rL   N)modelsr   r   r   r   rL   r   r   r   r   <module>   s
   	