diff --git a/.gitignore b/.gitignore index 1de7f0abdf..e9a081035a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ dist.zip packages/jspsych/README.md .turbo *.pyc -cache.db +docs/__generator__/cache diff --git a/docs/__generator__/plugins.py b/docs/__generator__/plugins.py index 8c1f28f3bc..ab7c8bb151 100644 --- a/docs/__generator__/plugins.py +++ b/docs/__generator__/plugins.py @@ -1,23 +1,38 @@ from pathlib import Path from docs.__generator__.utils import ( - cache, + convert_blockquote_admonitions, + generate_badge_svg, + get_package_info, get_plugin_description, get_value_by_path, get_values_by_path, + jsdoc_to_inline_markdown, jsdoc_to_markdown, + plugin_name_to_camel_case, ) PARAMETER_TYPE_MAPPING = { - "HTML_STRING": "HTML string", "KEYS": "array of strings", "BOOL": "boolean", + "STRING": "string", "INT": "numeric", + "FLOAT": "numeric", + "FUNCTION": "function", + "KEY": "string", + "KEYS": "array of strings", + # "SELECT": "", + "HTML_STRING": "HTML string", + "IMAGE": "image file", + "AUDIO": "audio file", + "VIDEO": "video file", + # "OBJECT": "", + # "COMPLEX": "", + # "TIMELINE": "", } -@cache.memoize(expire=60 * 60 * 24 * 30) # 1 month in seconds -def generate_plugin_parameters_section(plugin_dir: Path, source_hash: str): +def generate_plugin_parameters_section(plugin_dir: Path): description = get_plugin_description(plugin_dir) output = """ @@ -47,19 +62,98 @@ def generate_plugin_parameters_section(plugin_dir: Path, source_hash: str): is_array = get_value_by_path( parameter, "$.type.declaration.children[?name = array].type.value" ) + if is_array: + parameter_type = f"array of {parameter_type}s" - default_value = get_value_by_path( - parameter, "$.type.declaration.children[?name = default].defaultValue" + default_value_description = get_value_by_path( + parameter, "$.type.declaration.children[?name = default]" ) + + # If `default_value` has a TSDoc summary, display it as the default value + default_value_summary = get_value_by_path( + default_value_description, "$.comment.summary" + ) or get_value_by_path( + default_value_description, + "$.type.declaration.signatures[0].comment.summary", + ) + if default_value_summary: + default_value = jsdoc_to_inline_markdown(default_value_summary) + else: + default_value = get_value_by_path( + default_value_description, "$.defaultValue" + ) + + # Large arrays are not displayed by default, so assembling a custom string + # here + if is_array and default_value == "...": + default_array_values = get_values_by_path( + default_value_description, "$.type.target.elements[*].value" + ) + + if default_array_values: + separator = '", "' + default_value = f'["{separator.join(default_array_values)}"]' + is_required = default_value == "undefined" required_marker = "*" if is_required else "" if is_required: default_value = "" - description = jsdoc_to_markdown( + description = jsdoc_to_inline_markdown( get_values_by_path(parameter, "$.comment.summary[*]") ) output += f"{parameter_name}{required_marker} | {parameter_type} | {default_value} | {description} \n" return output + + +def generate_plugin_summary(plugin_dir: Path): + summary = get_value_by_path( + get_plugin_description(plugin_dir), + "$.children[?name = default].comment.summary", + ) + return convert_blockquote_admonitions(jsdoc_to_markdown(summary)) + + +def generate_plugin_version_info(plugin_dir: Path): + info = get_package_info(plugin_dir) + return f"[{generate_badge_svg('Current version',info['version'])}](https://github.com/jspsych/jsPsych/blob/main/{plugin_dir}/CHANGELOG.md)" + + +def generate_plugin_author_info(plugin_dir: Path): + author = get_value_by_path( + get_plugin_description(plugin_dir), + "$.children[?name = default].comment.blockTags[?tag = @author].content[0].text", + ) + return generate_badge_svg("Author", author, "lightgray") + + +def generate_plugin_installation_section(plugin_dir: Path): + info = get_package_info(plugin_dir) + plugin_dir_name = plugin_dir.name + + return f""" +## Install + +Using the CDN-hosted JavaScript file: + +```js + +``` + +Using the JavaScript file downloaded from a GitHub release dist archive: + +```js + +``` + +Using NPM: + +``` +npm install {info["name"]} +``` +```js +import {plugin_name_to_camel_case(plugin_dir_name)} from '{info["name"]}'; +``` +""" diff --git a/docs/__generator__/utils.py b/docs/__generator__/utils.py index f73ee847f9..f5728faa0f 100644 --- a/docs/__generator__/utils.py +++ b/docs/__generator__/utils.py @@ -1,15 +1,16 @@ import json -from logging import getLogger import subprocess from hashlib import md5 +from logging import getLogger from pathlib import Path from tempfile import NamedTemporaryFile from typing import Any, List +import requests from diskcache import Cache from jsonpath_ng.ext import parse -cache = Cache(Path(__file__).parent) +cache = Cache(Path(__file__).parent / "cache") logger = getLogger("mkdocs") @@ -19,6 +20,14 @@ def hash_file(path: Path): def get_plugin_description(plugin_dir: Path): + cache_key = ( + "get_plugin_description", + plugin_dir, + hash_file(plugin_dir / "src/index.ts"), + ) + if cache_key in cache: + return cache[cache_key] + logger.info(f"Collecting parameter infos for {plugin_dir}...") with NamedTemporaryFile() as json_file: @@ -47,7 +56,8 @@ def get_plugin_description(plugin_dir: Path): description = json.load(json_file) - return description + cache[cache_key] = description + return description def get_values_by_path(data, json_path: str): @@ -59,15 +69,67 @@ def get_value_by_path(data, json_path: str): return values[0] if len(values) > 0 else None -def jsdoc_to_markdown(parsed_parts: List[Any]): +def jsdoc_to_markdown(fragments: List[Any]): output = "" - for part in parsed_parts: - if part["kind"] in ["text", "code"]: - output += part["text"].replace("\n\n", "

").replace("\n", " ") + for fragment in fragments: + if fragment["kind"] in ["text", "code"]: + output += fragment["text"] - elif part["kind"] == "inline-tag": - if part["tag"] == "@link": - output += f'[{part["text"] or part["target"]}]({part["target"]})' + elif fragment["kind"] == "inline-tag": + if fragment["tag"] == "@link": + output += ( + f'[{fragment["text"] or fragment["target"]}]({fragment["target"]})' + ) return output + + +def jsdoc_to_inline_markdown(fragments: List[Any]): + return jsdoc_to_markdown(fragments).replace("\n\n", "

").replace("\n", " ") + + +def convert_blockquote_admonitions(input: str): + """ + Replace blockquote-based admonitions with MkDocs' admonition style + """ + lines = input.split("\n") + is_blockquote = False + for index, line in enumerate(lines): + if line.startswith("> **"): + lines[index] = "!!! " + line[2:].replace("**", "") + is_blockquote = True + + elif is_blockquote: + if line.startswith(">"): + lines[index] = " " + line[2:] + else: + is_blockquote = False + + return "\n".join(lines) + + +def plugin_name_to_camel_case(plugin_name: str): + words = plugin_name.split("-") + return words[1] + "".join([word.capitalize() for word in words[2:]]) + + +@cache.memoize(name="get_package_info", expire=60) +def get_package_info(package_dir: Path): + with (package_dir / "package.json").open() as package_json_file: + package_json = json.load(package_json_file) + return {"name": package_json["name"], "version": package_json["version"]} + + +@cache.memoize(name="generate_badge_svg") +def generate_badge_svg(label: str, message: str, color="4cae4f"): + + return requests.get( + f"https://img.shields.io/static/v1", + params={ + "label": label, + "message": message, + "color": color, + "style": "flat-square", + }, + ).text diff --git a/docs/__init__.py b/docs/__init__.py index 416657d8bb..daf5accc22 100644 --- a/docs/__init__.py +++ b/docs/__init__.py @@ -1,15 +1,29 @@ from pathlib import Path -from docs.__generator__.plugins import generate_plugin_parameters_section -from docs.__generator__.utils import hash_file +from docs.__generator__.plugins import ( + generate_plugin_author_info, + generate_plugin_installation_section, + generate_plugin_parameters_section, + generate_plugin_summary, + generate_plugin_version_info, +) # https://mkdocs-macros-plugin.readthedocs.io/en/latest/macros/ def define_env(env): @env.macro def plugin_parameters(plugin: str): + return generate_plugin_parameters_section(Path(f"packages/plugin-{plugin}")) + + @env.macro + def plugin_description(plugin: str): + return generate_plugin_summary(Path(f"packages/plugin-{plugin}")) + + @env.macro + def plugin_meta(plugin: str): plugin_dir = Path(f"packages/plugin-{plugin}") + return f"{generate_plugin_version_info(plugin_dir)} {generate_plugin_author_info(plugin_dir)}\n" - return generate_plugin_parameters_section( - plugin_dir, hash_file(plugin_dir / "src/index.ts") - ) + @env.macro + def plugin_installation(plugin: str): + return generate_plugin_installation_section(Path(f"packages/plugin-{plugin}")) diff --git a/docs/plugins/audio-button-response.md b/docs/plugins/audio-button-response.md index a91d7e1195..0e1b6b5373 100644 --- a/docs/plugins/audio-button-response.md +++ b/docs/plugins/audio-button-response.md @@ -1,31 +1,8 @@ # audio-button-response -Current version: 1.1.2. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-audio-button-response/CHANGELOG.md). - -This plugin plays audio files and records responses generated with a button click. - -If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio. - -Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using timeline variables or another dynamic method to specify the audio stimulus, you will need to [manually preload](../overview/media-preloading.md#manual-preloading) the audio. - -The trial can end when the participant responds, when the audio file has finished playing, or if the participant has failed to respond within a fixed length of time. You can also prevent a button response from being made before the audio has finished playing. - -## Parameters - -In addition to the [parameters available in all plugins](../overview/plugins.md#parameters-available-in-all-plugins), this plugin accepts the following parameters. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. - -| Parameter | Type | Default Value | Description | -| ------------------------------ | ---------------- | ---------------------------------------- | ---------------------------------------- | -| stimulus | audio file | *undefined* | Path to audio file to be played. | -| choices | array of strings | *undefined* | Labels for the buttons. Each different string in the array will generate a different button. | -| button_html | HTML string | `''` | A template of HTML for generating the button elements. You can override this to create customized buttons of various kinds. The string `%choice%` will be changed to the corresponding element of the `choices` array. You may also specify an array of strings, if you need different HTML to render for each button. If you do specify an array, the `choices` array and this array must have the same length. The HTML from position 0 in the `button_html` array will be used to create the button for element 0 in the `choices` array, and so on. | -| prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). | -| trial_duration | numeric | null | How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant fails to make a response before this timer is reached, the participant's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial will wait for a response indefinitely. | -| margin_vertical | string | '0px' | Vertical margin of the button(s). | -| margin_horizontal | string | '8px' | Horizontal margin of the button(s). | -| response_ends_trial | boolean | true | If true, then the trial will end whenever the participant makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. | -| trial_ends_after_audio | boolean | false | If true, then the trial will end as soon as the audio file finishes playing. | -| response_allowed_while_playing | boolean | true | If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before the button choices are enabled and a response is accepted. Once the audio has played all the way through, the buttons are enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls). | +{{ plugin_meta('audio-button-response') }} +{{ plugin_description('audio-button-response') }} +{{ plugin_parameters('audio-button-response') }} ## Data Generated @@ -42,28 +19,7 @@ In `data-only` simulation mode, the `response_allowed_while_playing` parameter d This is because the audio file is not loaded in `data-only` mode and therefore the length is unknown. This may change in a future version as we improve the simulation modes. -## Install - -Using the CDN-hosted JavaScript file: - -```js - -``` - -Using the JavaScript file downloaded from a GitHub release dist archive: - -```js - -``` - -Using NPM: - -``` -npm install @jspsych/plugin-audio-button-response -``` -```js -import audioButtonResponse from '@jspsych/plugin-audio-button-response'; -``` +{{ plugin_installation('audio-button-response') }} ## Examples diff --git a/docs/plugins/browser-check.md b/docs/plugins/browser-check.md index 4d7c516fc4..1a307e2f63 100644 --- a/docs/plugins/browser-check.md +++ b/docs/plugins/browser-check.md @@ -1,49 +1,8 @@ # browser-check -Current version: 1.0.2. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-browser-check/CHANGELOG.md). - -This plugin measures and records various features of the participant's browser and can end the experiment if defined inclusion criteria are not met. - -The plugin currently can record the following features: - -* The width and height of the browser window in pixels. -* The type of browser used (e.g., Chrome, Firefox, Edge, etc.) and the version number of the browser.* -* Whether the participant is using a mobile device.* -* The operating system.* -* Support for the WebAudio API. -* Support for the Fullscreen API, e.g., through the [fullscreen plugin](../plugins/fullscreen.md). -* The display refresh rate in frames per second. -* Whether the device has a webcam and microphone. Note that this only reveals whether a webcam/microphone exists. The participant still needs to grant permission in order for the experiment to use these devices. - -!!! warning - Features with an * are recorded by parsing the [user agent string](https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent). - This method is accurate most of the time, but is not guaranteed to be correct. - The plugin uses the [detect-browser package](https://github.com/DamonOehlman/detect-browser) to perform user agent parsing. - You can find a list of supported browsers and OSes in the [source file](https://github.com/DamonOehlman/detect-browser/blob/master/src/index.ts). - -The plugin begins by measuring the set of features requested. -An inclusion function is evaluated to see if the paricipant passes the inclusion criteria. -If they do, then the trial ends and the experiment continues. -If they do not, then the experiment ends immediately. -If a minimum width and/or minimum height is desired, the plugin will optionally display a message to participants whose browser windows are too small to give them an opportunity to make the window larger if possible. -See the examples below for more guidance. - -## Parameters - -In addition to the [parameters available in all plugins](../overview/plugins.md#parameters-available-in-all-plugins), this plugin accepts the following parameters. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. - -| Parameter | Type | Default Value | Description | -| ------------------------------ | ---------------- | ------------- | ---------------------------------------- | -| features | array of strings | `["width", "height", "webaudio", "browser", "browser_version", "mobile", "os", "fullscreen", "vsync_rate", "webcam", "microphone"]` | The list of browser features to record. The default value includes all of the available options. | -| skip_features | array of strings | `[]` | Any features listed here will be skipped, even if they appear in `features`. Use this when you want to run most of the defaults. -| vsync_frame_count | int | 60 | The number of frames to sample when measuring the display refresh rate (`"vsync_rate"`). Increasing the number will potenially improve the stability of the estimate at the cost of increasing the amount of time the plugin takes during this test. On most devices, 60 frames takes about 1 second to measure. -| allow_window_resize | bool | true | Whether to allow the participant to resize the browser window if the window is smaller than `minimum_width` and/or `minimum_height`. If `false`, then the `minimum_width` and `minimum_height` parameters are ignored and you can validate the size in the `inclusion_function`. -| minimum_height | int | 0 | If `allow_window_resize` is `true`, then this is the minimum height of the window (in pixels) that must be met before continuing. -| minimum_width | int | 0 | If `allow_window_resize` is `true`, then this is the minimum width of the window (in pixels) that must be met before continuing. -| window_resize_message | string | see description | The message that will be displayed during the interactive resize when `allow_window_resize` is `true` and the window is too small. If the message contains HTML elements with the special IDs `browser-check-min-width`, `browser-check-min-height`, `browser-check-actual-height`, and/or `browser-check-actual-width`, then the contents of those elements will be dynamically updated to reflect the `minimum_width`, `minimum_height` and measured width and height of the browser. The default message is: `

