
    
FZjM                     \    d dl mZ d dlmZ  G d dej                        Z G d de      Zy)    )UserList)apic                   "     e Zd ZdZ fdZ xZS )APIzAn experimental wrapper around the base MyGeotab API class that adds some helper methods to results when
    retrieving results with `get()`.
    c                 :    t        t        |   |fi ||      S )a  Gets entities using the API. Shortcut for using call() with the 'Get' method. This returns an EntityList
        with added convience methods.

        :param type_name: The type of entity.
        :type type_name: str
        :param parameters: Additional parameters to send.
        :raise MyGeotabException: Raises when an exception occurs on the MyGeotab server.
        :raise TimeoutException: Raises when the request does not respond after some time.
        :return: The results from the server.
        :rtype: EntityList
        	type_name)
EntityListsuperget)selfr	   
parameters	__class__s      YC:\Users\Rodrigo\frota-trucks-cliente\python\Lib\site-packages\mygeotab/ext/entitylist.pyr   zAPI.get   s      %'+i>:>)TT    )__name__
__module____qualname____doc__r   __classcell__r   s   @r   r   r      s    U Ur   r   c                        e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
e
Zd	 Zdd
Zed        Zed        Zed        ZddZ xZS )r
   zThe customized result listc                 :    t         t        |   |       || _        y)zGets entities using the API. Shortcut for using call() with the 'Get' method.

        :param data: The list of result data.
        :type data: list
        :param type_name: The type of entity.
        :type type_name: str
        N)r   r
   __init__r	   )r   datar	   r   s      r   r   zEntityList.__init__   s     	j$(."r   c                    |r+|j                  dj                  | j                               y|j                  ddj                  | j                        d      5  t	        | j
                        D ]9  \  }}|r!|j                  d       |j                          |j                  |       ; 	 ddd       y# 1 sw Y   yxY w)zThe pretty printer for IPythonz{}(...)   z{}([z]),N)textformatr	   group	enumerater   	breakablepretty)r   pcycleidxitems        r   _repr_pretty_zEntityList._repr_pretty_)   s    FF9##DNN34FMM$..94@!*499!5ICsHHTN	 "6 A@@s   AB66B?c                     t        |t              r)| j                  | j                  |   | j                        S | j                  |   S N)
isinstanceslicer   r   r	   )r   is     r   __getitem__zEntityList.__getitem__5   s7    a>>$))A,??99Q<r   c                     t        |d      }t        |d      }| j                  | j                  || | j                        S )Nr   )maxr   r   r	   )r   r.   js      r   __getslice__zEntityList.__getslice__;   s7    1I1I~~dii!ndnn==r   c                 |   t        |t              r3| j                  | j                  |j                  z   | j                        S t        |t        | j                              r)| j                  | j                  |z   | j                        S | j                  | j                  t        |      z   | j                        S r+   r,   r   r   r   r	   typelistr   others     r   __add__zEntityList.__add__@   s    eX&>>$))ejj"8$..IItDII/>>$))e"3T^^DD~~dii$u+5t~~FFr   c                 |   t        |t              r3| j                  |j                  | j                  z   | j                        S t        |t        | j                              r)| j                  || j                  z   | j                        S | j                  t        |      | j                  z   | j                        S r+   r5   r8   s     r   __radd__zEntityList.__radd__G   s    eX&>>%**tyy"8$..IItDII/>>%$))"3T^^DD~~d5kDII5t~~FFr   c                 T    | j                  | j                  |z  | j                        S r+   )r   r   r	   )r   ns     r   __mul__zEntityList.__mul__N   s    ~~dii!mT^^<<r   c                     | j                   j                  | j                   | j                        }|j                  j	                  | j                         | j                  d   d d  |j                  d<   |S )Nr   )r   __new__r	   __dict__update)r   insts     r   __copy__zEntityList.__copy__S   sW    ~~%%dnndnnET]]+ $f 5a 8fr   c                 t    fd}| j                  t        | j                  ||      | j                        S )zReturns an EntityList, sorted by a provided key.

        :param key: The key to sort the data with.
        :type key: str
        :param reverse: If true, reverse the sort direction.
        :type reverse: bool
        :rtype: EntityList
        c                 R    |    }t        |t              r|j                         S |S r+   )r,   strlower)entitypropkeys     r   sort_by_keyz'EntityList.sort_by.<locals>.sort_by_keyd   s'    #;D$$zz|#Kr   )rL   reverser   )r   sortedr   r	   )r   rL   rN   rM   s    `  r   sort_byzEntityList.sort_byZ   s1    	 ~~fTYYKQ]a]k]k~llr   c                 <    | j                   r| j                   d   S dS )zOGets the first entity in the list, if it exists.

        :rtype: dict
        r   Nr   r   s    r   firstzEntityList.firstl   s      $yytyy|2d2r   c                 <    | j                   r| j                   d   S dS )zNGets the last entity in the list, if it exists.

        :rtype: dict
        NrR   rS   s    r   lastzEntityList.lastt   s     !%		tyy}3t3r   c                 z    t        | j                        }|dk(  sJ dj                  |             | j                  S )zqLike `first`, but first asserts that there is only one entity in the results list.

        :rtype: dict
           z3Expecting one entity, but {} entities were returned)lenr   r    rT   )r   data_lengths     r   rJ   zEntityList.entity|   s;     $))naj!V!]!]^i!jjzzr   c                    	 ddl }|r	 |j                  | j                        S |j                  j                  | j                        S # t        $ r}t        d      |d}~ww xY w# t        $ r ddlm}  || j                        cY S w xY w)zTransforms the data into a pandas DataFrame

        :param normalize: Whether or not to normalize any nested objects in the results into distinct columns.
        :type normalize: bool
        :rtype: pandas.DataFrame
        r   Nz*The 'pandas' package could not be imported)json_normalize)pandasImportErrorr]   r   AttributeErrorpandas.io.json	DataFrame	from_dict)r   	normalizer^   excr]   s        r   to_dataframezEntityList.to_dataframe   s    	U 1,,TYY77 ))$))44  	UJKQTT	U
 " 19%dii001s(   A	 A& 		A#AA#&!B
	B
)F)r   r   r   r   r   r)   r/   r3   r:   r<   r?   __rmul__rE   rP   propertyrT   rW   rJ   rf   r   r   s   @r   r
   r
      s~    $	#
# >
GG= Hm$ 3 3 4 4  5r   r
   N)collectionsr   mygeotabr   r   r
    r   r   <module>rl      s-    ! U#'' U(~5 ~5r   