def _fit(self, **kwargs):
        get_logger('prediction').info('Условие для получения заголовков: %s',
                                      str(self.sample_condition))
        self.match_headers = get_match_headers(self.sample_condition)
        get_logger('prediction').info('Получены заголовки матчей: %u штук',
                                      self.match_headers.shape[0])

        # TODO: Решить, что с этим делать
        self.statistic = self.match_headers.copy()
Beispiel #2
0
def _print_tournament_data(match_date, tournament_id):
    content = ''

    whole_match_headers = get_match_headers()
    attainable_match_headers = whole_match_headers[ whole_match_headers['date'] <= eve_datetime(match_date) ]

    first_year = match_date.year if match_date.month >= 6 else match_date.year - 1
    tournament_season_match_headers = get_tournament_season_substatistic(attainable_match_headers, tournament_id, first_year)
    sorted_tournament_season_match_headers = tournament_season_match_headers.sort_values('date', ascending=True)

    home_teams = frozenset(tournament_season_match_headers['home'].values)
    away_teams = frozenset(tournament_season_match_headers['away'].values)
    teams = home_teams | away_teams

    data = { home: { away: None for away in teams } for home in teams }
    for (match_uuid, match_header) in sorted_tournament_season_match_headers.iterrows():
        events_counts = count_events_of_teams_by_match_uuid(is_corner, match_uuid)
        if events_counts is None:
            continue
        first_period_events_counts = count_events_of_teams_by_match_uuid(conjunct(is_corner, is_first_period), match_uuid)
        second_period_events_counts = count_events_of_teams_by_match_uuid(conjunct(is_corner, is_second_period), match_uuid)

        data[ match_header['home'] ][ match_header['away'] ] = (events_counts[0], events_counts[1], first_period_events_counts[0], first_period_events_counts[1], second_period_events_counts[0], second_period_events_counts[1])

    content += '<table>'
    content += '<tbody>'

    content += '<tr>'
    content += '<th></th>'
    for team in sorted(teams):
        content += '<th>' + team + '</th>'
    content += '</tr>'

    for home in sorted(teams):
        content += '<tr>'
        content += '<th>' + home + '</th>'
        for away in sorted(teams):
            match_data = data[home][away]
            if match_data is not None:
                content += '<td>%u : %u (%u : %u / %u : %u)</td>' % match_data
            else:
                content += '<td></td>'
        content += '</tr>'

    content += '</table>'

    return content
Beispiel #3
0
def _print_teams_statistic(match_header, is_home):
    content = ''

    team = match_header['home'] if is_home else match_header['away']

    whole_match_headers = get_match_headers()
    attainable_match_headers = whole_match_headers[ whole_match_headers['date'] <= eve_datetime(match_header['date']) ]
    attainable_team_match_headers = attainable_match_headers[ (attainable_match_headers['home'] == team) | (attainable_match_headers['away'] == team) ]
    last_match_headers = attainable_team_match_headers[:10]

    content += '<table>'
    content += '<thead>'
    content += '<tr>'
    content += '<th>Дата</th>'
    content += '<th>Хозяева</th>'
    content += '<th>Гости</th>'
    content += '<th>Угловые (матч)</th>'
    content += '<th>Угловые (1-й тайм)</th>'
    content += '<th>Угловые (2-й тайм)</th>'
    content += '</tr>'
    content += '</thead>'
    content += '<tbody>'

    for (match_uuid, match_header) in last_match_headers.iterrows():
        corners_counts = count_events_of_teams_by_match_uuid(is_corner, match_uuid)
        if corners_counts is None:
            continue
        first_period_corners_counts = count_events_of_teams_by_match_uuid(conjunct(is_corner, is_first_period), match_uuid)
        second_period_corners_counts = count_events_of_teams_by_match_uuid(conjunct(is_corner, is_second_period), match_uuid)

        if (is_home and match_header['home'] == team) or (not is_home and match_header['away'] == team):
            content += '<tr class="active">'
        else:
            content += '<tr>'
        content += '<td>' + match_header['date'].strftime('%Y-%m-%d') + '</td>'
        content += '<td>' + match_header['home'] + '</td>'
        content += '<td>' + match_header['away'] + '</td>'
        content += '<td>%u : %u</td>' % corners_counts
        content += '<td>%u : %u</td>' % first_period_corners_counts
        content += '<td>%u : %u</td>' % second_period_corners_counts
        content += '</tr>'

    content += '</tbody>'
    content += '</table>'

    return content
