add tests and descriptions of variables for logging

parent a05537c9
......@@ -8,6 +8,32 @@ import sp_experiment
from sp_experiment.define_ttl_triggers import provide_trigger_dict
def make_description_task_json():
"""Provide variable meanings for description task."""
events_json_dict = dict()
# Start populating the dict
events_json_dict['onset'] = {
'Description': 'onset of a lottery selection screen',
'Units': 'seconds'
}
events_json_dict['duration'] = {
'Description': ('duration until a button press was recorded while '
'showing the lottery selection screen.'),
'Units': 'seconds'
}
events_json_dict['trial'] = {
'Description': ('zero indexed trial counter, where a trial index '
'points to the lottery setting that was used in this '
'event by comparing with the trial column in the '
'spactive task.')
}
return events_json_dict
def make_events_json_dict():
"""Provide a dict to describe all collected variables."""
# Get the trigger values
......@@ -228,6 +254,12 @@ def make_data_dir():
json.dump(obj=variable_meanings_dict, fp=fout,
sort_keys=False, indent=4)
# Also need a JSON for description task
variable_meanings_dict = make_description_task_json()
with open(op.join(data_dir, 'task-description_events.json'), 'w') as fout:
json.dump(obj=variable_meanings_dict, fp=fout,
sort_keys=False, indent=4)
# Copy over the testing file
f1 = op.join(init_dir, 'tests', 'data', 'sub-999_task-spactive_events.tsv')
f2 = op.join(data_dir, 'sub-999_task-spactive_events.tsv')
......
......@@ -7,10 +7,10 @@ import os
import os.path as op
import pandas as pd
import numpy as np
from psychopy import visual, event, core
import sp_experiment
from sp_experiment.define_variable_meanings import make_description_task_json
from sp_experiment.define_instructions import instruct_str_descriptions
from sp_experiment.utils import _get_payoff_setting, KEYLIST_DESCRIPTION
......@@ -28,6 +28,7 @@ def run_descriptions(events_file, monitor='testMonitor', font='', lang='en'):
-------
data_file : str
Path to the output data file
"""
# Define monitor specific window object
win = visual.Window(color=(0, 0, 0), # Background color: RGB [-1,1]
......@@ -67,7 +68,8 @@ def run_descriptions(events_file, monitor='testMonitor', font='', lang='en'):
fname = sub_part + '_task-description_events.tsv'
data_file = op.join(head, fname)
variables = ['onset', 'duration', 'trial', 'selected_side']
variable_meanings_dict = make_description_task_json()
variables = list(variable_meanings_dict.keys())
with open(data_file, 'w') as fout:
header = '\t'.join(variables)
fout.write(header + '\n')
......@@ -106,7 +108,7 @@ def run_descriptions(events_file, monitor='testMonitor', font='', lang='en'):
side = KEYLIST_DESCRIPTION.index(key)
with open(data_file, 'a') as fout:
values = [onset, rt, trial, key]
values = [onset, rt, trial, side]
values = [str(val) for val in values]
fout.write('\t'.join(values))
......
......@@ -4,7 +4,8 @@ import os.path as op
import json
import sp_experiment
from sp_experiment.define_variable_meanings import (make_events_json_dict,
from sp_experiment.define_variable_meanings import (make_description_task_json,
make_events_json_dict,
make_data_dir)
......@@ -18,6 +19,10 @@ def test_make_events_json_dict():
assert isinstance(key, int)
assert key >= 0 and key <= 255
# Also test descriptions task json
events_json_dict = make_description_task_json()
assert isinstance(events_json_dict, dict)
def test_json():
"""Test json file."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment