Commit 96d2822f authored by Stefan Appelhoff's avatar Stefan Appelhoff

turn f-strs to strs.format style

parent 6070199b
This diff is collapsed.
......@@ -89,10 +89,11 @@ def run_descriptions(events_file, monitor='testMonitor', font='', lang='en'):
prob1_1 = setting[0, 6] * 10
mag1_2 = setting[0, 5]
prob1_2 = setting[0, 7] * 10
txt_stim.text = (f'{mag0_1} - {prob0_1}% | ' # noqa: E999
f'{mag1_1} - {prob1_1}%\n'
f'{mag0_2} - {prob0_2}% | '
f'{mag1_2} - {prob1_2}%')
txt_stim.text = ''
txt_stim.text += '{} - {}% | '.format(mag0_1, prob0_1)
txt_stim.text += '{} - {}%\n'.format(mag1_1, prob1_1)
txt_stim.text += '{} - {}% | '.format(mag0_2, prob0_2)
txt_stim.text += '{} - {}%'.format(mag1_2, prob1_2)
txt_stim.draw()
rt_clock.reset()
onset = exp_timer.getTime()
......
......@@ -210,14 +210,15 @@ def prep_logging(yoke_map, auto=False, gui_info=None):
# Data logging
# ============
fname = f'sub-{sub_id:02d}_task-sp{condition}_events.tsv' # noqa: E999
fname = 'sub-{:02d}_task-sp{}_events.tsv'.format(sub_id, condition)
# Check directory is present and file name not yet used
init_dir, data_dir = make_data_dir()
data_file = op.join(data_dir, fname)
if op.exists(data_file):
raise OSError(f'\n\nA data file for ID "{sub_id}" already exists.\n\n')
raise OSError('\n\nA data file for ID "{}" already exists.\n\n'
.format(sub_id))
# Write header to the tab separated log file
variable_meanings_dict = make_events_json_dict()
......@@ -231,12 +232,12 @@ def prep_logging(yoke_map, auto=False, gui_info=None):
# once. If it is done twice, then you can check which condition was first
# by checking the starting time in the events.tsv file.
if not isinstance(gui_info, dict):
fname = f'log_{sub_id}_{condition}.txt'
fname = 'log_{}_{}.txt'.format(sub_id, condition)
log_path = op.join(data_dir, fname)
prefixes = ['sub_id', 'age', 'sex', 'yoke_to']
with open(log_path, 'w') as fout:
for i, line in enumerate([sub_id, age, sex, yoke_to]):
fout.write(f'{prefixes[i]}: {line}')
fout.write('{}: {}'.format(prefixes[i], line))
fout.write('\n')
return sub_id, data_file, condition, yoke_to
......@@ -371,7 +372,7 @@ def run_flow(monitor='testMonitor', ser=Fake_serial(), max_ntrls=10,
# If we are in the passive condition, load pre-recorded data to replay
if condition == 'passive':
fname = f'sub-{yoke_to:02d}_task-spactive_events.tsv'
fname = 'sub-{:02d}_task-spactive_events.tsv'.format(yoke_to)
fpath = op.join(op.dirname(data_file), fname)
df = pd.read_csv(fpath, sep='\t')
error_trig = ord(trig_dict['trig_error'])
......
......@@ -43,7 +43,7 @@ def test_json():
try:
assert json.load(fin)
except ValueError as e:
print(f'invalid json: {e}') # noqa: E999
print('invalid json: {}'.format(e))
raise
......
......@@ -58,14 +58,15 @@ def calc_bonus_payoff(sub_id, exchange_rate=0.01, lang='en'):
data_dir = op.join(op.dirname(sp_experiment.__file__), 'experiment_data')
points = 0
for condition in ['active', 'passive']:
fname = f'sub-{sub_id:02d}_task-sp{condition}_events.tsv' # noqa: E999
fname = 'sub-{:02d}_task-sp{}_events.tsv'.format(sub_id, condition)
fpath = op.join(data_dir, fname)
if not op.exists(fpath):
modstr = 'A' if condition == 'active' else 'B'
if lang == 'de':
bonus = f'Aufgabe "{modstr}" wurde noch nicht durchgeführt.'
bonus = ('Aufgabe "{}" wurde noch nicht durchgeführt.'
.format(modstr))
elif lang == 'en':
bonus = f'did not yet complete task "{modstr}".'
bonus = 'did not yet complete task "{}".'.format(modstr)
return bonus
else:
df = pd.read_csv(fpath, sep='\t')
......@@ -77,9 +78,9 @@ def calc_bonus_payoff(sub_id, exchange_rate=0.01, lang='en'):
money = int(np.ceil(points * exchange_rate))
if lang == 'de':
bonus = f'{money} Euro wurden als Bonus verdient.'
bonus = '{} Euro wurden als Bonus verdient.'.format(money)
elif lang == 'en':
bonus = f'earned {money} Euros as bonus.'
bonus = 'earned {} Euros as bonus.'.format(money)
return bonus
......
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