Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/teletunes questions #678

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/experiment/actions/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os.path import join
import random

from django.conf import settings
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -88,3 +89,6 @@ def get_last_n_turnpoints(session, num_turnpoints):
all_results = session.result_set.filter(comment__iendswith='turnpoint').order_by('-created_at').all()
cutoff = min(all_results.count(), num_turnpoints)
return all_results[:cutoff]

def randomize_playhead(min_jitter, max_jitter, silence_time, continuation_correctness):
return silence_time + (random.uniform(min_jitter, max_jitter) if not continuation_correctness else 0)
3 changes: 2 additions & 1 deletion backend/experiment/actions/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from result.utils import prepare_result

from experiment.actions.styles import STYLE_BOOLEAN_NEGATIVE_FIRST
from experiment.actions.utils import randomize_playhead


def two_alternative_forced(session, section, choices, expected_response=None, style={}, comment='', scoring_rule=None, title='', config=None):
Expand Down Expand Up @@ -103,7 +104,7 @@ def song_sync(session, section, title, play_method='BUFFER',
'Did the track come back in the right place?'),
play_config={
'ready_time': 0,
'playhead': silence_time + (random.uniform(min_jitter, max_jitter) if not continuation_correctness else 0),
'playhead': randomize_playhead(min_jitter, max_jitter, silence_time, continuation_correctness),
'show_animation': True,
'resume_play': True
}),
Expand Down
12 changes: 12 additions & 0 deletions backend/experiment/rules/tele_tunes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from experiment.questions.musicgens import MUSICGENS_17_W_VARIANTS
from experiment.questions.demographics import DEMOGRAPHICS
from experiment.questions.utils import copy_shuffle
from .hooked import Hooked


Expand All @@ -11,3 +14,12 @@ class HookedTeleTunes(Hooked):
min_jitter = 5
max_jitter = 10
consent_file = 'consent_teletunes.html'

def __init__(self):
self.questions = [
# 1. Demographic questions (7 questions)
*copy_shuffle(DEMOGRAPHICS),
# 2. Musicgens questions with variants
*copy_shuffle(MUSICGENS_17_W_VARIANTS)
]

14 changes: 14 additions & 0 deletions backend/experiment/tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.test import TestCase

from experiment.actions.utils import randomize_playhead

class TestActions(TestCase):

def test_randomize_playhead(self):
silence_time = 4
min_jitter = 5
max_jitter = 10
unjittered_playhead = randomize_playhead(min_jitter, max_jitter, silence_time, True)
assert unjittered_playhead == silence_time
jittered_playhead = randomize_playhead(min_jitter, max_jitter, silence_time, False)
assert jittered_playhead >= silence_time + min_jitter
Loading