From 31c866ca3b316f05d2f0df5fc459d06dce649046 Mon Sep 17 00:00:00 2001 From: Drikus Roor Date: Fri, 7 Jun 2024 13:17:42 +0200 Subject: [PATCH] feat: Add playlist group validation to ToontjeHoger5Tempo rule --- backend/experiment/rules/toontjehoger_5_tempo.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/experiment/rules/toontjehoger_5_tempo.py b/backend/experiment/rules/toontjehoger_5_tempo.py index f7cc97452..84d6ad465 100644 --- a/backend/experiment/rules/toontjehoger_5_tempo.py +++ b/backend/experiment/rules/toontjehoger_5_tempo.py @@ -8,6 +8,7 @@ from experiment.actions.frontend_style import FrontendStyle, EFrontendStyle from experiment.actions.playback import Multiplayer from experiment.actions.styles import STYLE_NEUTRAL_INVERTED +from section.models import Playlist from .base import Base from experiment.utils import create_player_labels, non_breaking_spaces @@ -83,7 +84,7 @@ def get_random_section_pair(self, session, genre): valid_tag = False tag_base = "" tag_original = "" - while(not valid_tag): + while (not valid_tag): track = random.choice([1, 2, 3, 4, 5]) pair = random.choice([1, 2]) tag_base = "{}{}_P{}_".format(genre.upper(), track, pair, ) @@ -253,3 +254,16 @@ def get_final_round(self, session): ) return [*score, final, info] + + def validate_playlist(self, playlist: Playlist): + + errors = super().validate_playlist(playlist) + sections = playlist.section_set.all() + groups = sorted(list(set([section.group for section in sections]))) + + if groups != ['ch', 'or']: + errors.append( + "The playlist must contain two groups: 'or' and 'ch'. Found: {}".format(groups) + ) + + return errors