def __init__(self): ## Define update need with open('MPG_data/lazy_load.txt', 'rb') as fp: lazy_load = pickle.load(fp) if lazy_load == True: print('Lazy Load...') self.players = pd.read_csv('MPG_data/players.csv', index_col=False) print('Players loaded') self.data = pd.read_csv('MPG_data/data_edited.csv', index_col=False) print('Matches loaded') else: print("Update Load...") self.data = pd.read_csv('MPG_data/matches.csv') print('Data loaded') self.dict_players = {} self.list_players = [] print("Formatting Data...") self.format_data() print('Data formated \n Updating players...') self.init_players() print('Players updated') print('Lazy load active') with open('MPG_data/lazy_load.txt', 'wb') as fp: pickle.dump('1', fp) ## initialization self.last_season = max(self.data['season_year'].unique().tolist()) self.get_dict_players() self.format = mf.MyFormating()
def get_histogram(self): x = self.data_player['info_note_final_2015'].tolist() figure = mf.MyFormating().histogram_grades_player(x) return figure
def get_historic(self): y = self.data_player['info_note_final_2015'].tolist() x = self.data_player['info_date_time'].tolist() figure = mf.MyFormating().tableau_historic_figure(x, y) return figure
def stats_for_hover(self, hoverData): if hoverData == None: match_date = self.data_player.sort_values( by='info_date_time', ascending=False).iloc[0, :]['info_date_time'] print(match_date) else: match_date = hoverData['points'][0]['x'] self.data_player_match = self.data_player[ self.data_player['info_date_time'] == match_date] ## STATUS opponent = self.data_player_match.iloc[0, :]['info_opponent'] home_or_away = self.data_player_match.iloc[0, :]['info_where'] position = self.data_player_match.iloc[0, :]['info_position'] grade = self.data_player_match.iloc[0, :]['info_note_final_2015'] time_played = self.data_player_match.iloc[0, :]['info_mins_played'] substitute = self.data_player_match.iloc[0, :]['info_sub'] ## pre-STATS shot_missed = self.data_player_match.iloc[0, :][ 'stat_shot_off_target'] ### dont take shot missed ## STATS goals_scored = self.data_player_match.iloc[0, :]['info_goals'] assist = self.data_player_match.iloc[0, :]['stat_goal_assist'] scoring_att = self.data_player_match.iloc[ 0, :]['stat_total_scoring_att'] accurate_shots = scoring_att - shot_missed shot_precision = round((scoring_att - shot_missed) / scoring_att, 2) touches = self.data_player_match.iloc[0, :]['stat_touches'] pass_precision = round( self.data_player_match.iloc[0, :]['stat_pass'], 2) ## Ocasional injured_status = self.injured( self.data_player_match.iloc[0, :]['stat_subReason']) red_card = self.data_player_match.iloc[0, :]['info_red_card'] yellow_card = self.data_player_match.iloc[0, :]['info_yellow_card'] hover_stats = [ ## STATUS opponent, #0 home_or_away, position, grade, time_played, substitute, #5 ## STATS goals_scored, assist, scoring_att, accurate_shots, shot_precision, #10 touches, pass_precision, ## Ocasionnal injured_status, red_card, yellow_card #15 ] text_hover = mf.MyFormating().stats_hover(hover_stats) return text_hover
def stats_for_app(self): text = mf.MyFormating().stats_player(self.list_stats) return text
dict_ligue = json.load(open('MPG_data/championships.json', 'r')) inv_dic = {v: k for k, v in dict_ligue.items()} """ Application http://127.0.0.1:8050/ Note : In Dash : the class name columns represent 1/12 of the space : ex : 4 columns means you divide your space in 3 (4/2) """ ### line for heroku deploy server = app.server colors = mf.MyFormating().colors app.layout = html.Div( style={'backgroundColor': colors['background']}, children=[ ############################################## # Head (children 1) ############################################## html.Div([ html.Div( html.Img(src = 'https://pbs.twimg.com/profile_images/716008797987143680/32rcyJWQ_400x400.jpg', style = { 'height':'150px', 'width':'auto'