dynamic scoring for events, i'm pretty sure everything is gonna break
This commit is contained in:
parent
9f2d78ac33
commit
aabba3ea53
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.1.5 on 2022-02-12 18:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('events', '0007_event_auto_match'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='event',
|
||||||
|
name='dynamic',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -16,6 +16,7 @@ class Event(models.Model):
|
||||||
slug = models.SlugField(max_length=55)
|
slug = models.SlugField(max_length=55)
|
||||||
team_size = models.PositiveIntegerField(default=1)
|
team_size = models.PositiveIntegerField(default=1)
|
||||||
auto_match = models.BooleanField(default=False)
|
auto_match = models.BooleanField(default=False)
|
||||||
|
dynamic = models.BooleanField(default=False)
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
{% elif errorform == True %}
|
{% elif errorform == True %}
|
||||||
<p>{% trans "Error while processing your request. (Invalid Form)" %}</p>
|
<p>{% trans "Error while processing your request. (Invalid Form)" %}</p>
|
||||||
{% elif notsub == True %}
|
{% elif notsub == True %}
|
||||||
<span class="message error-msg">{% trans "Error: you're not registered to this event, so you can't register scores, fucking logic." %}</span>
|
<span class="message error-msg">{% trans "You must register to the event before submitting flags." %}</span>
|
||||||
{% elif noteam == True %}
|
{% elif noteam == True %}
|
||||||
<span class="message error-msg">{% trans "This is a team event, please create or join a team before submitting flags." %}</span>
|
<span class="message error-msg">{% trans "This is a team event, please create or join a team before submitting flags." %}</span>
|
||||||
{% if ctf.ctf_url %}
|
{% if ctf.ctf_url %}
|
||||||
|
|
|
@ -7,6 +7,7 @@ from ctfs.models import CTF, CTF_flags, Category
|
||||||
from django.utils.translation import get_language
|
from django.utils.translation import get_language
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from math import log
|
||||||
|
|
||||||
def get_description_by_lang(ctf):
|
def get_description_by_lang(ctf):
|
||||||
lang = get_language()
|
lang = get_language()
|
||||||
|
@ -21,6 +22,24 @@ def get_description_by_lang(ctf):
|
||||||
ret = ctf.description_ru
|
ret = ctf.description_ru
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def actualize_points(ctf):
|
||||||
|
solves = CTF_flags.objects.filter(ctf=ctf)
|
||||||
|
nb_solves = len(solves)
|
||||||
|
|
||||||
|
new_points = max(50 - int(log(nb_solves)*2.5)*5, 5)
|
||||||
|
|
||||||
|
if new_points != ctf.points:
|
||||||
|
diff = ctf.points - new_points
|
||||||
|
ctf.points = new_points
|
||||||
|
ctf.save()
|
||||||
|
for s in solves:
|
||||||
|
player = EventPlayer.objects.get(event=ctf.event, user=s.user)
|
||||||
|
player.score -= diff
|
||||||
|
player.save()
|
||||||
|
if player.team:
|
||||||
|
player.team.score -= diff
|
||||||
|
player.team.save()
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def events(request):
|
def events(request):
|
||||||
list_events = Event.objects.filter().order_by('-end_date', 'start_date')
|
list_events = Event.objects.filter().order_by('-end_date', 'start_date')
|
||||||
|
@ -115,6 +134,7 @@ def event(request, event_slug):
|
||||||
def submit_event_flag(request, event_slug, chall_slug):
|
def submit_event_flag(request, event_slug, chall_slug):
|
||||||
ev = get_object_or_404(Event, slug=event_slug)
|
ev = get_object_or_404(Event, slug=event_slug)
|
||||||
response = redirect('events:event_chall_info', event_slug=event_slug, chall_slug=chall_slug)
|
response = redirect('events:event_chall_info', event_slug=event_slug, chall_slug=chall_slug)
|
||||||
|
flagged = False
|
||||||
|
|
||||||
if timezone.now() >= ev.end_date:
|
if timezone.now() >= ev.end_date:
|
||||||
response['Location'] += '?EventIsOver=1'
|
response['Location'] += '?EventIsOver=1'
|
||||||
|
@ -126,8 +146,10 @@ def submit_event_flag(request, event_slug, chall_slug):
|
||||||
response['Location'] += '?ChallengeNotFound=1'
|
response['Location'] += '?ChallengeNotFound=1'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
flagged = False
|
try:
|
||||||
player = EventPlayer.objects.get(user=request.user, event=ev)
|
player = EventPlayer.objects.get(event=ev, user=request.user)
|
||||||
|
except:
|
||||||
|
player = None
|
||||||
|
|
||||||
if player:
|
if player:
|
||||||
if ev.team_size > 1 and player.team is None:
|
if ev.team_size > 1 and player.team is None:
|
||||||
|
@ -160,6 +182,8 @@ def submit_event_flag(request, event_slug, chall_slug):
|
||||||
player.team.last_submission_date = timezone.now()
|
player.team.last_submission_date = timezone.now()
|
||||||
player.team.score += ctf_info.points
|
player.team.score += ctf_info.points
|
||||||
player.team.save()
|
player.team.save()
|
||||||
|
if ev.dynamic:
|
||||||
|
actualize_points(ctf_info)
|
||||||
response['Location'] += '?Congrat=1'
|
response['Location'] += '?Congrat=1'
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue