def get(self, request, standings_label): standings = get_object_or_404(Standings, label=standings_label) group_list = standings.groups.all() if len(group_list) == 0: group_list = standings.course.groups.all() users_data = [] users = [] for group in group_list: users.extend(group.participants.all()) for group in group_list: for user in group.participants.all(): users_data.append({ 'id': user.id, 'name': user.name, 'group': group.name, 'group_short': group.short_name, }) contests = standings.contests.order_by( '-date', '-id').filter(contest_id__isnull=False) contests = [load_contest(contest, users) for contest in contests] contests = [contest for contest in contests if contest is not None] return JsonResponse({ 'users': users_data, 'contests': contests, })
def get(self, request, standings_id): standings = get_object_or_404(Standings, id=standings_id) users = [] for group in standings.course.groups.all(): users.extend(group.participants.all()) users_data = [] for group in standings.course.groups.all(): for user in group.participants.all(): users_data.append({ 'id': user.id, 'name': user.name, 'group': group.name, 'group_short': group.short_name, }) contests = standings.contests.order_by('-date', '-id').all() contests = [load_contest(contest, users) for contest in contests] contests = [contest for contest in contests if contest is not None] return JsonResponse({ 'users': users_data, 'contests': contests, })
def get(self, request, battleship_id): if not request.user.is_superuser: return HttpResponseBadRequest battleship = get_object_or_404(Battleship, id=battleship_id) teams = battleship.battleship_teams.all() participants = [] for team in teams: participants.extend(team.participants.all()) users = [] for participant in participants: users.append(participant.participant) standings = load_contest(battleship.contest, users) problem_names = standings["problems"] fields = [{ 'name': '', 'field': [dict() for i in range(len(teams[j].participants.all()))], 'success': 0, 'fail': 0, 'ship_success': 0, 'ship_fail': 0, } for j in range(len(teams))] for i in range(len(teams)): team = teams[i] fields[i]["name"] = team.name for j, user in enumerate(team.participants.order_by("order", "id")): row = fields[i]['field'][j] row['name'] = user.participant.name row['problems'] = [0] * len(problem_names) row['submits'] = 0 for p, res in enumerate( standings['users'][user.participant.id]): row['submits'] += res['penalty'] fields[i]['fail'] += res['penalty'] if res['verdict'] == EJUDGE_OK: row['problems'][p] = 1 fields[i]['success'] += 1 elif res['penalty'] > 0: row['problems'][p] = -1 for ship in team.ships.all(): fields[i]['field'][ship.y]['problems'][ship.x] = 2 fields[i]['ship_success'] += 1 fields[i][ 'ship_fail'] = fields[i]['success'] - fields[i]['ship_success'] return render( request, 'battleship.html', { 'name': battleship.name, 'fields': fields, 'problem_names': problem_names, })