Your browser window is too small to complete this experiment. Please maximize the size of your browser window. If your browser window is already maximized, you will not be able to complete this experiment.

The minimum window width is px.

Your current window width is px.

The minimum window height is px.

Your current window height is px.

`. -resize_fail_button_text | string | `"I cannot make the window any larger"` | During the interactive resize, a button with this text will be displayed below the `window_resize_message` for the participant to click if the window cannot meet the minimum size needed. When the button is clicked, the experiment will end and `exclusion_message` will be displayed. -inclusion_function | function | `() => { return true; }` | A function that evaluates to `true` if the browser meets all of the inclusion criteria for the experiment, and `false` otherwise. The first argument to the function will be an object containing key value pairs with the measured features of the browser. The keys will be the same as those listed in `features`. See example below. -exclusion_message | function | `() => { return

Your browser does not meet the requirements to participate in this experiment.

}` | A function that returns the message to display if `inclusion_function` evaluates to `false` or if the participant clicks on the resize fail button during the interactive resize. In order to allow customization of the message, the first argument to the function will be an object containing key value pairs with the measured features of the browser. The keys will be the same as those listed in `features`. See example below. +{{ plugin_meta('browser-check') }} +{{ plugin_description('browser-check') }} +{{ plugin_parameters('browser-check') }} ## Data Generated @@ -75,28 +34,7 @@ In `visual` mode, if `allow_window_resize` is true and the browser's width and h As with all simulated plugins, you can override the default (actual) data with fake data using `simulation_options`. This allows you to test your exclusion criteria by simulating other configurations. -## Install - -Using the CDN-hosted JavaScript file: - -```js - -``` - -Using the JavaScript file downloaded from a GitHub release dist archive: - -```js - -``` - -Using NPM: - -``` -npm install @jspsych/plugin-browser-check -``` -```js -import browserCheck from '@jspsych/plugin-browser-check'; -``` +{{ plugin_installation('browser-check') }} ## Examples diff --git a/docs/plugins/html-keyboard-response.md b/docs/plugins/html-keyboard-response.md index 7bba8e36ad..4806b28f23 100644 --- a/docs/plugins/html-keyboard-response.md +++ b/docs/plugins/html-keyboard-response.md @@ -1,9 +1,7 @@ # html-keyboard-response -Current version: 1.1.2. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-html-keyboard-response/CHANGELOG.md). - -This plugin displays HTML content and records responses generated with the keyboard.The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the participant has failed to respond within a fixed length of time. - +{{ plugin_meta('html-keyboard-response') }} +{{ plugin_description('html-keyboard-response') }} {{ plugin_parameters('html-keyboard-response') }} ## Data Generated @@ -16,28 +14,7 @@ In addition to the [default data collected by all plugins](../overview/plugins.m | rt | numeric | The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus first appears on the screen until the participant's response. | | stimulus | string | The HTML content that was displayed on the screen. | -## Install - -Using the CDN-hosted JavaScript file: - -```js - -``` - -Using the JavaScript file downloaded from a GitHub release dist archive: - -```js - -``` - -Using NPM: - -``` -npm install @jspsych/plugin-html-keyboard-response -``` -```js -import htmlKeyboardResponse from '@jspsych/plugin-html-keyboard-response'; -``` +{{ plugin_installation('html-keyboard-response') }} ## Examples diff --git a/packages/plugin-audio-button-response/src/index.ts b/packages/plugin-audio-button-response/src/index.ts index 942063164f..f28307fcab 100644 --- a/packages/plugin-audio-button-response/src/index.ts +++ b/packages/plugin-audio-button-response/src/index.ts @@ -3,65 +3,102 @@ import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych"; const info = { name: "audio-button-response", parameters: { - /** The audio to be played. */ + /** Path to audio file to be played. */ stimulus: { type: ParameterType.AUDIO, pretty_name: "Stimulus", default: undefined, }, - /** Array containing the label(s) for the button(s). */ + + /** + * Labels for the buttons. Each different string in the array will generate a different button. + */ choices: { type: ParameterType.STRING, pretty_name: "Choices", default: undefined, array: true, }, - /** The HTML for creating button. Can create own style. Use the "%choice%" string to indicate where the label from the choices parameter should be inserted. */ + + /** + * A template of HTML for generating the button elements. You can override this to create + * customized buttons of various kinds. The string `%choice%` will be changed to the + * corresponding element of the `choices` array. You may also specify an array of strings, if + * you need different HTML to render for each button. If you do specify an array, the `choices` + * array and this array must have the same length. The HTML from position 0 in the `button_html` + * array will be used to create the button for element 0 in the `choices` array, and so on. + **/ button_html: { type: ParameterType.HTML_STRING, pretty_name: "Button HTML", default: '', array: true, }, - /** Any content here will be displayed below the stimulus. */ + + /** + * This string can contain HTML markup. Any content here will be displayed below the stimulus. + * The intention is that it can be used to provide a reminder about the action the participant + * is supposed to take (e.g., which key to press). + */ prompt: { type: ParameterType.HTML_STRING, pretty_name: "Prompt", default: null, }, - /** The maximum duration to wait for a response. */ + + /** + * How long to wait for the participant to make a response before ending the trial in + * milliseconds. If the participant fails to make a response before this timer is reached, the + * participant's response will be recorded as null for the trial and the trial will end. If the + * value of this parameter is null, the trial will wait for a response indefinitely. + */ trial_duration: { type: ParameterType.INT, pretty_name: "Trial duration", default: null, }, - /** Vertical margin of button. */ + + /** Vertical margin of the button(s). */ margin_vertical: { type: ParameterType.STRING, pretty_name: "Margin vertical", default: "0px", }, - /** Horizontal margin of button. */ + + /** Horizontal margin of the button(s). */ margin_horizontal: { type: ParameterType.STRING, pretty_name: "Margin horizontal", default: "8px", }, - /** If true, the trial will end when user makes a response. */ + + /** + * If true, then the trial will end whenever the participant makes a response (assuming they + * make their response before the cutoff specified by the `trial_duration` parameter). If false, + * then the trial will continue until the value for `trial_duration` is reached. You can set + * this parameter to `false` to force the participant to listen to the stimulus for a fixed + * amount of time, even if they respond before the time is complete. + */ response_ends_trial: { type: ParameterType.BOOL, pretty_name: "Response ends trial", default: true, }, - /** If true, then the trial will end as soon as the audio file finishes playing. */ + + /** + * If true, then the trial will end as soon as the audio file finishes playing. + */ trial_ends_after_audio: { type: ParameterType.BOOL, pretty_name: "Trial ends after audio", default: false, }, + /** - * If true, then responses are allowed while the audio is playing. - * If false, then the audio must finish playing before a response is accepted. + * If true, then responses are allowed while the audio is playing. If false, then the audio must + * finish playing before the button choices are enabled and a response is accepted. Once the + * audio has played all the way through, the buttons are enabled and a response is allowed + * (including while the audio is being re-played via on-screen playback controls). */ response_allowed_while_playing: { type: ParameterType.BOOL, @@ -74,12 +111,26 @@ const info = { type Info = typeof info; /** - * **audio-button-response** + * This plugin plays audio files and records responses generated with a button click. + * + * If the browser supports it, audio files are played using the WebAudio API. This allows for + * reasonably precise timing of the playback. The timing of responses generated is measured against + * the WebAudio specific clock, improving the measurement of response times. If the browser does not + * support the WebAudio API, then the audio file is played with HTML5 audio. + * + * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). + * However, if you are using timeline variables or another dynamic method to specify the audio + * stimulus, you will need to [manually preload](../overview/media-preloading.md#manual-preloading) + * the audio. + * + * The trial can end when the participant responds, when the audio file has finished playing, or if + * the participant has failed to respond within a fixed length of time. You can also prevent a + * button response from being made before the audio has finished playing. * - * jsPsych plugin for playing an audio file and getting a button response * * @author Kristin Diep - * @see {@link https://www.jspsych.org/plugins/jspsych-audio-button-response/ audio-button-response plugin documentation on jspsych.org} + * @see + {@link https://www.jspsych.org/latest/plugins/jspsych-audio-button-response/} */ class AudioButtonResponsePlugin implements JsPsychPlugin { static info = info; diff --git a/packages/plugin-browser-check/src/index.ts b/packages/plugin-browser-check/src/index.ts index 4fb0b7dbda..e9fdfe6d42 100644 --- a/packages/plugin-browser-check/src/index.ts +++ b/packages/plugin-browser-check/src/index.ts @@ -5,7 +5,8 @@ const info = { name: "browser-check", parameters: { /** - * List of features to check and record in the data + * The list of browser features to record. The default value includes all of the available + * options. */ features: { type: ParameterType.STRING, @@ -24,51 +25,74 @@ const info = { "microphone", ], }, + /** - * Any features listed here will be skipped, even if they appear in `features`. Useful for - * when you want to run most of the defaults. + * Any features listed here will be skipped, even if they appear in `features`. Use this when + * you want to run most of the defaults. */ skip_features: { type: ParameterType.STRING, array: true, default: [], }, + /** - * The number of animation frames to sample when calculating vsync_rate. + * The number of frames to sample when measuring the display refresh rate (`"vsync_rate"`). + * Increasing the number will potenially improve the stability of the estimate at the cost of + * increasing the amount of time the plugin takes during this test. On most devices, 60 frames + * takes about 1 second to measure. */ vsync_frame_count: { type: ParameterType.INT, default: 60, }, + /** - * If `true`, show a message when window size is too small to allow the user - * to adjust if their screen allows for it. + * Whether to allow the participant to resize the browser window if the window is smaller than + * `minimum_width` and/or `minimum_height`. If `false`, then the `minimum_width` and + * `minimum_height` parameters are ignored and you can validate the size in the + * `inclusion_function`. */ allow_window_resize: { type: ParameterType.BOOL, default: true, }, + /** - * When `allow_window_resize` is `true`, this is the minimum width (px) that the window - * needs to be before the experiment will continue. + * If `allow_window_resize` is `true`, then this is the minimum width of the window (in pixels) + * that must be met before continuing. */ minimum_width: { type: ParameterType.INT, default: 0, }, + /** - * When `allow_window_resize` is `true`, this is the minimum height (px) that the window - * needs to be before the experiment will continue. + * If `allow_window_resize` is `true`, then this is the minimum height of the window (in pixels) + * that must be met before continuing. */ minimum_height: { type: ParameterType.INT, default: 0, }, + /** - * Message to display during interactive window resizing. + * The message that will be displayed during the interactive resize when `allow_window_resize` + * is `true` and the window is too small. If the message contains HTML elements with the special + * IDs `browser-check-min-width`, `browser-check-min-height`, `browser-check-actual-height`, + * and/or `browser-check-actual-width`, then the contents of those elements will be dynamically + * updated to reflect the `minimum_width`, `minimum_height` and measured width and height of the + * browser. The default message is: `

