o
    g/h
                     @   s4   d dl Z d dlZd dlZdd Zdd Zdd ZdS )    Nc           	      C   s   g d}t | ddd}|d }tjtj|dd t |ddd	d
}t|}tj||dd}|  |D ]B}|d dkrBd|d< n0|d dkrMd|d< n%|d dkrXd|d< n|d dkrcd|d< n|d dkrnd|d< nt	d |
| q5dS )z Creates a file with only important data columns for each player

    Args:
        filename (str): Name of the file that contains the full data for each player
    )
first_namesecond_namegoals_scoredassiststotal_pointsminutesgoals_conceded
creativity	influencethreatbonusbps	ict_indexclean_sheets	red_cardsyellow_cardsselected_by_percentnow_costelement_typer+utf-8encodingzcleaned_players.csvTexist_okw+ r   newlineignoreextrasactionr   1GK2DEF3MID4FWD5AMzUnknown element typeN)openosmakedirspathdirnamecsv
DictReader
DictWriterwriteheaderprintwriterow)	filenamebase_filenameheadersfinoutnamefoutreaderwriterline r@   6/var/www/html/fpl_model_app/scripts/utills/cleaners.pyclean_players   s,   





rB   c           	      C   s~   g d}t | ddd}|d }tjtj|dd t |ddd	d
}t|}tj||dd}|  |D ]}|	| q5dS )z Creates a file that contains the name to id mappings for each player

    Args:
        players_filename (str): Name of the file that contains the full data for each player
    )r   r   idr   r   r   player_idlist.csvTr   r   r   r   r   r    N)
r,   r-   r.   r/   r0   r1   r2   r3   r4   r6   )	players_filenamer8   r9   r:   r;   r<   r=   r>   r?   r@   r@   rA   
id_players"   s   
rF   c                 C   sZ   | d }t |ddd}t|}i }|D ]}t|d }|d d |d  }|||< q|S )	z6 Gets the list of all player ids and player names
    rD   r   r   r   rC   r   _r   )r,   r1   r2   int)r8   r7   r:   r=   
player_idsr?   kvr@   r@   rA   get_player_ids3   s   

rL   )r1   mathr-   rB   rF   rL   r@   r@   r@   rA   <module>   s    