Skip to content

Commit

Permalink
Merge pull request #1167 from Amsterdam-Music-Lab/feature/back-to-col…
Browse files Browse the repository at this point in the history
…lection

Feature/back to collection
  • Loading branch information
BeritJanssen authored Jul 9, 2024
2 parents aaa29b9 + 0c8ecc9 commit 6126239
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 1,009 deletions.
52 changes: 1 addition & 51 deletions README_TOONTJEHOGER.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
# ToontjeHoger

This repository contains the experiments for ToontjeHoger (2022), a website that shows music related research to a wider audience.

## Homepage

The ToontjeHoger homepage backend code can be found in:

```
backend/experiment/rules/toontjehoger_home.py
```

- To add/remove change experiments, update the contents of EXPERIMENT_DATA
- Note that the ToontjeHoger experiment slugs are hard coded here
- This file contains all textual content that is shown on the home/about page

It uses a custom experiment view which contains both the home and about page:

```
backend/experiment/rules/views/toontjehoger.py
```

With corresponding frontend view:

```
frontend/src/components/ToontjeHoger/ToontjeHoger.js
```

Styling for the home and about page, as well as the general ToontjeHoger experiments styling (e.g. background image) can be found in:

```
frontend/src/components/ToontjeHoger/ToontjeHoger.scss
```

### Experiment config
### Experiment config of ToontjeHoger experiments

Set the following experiment values in the admin:

