sweetbean.stimulus.RatingResponse
Discrete N-point rating widget that doubles as a static display.
Two modes, switched by the value argument:
- Display mode (
valueis an int 0..n_points): renders the rating with the firstvaluepips filled. No input is collected; the trial auto-advances afterdurationms (default 1500 ms when not specified). - Response mode (
value is None): renders an empty rating; the subject presses a number key1..n_pointsto choose a value. The pressed key is recorded asbean_response(string of the digit). The trial ends on any valid key press.
Use the module-level :func:render_rating_html helper to embed a rating
bar inside the HTML string of another stimulus (e.g. when several ratings
appear together as part of a larger choice screen).
RatingResponse
Bases: HtmlKeyboardResponse
Discrete N-point rating; works as response widget or static display.
See module docstring for the two modes and when to use each.
Source code in sweetbean/stimulus/RatingResponse.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
__init__(n_points=5, value=None, label=None, duration=None, side_effects=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_points
|
int
|
Number of discrete points on the scale, 2..10. |
5
|
value
|
int | None | Variable
|
If set, switches to display mode
with |
None
|
label
|
str | None
|
Optional caption shown above the pips. |
None
|
duration
|
int | None
|
Trial duration in ms. - Display mode: defaults to 1500 ms when None (so the trial auto-advances). Pass an explicit value to override. - Response mode: defaults to None (waits for key press). |
None
|
side_effects
|
dict | None
|
Standard sweetbean side-effects. |
None
|
Emits (adds to jsPsych data):
- bean_response (str | None): Pressed digit '1'..'n_points'
in response mode; absent/None in display mode.
Source code in sweetbean/stimulus/RatingResponse.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
render_rating_html(value, n_points, label=None)
Return an HTML snippet for an N-point rating bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int | None
|
If int, the first |
required |
n_points
|
int
|
Total number of pips, 1..10. (n_points=1 gives a single pip that is either filled or empty — a binary on/off indicator.) |
required |
label
|
str | None
|
Optional caption rendered above the pips. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
HTML suitable for embedding in another stimulus's |
|
|
argument or in a larger HTML composition. |
Notes
- Pure literals only — safe to call from inside a sweetbean FunctionVariable (Transcrypt rejects non-local globals).
- Renders inline-block; layout flows with surrounding HTML.
Source code in sweetbean/stimulus/RatingResponse.py
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 | |