From 930fec413fbdbc9dae8889fc1ada65f39daf3047 Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Mon, 10 Jun 2024 16:02:31 +0200 Subject: [PATCH 1/6] fix: check that sections have groups ['1','2'] --- backend/experiment/rules/toontjehoger_1_mozart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/experiment/rules/toontjehoger_1_mozart.py b/backend/experiment/rules/toontjehoger_1_mozart.py index 68072134b..d4d5a05f7 100644 --- a/backend/experiment/rules/toontjehoger_1_mozart.py +++ b/backend/experiment/rules/toontjehoger_1_mozart.py @@ -253,7 +253,7 @@ def validate_playlist(self, playlist: Playlist): errors.append("The sections should have different groups") # Check if sections have group 1 and 2 - if not (1 in groups and 2 in groups): + if sorted(groups) != ['1', '2']: errors.append("The sections should have groups 1 and 2") return errors From 905411eabf71d174b087304717a26872fe677fce Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 11 Jun 2024 16:12:50 +0200 Subject: [PATCH 2/6] fix: correct preverbal playlist validation --- backend/experiment/rules/toontjehoger_2_preverbal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/experiment/rules/toontjehoger_2_preverbal.py b/backend/experiment/rules/toontjehoger_2_preverbal.py index 9c7c6b3e4..36a6306ba 100644 --- a/backend/experiment/rules/toontjehoger_2_preverbal.py +++ b/backend/experiment/rules/toontjehoger_2_preverbal.py @@ -40,7 +40,7 @@ def validate_playlist(self, playlist: Playlist): if first_round_sections.count() != 3: errors.append( 'There should be 3 sections with group 1 (first round)') - if sorted(first_round_sections.values('tag').distinct()) != ['a', 'b', 'c']: + if sorted(first_round_sections.values_list('tag', flat=True).distinct()) != ['a', 'b', 'c']: errors.append( 'The first round sections should have tags a, b, c' ) @@ -49,7 +49,7 @@ def validate_playlist(self, playlist: Playlist): if second_round_sections.count() != 2: errors.append( 'There should be 2 sections with group 2 (second round)') - if sorted(second_round_sections.values('tag').distinct()) != ['a', 'b']: + if sorted(second_round_sections.values_list('tag', flat=True).distinct()) != ['a', 'b']: errors.append( 'The second round sections should have tags a, b' ) From ea8c31680c3e2d56a7ebad69dfb448c0fa203eac Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 11 Jun 2024 16:18:41 +0200 Subject: [PATCH 3/6] fix: override `validate_era_and_mood` in thk plink --- backend/experiment/rules/toontjehoger_3_plink.py | 5 +++-- backend/experiment/rules/toontjehogerkids_3_plink.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/experiment/rules/toontjehoger_3_plink.py b/backend/experiment/rules/toontjehoger_3_plink.py index 16cee8099..d972b722e 100644 --- a/backend/experiment/rules/toontjehoger_3_plink.py +++ b/backend/experiment/rules/toontjehoger_3_plink.py @@ -43,10 +43,11 @@ def validate_playlist(self, playlist: Playlist): 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) + errors += self.validate_era_and_mood(sections) return errors - def validate_era_and_mood(self, sections, 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): diff --git a/backend/experiment/rules/toontjehogerkids_3_plink.py b/backend/experiment/rules/toontjehogerkids_3_plink.py index b84f74c5f..0a925536c 100644 --- a/backend/experiment/rules/toontjehogerkids_3_plink.py +++ b/backend/experiment/rules/toontjehogerkids_3_plink.py @@ -24,6 +24,9 @@ class ToontjeHogerKids3Plink(ToontjeHoger3Plink): SCORE_EXTRA_2_CORRECT = 4 SCORE_EXTRA_WRONG = 0 + def validate_era_and_mood(self, sections): + return [] + def first_round(self, experiment): """Create data for the first experiment rounds.""" From 46a1fd9924f8e71b72d231825ece69afe19d0d4d Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 11 Jun 2024 16:39:09 +0200 Subject: [PATCH 4/6] fix: toontjehoger4 playlist validation and kids version override --- backend/experiment/rules/toontjehoger_4_absolute.py | 5 +++-- backend/experiment/rules/toontjehogerkids_4_absolute.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/experiment/rules/toontjehoger_4_absolute.py b/backend/experiment/rules/toontjehoger_4_absolute.py index 53b6dacdf..6e44242a2 100644 --- a/backend/experiment/rules/toontjehoger_4_absolute.py +++ b/backend/experiment/rules/toontjehoger_4_absolute.py @@ -199,7 +199,7 @@ def validate_playlist_groups(self, groups): # Check if the groups are sequential and unique integer_groups.sort() if integer_groups != list(range(1, len(groups) + 1)): - return ['Groups in playlist sections should be sequential numbers starting from 1 to the number of sections in the playlist ({}). E.g. "1, 2, 3, ... {}"'.format(len(groups), len(groups))] + return ['Groups in playlist sections should be sequential numbers starting from 1 to the number of test items ({}). E.g. "1, 2, 3, ... {}"'.format(self.PLAYLIST_ITEMS, self.PLAYLIST_ITEMS)] return [] @@ -207,7 +207,8 @@ def validate_playlist(self, playlist: Playlist): errors = super().validate_playlist(playlist) # Get group values from sections, ordered by group - groups = list(playlist.section_set.values_list('group', flat=True)) + groups = list(playlist.section_set.values_list( + 'group', flat=True).distinct()) # Check if the groups are sequential and unique errors += self.validate_playlist_groups(groups) diff --git a/backend/experiment/rules/toontjehogerkids_4_absolute.py b/backend/experiment/rules/toontjehogerkids_4_absolute.py index b6ecad857..accce19f2 100644 --- a/backend/experiment/rules/toontjehogerkids_4_absolute.py +++ b/backend/experiment/rules/toontjehogerkids_4_absolute.py @@ -7,7 +7,7 @@ class ToontjeHogerKids4Absolute(ToontjeHoger4Absolute): ID = 'TOONTJE_HOGER_KIDS_4_ABSOLUTE' - PLAYLIST_ITEMS = 13 + PLAYLIST_ITEMS = 12 def first_round(self, experiment): """Create data for the first experiment rounds.""" From 1a1071ffd4972678f42d1df25b35cdc39cb638dc Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 11 Jun 2024 16:51:43 +0200 Subject: [PATCH 5/6] fix: simplify section selection and feedback thk tempo --- .../rules/toontjehogerkids_5_tempo.py | 85 +++---------------- 1 file changed, 14 insertions(+), 71 deletions(-) diff --git a/backend/experiment/rules/toontjehogerkids_5_tempo.py b/backend/experiment/rules/toontjehogerkids_5_tempo.py index f74cb0053..d192c7540 100644 --- a/backend/experiment/rules/toontjehogerkids_5_tempo.py +++ b/backend/experiment/rules/toontjehogerkids_5_tempo.py @@ -37,84 +37,37 @@ def first_round(self, experiment): def get_random_section_pair(self, session, genre): """ - session: current Session - - genre: (C)lassic (J)azz (R)ock - - Voor de track: genereer drie random integers van 1-5 (bijv. [4 2 4]) - Plak deze aan de letters C, J en R (bijv. [C4, J2, R4]) - Voor het paar: genereer drie random integers van 1-2 (bijv. [1 2 2]) - Plak deze aan de letter P (bijv. P1, P2, P2) - We willen zowel de originele als de veranderde versie van het paar. Dus combineer - bovenstaande met OR en CH (bijv. “C4_P1_OR”, “C4_P1_CH”, etc.) + - genre: unused + + return a section from an unused song, in both its original and changed variant """ - # Previous tags - previous_tags = [ - result.section.tag for result in session.result_set.all()] - - # Get a random, unused track - # Loop until there is a valid tag - iterations = 0 - valid_tag = False - tag_base = "" - tag_original = "" - 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, ) - tag_original = tag_base + "OR" - if not (tag_original in previous_tags): - valid_tag = True - - # Failsafe: prevent infinite loop - # If this happens, just reuse a track - iterations += 1 - if iterations > 10: - valid_tag = True - - tag_changed = tag_base + "CH" - - section_original = session.section_from_any_song( - filter_by={'tag': tag_original, 'group': "or"}) + + section_original = session.section_from_unused_song( + filter_by={'group': "or"}) if not section_original: raise Exception( "Error: could not find original section: {}".format(tag_original)) section_changed = self.get_section_changed( - session=session, tag=tag_changed) + session=session, song=section_original.song) sections = [section_original, section_changed] random.shuffle(sections) return sections - def get_section_changed(self, session, tag): - section_changed = session.section_from_any_song( - filter_by={'tag': tag, 'group': "ch"}) + def get_section_changed(self, session, song): + section_changed = session.playlist.section_set.get( + song__name=song.name, song__artist=song.artist, group='ch' + ) if not section_changed: raise Exception( - "Error: could not find changed section: {}".format(tag)) + "Error: could not find changed section: {}".format(song)) return section_changed def get_trial_question(self): return "Kan jij horen waar de klikjes goed bij de maat van de muziek passen?" - def get_section_pair_from_result(self, result): - section_original = result.section - - if section_original is None: - raise Exception( - "Error: could not get section from result") - - tag_changed = section_original.tag.replace("OR", "CH") - section_changed = self.get_section_changed( - session=result.session, tag=tag_changed) - - if section_changed is None: - raise Exception( - "Error: could not get changed section for tag: {}".format( - tag_changed)) - - return (section_original, section_changed) - def get_score(self, session): # Feedback last_result = session.last_result() @@ -130,20 +83,10 @@ def get_score(self, session): feedback = "Helaas! Het juiste antwoord was {}.".format( last_result.expected_response.upper()) - section_original, section_changed = self.get_section_pair_from_result( - last_result) - # Create feedback message # - Track names are always the same - # - Artist could be different - if section_original.song.artist == section_changed.song.artist: - feedback += " Je hoorde {}, in beide fragmenten uitgevoerd door {}.".format( - last_result.section.song.name, last_result.section.song.artist) - else: - section_a = section_original if last_result.expected_response == "A" else section_changed - section_b = section_changed if section_a.id == section_original.id else section_original - feedback += " Je hoorde {} uitgevoerd door A) {} en B) {}.".format( - section_a.song.name, non_breaking_spaces(section_a.song.artist), non_breaking_spaces(section_b.song.artist)) + feedback += " Je hoorde '{}' van {}.".format( + last_result.section.song.name, last_result.section.song.artist) # Return score view config = {'show_total_score': True} From 70b75314e6b1f0a8059ddbb1a5d480ba1a8e6276 Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 11 Jun 2024 17:26:56 +0200 Subject: [PATCH 6/6] fix unit test --- .../experiment/rules/tests/test_toontjehoger_4_absolute.py | 4 ++-- backend/experiment/rules/toontjehoger_4_absolute.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py b/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py index 8f8871b35..df23a476a 100644 --- a/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py +++ b/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py @@ -62,7 +62,7 @@ def test_validate_invalid_integer_groups(self): self.assertEqual( toontje_hoger_4_absolute.validate_playlist(playlist), - ["Groups in playlist sections should be numbers. This playlist has groups: ['a', '2', '4', '4', '11', '7']"] + ["Groups in playlist sections should be numbers. This playlist has groups: ['11', '2', '4', '7', 'a']"] ) def test_validate_invalid_sequential_groups(self): @@ -82,7 +82,7 @@ def test_validate_invalid_sequential_groups(self): self.assertEqual( toontje_hoger_4_absolute.validate_playlist(playlist), - ['Groups in playlist sections should be sequential numbers starting from 1 to the number of sections in the playlist (6). E.g. "1, 2, 3, ... 6"'] + ['Groups in playlist sections should be sequential numbers starting from 1 to the number of items in the playlist (13). E.g. "1, 2, 3, ... 13"'] ) def test_validate_invalid_tags(self): diff --git a/backend/experiment/rules/toontjehoger_4_absolute.py b/backend/experiment/rules/toontjehoger_4_absolute.py index 6e44242a2..b875c95ab 100644 --- a/backend/experiment/rules/toontjehoger_4_absolute.py +++ b/backend/experiment/rules/toontjehoger_4_absolute.py @@ -199,7 +199,7 @@ def validate_playlist_groups(self, groups): # Check if the groups are sequential and unique integer_groups.sort() if integer_groups != list(range(1, len(groups) + 1)): - return ['Groups in playlist sections should be sequential numbers starting from 1 to the number of test items ({}). E.g. "1, 2, 3, ... {}"'.format(self.PLAYLIST_ITEMS, self.PLAYLIST_ITEMS)] + return ['Groups in playlist sections should be sequential numbers starting from 1 to the number of items in the playlist ({}). E.g. "1, 2, 3, ... {}"'.format(self.PLAYLIST_ITEMS, self.PLAYLIST_ITEMS)] return []