Skip to content

Commit

Permalink
Merge pull request #1085 from Amsterdam-Music-Lab/fix/question-models
Browse files Browse the repository at this point in the history
Fix: Teletunes questions import and circular import
  • Loading branch information
BeritJanssen authored Jun 10, 2024
2 parents 295a3ff + 2c08c0c commit a0f0a9c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 32 deletions.
6 changes: 2 additions & 4 deletions backend/experiment/rules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
from django.core.exceptions import ValidationError

from experiment.actions import Final, Form, Trial
from question.demographics import DEMOGRAPHICS
from question.utils import unanswered_questions
from section.models import Playlist
from question.questions import get_questions_from_series, QUESTION_GROUPS
from result.score import SCORING_RULES
from section.models import Playlist
from session.models import Session

from question.questions import get_questions_from_series, QUESTION_GROUPS

logger = logging.getLogger(__name__)


Expand Down
9 changes: 1 addition & 8 deletions backend/experiment/rules/hooked.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@
from experiment.actions import Consent, Explainer, Final, Playlist, Score, Step, Trial
from experiment.actions.form import BooleanQuestion, Form
from experiment.actions.playback import Autoplay
from question.questions import QUESTION_GROUPS
from question.demographics import DEMOGRAPHICS
from question.goldsmiths import MSI_OTHER
from question.utils import question_by_key
from question.utils import copy_shuffle
from question.goldsmiths import MSI_FG_GENERAL, MSI_ALL
from question.stomp import STOMP20
from question.tipi import TIPI
from experiment.actions.styles import STYLE_BOOLEAN_NEGATIVE_FIRST
from experiment.actions.wrappers import song_sync
from question.questions import QUESTION_GROUPS
from result.utils import prepare_result


Expand Down
6 changes: 1 addition & 5 deletions backend/experiment/rules/huang_2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
from experiment.actions import HTML, Final, Explainer, Step, Consent, Redirect, Playlist, Trial
from experiment.actions.form import BooleanQuestion, Form
from experiment.actions.playback import Autoplay
from question.demographics import EXTRA_DEMOGRAPHICS
from question.goldsmiths import MSI_ALL, MSI_OTHER
from question.other import OTHER
from question.utils import question_by_key
from question.questions import QUESTION_GROUPS
from experiment.actions.styles import STYLE_BOOLEAN_NEGATIVE_FIRST
from question.questions import QUESTION_GROUPS
from result.utils import prepare_result
from .hooked import Hooked

Expand Down
4 changes: 1 addition & 3 deletions backend/experiment/rules/tele_tunes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from question.musicgens import MUSICGENS_17_W_VARIANTS
from question.demographics import DEMOGRAPHICS
from question.utils import copy_shuffle
from question.questions import QUESTION_GROUPS
from .hooked import Hooked


Expand Down
4 changes: 1 addition & 3 deletions backend/experiment/rules/thats_my_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

from experiment.actions import Final, Trial
from experiment.actions.form import Form, ChoiceQuestion
from question.utils import copy_shuffle, question_by_key
from question.musicgens import MUSICGENS_17_W_VARIANTS
from question.questions import QUESTION_GROUPS
from .hooked import Hooked
from result.utils import prepare_result
from .hooked import Hooked


class ThatsMySong(Hooked):
Expand Down
13 changes: 8 additions & 5 deletions backend/question/demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from experiment.standards.iso_countries import ISO_COUNTRIES
from experiment.standards.iso_languages import ISO_LANGUAGES
from experiment.standards.isced_education import ISCED_EDUCATION_LEVELS
from .utils import question_by_key


ATTAINED_EDUCATION_CHOICES = dict(
ISCED_EDUCATION_LEVELS,
Expand Down Expand Up @@ -148,19 +150,20 @@


def demographics_other():
from .utils import question_by_key

questions = []

question = question_by_key('dgf_education', drop_choices=['isced-2', 'isced-5'])
question = question_by_key('dgf_education', DEMOGRAPHICS, drop_choices=[
'isced-2', 'isced-5'])
question.key = 'dgf_education_matching_pairs'
questions.append(question)

question = question_by_key('dgf_education', drop_choices=['isced-1'])
question = question_by_key(
'dgf_education', DEMOGRAPHICS, drop_choices=['isced-1'])
question.key = 'dgf_education_gold_msi'
questions.append(question)

question = question_by_key('dgf_education', drop_choices=['isced-5'])
question = question_by_key(
'dgf_education', DEMOGRAPHICS, drop_choices=['isced-5'])
question.key = 'dgf_education_huang_2022'
questions.append(question)

Expand Down
6 changes: 2 additions & 4 deletions backend/question/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@

from result.utils import prepare_profile_result

from .demographics import DEMOGRAPHICS


def copy_shuffle(questions):
qcopy = deepcopy(questions)
random.shuffle(qcopy)
return qcopy


def total_unanswered_questions(participant, questions=DEMOGRAPHICS):
def total_unanswered_questions(participant, questions):
""" Return how many questions have not been answered yet by the participant"""
profile_questions = participant.profile().values_list('question_key', flat=True)
return len([question for question in questions if question.key not in profile_questions])


def question_by_key(key, questions=DEMOGRAPHICS, is_skippable=None, drop_choices=[]):
def question_by_key(key, questions, is_skippable=None, drop_choices=[]):
"""Return question by given key"""
for question in questions:
if question.key == key:
Expand Down

0 comments on commit a0f0a9c

Please sign in to comment.