Your browser window is too small to complete this + * experiment. Please maximize the size of your browser window. If your browser window is + * already maximized, you will not be able to complete this experiment.

The minimum window + * width is px.

Your current window width is + * px.

The minimum window height is px.

Your current window height is px.

`. */ window_resize_message: { type: ParameterType.HTML_STRING, + /** see description */ default: `

Your browser window is too small to complete this experiment. Please maximize the size of your browser window. If your browser window is already maximized, you will not be able to complete this experiment.

The minimum window width is px.

@@ -76,33 +100,50 @@ const info = {

The minimum window height is px.

Your current window height is px.

`, }, + /** * During the interactive resize, a button with this text will be displayed below the - * `window_resize_message` for the participant to click if the window cannot meet the - * minimum size needed. When the button is clicked, the experiment will end and - * `exclusion_message` will be displayed. + * `window_resize_message` for the participant to click if the window cannot meet the minimum + * size needed. When the button is clicked, the experiment will end and `exclusion_message` will + * be displayed. */ resize_fail_button_text: { type: ParameterType.STRING, default: "I cannot make the window any larger", }, + /** - * A function that evaluates to `true` if the browser meets all of the inclusion criteria - * for the experiment, and `false` otherwise. The first argument to the function will be - * an object containing key value pairs with the measured features of the browser. The - * keys will be the same as those listed in `features`. + * A function that evaluates to `true` if the browser meets all of the inclusion criteria for + * the experiment, and `false` otherwise. The first argument to the function will be an object + * containing key value pairs with the measured features of the browser. The keys will be the + * same as those listed in `features`. See example below. */ inclusion_function: { type: ParameterType.FUNCTION, + /** + * ``` + * () => true + * ``` + */ default: () => { return true; }, }, + /** - * The message to display if `inclusion_function` returns `false` + * A function that returns the message to display if `inclusion_function` evaluates to `false` + * or if the participant clicks on the resize fail button during the interactive resize. In + * order to allow customization of the message, the first argument to the function will be an + * object containing key value pairs with the measured features of the browser. The keys will be + * the same as those listed in `features`. See example below. */ exclusion_message: { type: ParameterType.FUNCTION, + /** + * ``` + * () => `

Your browser does not meet the requirements to participate in this experiment.

` + * ``` + */ default: () => { return `

Your browser does not meet the requirements to participate in this experiment.

`; }, @@ -113,12 +154,42 @@ const info = { type Info = typeof info; /** - * **browser-check** + * This plugin measures and records various features of the participant's browser and can end the + * experiment if defined inclusion criteria are not met. + * + * The plugin currently can record the following features: + * + * * The width and height of the browser window in pixels. + * * The type of browser used (e.g., Chrome, Firefox, Edge, etc.) and the version number of the + * browser.* + * * Whether the participant is using a mobile device.* + * * The operating system.* + * * Support for the WebAudio API. + * * Support for the Fullscreen API, e.g., through the [fullscreen + * plugin](../plugins/fullscreen.md). + * * The display refresh rate in frames per second. + * * Whether the device has a webcam and microphone. Note that this only reveals whether a + * webcam/microphone exists. The participant still needs to grant permission in order for the + * experiment to use these devices. + * + * > **Warning** + * > + * > Features with an * are recorded by parsing the [user agent + * > string](https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent). + * > This method is accurate most of the time, but is not guaranteed to be correct. The plugin uses + * > the [detect-browser package](https://github.com/DamonOehlman/detect-browser) to perform user + * > agent parsing. You can find a list of supported browsers and OSes in the [source + * > file](https://github.com/DamonOehlman/detect-browser/blob/master/src/index.ts). * - * jsPsych plugin for checking features of the browser and validating against a set of inclusion criteria. + * The plugin begins by measuring the set of features requested. An inclusion function is evaluated + * to see if the paricipant passes the inclusion criteria. If they do, then the trial ends and the + * experiment continues. If they do not, then the experiment ends immediately. If a minimum width + * and/or minimum height is desired, the plugin will optionally display a message to participants + * whose browser windows are too small to give them an opportunity to make the window larger if + * possible. See the examples below for more guidance. * * @author Josh de Leeuw - * @see {@link https://www.jspsych.org/plugins/jspsych-browser-check/ browser-check plugin documentation on jspsych.org} + * @see {@link https://www.jspsych.org/latest/plugins/jspsych-browser-check/} */ class BrowserCheckPlugin implements JsPsychPlugin { static info = info; diff --git a/packages/plugin-html-keyboard-response/src/index.ts b/packages/plugin-html-keyboard-response/src/index.ts index 44d9bf562c..fecaa79e2f 100644 --- a/packages/plugin-html-keyboard-response/src/index.ts +++ b/packages/plugin-html-keyboard-response/src/index.ts @@ -83,12 +83,12 @@ const info = { type Info = typeof info; /** - * **html-keyboard-response** - * - * jsPsych plugin for displaying a stimulus and getting a keyboard response + * This plugin displays HTML content and records responses generated with the keyboard. The stimulus + * can be displayed until a response is given, or for a pre-determined amount of time. The trial can + * be ended automatically if the participant has failed to respond within a fixed length of time. * * @author Josh de Leeuw - * @see {@link https://www.jspsych.org/plugins/jspsych-html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org} + * @see {@link https://www.jspsych.org/latest/plugins/jspsych-html-keyboard-response/} */ class HtmlKeyboardResponsePlugin implements JsPsychPlugin { static info = info; diff --git a/poetry.lock b/poetry.lock index 2b0a884e10..b27ec9fb80 100644 --- a/poetry.lock +++ b/poetry.lock @@ -20,6 +20,25 @@ d = ["aiohttp (>=3.7.4)"] jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] +[[package]] +name = "certifi" +version = "2022.9.24" +description = "Python package for providing Mozilla's CA Bundle." +category = "main" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "charset-normalizer" +version = "2.1.1" +description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "main" +optional = false +python-versions = ">=3.6.0" + +[package.extras] +unicode-backport = ["unicodedata2"] + [[package]] name = "click" version = "8.1.3" @@ -69,6 +88,14 @@ python-dateutil = ">=2.8.1" [package.extras] dev = ["flake8", "markdown", "twine", "wheel"] +[[package]] +name = "idna" +version = "3.4" +description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" +optional = false +python-versions = ">=3.5" + [[package]] name = "importlib-metadata" version = "4.11.3" @@ -346,6 +373,24 @@ python-versions = ">=3.6" [package.dependencies] pyyaml = "*" +[[package]] +name = "requests" +version = "2.28.1" +description = "Python HTTP for Humans." +category = "main" +optional = false +python-versions = ">=3.7, <4" + +[package.dependencies] +certifi = ">=2017.4.17" +charset-normalizer = ">=2,<3" +idna = ">=2.5,<4" +urllib3 = ">=1.21.1,<1.27" + +[package.extras] +socks = ["PySocks (>=1.5.6,!=1.5.7)"] +use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] + [[package]] name = "six" version = "1.16.0" @@ -381,6 +426,19 @@ category = "dev" optional = false python-versions = ">=3.7" +[[package]] +name = "urllib3" +version = "1.26.13" +description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" + +[package.extras] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] +secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] +socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] + [[package]] name = "verspec" version = "0.1.0" @@ -418,7 +476,7 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>= [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "1c8d4dcf5a9244ea811f4e585311114536e369408066ebe6e7d1fb46e7f3b457" +content-hash = "10332520403d432b0488a65490d6041d20520490ad30d3fb0807a27774c37416" [metadata.files] black = [ @@ -444,6 +502,14 @@ black = [ {file = "black-22.10.0-py3-none-any.whl", hash = "sha256:c957b2b4ea88587b46cf49d1dc17681c1e672864fd7af32fc1e9664d572b3458"}, {file = "black-22.10.0.tar.gz", hash = "sha256:f513588da599943e0cde4e32cc9879e825d58720d6557062d1098c5ad80080e1"}, ] +certifi = [ + {file = "certifi-2022.9.24-py3-none-any.whl", hash = "sha256:90c1a32f1d68f940488354e36370f6cca89f0f106db09518524c88d6ed83f382"}, + {file = "certifi-2022.9.24.tar.gz", hash = "sha256:0d9c601124e5a6ba9712dbc60d9c53c21e34f5f641fe83002317394311bdce14"}, +] +charset-normalizer = [ + {file = "charset-normalizer-2.1.1.tar.gz", hash = "sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845"}, + {file = "charset_normalizer-2.1.1-py3-none-any.whl", hash = "sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"}, +] click = [ {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, @@ -464,6 +530,10 @@ ghp-import = [ {file = "ghp-import-2.1.0.tar.gz", hash = "sha256:9c535c4c61193c2df8871222567d7fd7e5014d835f97dc7b7439069e2413d343"}, {file = "ghp_import-2.1.0-py3-none-any.whl", hash = "sha256:8337dd7b50877f163d4c0289bc1f1c7f127550241988d568c1db512c4324a619"}, ] +idna = [ + {file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"}, + {file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"}, +] importlib-metadata = [ {file = "importlib_metadata-4.11.3-py3-none-any.whl", hash = "sha256:1208431ca90a8cca1a6b8af391bb53c1a2db74e5d1cef6ddced95d4b2062edc6"}, {file = "importlib_metadata-4.11.3.tar.gz", hash = "sha256:ea4c597ebf37142f827b8f39299579e31685c31d3a438b59f469406afd0f2539"}, @@ -633,6 +703,10 @@ pyyaml-env-tag = [ {file = "pyyaml_env_tag-0.1-py3-none-any.whl", hash = "sha256:af31106dec8a4d68c60207c1886031cbf839b68aa7abccdb19868200532c2069"}, {file = "pyyaml_env_tag-0.1.tar.gz", hash = "sha256:70092675bda14fdec33b31ba77e7543de9ddc88f2e5b99160396572d11525bdb"}, ] +requests = [ + {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, + {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, +] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, @@ -649,6 +723,10 @@ typing-extensions = [ {file = "typing_extensions-4.4.0-py3-none-any.whl", hash = "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e"}, {file = "typing_extensions-4.4.0.tar.gz", hash = "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa"}, ] +urllib3 = [ + {file = "urllib3-1.26.13-py2.py3-none-any.whl", hash = "sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc"}, + {file = "urllib3-1.26.13.tar.gz", hash = "sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"}, +] verspec = [ {file = "verspec-0.1.0-py3-none-any.whl", hash = "sha256:741877d5633cc9464c45a469ae2a31e801e6dbbaa85b9675d481cda100f11c31"}, {file = "verspec-0.1.0.tar.gz", hash = "sha256:c4504ca697b2056cdb4bfa7121461f5a0e81809255b41c03dda4ba823637c01e"}, diff --git a/pyproject.toml b/pyproject.toml index 5b05c7fccc..6d334f110b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ authors = [] [tool.poetry.dependencies] python = "^3.8" diskcache = "^5.4.0" +requests = "^2.28.1" [tool.poetry.dev-dependencies] mkdocs = "^1.3.0"