Skip to content

Commit

Permalink
Merge pull request #1084 from Amsterdam-Music-Lab/feature/validate-plink
Browse files Browse the repository at this point in the history
TH3: add Plink validation
  • Loading branch information
BeritJanssen authored Jun 11, 2024
2 parents a18ad9b + 0566048 commit 418748b
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions backend/experiment/rules/toontjehoger_3_plink.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import logging
from os.path import join
import re

from django.template.loader import render_to_string

from .toontjehoger_1_mozart import toontjehoger_ranks
from experiment.actions import Explainer, Step, Score, Final, Playlist, Info, Trial
from experiment.actions.playback import PlayButton
from experiment.actions.form import AutoCompleteQuestion, RadiosQuestion, Form
from .base import Base

from experiment.utils import non_breaking_spaces

from result.utils import prepare_result
from section.models import Playlist

logger = logging.getLogger(__name__)

Expand All @@ -24,6 +25,41 @@ class ToontjeHoger3Plink(Base):
SCORE_EXTRA_2_CORRECT = 4
SCORE_EXTRA_WRONG = 0

def validate_playlist(self, playlist: Playlist):
""" The original Toontjehoger (Plink) playlist has the following format:
```
Billy Joel,Piano Man,0.0,1.0,toontjehoger/plink/2021-005.mp3,70s,vrolijk
Boudewijn de Groot,Avond,0.0,1.0,toontjehoger/plink/2021-010.mp3,90s,tederheid
Bruce Springsteen,The River,0.0,1.0,toontjehoger/plink/2021-016.mp3,80s,droevig
```
"""
errors = []
sections = playlist.section_set.all()
if not [s.song for s in sections]:
errors.append(
'Sections should have associated song objects.')
artist_titles = sections.values_list(
'song__name', 'song__artist').distinct()
if len(artist_titles) != len(sections):
errors.append(
'Sections should have unique combinations of song.artist and song.name fields.')
self.validate_era_and_mood(sections, errors)
return errors

def validate_era_and_mood(self, sections, errors):
eras = sorted(sections.order_by('tag').values_list(
'tag', flat=True).distinct())
if not all(re.match(r'[0-9]0s', e) for e in eras):
errors.append(
'The sections should be tagged with an era in the format [0-9]0s, e.g., 90s')
moods = sorted(sections.order_by('group').values_list(
'group', flat=True).distinct())
if 'droevig' not in moods:
errors.append(
"The sections' groups should be indications of the songs' moods in Dutch"
)
return errors

def first_round(self, experiment):
"""Create data for the first experiment rounds."""

Expand Down Expand Up @@ -206,7 +242,7 @@ def get_era_question(self, session, section):
'era',
session,
section=section,
expected_response=section.group.split(';')[0]
expected_response=section.tag
)
)

Expand All @@ -228,7 +264,7 @@ def get_emotion_question(self, session, section):
'emotion',
session,
section=section,
expected_response=section.group.split(';')[1]
expected_response=section.group
)
)

Expand Down

0 comments on commit 418748b

Please sign in to comment.