<commit_before>from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django import forms

from decimal import *

from .models import QRound, QTeam, QAnswer

class PostedForm(forms.Form):
    score = forms.DecimalField(max_digits=6, decimal_places=1)

class ScoreForm(forms.Form):
    def __init__(self, max_value=None, *args, **kwargs):
        super(ScoreForm, self).__init__(*args, **kwargs)
        self.fields['score'] = forms.DecimalField(max_digits=6, decimal_places=1, min_value=0, max_value=max_value)

    score = forms.DecimalField(max_digits=6, decimal_places=1, min_value=0)

#   Initial views contain overviews only
def index(request):
    # List all teams and all rounds. This is the main jury view from where to add scores
    round_list = QRound.objects.all()
    team_list = QTeam.objects.all()

    round_status = []
    for r in round_list:
        if r.qanswer_set.count() == team_list.count():
            round_status.append((r, "Complete"))
        else:
            round_status.append((r, "%d / %d" % (r.qanswer_set.count(), team_list.count())))

    context = {'round_list': round_status, 'team_list': team_list}
    return render(request, 'kwis/index.html', context)

def ranking(request):
    # This is the main view for contestants: ranking of teams based on their results

    # First identify completed rounds. A completed round has as much elements in its
    # qanswer_set as there are participating teams.
    rnd_complete = []
    for rnd in QRound.objects.all():
        if rnd.qanswer_set.count() == QTeam.objects.count():
            rnd_complete.append(rnd)

    if len(rnd_complete) == QRound.objects.count():
        caption = "Final ranking"
    elif len(rnd_complete) == 0:
        caption = "No results yet"
    else:
        caption = "Ranking after "
        for rnd in rnd_complete:
            caption += rnd.round_name + ", "
        caption = caption[:-2]

    result = []
    for team in QTeam.objects.all():
        teamtotal = 0
        for a in team.qanswer_set.all():
            # Only add results for complete rounds
            if a in rnd_complete:
                teamtotal += a.score
        result.append((team.team_name, teamtotal))
<commit_msg>fix for empty scores in ranking<commit_after>from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django import forms

from decimal import *

from .models import QRound, QTeam, QAnswer

class PostedForm(forms.Form):
    score = forms.DecimalField(max_digits=6, decimal_places=1)

class ScoreForm(forms.Form):
    def __init__(self, max_value=None, *args, **kwargs):
        super(ScoreForm, self).__init__(*args, **kwargs)
        self.fields['score'] = forms.DecimalField(max_digits=6, decimal_places=1, min_value=0, max_value=max_value)

    score = forms.DecimalField(max_digits=6, decimal_places=1, min_value=0)

#   Initial views contain overviews only
def index(request):
    # List all teams and all rounds. This is the main jury view from where to add scores
    round_list = QRound.objects.all()
    team_list = QTeam.objects.all()

    round_status = []
    for r in round_list:
        if r.qanswer_set.count() == team_list.count():
            round_status.append((r, "Complete"))
        else:
            round_status.append((r, "%d / %d" % (r.qanswer_set.count(), team_list.count())))

    context = {'round_list': round_status, 'team_list': team_list}
    return render(request, 'kwis/index.html', context)

def ranking(request):
    # This is the main view for contestants: ranking of teams based on their results

    # First identify completed rounds. A completed round has as much elements in its
    # qanswer_set as there are participating teams.
    rnd_complete = []
    for rnd in QRound.objects.all():
        if rnd.qanswer_set.count() == QTeam.objects.count():
            rnd_complete.append(rnd)

    if len(rnd_complete) == QRound.objects.count():
        caption = "Final ranking"
    elif len(rnd_complete) == 0:
        caption = "No results yet"
    else:
        caption = "Ranking after "
        for rnd in rnd_complete:
            caption += rnd.round_name + ", "
        caption = caption[:-2]

    result = []
    for team in QTeam.objects.all():
        teamtotal = 0
        for a in team.qanswer_set.all():
            # Only add results for complete rounds
            if a.rnd in rnd_complete:
                teamtotal += a.score
        result.append((team.team_name, teamtotal))

{'fraction_non_alphanumeric': 0.1060475161987041, 'fraction_numerical': 0.006047516198704104, 'mean_word_length': 3.0587204206836107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677499', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1388, 'n_words': 399}