Limit winning streaks to 5 wins
This commit is contained in:
parent
ea0655dc77
commit
b7373d2b98
10
pt/views.py
10
pt/views.py
|
@ -15,11 +15,15 @@ def compare(request):
|
||||||
if "left" not in request.session:
|
if "left" not in request.session:
|
||||||
left_pic = random_pic()
|
left_pic = random_pic()
|
||||||
request.session["left"] = left_pic.id
|
request.session["left"] = left_pic.id
|
||||||
|
request.session["left_count"] = 0
|
||||||
if "right" not in request.session:
|
if "right" not in request.session:
|
||||||
right_pic = random_pic()
|
right_pic = random_pic()
|
||||||
request.session["right"] = right_pic.id
|
request.session["right"] = right_pic.id
|
||||||
|
request.session["right_count"] = 0
|
||||||
left_pic = models.Picture.objects.get(id=request.session["left"])
|
left_pic = models.Picture.objects.get(id=request.session["left"])
|
||||||
right_pic = models.Picture.objects.get(id=request.session["right"])
|
right_pic = models.Picture.objects.get(id=request.session["right"])
|
||||||
|
request.session["left_count"] += 1
|
||||||
|
request.session["right_count"] += 1
|
||||||
context = {
|
context = {
|
||||||
"left": left_pic,
|
"left": left_pic,
|
||||||
"right": right_pic,
|
"right": right_pic,
|
||||||
|
@ -48,6 +52,9 @@ def left_wins(request):
|
||||||
right.elo -= adjust
|
right.elo -= adjust
|
||||||
right.save()
|
right.save()
|
||||||
log.info("after: left=%f, right=%f", left.elo, right.elo)
|
log.info("after: left=%f, right=%f", left.elo, right.elo)
|
||||||
|
log.info("counts: left=%d, right=%d", request.session["left_count"], request.session["right_count"])
|
||||||
|
if request.session["left_count"] >= 5:
|
||||||
|
del request.session["left"]
|
||||||
del request.session["right"]
|
del request.session["right"]
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('compare'))
|
return HttpResponseRedirect(reverse('compare'))
|
||||||
|
@ -65,6 +72,9 @@ def right_wins(request):
|
||||||
right.elo += adjust
|
right.elo += adjust
|
||||||
right.save()
|
right.save()
|
||||||
log.info("after: left=%f, right=%f", left.elo, right.elo)
|
log.info("after: left=%f, right=%f", left.elo, right.elo)
|
||||||
|
log.info("counts: left=%d, right=%d", request.session["left_count"], request.session["right_count"])
|
||||||
|
if request.session["right_count"] >= 5:
|
||||||
|
del request.session["right"]
|
||||||
del request.session["left"]
|
del request.session["left"]
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('compare'))
|
return HttpResponseRedirect(reverse('compare'))
|
||||||
|
|
Loading…
Reference in New Issue