Ejemplo n.º 1
0
    def league_matches(self, data_frame):
        condition_records = []
        match_records = []
        remote_ids = []
        local_ids = []
        fields = ['match_date', 'competition_id', 'season_id', 'venue_id', 'home_team_id', 'away_team_id',
                  'home_manager_id', 'away_manager_id', 'referee_id', 'attendance', 'matchday']
        condition_fields = ['kickoff_time', 'kickoff_temp', 'kickoff_humidity',
                            'kickoff_weather', 'halftime_weather', 'fulltime_weather']
        for idx, row in data_frame.iterrows():
            match_dict = {field: row[field] for field in fields if field in row and row[field] is not None}
            condition_dict = {field: row[field] for field in condition_fields
                              if field in row and row[field] is not None}
            if not self.record_exists(mc.ClubLeagueMatches, **match_dict):
                match_dict.update(id=uuid.uuid4())
                match_records.append(mc.ClubLeagueMatches(**match_dict))
                condition_records.append(mcm.MatchConditions(id=match_dict['id'], **condition_dict))
                remote_ids.append(row['remote_id'])
                local_ids.append(match_dict['id'])

        self.session.bulk_save_objects(match_records)
        self.session.bulk_save_objects(condition_records)

        map_records = [mcs.MatchMap(id=local_id, remote_id=remote_id, supplier_id=self.supplier_id)
                       for remote_id, local_id in zip(remote_ids, local_ids) if remote_id]
        self.session.bulk_save_objects(map_records)
        self.session.commit()
Ejemplo n.º 2
0
def test_club_league_match_insert(session, club_data):
    league_match = mc.ClubLeagueMatches(matchday=5, **club_data)
    session.add(league_match)

    match_from_db = session.query(mc.ClubLeagueMatches).join(mco.DomesticCompetitions)\
        .filter(mco.DomesticCompetitions.name == club_data['competition'].name).all()[0]

    assert match_from_db.phase == "league"
    assert match_from_db.matchday == 5
    assert match_from_db.season.name == "2014-2015"
    assert match_from_db.competition.name == u"Test Competition"
    assert match_from_db.competition.country.name == u"England"
    assert match_from_db.venue.name == u"Emirates Stadium"
    assert match_from_db.home_team.name == u"Arsenal FC"
    assert match_from_db.away_team.name == u"Lincoln City FC"
    assert match_from_db.home_manager.full_name == u"Arsène Wenger"
    assert match_from_db.away_manager.full_name == u"Gary Simpson"
    assert match_from_db.referee.full_name == u"Mark Clattenburg"
Ejemplo n.º 3
0
def club_match_lineup(session, club_data, person_data, position_data):
    match = mc.ClubLeagueMatches(matchday=15, **club_data)
    session.add(match)
    session.commit()

    club = session.query(mc.Clubs).filter(mc.Clubs.name == u"Arsenal FC").one()

    lineups = [
        mc.ClubMatchLineups(match_id=match.id,
                            team_id=club.id,
                            player=mcp.Players(**plyr),
                            position=pos,
                            is_starting=True,
                            is_captain=False)
        for j, (plyr,
                pos) in enumerate(zip(person_data['player'], position_data))
    ]
    session.add_all(lineups)
    session.commit()

    return club, match, lineups
Ejemplo n.º 4
0
def test_club_match_lineup_insert(session, club_data, person_data,
                                  position_data):
    match = mc.ClubLeagueMatches(matchday=15, **club_data)
    session.add(match)
    player = mcp.Players(position=position_data[0], **person_data['player'][0])
    session.add(player)
    session.commit()

    club_from_db = session.query(
        mc.Clubs).filter(mc.Clubs.name == u"Arsenal FC").one()

    lineup = mc.ClubMatchLineups(match_id=match.id,
                                 team_id=club_from_db.id,
                                 player_id=player.player_id,
                                 position_id=player.position_id)
    session.add(lineup)

    lineup_from_db = session.query(mc.ClubMatchLineups).join(mc.ClubLeagueMatches)\
        .filter(mc.ClubLeagueMatches.id == match.id)

    assert lineup_from_db.count() == 1
    assert unicode(lineup_from_db[0]) == u"<ClubMatchLineup(match={}, player=Miguel Ángel Ponce, team=Arsenal FC, " \
                                         u"position=Left back, starter=False, captain=False)>".format(match.id)