Expand Down Expand Up @@ -89,22 +55,6 @@ backend/templates/info/toontjehoger/experiment5.html
backend/templates/info/toontjehoger/experiment6.html
```

## Environment

Use the following .env variables to configure your ToontjeHoger instance:

```
FRONTEND_EXPERIMENT_SLUG=toontjehoger
FRONTEND_AML_HOME=/toontjehoger
FRONTEND_LOGO_URL=/images/experiments/toontjehoger/logo-white.svg
FRONTEND_HTML_PAGE_TITLE=ToontjeHoger
FRONTEND_HTML_OG_DESCRIPTION=ToontjeHoger is een website met spelletjes die de luisteraar laat inzien dat zij muzikaler is dan je zou denken.
FRONTEND_HTML_OG_IMAGE=https://toontjehoger.changeme.example.com/images/og-hooked.jpg
FRONTEND_HTML_OG_TITLE=ToontjeHoger
FRONTEND_HTML_OG_URL=https://toontjehoger.changeme.example.com/
FRONTEND_HTML_BODY_CLASS=toontjehoger
```

## Playlists

Each experiment uses a playlist with additional information in the tag/group field.
Expand Down
1 change: 0 additions & 1 deletion backend/experiment/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
from .playlist import Playlist
from .redirect import Redirect
from .score import Score
from .toontjehoger import ToontjeHoger
from .trial import Trial
20 changes: 19 additions & 1 deletion backend/experiment/actions/tests/test_action_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
from django.test import TestCase

from experiment.actions.utils import randomize_playhead
from experiment.actions.utils import COLLECTION_KEY, get_current_collection_url, randomize_playhead
from experiment.models import Block
from participant.models import Participant
from section.models import Playlist
from session.models import Session


class TestActions(TestCase):

def setUp(self) -> None:
self.playlist = Playlist.objects.create(name='TestPlaylist')
self.participant = Participant.objects.create()
self.block = Block.objects.create(name='TestBlock')
self.session = Session.objects.create(
block=self.block, participant=self.participant, playlist=self.playlist)

def test_collection_url(self):
self.assertEqual(get_current_collection_url(self.session), None)
self.session.save_json_data({COLLECTION_KEY: 'superdupercollection'})
self.assertEqual(get_current_collection_url(self.session), '/collection/superdupercollection')
self.participant.participant_id_url = 'participant42'
self.assertEqual(get_current_collection_url(self.session), '/collection/superdupercollection?participant_id=participant42')

def test_randomize_playhead(self):
min_jitter = 5
max_jitter = 10
Expand Down
27 changes: 0 additions & 27 deletions backend/experiment/actions/toontjehoger.py

This file was deleted.

21 changes: 14 additions & 7 deletions backend/experiment/actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@
from django.template.loader import render_to_string

from experiment.actions import Final
from session.models import Session

COLLECTION_KEY = 'experiment_collection'


def final_action_with_optional_button(session, final_text='', title=_('End'), button_text=_('Continue')):
""" given a session, a score message and an optional session dictionary from an experiment collection,
return a Final.action, which has a button to continue to the next block if series is defined
"""
def get_current_collection_url(session: Session) -> str:
collection_slug = session.load_json_data().get(COLLECTION_KEY)
if not collection_slug:
return None

if session.participant.participant_id_url:
participant_id_url = session.participant.participant_id_url
redirect_url = f'/collection/{collection_slug}?participant_id_url={participant_id_url}'
return f'/collection/{collection_slug}?participant_id={participant_id_url}'
else:
redirect_url = f'/collection/{collection_slug}'
return f'/collection/{collection_slug}'


def final_action_with_optional_button(session, final_text='', title=_('End'), button_text=_('Continue')):
""" given a session, a score message and an optional session dictionary from an experiment collection,
return a Final.action, which has a button to continue to the next block if series is defined
"""
redirect_url = get_current_collection_url(session)

if collection_slug:
if redirect_url:
return Final(
title=title,
session=session,
Expand Down
2 changes: 0 additions & 2 deletions backend/experiment/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from .toontjehogerkids_4_absolute import ToontjeHogerKids4Absolute
from .toontjehogerkids_5_tempo import ToontjeHogerKids5Tempo
from .toontjehogerkids_6_relative import ToontjeHogerKids6Relative
from .toontjehoger_home import ToontjeHogerHome
from .visual_matching_pairs import VisualMatchingPairsGame

# Rules available to this application
Expand Down Expand Up @@ -74,7 +73,6 @@
ToontjeHoger4Absolute.ID: ToontjeHoger4Absolute,
ToontjeHoger5Tempo.ID: ToontjeHoger5Tempo,
ToontjeHoger6Relative.ID: ToontjeHoger6Relative,
ToontjeHogerHome.ID: ToontjeHogerHome,
ToontjeHogerKids1Mozart.ID: ToontjeHogerKids1Mozart,
ToontjeHogerKids2Preverbal.ID: ToontjeHogerKids2Preverbal,
ToontjeHogerKids3Plink.ID: ToontjeHogerKids3Plink,
Expand Down
3 changes: 2 additions & 1 deletion backend/experiment/rules/toontjehoger_1_mozart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from experiment.actions.styles import STYLE_TOONTJEHOGER
from .base import Base
from experiment.utils import non_breaking_spaces
from experiment.actions.utils import get_current_collection_url

from result.utils import prepare_result

Expand Down Expand Up @@ -232,7 +233,7 @@ def get_final_round(self, session):
body=body,
heading="Het Mozart effect",
button_label="Terug naar ToontjeHoger",
button_link="/collection/toontjehoger"
button_link=get_current_collection_url(session)
)

return [*answer_explainer, *score, final, info]
Expand Down
3 changes: 2 additions & 1 deletion backend/experiment/rules/toontjehoger_2_preverbal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from experiment.actions.playback import ImagePlayer
from experiment.actions.styles import STYLE_NEUTRAL_INVERTED
from experiment.actions.frontend_style import FrontendStyle, EFrontendStyle
from experiment.actions.utils import get_current_collection_url
from experiment.utils import create_player_labels
from .base import Base
from result.utils import prepare_result
Expand Down Expand Up @@ -290,7 +291,7 @@ def get_final_round(self, session):
body=body,
heading="Het eerste luisteren",
button_label="Terug naar ToontjeHoger",
button_link="/collection/toontjehoger"
button_link=get_current_collection_url(session)
)

return [*score, final, info]
3 changes: 2 additions & 1 deletion backend/experiment/rules/toontjehoger_3_plink.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from experiment.actions import Explainer, Step, Score, Final, Playlist, Info, Trial
from experiment.actions.playback import PlayButton
from experiment.actions.form import AutoCompleteQuestion, RadiosQuestion, Form
from experiment.actions.utils import get_current_collection_url
from .base import Base
from experiment.utils import non_breaking_spaces
from result.utils import prepare_result
Expand Down Expand Up @@ -311,7 +312,7 @@ def get_final_round(self, session):
body=body,
heading="Muziekherkenning",
button_label="Terug naar ToontjeHoger",
button_link="/collection/toontjehoger"
button_link=get_current_collection_url(session)
)

return [score, final, info]
3 changes: 2 additions & 1 deletion backend/experiment/rules/toontjehoger_4_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from experiment.actions.frontend_style import FrontendStyle, EFrontendStyle
from experiment.actions.playback import Multiplayer
from experiment.actions.styles import STYLE_NEUTRAL_INVERTED
from experiment.actions.utils import get_current_collection_url
from experiment.utils import create_player_labels
from .base import Base
from result.utils import prepare_result
Expand Down Expand Up @@ -182,7 +183,7 @@ def get_final_round(self, session):
body=body,
heading="Absoluut gehoor",
button_label="Terug naar ToontjeHoger",
button_link="/collection/toontjehoger"
button_link=get_current_collection_url(session)
)

return [*score, final, info]
Expand Down
3 changes: 2 additions & 1 deletion backend/experiment/rules/toontjehoger_5_tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from experiment.actions.frontend_style import FrontendStyle, EFrontendStyle
from experiment.actions.playback import Multiplayer
from experiment.actions.styles import STYLE_NEUTRAL_INVERTED
from experiment.actions.utils import get_current_collection_url
from section.models import Playlist
from .base import Base
from experiment.utils import create_player_labels, non_breaking_spaces
Expand Down Expand Up @@ -251,7 +252,7 @@ def get_final_round(self, session):
body=body,
heading="Timing en tempo",
button_label="Terug naar ToontjeHoger",
button_link="/collection/toontjehoger"
button_link=get_current_collection_url(session)
)

return [*score, final, info]
Expand Down
3 changes: 2 additions & 1 deletion backend/experiment/rules/toontjehoger_6_relative.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from experiment.actions.playback import Multiplayer
from experiment.actions.frontend_style import FrontendStyle, EFrontendStyle
from experiment.actions.styles import STYLE_BOOLEAN
from experiment.actions.utils import get_current_collection_url
from section.models import Playlist
from .base import Base
from .toontjehoger_1_mozart import toontjehoger_ranks
Expand Down Expand Up @@ -180,7 +181,7 @@ def get_final_round(self, session):
body=body,
heading="Relatief gehoor",
button_label="Terug naar ToontjeHoger",
button_link="/collection/toontjehoger"
button_link=get_current_collection_url(session)
)

return [*score, final, info]
Loading

0 comments on commit 6126239

Please sign in to comment.