Ejemplo n.º 1
0
def list_league_scoreboards():

    events = ChannelService.get_cups(iscup=0)

    if events:
        default_id = events[1]['id']
    else:
        return render_template('admin/scoreboard/league_list.html',
                               groups=[],
                               events=events)

    try:
        event_id = int(request.args.get('event_id', default_id))
    except:
        raise InvalidArgument()

    teams = EventTeamService.get_all(event_id=event_id)

    def get_selected_team(group):
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['name'] = team_info['name']
        return group

    teams = map(get_selected_team, teams)

    scoreboard_teams = ScoreboardService.get_all(event_id=event_id)

    def get_group_info(num, group):
        group['ranking'] = num
        group['section'] = group['wins'] + group['draws'] + group['loses']
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['team_name'] = team_info['name']
            group['team_badge'] = team_info['badge']
        return group

    groups = [
        get_group_info(num + 1, group)
        for num, group in enumerate(scoreboard_teams)
    ]

    return render_template('admin/scoreboard/league_list.html',
                           groups=groups,
                           teams=teams,
                           event_id=event_id,
                           events=events)
Ejemplo n.º 2
0
def list_cup_scoreboards():

    group_list = ['A', 'B', 'C', 'D', 'E', 'F']

    events = ChannelService.get_cups(iscup=1)

    if events:
        default_id = events[0]['id']
    else:
        return render_template('admin/scoreboard/cup_list.html',
                               groups=[],
                               events=events)

    try:
        event_id = int(request.args.get('event_id', default_id))
    except:
        raise InvalidArgument()

    teams = EventTeamService.get_all(event_id=event_id)

    def get_selected_team(group):
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['name'] = team_info['name']
        return group

    teams = map(get_selected_team, teams)

    team_groups = EventTeamService.get_all(event_id)

    def get_team_info(group):
        team_info = TeamService.get_one(group['team_id'])
        if team_info:
            group['team_name'] = team_info['name']
            group['team_badge'] = team_info['badge']

        score = ScoreboardService.get_filter_one(group['event_id'],
                                                 group['team_id'])
        if score:
            group['id'] = score['id']
            group['wins'] = score['wins']
            group['draws'] = score['draws']
            group['loses'] = score['loses']
            group['goals_differential'] = score['goals_differential']
            group['points'] = score['points']
            group['section'] = group['wins'] + group['draws'] + group['loses']

        return group

    team_groups = map(get_team_info, team_groups)

    groups = defaultdict(list)

    for item in team_groups:
        groups[item["group"]].append(item)

    count_len = len(groups.keys())

    group_list[0:count_len]

    # sort points
    for key in group_list:
        if groups[key]:
            for item in groups[key]:
                if 'points' in item.keys():
                    groups[key].sort(key=operator.itemgetter('points'),
                                     reverse=True)
                else:
                    item['points'] = 0

    return render_template('admin/scoreboard/cup_list.html',
                           groups=groups,
                           group_list=group_list,
                           teams=teams,
                           event_id=event_id,
                           events=events)