Skip to content

Commit

Permalink
Added bonus points when round 3 of a fight is saved (and has scores).
Browse files Browse the repository at this point in the history
  • Loading branch information
xuod committed Mar 26, 2017
1 parent a303add commit bc5bf76
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
5 changes: 3 additions & 2 deletions ipt_connect/FPT2017/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ def get_queryset(self,request):

class JuryAdmin(admin.ModelAdmin):

list_display = ('name','surname','team','affiliation','pf1','pf2','pf3','remark',)
list_display = ('surname','name','team','affiliation','pf1','pf2','pf3','remark',)
list_filter = ('team','pf1','pf2','pf3',)
search_fields = ('name','surname','affiliation',)
search_fields = ('surname','name','affiliation',)
# inlines = ('surname')

# Register your models here.
admin.site.register(Team,TeamAdmin)
Expand Down
27 changes: 21 additions & 6 deletions ipt_connect/FPT2017/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
grade_choices = [(ind, ind) for ind in range(10+1)]

def mean(vec):
return float(sum(vec)) / len(vec)
return float(sum(vec)) / max(len(vec),1)


@deconstructible
Expand Down Expand Up @@ -719,18 +719,27 @@ def ident(self):
return ind+1

class Jury(models.Model):
name = models.CharField(max_length=50,verbose_name='Prénom')
surname = models.CharField(max_length=50,verbose_name='Nom')
name = models.CharField(max_length=50,verbose_name='Prénom')
affiliation = models.CharField(max_length=100,blank=True,verbose_name='Affiliation à afficher')
team = models.ForeignKey('Team', null=True, blank=True)
pf1 = models.BooleanField(default=False,verbose_name='Présent lors du PF 1 ?')
pf2 = models.BooleanField(default=False,verbose_name='Présent lors du PF 2 ?')
pf3 = models.BooleanField(default=False,verbose_name='Présent lors du PF 3 ?')
remark = models.TextField(blank=True,verbose_name='Remarques')


# functions
def fullname(self):
"""
:return: return the full name of the participant
"""
return self.name+' '+self.surname

def __unicode__(self):
return self.name
"""
:return: return the full name of the participant
"""
return self.fullname()

class Round(models.Model):

Expand Down Expand Up @@ -927,11 +936,11 @@ class JuryGrade(models.Model):
)

def __unicode__(self):
return "Grade of %s" % self.jury.name
return "Grade of %s" % self.jury.name + self.jury.surname

def info(self):
print "=" * 36
print u"Grade of %s" % self.jury.name
print u"Grade of %s" % self.jury.name + self.jury.surname
print self.round
print "Reporter %s from %s : %i" % (self.round.name_reporter, self.round.reporter, self.grade_reporter)
print "Opponent %s from %s : %i" % (self.round.name_opponent, self.round.opponent, self.grade_opponent)
Expand Down Expand Up @@ -982,3 +991,9 @@ def update_points(sender, instance, **kwargs):

# and the problem mean scores
instance.problem_presented.update_scores()

def update_all():
for team in Team.objects.all():
team.update_scores()
for pb in Problem.objects.all():
pb.update_scores()
6 changes: 3 additions & 3 deletions ipt_connect/FPT2017/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def home(request):
cache_duration_short = 60 * 1
cache_duration = 60 * 60

ninja_mode = True
ninja_mode = False

def ninja_test(user):
return user.is_staff or not ninja_mode
Expand Down Expand Up @@ -301,7 +301,7 @@ def round_detail(request, pk):
meangrades = []

# has the round started ? If so, then reporter_team, opponent_team and reviewer_team must be defined
if None in [round.reporter_team, round.opponent_team, round.reviewer_team]:
if None in [round.reporter_team, round.opponent_team, round.reviewer_team, round.problem_presented]:
started = False
else:
started = True
Expand Down Expand Up @@ -334,7 +334,7 @@ def finalround_detail(request, pk):
meangrades = []

# has the round started ? If so, then reporter_team, opponent_team and reviewer_team must be defined
if None in [thisround.reporter_team, thisround.opponent_team, thisround.reviewer_team]:
if None in [thisround.reporter_team, thisround.opponent_team, thisround.reviewer_team, thisround.problem_presented]:
started = False
else:
started = True
Expand Down
46 changes: 45 additions & 1 deletion ipt_connect/IPT2017/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ class Jury(models.Model):
pf4 = models.BooleanField(default=False,verbose_name='PF 4')
final = models.BooleanField(default=False,verbose_name='Final')
remark = models.TextField(blank=True,verbose_name='Remarks')

class Meta:
verbose_name = "Juror"

Expand Down Expand Up @@ -991,3 +991,47 @@ def update_points(sender, instance, **kwargs):

# and the problem mean scores
instance.problem_presented.update_scores()

# If this is the last round of a fight, it is time to distribute bonus points !
if instance.round_number == 3 :
rounds = Round.objects.filte(pf_number=instance.pf_number).filter(room=instance.room).order_by('round_number')

assert len(rounds) == 3, "didn't get the correct number of rounds"

# get the points of the physics fight for the 2 teams (without bonuses) in a dictionary
points_dict = {}
for team in teams:
points_dict[team] = 0.0
for round in rounds :
# add the points of each round
points_dict[round.reporter_team] += round.points_reviewer
points_dict[round.opponent_team] += round.points_opponent
points_dict[round.reviewer_team] += round.points_reviewer

# get teams sorted by total points for the physics fight
team_podium = sorted(teams, key = lambda t : points_dict[t], reverse=True)
points_list = [points_dict[t] for t in team_podium]

# If everyone is ex-aequo
if points_list[0] == points_list[1] and points_list[0] == points_list[2] :
team_podium[0].total_points += 1.
team_podium[1].total_points += 1.
team_podium[2].total_points += 1.
# If 1 and 2 are ex-aequo
elif points_list[0] == points_list[1]:
team_podium[0].total_points += 1.5
team_podium[1].total_points += 1.5
team_podium[2].total_points += 0.0
# If 2 and 3 are ex-aequo
elif points_list[1] == points_list[2]:
team_podium[0].total_points += 2.0
team_podium[1].total_points += 0.5
team_podium[2].total_points += 0.5
# If no ex-aequo
else:
team_podium[0].total_points += 2.0
team_podium[1].total_points += 1.0
team_podium[2].total_points += 0.0

for team in teams:
team.save()

0 comments on commit bc5bf76

Please sign in to comment.