Skip to content

Commit

Permalink
Merge branches 'BACKEND-BZE', 'decimal-step' and 'task/2353' into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
tienne-B committed Mar 24, 2024
3 parents fbd22f8 + 993134b + 4eda790 commit 09201fc
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 113 deletions.
6 changes: 5 additions & 1 deletion tabbycat/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class V1LinksSerializer(serializers.Serializer):

class CheckinSerializer(serializers.Serializer):
object = serializers.HyperlinkedIdentityField(view_name='api-root')
barcode = serializers.IntegerField()
barcode = serializers.CharField()
checked = serializers.BooleanField()
timestamp = serializers.DateTimeField()

Expand Down Expand Up @@ -465,6 +465,7 @@ class SpeakerLinksSerializer(serializers.Serializer):
queryset=SpeakerCategory.objects.all(),
)
_links = SpeakerLinksSerializer(source='*', read_only=True)
barcode = serializers.CharField(source='checkin_identifier.barcode', read_only=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -474,6 +475,7 @@ def __init__(self, *args, **kwargs):
self.fields.pop('phone')
self.fields.pop('pronoun')
self.fields.pop('url_key')
self.fields.pop('barcode')

if kwargs['context']['tournament'].pref('participant_code_names') == 'everywhere':
self.fields.pop('name')
Expand Down Expand Up @@ -528,6 +530,7 @@ class AdjudicatorLinksSerializer(serializers.Serializer):
)
venue_constraints = VenueConstraintSerializer(many=True, required=False)
_links = AdjudicatorLinksSerializer(source='*', read_only=True)
barcode = serializers.CharField(source='checkin_identifier.barcode', read_only=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -554,6 +557,7 @@ def __init__(self, *args, **kwargs):
self.fields.pop('phone')
self.fields.pop('pronoun')
self.fields.pop('url_key')
self.fields.pop('barcode')

class Meta:
model = Adjudicator
Expand Down
6 changes: 3 additions & 3 deletions tabbycat/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def get_queryset(self):
return super().get_queryset().select_related('tournament').prefetch_related(
Prefetch(
'speaker_set',
queryset=Speaker.objects.all().prefetch_related(category_prefetch).select_related('team__tournament'),
queryset=Speaker.objects.all().prefetch_related(category_prefetch).select_related('team__tournament', 'checkin_identifier'),
),
'institution_conflicts', 'venue_constraints__category__tournament',
'break_categories', 'break_categories__tournament',
Expand Down Expand Up @@ -387,7 +387,7 @@ def get_queryset(self):
if self.request.query_params.get('break') and self.get_break_permission():
filters &= Q(breaking=True)

return super().get_queryset().prefetch_related(
return super().get_queryset().select_related('checkin_identifier').prefetch_related(
'team_conflicts', 'team_conflicts__tournament',
'adjudicator_conflicts', 'adjudicator_conflicts__tournament',
'institution_conflicts', 'venue_constraints__category__tournament',
Expand Down Expand Up @@ -442,7 +442,7 @@ def get_queryset(self):
if not self.request.user or not self.request.user.is_staff:
category_prefetch.queryset = category_prefetch.queryset.filter(public=True)

return super().get_queryset().prefetch_related(category_prefetch)
return super().get_queryset().select_related('checkin_identifier').prefetch_related(category_prefetch)


@extend_schema(tags=['venues'], parameters=[tournament_parameter])
Expand Down
2 changes: 1 addition & 1 deletion tabbycat/importer/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def import_debates(self):

# Debate-teams
for j, side in enumerate(debate.findall('side'), side_start):
position = list(DebateTeam.Side)[j][0]
position = list(DebateTeam.Side)[j]
debateteam_obj = DebateTeam(debate=debate_obj, team=self.teams[side.get('team')], side=position)
debateteam_obj.save()
self.debateteams[(debate.get('id'), side.get('team'))] = debateteam_obj
Expand Down
28 changes: 15 additions & 13 deletions tabbycat/options/preferences.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from decimal import Decimal

from django.core.validators import MinValueValidator, validate_slug
from django.utils.translation import gettext_lazy as _
from django_summernote.widgets import SummernoteWidget
from dynamic_preferences.preferences import Section
from dynamic_preferences.registries import global_preferences_registry
from dynamic_preferences.types import BooleanPreference, ChoicePreference, FloatPreference, IntegerPreference, LongStringPreference, StringPreference
from dynamic_preferences.types import BooleanPreference, ChoicePreference, DecimalPreference, FloatPreference, IntegerPreference, LongStringPreference, StringPreference

from standings.speakers import SpeakerStandingsGenerator
from standings.teams import TeamStandingsGenerator
Expand All @@ -20,30 +22,30 @@


@tournament_preferences_registry.register
class MinimumSpeakerScore(FloatPreference):
class MinimumSpeakerScore(DecimalPreference):
help_text = _("Minimum allowed score for substantive speeches")
section = scoring
name = 'score_min'
verbose_name = _("Minimum speaker score")
default = 68.0
default = Decimal('68')


@tournament_preferences_registry.register
class MaximumSpeakerScore(FloatPreference):
class MaximumSpeakerScore(DecimalPreference):
verbose_name = _("Maximum speaker score")
help_text = _("Maximum allowed score for substantive speeches")
section = scoring
name = 'score_max'
default = 82.0
default = Decimal('82')


@tournament_preferences_registry.register
class SpeakerScoreStep(FloatPreference):
class SpeakerScoreStep(DecimalPreference):
verbose_name = _("Speaker score step")
help_text = _("Score steps allowed for substantive speeches, e.g. full points (1) or half points (0.5)")
section = scoring
name = 'score_step'
default = 1.0
default = Decimal('1')


@tournament_preferences_registry.register
Expand All @@ -57,30 +59,30 @@ class MaximumMargin(FloatPreference):


@tournament_preferences_registry.register
class MinimumReplyScore(FloatPreference):
class MinimumReplyScore(DecimalPreference):
help_text = _("Minimum allowed score for reply speeches")
verbose_name = _("Minimum reply score")
section = scoring
name = 'reply_score_min'
default = 34.0
default = Decimal('34.0')


@tournament_preferences_registry.register
class MaximumReplyScore(FloatPreference):
class MaximumReplyScore(DecimalPreference):
help_text = _("Maximum allowed score for reply speeches")
verbose_name = _("Maximum reply score")
section = scoring
name = 'reply_score_max'
default = 41.0
default = Decimal('41.0')


@tournament_preferences_registry.register
class ReplyScoreStep(FloatPreference):
class ReplyScoreStep(DecimalPreference):
help_text = _("Score steps allowed for reply speeches, e.g. full points (1) or half points (0.5)")
verbose_name = _("Reply score step")
section = scoring
name = 'reply_score_step'
default = 0.5
default = Decimal('0.5')


@tournament_preferences_registry.register
Expand Down
71 changes: 36 additions & 35 deletions tabbycat/options/presets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from copy import copy
from decimal import Decimal

from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -84,12 +85,12 @@ class AustralsPreferences(PreferencesPreset):
show_in_list = True

# Scoring
scoring__score_min = 70.0 # Technically the speaks
scoring__score_max = 80.0 # range is at the adj
scoring__score_step = 1.0 # core's discretion (it's
scoring__reply_score_min = 35.0 # not in the constitution)
scoring__reply_score_max = 40.0
scoring__reply_score_step = 0.5
scoring__score_min = Decimal('70') # Technically the speaks
scoring__score_max = Decimal('80') # range is at the adj
scoring__score_step = Decimal('1') # core's discretion (it's
scoring__reply_score_min = Decimal('35.0') # not in the constitution)
scoring__reply_score_max = Decimal('40.0')
scoring__reply_score_step = Decimal('0.5')
scoring__maximum_margin = 0.0 # Rob Confirmed
# Draws
draw_rules__avoid_same_institution = True
Expand Down Expand Up @@ -122,9 +123,9 @@ class BritishParliamentaryPreferences(PreferencesPreset):
description = _("2 vs 2 vs 2 vs 2. Compliant with WUDC rules.")
show_in_list = True

scoring__score_min = 50.0
scoring__score_max = 99.0
scoring__score_step = 1.0
scoring__score_min = Decimal('50')
scoring__score_max = Decimal('99')
scoring__score_step = Decimal('1')
scoring__maximum_margin = 0.0
scoring__teamscore_includes_ghosts = True # WUDC 34.9.3.2
# Debate Rules
Expand Down Expand Up @@ -168,8 +169,8 @@ class CanadianParliamentaryPreferences(PreferencesPreset):
description = _("2 vs 2 with replies (unscored) and POIs. May require "
"additional configuration depending on regional variations.")
# Scoring
scoring__score_min = 50.0
scoring__score_max = 100.0
scoring__score_min = Decimal('50')
scoring__score_max = Decimal('100')
# Debate Rules
debate_rules__reply_scores_enabled = False # Not scored
debate_rules__substantive_speakers = 2
Expand All @@ -194,8 +195,8 @@ class AustralianEastersPreferences(AustralsPreferences):
"bubbles, one-up-one-down. Compliant with AIDA rules.")

# Scoring
scoring__score_min = 70.0
scoring__score_max = 80.0
scoring__score_min = Decimal('70')
scoring__score_max = Decimal('80')
scoring__maximum_margin = 15.0
# Debate Rules
debate_rules__reply_scores_enabled = False
Expand All @@ -214,10 +215,10 @@ class NZEastersPreferences(AustralsPreferences):
"novice statuses.")

# Scoring
scoring__score_min = 60.0
scoring__score_max = 80.0
scoring__reply_score_min = 30.0
scoring__reply_score_max = 40.0
scoring__score_min = Decimal('60')
scoring__score_max = Decimal('80')
scoring__reply_score_min = Decimal('30.0')
scoring__reply_score_max = Decimal('40.0')
# Debate Rules
debate_rules__reply_scores_enabled = True
motions__motion_vetoes_enabled = True
Expand All @@ -241,10 +242,10 @@ class JoyntPreferences(AustralsPreferences):
"and motions, and novice statuses.")

# Scoring
scoring__score_min = 60.0
scoring__score_max = 80.0
scoring__reply_score_min = 30.0
scoring__reply_score_max = 40.0
scoring__score_min = Decimal('60')
scoring__score_max = Decimal('80')
scoring__reply_score_min = Decimal('30.0')
scoring__reply_score_max = Decimal('40.0')
# Debate Rules
debate_rules__reply_scores_enabled = True
motions__motion_vetoes_enabled = False
Expand All @@ -271,12 +272,12 @@ class UADCPreferences(AustralsPreferences):

# Rules source = https://docs.google.com/document/d/10AVKBhev_OFRtorWsu2VB9B5V1a2f20425HYkC5ztMM/edit
# Scoring
scoring__score_min = 69.0 # From Rules Book
scoring__score_max = 81.0 # From Rules Book
scoring__score_step = 1.0
scoring__reply_score_min = 34.5 # Not specified; assuming half of substantive
scoring__reply_score_max = 42.0 # Not specified; assuming half of substantive
scoring__reply_score_step = 0.5
scoring__score_min = Decimal('69') # From Rules Book
scoring__score_max = Decimal('81') # From Rules Book
scoring__score_step = Decimal('1')
scoring__reply_score_min = Decimal('34.5') # Not specified; assuming half of substantive
scoring__reply_score_max = Decimal('42.0') # Not specified; assuming half of substantive
scoring__reply_score_step = Decimal('0.5')
scoring__maximum_margin = 0.0 # TODO= check this
scoring__margin_includes_dissenters = False # From Rules 20.3.2
# Draws
Expand Down Expand Up @@ -310,12 +311,12 @@ class WSDCPreferences(AustralsPreferences):

# Rules source = http://mkf2v40tlr04cjqkt2dtlqbr.wpengine.netdna-cdn.com/wp-content/uploads/2014/05/WSDC-Debate-Rules-U-2015.pdf
# Score (strictly specified in the rules)
scoring__score_min = 60.0
scoring__score_max = 80.0
scoring__score_step = 1.0
scoring__reply_score_min = 30.0
scoring__reply_score_max = 40.0
scoring__reply_score_step = 0.5
scoring__score_min = Decimal('60')
scoring__score_max = Decimal('80')
scoring__score_step = Decimal('1')
scoring__reply_score_min = Decimal('30.0')
scoring__reply_score_max = Decimal('40.0')
scoring__reply_score_step = Decimal('0.5')
# Debates
motions__motion_vetoes_enabled = False # Single motions per round
motions__enable_motions = False
Expand All @@ -335,8 +336,8 @@ class APDAPreferences(PreferencesPreset):
show_in_list = True
description = _("2 vs 2 with speech rankings and byes")

scoring__score_min = 15
scoring__score_max = 40
scoring__score_min = Decimal('15')
scoring__score_max = Decimal('40')
motions__motion_vetoes_enabled = False # Single motions per round
motions__enable_motions = False
draw_rules__draw_odd_bracket = 'pullup_bottom'
Expand Down
11 changes: 6 additions & 5 deletions tabbycat/options/tests/management/commands/test_applypreset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from decimal import Decimal
from unittest.mock import patch

from django.core.management import call_command
Expand All @@ -15,8 +16,8 @@ class TestPreset(PreferencesPreset):
show_in_list = False

# Scoring
scoring__score_min = 70
scoring__score_max = 80
scoring__score_min = Decimal('70')
scoring__score_max = Decimal('80')


class ApplyPresetTests(TestCase):
Expand All @@ -37,9 +38,9 @@ def test_set_invalid_preset(self, mock_all_presets):
@patch('options.management.commands.applypreset.all_presets', return_value=[TestPreset])
def test_set_valid_preset(self, mock_all_presets):
tournament = Tournament.objects.create(slug="command", name="Command Testing")
tournament.preferences['scoring__score_min'] = 0
tournament.preferences['scoring__score_max'] = 100
tournament.preferences['scoring__score_min'] = Decimal('0')
tournament.preferences['scoring__score_max'] = Decimal('100')

call_command('applypreset', ['-t', 'command', 'testpreset'])
for pref, val in [('scoring__score_min', 70), ('scoring__score_max', 80)]:
for pref, val in [('scoring__score_min', Decimal('70')), ('scoring__score_max', Decimal('80'))]:
self.assertEqual(tournament.preferences[pref], val)
5 changes: 3 additions & 2 deletions tabbycat/options/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from decimal import Decimal
from unittest.mock import patch

from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -36,8 +37,8 @@ def test_falsy_preference_change(self):

def test_validation_between_prefs(self):
tests = [
('scoring', (('score_min', 100), ('score_max', 0))),
('scoring', (('reply_score_min', 100), ('reply_score_max', 0))),
('scoring', (('score_min', Decimal('100')), ('score_max', Decimal('0')))),
('scoring', (('reply_score_min', Decimal('100')), ('reply_score_max', Decimal('0')))),
('feedback', (('adj_min_score', 100), ('adj_max_score', 0))),
('draw_rules', (('draw_side_allocations', 'balance'), ('draw_odd_bracket', 'intermediate1'))),
('debate_rules', (('ballots_per_debate_prelim', 'per-adj'), ('teams_in_debate', 'bp'))),
Expand Down
Loading

0 comments on commit 09201fc

Please sign in to comment.