Skip to content

Commit

Permalink
correct offsets for round indications; fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BeritJanssen committed Nov 28, 2023
1 parent 70918d7 commit 7a9ebe4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 34 deletions.
10 changes: 5 additions & 5 deletions backend/experiment/rules/eurovision_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def next_heard_before_action(self, session):
# Get section.
section = None
if round_number <= len(songs) and round_number <= len(tags):
section = \
session.playlist.get_section(
{'tag': str(tags[round_number])},
[songs[round_number]]
)
section = session.playlist.get_section(
{'tag': str(tags[round_number])},
[songs[round_number]]
)

if not section:
print("Warning: no heard_before section found")
section = session.playlist.get_section()
Expand Down
28 changes: 12 additions & 16 deletions backend/experiment/rules/hooked.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,18 @@ def final_score_message(self, session):
n_old_new_correct = 0

for result in session.result_set.all():
json_data = result.load_json_data()
try:
if json_data['view'] == 'SONG_SYNC':
if json_data['result']['type'] == 'recognized':
n_sync_guessed += 1
sync_time += json_data['result']['recognition_time']
if result.score > 0:
n_sync_correct += 1
else:
if result.expected_response == 'old':
n_old_new_expected += 1
if result.score > 0:
n_old_new_correct += 1
except KeyError as error:
print('KeyError: %s' % str(error))
continue
if result.question_key == 'recognize':
if result.given_response == 'yes':
n_sync_guessed += 1
json_data = result.load_json_data()
sync_time += json_data.get('decision_time')
if result.score > 0:
n_sync_correct += 1
else:
if result.expected_response == 'old':
n_old_new_expected += 1
if result.score > 0:
n_old_new_correct += 1

score_message = "Well done!" if session.final_score > 0 else "Too bad!"
if n_sync_guessed == 0:
Expand Down
11 changes: 4 additions & 7 deletions backend/experiment/rules/huang_2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def next_round(self, session):
else:
# Load the heard_before offset.

heard_before_offset = len(plan['song_sync_sections']) + 1
heard_before_offset = len(plan['song_sync_sections'])

# show score
score = self.get_score(session, round_number)
Expand All @@ -163,10 +163,10 @@ def next_round(self, session):
actions.append(self.heard_before_explainer())
actions.append(
self.next_heard_before_action(session))
elif heard_before_offset < round_number <= total_rounds:
elif heard_before_offset < round_number < total_rounds:
actions.append(
self.next_heard_before_action(session))
elif round_number == total_rounds + 1:
else:
questionnaire = self.get_questionnaire(session)
if questionnaire:
actions.extend([Explainer(
Expand All @@ -175,11 +175,8 @@ def next_round(self, session):
steps=[],
step_numbers=True,
button_label=_("Let's go!")), *questionnaire])
session.increment_round()
else:
actions.append(self.finalize(session))
else:
return [self.finalize(session)]
return [self.finalize(session)]
return actions

def finalize(self, session):
Expand Down
7 changes: 3 additions & 4 deletions backend/experiment/rules/tests/test_hooked.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_thats_my_song(self):

for i in range(0, experiment.rounds):
actions = rules.next_round(session)
if i == experiment.rounds:
if i == experiment.rounds + 1:
assert len(actions) == 2
assert actions[1].ID == 'FINAL'
elif i == 0:
Expand Down Expand Up @@ -113,9 +113,8 @@ def test_thats_my_song(self):
assert actions[2].feedback_form.form[0].key == 'heard_before'
else:
assert len(actions) == 3
assert actions[1].feedback_form.form[0].key == 'heard_before'
assert actions[2].feedback_form.form[0].key in musicgen_keys
session.increment_round()
assert actions[1].feedback_form.form[0].key in musicgen_keys
assert actions[2].feedback_form.form[0].key == 'heard_before'

def test_hooked_china(self):
experiment = Experiment.objects.get(name='Hooked-China')
Expand Down
4 changes: 2 additions & 2 deletions backend/experiment/rules/thats_my_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def next_round(self, session):

# If the number of results equals the number of experiment.rounds,
# close the session and return data for the final_score view.
if round_number == session.experiment.rounds:
if round_number == session.experiment.rounds + self.round_modifier:

# Finish session.
session.finish()
Expand All @@ -73,7 +73,7 @@ def next_round(self, session):
# Return a score and final score action.
social_info = self.social_media_info(session.experiment, session.final_score)
return [
self.get_score(session, round_number),
self.get_score(session, round_number - self.round_modifier),
Final(
session=session,
final_text=self.final_score_message(session) + " For more information about this experiment, visit the Vanderbilt University Medical Center Music Cognition Lab.",
Expand Down

0 comments on commit 7a9ebe4

Please sign in to comment.