new module for instruction strings and flows

parent 7ec620fd
"""Functions that either provide an instruction flow or a string to display."""
import numpy as np
import pandas as pd
from sp_experiment.utils import get_final_choice_outcomes
def provide_blockfbk_str(data_file, current_nblocks, nblocks, lang):
"""Provide a string to be displayed during block feedback.
Parameters
----------
data_file : str
Path to the data file from which to calculate current amount of points.
current_nblocks : int
nblocks : int
lang : str
Language, can be 'de' or 'en' for German or English.
Returns
-------
block_feedback : str
"""
# Current number of points
df_tmp = pd.read_csv(data_file, sep='\t')
outcomes = get_final_choice_outcomes(df_tmp)
points = int(np.sum(outcomes))
if lang == 'de':
block_feedback = (f'Block {current_nblocks}/{nblocks} beendet!' # noqa: E999 E501
f' Sie haben bisher {points} Punkte gesammelt.'
' Am Ende des Experiments werden Ihre Punkte'
' in Euro umgerechnet und Ihnen als Bonus gezahlt.'
' Machen Sie jetzt eine kurze Pause.'
' Druecken Sie einen beliebigen Knopf um'
' fortzufahren.')
elif lang == 'en':
block_feedback = (f'Block {current_nblocks}/{nblocks} done!' # noqa: E999 E501
f' You earned {points} points so far.'
' Remember that your points will be '
' converted to Euros and paid to you at'
' the end of the experiment as a bonus.'
' Take a short break now.'
' Then press any key to continue.')
return block_feedback
......@@ -38,12 +38,12 @@ from sp_experiment.utils import (KEYLIST_SAMPLES,
get_payoff_dict,
get_passive_action,
get_passive_outcome,
get_final_choice_outcomes
)
from sp_experiment.define_payoff_settings import (get_payoff_settings,
get_random_payoff_dict,
)
from sp_experiment.define_ttl_triggers import provide_trigger_dict
from sp_experiment.define_instructions import (provide_blockfbk_str)
def navigation(nav='initial', bonus=''):
......@@ -649,18 +649,11 @@ def run_flow(monitor='testMonitor', ser=Fake_serial(), max_ntrls=10,
# provide a short break
if (current_ntrls+1) % block_size == 0:
current_nblocks += 1
df_tmp = pd.read_csv(data_file, sep='\t')
outcomes = get_final_choice_outcomes(df_tmp)
points = int(np.sum(outcomes))
[stim.setAutoDraw(False) for stim in fixation_stim_parts]
txt_stim.text = (f'Block {current_nblocks}/{nblocks} done!'
f' You earned {points} points so far.'
' Remember that your points will be '
' converted to Euros and paid to you at'
' the end of the experiment as a bonus.'
' Take a short break now.'
' Then press any key to continue.')
txt_stim.text = provide_blockfbk_str(data_file,
current_nblocks,
nblocks,
lang='de')
txt_stim.pos = (0, 0)
txt_stim.height = 1
txt_stim.draw()
......
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