Experiment actions
experiment.actions.base_action
BaseAction
Bases: object
base class for the experiment actions. Actions are used to configure components to be rendered on the frontend.
Source code in experiment/actions/base_action.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
action()
The action that can be sent to the frontend
Returns:
Name | Type | Description |
---|---|---|
action_dict |
dict
|
Frontend component configuration |
Source code in experiment/actions/base_action.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
experiment.actions.consent
Consent
Bases: BaseAction
Provide data for a view that ask consent for using the experiment data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
File
|
Uploaded file via an experiment’s translated content’s consent (fileField) |
required |
title |
str
|
The title to be displayed |
'Informed consent'
|
confirm |
str
|
The text on the confirm button |
'I agree'
|
deny |
str
|
The text on the deny button |
'Stop'
|
url |
str
|
If no text is provided the url will be used to load a template (HTML or MARKDOWN) HTML: (default) Allowed tags: html, django template language MARKDOWN: Allowed tags: Markdown language |
''
|
Note
Relates to client component: Consent.js
Source code in experiment/actions/consent.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
get_render_format(url)
Detect markdown file based on file extension
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Url of the consent file |
required |
Returns:
Type | Description |
---|---|
str
|
File format |
Source code in experiment/actions/consent.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
render_html_or_markdown(dry_text, render_format)
render html or markdown
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dry_text |
str
|
contents of a markdown or html file |
required |
render_format |
str
|
type of contents, either ‘HTML’ or ‘MARKDOWN’ |
required |
Returns:
Type | Description |
---|---|
str
|
Content rendered to html |
Source code in experiment/actions/consent.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
experiment.actions.explainer
Explainer
Bases: BaseAction
Provide data for a explainer that explains the experiment steps
Relates to client component: Explainer.js
Explainer view automatically proceeds to the following view after timer (in ms) expires. If timer=None, explainer view will proceed to the next view only after a click of a button. Intro explainers should always have timer=None (i.e. interaction with a browser is required), otherwise the browser will not autoplay the first segment.
Source code in experiment/actions/explainer.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
action()
Get data for explainer action
Source code in experiment/actions/explainer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Step
Bases: object
Source code in experiment/actions/explainer.py
37 38 39 40 41 42 43 44 45 46 47 48 |
|
action(number=None)
Create an explainer step, with description and optional number
Source code in experiment/actions/explainer.py
43 44 45 46 47 48 |
|
experiment.actions.final
Final
Bases: BaseAction
Provide data for a final view
Relates to client component: Final.js
Source code in experiment/actions/final.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
action()
Get data for final action
Source code in experiment/actions/final.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
experiment.actions.form
Form
Bases: BaseAction
Form is a view which brings together an array of questions with submit and optional skip button - form: array of questions - button_label: label of submit button - skip_label: label of skip button - is_skippable: can this question form be skipped
Source code in experiment/actions/form.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
Question
Bases: BaseAction
Question is part of a form. - key: description of question in results table - view: which widget the question should use in the frontend - explainer: optional instructions for this specific question - question: the question text - scoring_rule: optionally, specify a scoring rule which should be applied - is_skippable: whether the question can be skipped - submits: whether entering a value for the question submits the form - style: one (string) or multiple (dict) class names to apply for styling the frontend component
Source code in experiment/actions/form.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
experiment.actions.frontend_style
FrontendStyle
Source code in experiment/actions/frontend_style.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
VALID_STYLES = EFrontendStyle.__members__.values()
class-attribute
instance-attribute
Initialize the FrontendStyle with a root style. :param root_style: The style name for the root element.
apply_style(element, style)
Apply a specific style to an element after validating the style. :param element: The element identifier to apply the style to. :param style: The style name to apply.
Source code in experiment/actions/frontend_style.py
45 46 47 48 49 50 51 52 53 54 55 |
|
get_style(element)
Get the style for a specific element. :param element: The element identifier for which to get the style. :return: The style name for the given element.
Source code in experiment/actions/frontend_style.py
37 38 39 40 41 42 43 |
|
experiment.actions.html
HTML
Bases: BaseAction
A custom view that handles a custom HTML question Relates to client component: HTML.js
Source code in experiment/actions/html.py
5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
__init__(body)
- body: HTML body
Source code in experiment/actions/html.py
13 14 15 16 17 |
|
experiment.actions.info
Info
Bases: BaseAction
Provide data for a view that shows information (HTML)
Relates to client component: Info.js
Source code in experiment/actions/info.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
__init__(body, heading='', button_label=None, button_link=None)
Info shows an formatted information page with an HTML body body: html body heading: title/heading on top button_label: label of button on bottom button_link: (optional) button link. If no link is set, ‘onNext’ is called
Source code in experiment/actions/info.py
13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
experiment.actions.playback
Autoplay
Bases: Playback
This player starts playing automatically - show_animation: if True, show a countdown and moving histogram
Source code in experiment/actions/playback.py
61 62 63 64 65 66 67 68 69 |
|
ImagePlayer
Bases: Multiplayer
This is a special case of the Multiplayer: it shows an image next to each play button
Source code in experiment/actions/playback.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
MatchingPairs
Bases: Multiplayer
This is a special case of multiplayer: play buttons are represented as cards - sections: a list of sections (in many cases, will only contain one section) - score_feedback_display: how to display the score feedback (large-top, small-bottom-right, hidden)
Source code in experiment/actions/playback.py
130 131 132 133 134 135 136 137 138 139 140 141 |
|
Multiplayer
Bases: PlayButton
This is a player with multiple play buttons - stop_audio_after: after how many seconds to stop audio - labels: pass list of strings if players should have custom labels
Source code in experiment/actions/playback.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
PlayButton
Bases: Playback
This player shows a button, which triggers playback - play_once: if True, button will be disabled after one play
Source code in experiment/actions/playback.py
72 73 74 75 76 77 78 79 80 81 |
|
Playback
Bases: BaseAction
A playback base class for different kinds of players - sections: a list of sections (in many cases, will only contain one section) - preload_message: text to display during preload - instruction: text to display during presentation of the sound - play_from: where in the audio file to start playing/ - show_animation: whether to show animations with this player - mute: whether to mute the audio - timeout_after_playback: once playback has finished, add optional timeout (in seconds) before proceeding - stop_audio_after: stop playback after so many seconds - resume_play: if the playback should resume from where a previous view left off
Source code in experiment/actions/playback.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
experiment.actions.redirect
experiment.actions.score
Score
Bases: BaseAction
Provide data for an intermediate score view
Relates to client component: Score.js
Source code in experiment/actions/score.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
__init__(session, title=None, score=None, score_message=None, config=None, icon=None, timer=None, feedback=None)
Score presents feedback to a participant after a Trial - session: a Session object - title: the title of the score page - score_message: a function which constructs feedback text based on the score - config: a dict with the following settings: - show_section: whether metadata of the previous section should be shown - show_total_score: whether the total score should be shown - icon: the name of a themify-icon shown with the view or None - timer: int or None. If int, wait for as many seconds until showing the next view - feedback: An additional feedback text
Source code in experiment/actions/score.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
action()
Serialize score data
Source code in experiment/actions/score.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
default_score_message(score)
Fallback to generate a message for the given score
Source code in experiment/actions/score.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
experiment.actions.styles
experiment.actions.trial
Trial
Bases: BaseAction
A view that may include Playback and/or a Form Relates to client component: Trial.js
Parameters: - playback: player(s) to be displayed in this view - feedback_form: array of form elements - title: page title - defaults to empty
Source code in experiment/actions/trial.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
__init__(playback=None, html=None, feedback_form=None, title='', config=None, style=FrontendStyle())
- playback: Playback object (may be None)
- html: HTML object (may be None)
- feedback_form: Form object (may be None)
- title: string setting title in header of experiment
- config: dictionary with following settings
- response_time: how long to wait until stopping the player / proceeding to the next view
- auto_advance: proceed to next view after player has stopped
- listen_first: whether participant can submit before end of sound
- break_round_on: result values upon which consecutive rounds in the current next_round array will be skipped
- continue_label: if there is no form, how to label a button to proceed to next view
- style: style class to add to elements in form and playback
- neutral: first element is blue, second is yellow, third is teal
- neutral-inverted: first element is yellow, second is blue, third is teal
- boolean: first element is green, second is red
- boolean-negative-first: first element is red, second is green
Source code in experiment/actions/trial.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
action()
Serialize data for a block action
Source code in experiment/actions/trial.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
experiment.actions.utils
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, return a Final.action, which has a button to continue to the next block if series is defined
Source code in experiment/actions/utils.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
get_average_difference(session, num_turnpoints, initial_value)
return the average difference in milliseconds participants could hear
Source code in experiment/actions/utils.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
get_average_difference_level_based(session, num_turnpoints, initial_value)
calculate the difference based on exponential decay, starting from an initial_value
Source code in experiment/actions/utils.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
get_fallback_result(session)
if there were no turnpoints (outliers): return the last result, or if there are no results, return None
Source code in experiment/actions/utils.py
91 92 93 94 95 96 97 98 |
|
get_last_n_turnpoints(session, num_turnpoints)
select all results associated with turnpoints in the result set return the last num_turnpoints results, or all turnpoint results if fewer than num_turnpoints
Source code in experiment/actions/utils.py
101 102 103 104 105 106 107 108 |
|
render_feedback_trivia(feedback, trivia)
Given two texts of feedback and trivia, render them in the final/feedback_trivia.html template.
Source code in experiment/actions/utils.py
50 51 52 53 54 55 |
|
experiment.actions.wrappers
two_alternative_forced(session, section, choices, expected_response=None, style={}, comment='', scoring_rule=None, title='', config=None)
Provide data for a Two Alternative Forced view that (auto)plays a section, shows a question and has two customizable buttons
Source code in experiment/actions/wrappers.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|