Beispiel #1
0
def create_dataframe_with_stats():

    logger.info("begin - create_dataframe_with_stats")

    TMatch = aliased(Match, name=f.MATCH)
    TChamp = aliased(Championship, name=f.CHAMPIONSHIP)
    THome = aliased(Table, name=f.STATS_HOME)
    TAway = aliased(Table, name=f.STATS_AWAY)

    results = session.query(TChamp, TMatch, THome, TAway).filter(
        TChamp.id == TMatch.championship_id,
        TMatch.home_team_id == THome.team_id,
        TMatch.away_team_id == TAway.team_id, TMatch.id == THome.next_match_id,
        TMatch.id == TAway.next_match_id,
        THome.matches_played == THome.last_matches_num,
        TAway.matches_played == TAway.last_matches_num).order_by(
            TMatch.championship_id, TMatch.match_date)

    # with_labels() beacause exists ambiguous columns name.
    df = pd.read_sql(results.with_labels().statement, session.bind)

    add_stats_mean(df)
    add_results(df)

    df.to_csv(PATH_DATAFRAMES + 'bts_stats.csv', index=False)

    logger.info("end - create_dataframe_with_stats")
Beispiel #2
0
def create_dataframe_with_odds():
    logger.info("create_dataframe_with_odds: begin")

    TMatch = aliased(Match, name=f.MATCH)
    TChamp = aliased(Championship, name=f.CHAMPIONSHIP)
    TOddsML = aliased(ResumeOddsMLI, name=f.ODDS_MLI)
    TOddsBTS = aliased(ResumeOddsBTS, name=f.ODDS_BTS)
    THome = aliased(Table, name=f.STATS_HOME)
    TAway = aliased(Table, name=f.STATS_AWAY)

    results = session.query(
        TChamp, TMatch, TOddsML, TOddsBTS, THome, TAway).filter(
            TChamp.id == TMatch.championship_id,
            TMatch.id == TOddsBTS.match_id,
            TMatch.home_team_id == THome.team_id,
            TMatch.away_team_id == TAway.team_id,
            TMatch.id == THome.next_match_id, TMatch.id == TAway.next_match_id,
            or_(THome.last_matches_num == THome.matches_played,
                THome.last_matches_num == None),
            or_(TAway.last_matches_num == TAway.matches_played,
                TAway.last_matches_num == None),
            TMatch.id == TOddsML.match_id).order_by(TMatch.championship_id,
                                                    TMatch.match_date)

    # with_labels() beacause exists ambiguous columns name.
    df = pd.read_sql(results.with_labels().statement, session.bind)

    add_stats_mean(df)

    add_mli_fmu(df)
    add_mli_prob(df)

    add_bts_fu(df)
    add_bts_prob(df)

    add_results(df)

    df.to_csv(PATH_DATAFRAMES + 'bts_total.csv', index=False)

    # print(*df.columns,sep='\n')
    logger.info("create_dataframe_with_odds: end")
Beispiel #3
0
 def list_tables(self):
     return session.query(Table).filter(
         Table.championship_id == self.id,
         Table.last_matches_num == Table.matches_played,
         Table.next_match_id == Match.id).order_by(
             Match.matchGroupNum).all()
Beispiel #4
0
 def list_teams(self):
     return session.query(Team).filter(or_(Match.away_team_id == Team.id, Match.homeTeamId == Team.id), \
                                       Match.championship_id == self.id).distinct().all()
Beispiel #5
0
 def list_matches(self):
     return session.query(Match).filter(
         Match.championshipId == self.id).order_by(Match.matchDate).all()
Beispiel #6
0
 def list_by_name(championship_name):
     return session.query(Championship).filter(
         Championship.name == championship_name).all()
Beispiel #7
0
 def get_by_id(champId):
     return session.query(Championship).filter(
         Championship.id == champId).one()
Beispiel #8
0
 def get_by_id(self, teamId):
     return session.query(Team).filter(Team.id == teamId).one()
Beispiel #9
0
 def get(self, match_id):
     return session.query(ResumeOddsBTS).filter(
         ResumeOddsBTS.match_id == match_id).one()
Beispiel #10
0
 def list():
     return session.query(ResumeOddsMLI).filter().all()
Beispiel #11
0
 def get(match_id):
     return session.query(ResumeOddsMLI).filter(
         ResumeOddsMLI.match_id == match_id).one()
Beispiel #12
0
 def get_by_match(match_id):
     return session.query(Table).filter(
         Table.next_match_id == match_id).all()
Beispiel #13
0
 def list(cls):
     return session.query(cls).filter().all()
Beispiel #14
0
 def list():
     return session.query(Match).filter().all()
Beispiel #15
0
 def get(match_id):
     return session.query(Match).filter(Match.id == match_id).one()
Beispiel #16
0
 def list_names():
     return session.query(distinct(Championship.name)).all()
Beispiel #17
0
 def get(self, teamName):
     return session.query(Team).filter(Team.name == teamName).one()
Beispiel #18
0
 def list(self):
     return session.query(ResumeOddsBTS).filter().all()
Beispiel #19
0
 def list_matches(self, championship_id):
     return session.query(Match).filter(or_(Match.away_team_id == self.id, Match.home_team_id == self.id), \
                                        Match.championship_id == championship_id).order_by(Match.match_date).all()
Beispiel #20
0
 def get(championship_name, year):
     return session.query(Championship).filter(
         Championship.name == championship_name,
         Championship.year == year).one()