Add value field to MusicGameOrder and update score calculation logic
This commit is contained in:
parent
178a7cab03
commit
92abcb584c
3 changed files with 45 additions and 25 deletions
|
@ -9,7 +9,7 @@ from django.contrib.auth.models import User
|
|||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import IntegrityError
|
||||
from django.db.models import Count, F, Q
|
||||
from django.db.models import Count, Q
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.views import View
|
||||
from django.views.generic import TemplateView
|
||||
|
@ -471,33 +471,11 @@ class GameEndView(LoginRequiredMixin, SingleObjectMixin, View):
|
|||
raise PermissionDenied()
|
||||
game.over = True
|
||||
|
||||
value = {}
|
||||
for go in game.musicgameorder_set.all():
|
||||
value[go.pk] = 1000 / (
|
||||
1
|
||||
+ (
|
||||
(go.musicgameanswer_set.filter(game__player=F("answer")).count())
|
||||
- 1 / game.players.count()
|
||||
)
|
||||
** 2
|
||||
)
|
||||
go.update_value()
|
||||
|
||||
for player in game.players.all():
|
||||
score = sum(
|
||||
[
|
||||
value[ga.game.pk]
|
||||
for ga in player.musicgameanswer_set.filter(game__game=game)
|
||||
.exclude(game__player=player)
|
||||
.filter(game__player=F("answer"))
|
||||
]
|
||||
)
|
||||
score -= (
|
||||
500
|
||||
* player.musicgameanswer_set.filter(game__game=game)
|
||||
.filter(game__player=player)
|
||||
.exclude(game__player=F("answer"))
|
||||
.count()
|
||||
)
|
||||
score = player.musicgameanswer_set.score(game, player)
|
||||
models.MusicGameResults.objects.create(
|
||||
game=game, player=player, score=score
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue