
    g                         d dl mZ 	  G d d      Z G d de      Z G d de      Z G d d	e      Z	  G d
 de      Z	 d dlmZ  G d d      Z	y)    reducec                       e Zd Zd Zd Zd Zy)Vehiclec                      || _         || _        y N)weight
horsepower)selfr	   r
   s      @c:\WORK\www\ai.huynhdous.com\UCI\Inter_Python\week_6_homework.py__init__zVehicle.__init__   s    $    c                     t        d       y )NzThe vehicle is now driving.printr   s    r   drivezVehicle.drive   s    +,r   c                     t        d       y )NzThe vehicle is now stopping.r   r   s    r   stopzVehicle.stop   s    ,-r   N)__name__
__module____qualname__r   r   r    r   r   r   r      s    %-.r   r   c                        e Zd Z fdZ xZS )Carc                 4    t         |   ||       d| _        y )N   superr   wheelsr   r	   r
   	__class__s      r   r   zCar.__init__       ,r   )r   r   r   r   __classcell__r"   s   @r   r   r      s     r   r   c                   $     e Zd Z fdZd Z xZS )
Motorcyclec                 4    t         |   ||       d| _        y )N   r   r!   s      r   r   zMotorcycle.__init__   r#   r   c                     t        d       y )Nz"The motorcycle is doing a wheelie!r   r   s    r   wheeliezMotorcycle.wheelie   s    23r   )r   r   r   r   r+   r$   r%   s   @r   r'   r'      s    4r   r'   c                   $     e Zd Z fdZd Z xZS )Truckc                 4    t         |   ||       d| _        y )N   r   r!   s      r   r   zTruck.__init__    r#   r   c                     t        d       y )NzThe truck is dumping its load!r   r   s    r   dumpz
Truck.dump$   s    ./r   )r   r   r   r   r1   r$   r%   s   @r   r-   r-      s    0r   r-   c                       e Zd Zd Zy)NumericListc                     t        d | d      S )Nc                     | |z  S r   r   )xys     r   <lambda>z%NumericList.product.<locals>.<lambda>-   s
    1q5 r      r   r   s    r   productzNumericList.product,   s    ($22r   N)r   r   r   r:   r   r   r   r3   r3   +   s    3r   r3   )datetimec                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)Customera  
    A class to model customers

    Parameters
    ----------
    customer_number : int, str
        the numerical customer id

    customer_info_filepath : str
        the filepath to the customer info file

    purchases_filepath : str
        the filepath to the purchases file

    c                 N    t        |      | _        || _        || _        i | _        y r   )strcustomer_numbercustomer_info_filepathpurchases_filepath	purchases)r   r@   rA   rB   s       r   r   zCustomer.__init__J   s&    "?3&<#"4r   c                 
   t        | j                  d      5 }|D ]S  }|j                         j                  d      }|d   | j                  k(  s5|d   | _        |d   | _        |d   | _         n ddd       y# 1 sw Y   yxY w)z;Load the data from the customer info file for this customerr,r   r9   r)      N)openrA   stripsplitr@   nameagestate)r   	read_filelineline_splitss       r   _load_customer_infozCustomer._load_customer_infoP   s    $--s3 	y! "jjl005q>T%9%99 +ADI*1~DH!,QDJ	 	 	s   7A9!A99Bc                 :   t        | j                  d      5 }|D ]j  }|j                         j                  d      }|d   | j                  k(  s5t        j                  |d   d      }t        |d         }|| j                  |<   l 	 ddd       y# 1 sw Y   yxY w)zBLoad the purchases data from the purchases file, for this customerrE   rF   r   r9   z%Y-%m-%d %H:%M:%Sr)   N)	rH   rB   rI   rJ   r@   r;   strptimefloatrC   )r   rN   rO   rP   purchase_datepurchase_values         r   _load_purchaseszCustomer._load_purchases[   s    $))3/ 	C9! C"jjl005q>T%9%99$,$5$5k!nFY$ZM%*;q>%:N4BDNN=1C	C 	C 	Cs   7B8BBc                 D    | j                          | j                          y)zLoad all the customers dataN)rQ   rW   r   s    r   	load_datazCustomer.load_datae   s      "r   c                 |    | j                   sy| j                   t        | j                   j                                  S )z4Return the most recent purchase made by the customerN)rC   maxkeysr   s    r   get_last_purchasezCustomer.get_last_purchasej   -    ~~~~c$.."5"5"7899r   c                 |    | j                   sy| j                   t        | j                   j                                  S )z.Return the first purchase made by the customerN)rC   minr\   r   s    r   get_first_purchasezCustomer.get_first_purchasep   r^   r   c                 ,    t        | j                        S )z4Return the number of purchases the customer has made)lenrC   r   s    r   get_num_purchaseszCustomer.get_num_purchasesv   s    4>>""r   c                 H    t        | j                  j                               S )z4Return the sum of all purchases made by the customer)sumrC   valuesr   s    r   get_sum_of_purchaseszCustomer.get_sum_of_purchasesz   s    4>>((*++r   N)r   r   r   __doc__r   rQ   rW   rY   r]   ra   rd   rh   r   r   r   r=   r=   :   s0    	C
::#,r   r=   N)
	functoolsr   r   r   r'   r-   listr3   r;   r=   r   r   r   <module>rl      sb    	. 	.' 
4 40G 03$ 3 B, B,r   