Skip to content

Commit

Permalink
Merge pull request #1209 from Amsterdam-Music-Lab/feature/cleanup-rou…
Browse files Browse the repository at this point in the history
…nd-getters

Feature/cleanup round getters
  • Loading branch information
BeritJanssen authored Aug 9, 2024
2 parents 689ccfb + 6bf0710 commit 71ca8b7
Show file tree
Hide file tree
Showing 32 changed files with 328 additions and 526 deletions.
4 changes: 2 additions & 2 deletions backend/experiment/actions/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(self, session, title: str = None, score=None, score_message=None, c
- feedback: An additional feedback text
"""
self.session = session
self.title = title or _('Round {rounds_passed} / {total_rounds}').format(
rounds_passed=session.rounds_passed(),
self.title = title or _('Round {get_rounds_passed} / {total_rounds}').format(
get_rounds_passed=session.get_rounds_passed(),
total_rounds=self.session.block.rounds
)
self.score = score or session.last_score()
Expand Down
2 changes: 1 addition & 1 deletion backend/experiment/actions/tests/test_actions_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setUp(self):
self.mock_session.last_score.return_value = 10
self.mock_session.last_song.return_value = "Test Song"
self.mock_session.total_score.return_value = 50
self.mock_session.rounds_passed.return_value = 2
self.mock_session.get_rounds_passed.return_value = 2
self.mock_session.block.rounds = 5

def test_initialization_full_parameters(self):
Expand Down
1 change: 1 addition & 0 deletions backend/experiment/rules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Base(object):
"""Base class for other rules classes"""

contact_email = settings.CONTACT_MAIL
counted_result_keys = []

def __init__(self):
self.question_series = []
Expand Down
3 changes: 0 additions & 3 deletions backend/experiment/rules/beat_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ def next_round(self, session):
final_text = render_feedback_trivia(feedback, trivia)
return final_action_with_optional_button(session, final_text)

# Next round number, can be used to return different actions
next_round_number = session.get_next_round()

# Practice rounds
if not session.load_json_data().get('done_practice'):
practice_rounds = []
Expand Down
26 changes: 13 additions & 13 deletions backend/experiment/rules/categorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def next_round(self, session):
return final

# Calculate round number from passed training rounds
rounds_passed = (session.rounds_passed() -
get_rounds_passed = (session.get_rounds_passed() -
int(json_data['training_rounds']))
# Change phase to enable collecting results of second half of training-1
if session.rounds_passed() == 10:
if session.get_rounds_passed() == 10:
json_data['phase'] = 'training-1B'
session.save_json_data(json_data)
session.save()

if rounds_passed == 0:
if get_rounds_passed == 0:
# Check if participants wants to exit after failed traning
profiles = session.participant.profile()
for profile in profiles:
Expand All @@ -110,7 +110,7 @@ def next_round(self, session):
json_data = self.plan_phase(session)

if 'training' in json_data['phase']:
if rounds_passed == 0:
if get_rounds_passed == 0:
explainer2 = Explainer(
instruction="The experiment will now begin. Please don't close the browser during the experiment. You can only run it once. Click to start a sound sequence.",
steps=[],
Expand All @@ -120,7 +120,7 @@ def next_round(self, session):
return [explainer2, trial]

# Get next training action
elif rounds_passed < len(json_data['sequence']):
elif get_rounds_passed < len(json_data['sequence']):
return self.get_trial_with_feedback(session)

# Training phase completed, get the results
Expand All @@ -138,7 +138,7 @@ def next_round(self, session):
# End of training?
if score_avg >= SCORE_AVG_MIN_TRAINING:
json_data['phase'] = "testing"
json_data['training_rounds'] = session.rounds_passed()
json_data['training_rounds'] = session.get_rounds_passed()
session.save_json_data(json_data)
session.save()
explainer = Explainer(
Expand All @@ -148,7 +148,7 @@ def next_round(self, session):
)
else:
# Update passed training rounds for calc round_number
json_data['training_rounds'] = session.rounds_passed()
json_data['training_rounds'] = session.get_rounds_passed()
session.save_json_data(json_data)
session.save()

Expand Down Expand Up @@ -186,9 +186,9 @@ def next_round(self, session):
return [feedback, explainer]

elif json_data['phase'] == 'testing':
if rounds_passed < len(json_data['sequence']):
if get_rounds_passed < len(json_data['sequence']):
# Determine wether this round has feedback
if rounds_passed in json_data['feedback_sequence']:
if get_rounds_passed in json_data['feedback_sequence']:
return self.get_trial_with_feedback(session)
return self.next_trial_action(session)

Expand Down Expand Up @@ -470,10 +470,10 @@ def next_trial_action(self, session):
json_data = session.load_json_data()

# Retrieve next section in the sequence
rounds_passed = (session.rounds_passed() -
get_rounds_passed = (session.get_rounds_passed() -
int(json_data['training_rounds']))
sequence = json_data['sequence']
this_section = sequence[rounds_passed]
this_section = sequence[get_rounds_passed]
section = session.playlist.get_section(song_ids=[this_section])
# Determine expected response
if section.tag == '1A' or section.tag == '2A':
Expand All @@ -494,9 +494,9 @@ def next_trial_action(self, session):

def get_title(self, session):
json_data = session.load_json_data()
rounds_passed = (session.rounds_passed() -
get_rounds_passed = (session.get_rounds_passed() -
int(json_data['training_rounds'])+1)
return f"Round {rounds_passed} / {len(json_data['sequence'])}"
return f"Round {get_rounds_passed} / {len(json_data['sequence'])}"


repeat_training_or_quit = ChoiceQuestion(
Expand Down
Loading

0 comments on commit 71ca8b7

Please sign in to comment.