Beispiel #4
0
def index():
    match_headers_collection = db['match_headers']

    match_headers = get_match_headers()

    today = datetime.date.today()
    first_date = today - datetime.timedelta(days=90)
    last_date = today
    date_range = pd.date_range(first_date, last_date, freq='D')

    content = ''
    content += '<h2>Матчи</h2>'

    for date_ in date_range:
        date_str = date_.strftime('%Y-%m-%d')
        content += '<h3>' + date_str + '</h3>'

        whoscored_tournament_ids = set(tournaments_data['whoscoredTournamentId'].values)
        for whoscored_tournament_id in whoscored_tournament_ids:
            this_date_tournament_match_headers = match_headers[ (match_headers['date'] == date_) & (match_headers['tournament_id'] == whoscored_tournament_id) ]
            if this_date_tournament_match_headers.shape[0] == 0:
                continue

            betcity_tournament_name = get_value(tournaments_data, 'whoscoredTournamentId', whoscored_tournament_id, 'betcityTournamentName')
            content += '<h4>' + betcity_tournament_name + '</h4>'
            content += '<table>'
            content += '<tbody>'

            for (match_uuid, match_header) in this_date_tournament_match_headers.iterrows():
                match_href = '/matches/%s' % (match_uuid,)

                content += '<tr>'
                content += '<td>' + date_str + '</td>'
                content += '<td><a href="' + match_href + '">' + match_uuid + '</a></td>'
                content += '<td><a href="' + match_href + '">' + match_header['home'] + '</a></td>'
                content += '<td><a href="' + match_href + '">' + match_header['away'] + '</a></td>'
                content += '</tr>'

            content += '</tbody>'
            content += '</table>'

    return { 'content': content }
Beispiel #5
0
def _print_players_statistic(match_header, is_home):
    team = match_header['home'] if is_home else match_header['away']
    k = 'homePlayers' if is_home else 'awayPlayers'

    additional_info_collection = db['additional_info']
    additional_info = additional_info_collection.find_one({ 'match_uuid': match_header['uuid'] })
    if k not in additional_info:
        return ''

    player_names = [ player['playerName'] for player in additional_info[k] if player['isFirstEleven'] ]
    data = { player_name: {} for player_name in player_names }
    first_period_data = { player_name: {} for player_name in player_names }
    second_period_data = { player_name: {} for player_name in player_names }

    whole_match_headers = get_match_headers()
    attainable_match_headers = whole_match_headers[ whole_match_headers['date'] <= eve_datetime(match_header['date']) ]
    attainable_team_match_headers = attainable_match_headers[ (attainable_match_headers['home'] == team) | (attainable_match_headers['away'] == team) ]
    last_match_headers = attainable_team_match_headers[:10]

    for (match_uuid_, match_header_) in last_match_headers.iterrows():
        player_counts = count_events_of_players_by_match_uuid(is_corner, match_uuid_)
        if player_counts is None:
            continue
        first_period_player_counts = count_events_of_players_by_match_uuid(conjunct(is_corner, is_first_period), match_uuid_)
        second_period_player_counts = count_events_of_players_by_match_uuid(conjunct(is_corner, is_second_period), match_uuid_)

        for player_name in player_counts:
            if player_name in data:
                data[player_name][match_uuid_] = player_counts[player_name]
                first_period_data[player_name][match_uuid_] = first_period_player_counts[player_name]
                second_period_data[player_name][match_uuid_] = second_period_player_counts[player_name]

    content = ''

    content += '<table>'
    content += '<tbody>'

    content += '<tr>'
    content += '<th></th>'
    for (match_uuid, match_header) in last_match_headers.iterrows():
        content += '<th>' + get_match_title(match_header) + '</th>'
    content += '</tr>'

    for player_name in player_names:
        content += '<tr>'
        content += '<th>' + player_name + '</th>'
        for (match_uuid, match_header) in last_match_headers.iterrows():
            if match_uuid in data[player_name]:
                content += '<td>%u (%u / %u)</td>' % (data[player_name][match_uuid], first_period_data[player_name][match_uuid], second_period_data[player_name][match_uuid])
            else:
                content += '<td></td>'
        content += '</tr>'

    content += '<tr><td>(%u игроков)</td></tr>' % (len(player_names),)

    content += '</tbody>'
    content += '</table>'

    content += _print_unmatched_player_names(match_header, is_home)

    return content