caqe.experiment module

Contains functions related to the experimental design of the listening test

caqe.experiment.assign_conditions(participant, limit_to_condition_ids=None)[source]

Assign experimental conditions for a participant’s trial.

Parameters:
Returns:

condition_ids

Return type:

list of int

caqe.experiment.decrypt_audio_stimuli(condition_data)[source]

Decrypt the audio stimuli URLs from submitted trial data

Parameters:condition_data (dict) – The condition data with encrypted audio URLs
Returns:trial_data
Return type:dict
caqe.experiment.encrypt_audio_stimuli(audio_stimuli, participant_id, condition_group_id)[source]

Reorder and encrypt the condition files. Do this by encoding each file as a special URL. One in which is an encrypted, serialized, dictionary. The dictionary contains, the participant_id (p_id), the condition_group_id (g_id), the stimuli_id (s_id), and a encrypted stimuli_id (e_id)

Parameters:
  • audio_stimuli (list of tuple) – The first element of each duple is a key, the second is the audio_file_path For all non-references, the key should be of the form S[0-9+]
  • participant_id (int) –
  • condition_group_id (int) –
Returns:

encrypted_audio_stimuli – The first element of each duple is a key, the second is the encrypted audio_file_path For all non-references, the key should be of the form E[0-9+].

Return type:

list of tuple

caqe.experiment.generate_comparison_pairs(condition_datas)[source]

Generate all stimulus comparison pairs for a condition and return in a random order for a paired comparison test.

Parameters:condition_datas (list of dict) – List of dictionary of condition data as returned in the test_configuration defined by get_test_configurations()
Returns:condition_datas – List of updated dictionary of condition data with a new field, comparison_pairs, which is a list of stimulus pairs, e.g. ((‘E1’,’E2’),(‘E5’,’E8’),...)
Return type:list of dict
caqe.experiment.get_available_conditions(limit_to_condition_ids=None)[source]

Get conditions available without regard to participant.

Parameters:limit_to_condition_ids (list of int) – List of conditions ids to limit to.
Returns:conditions – The available conditions
Return type:list of Condition
caqe.experiment.get_encoding_maps(encrypted_audio_stimuli)[source]

Build a stimulus key translation map from the encypted_audio_stimuli.

Parameters:encrypted_audio_stimuli (list of tuple) – The first element of each duple is a key, the second is the encrypted audio_file_path For all non-references, the key should be of the form E[0-9+]. The order of the stimuli will be random (except for the references)
Returns:
  • encoding_map (dict) – A map from unencoded to encoded stimulus keys
  • decoding_map (dict) – A map from encoded to unencoded stimulus keys
  • decrypted_filenames (dict) – A map from stimulus key to filename
caqe.experiment.get_test_configurations(condition_ids, participant_id)[source]

Generate template configuration variables from the list of experimental conditions.

Parameters:
  • condition_ids (list) –
  • participant_id (int) –
Returns:

test_configuration – A list of dictionaries containing all the configuration variables for each test, including a list of conditions and their variables

Return type:

list of list of dict

caqe.experiment.insert_tests_and_conditions(config=None)[source]

This is where you configure and define the listening test. If you need to change HTML content based on the testing condition, you configure it here as well, overriding the default values in CONFIGURATION. Running this doctest initializes the development database.

Parameters:config (flask.Config) – The application configuration
Returns:
Return type:None

Examples

To call this you need the application context, e.g.:

>>> import os
>>> os.environ['APP_MODE'] = 'DEVELOPMENT' # for testing the Development configuration
>>> from caqe import db
APP_MODE=DEVELOPMENT
>>> db.drop_all()
>>> db.create_all()
>>> import caqe
>>> import caqe.experiment as experiment
>>> with caqe.app.app_context():
...     experiment.insert_tests_and_conditions()
caqe.experiment.is_pre_test_survey_valid(survey, inclusion_criteria)[source]

Make sure the participant meets the inclusion critera.

Parameters:
  • survey (dict) –
  • inclusion_criteria (list) – List of expressions as strings which we will evaluate. If any of these inclusion criteria are False, return False.
Returns:

Return type:

bool