Creating feedback per trial that present latency

30 views
Skip to first unread message

Snir Barzilay

unread,
Jan 25, 2020, 3:39:25 AM1/25/20
to Minno.js
Hello everyone,

In the practice phase of my task I want to insert during a 1 ms blank screen a feedback that displays user's input latency after every trial. 
For example:

Correct!
870 ms response time. 

How could I do that? also could I save the relevant data in one interaction and use it in the next interaction? 
I want to insert the feedbank when 'blankcorrect' or 'blankerror' is triggered.

Best,

Snir

API.addTrialSets('base_local',[{
input: [
{handle:'left',on:'keypressed',key:'left'},
{handle:'right',on:'keypressed',key:'right'}
],

interactions: [
/* Display the cue stimulus. */
{
conditions:[{type:'begin'}],
actions: [
{type:'showStim',handle: 'fixation'},
{type:'removeInput',handle : ['left','right']},
{type:'setInput',input:{handle:'showMyStim', on:'timeout',duration:1000}}
]
},
{
conditions:[{type:'inputEquals',value:'showMyStim'}],
actions: [
{type:'resetTimer'},
{type:'hideStim',handle: 'fixation'},
{type:'showStim', handle: 'cue'},
{type:'setInput',input:{handle:'end',on:'timeout',duration:1500}},
{type:'setInput',input:{handle:'right',on: 'keypressed', key:['p','P']}},
{type:'setInput',input:{handle:'left',on: 'keypressed', key:['q','Q']}}
]
},


// ### Error feedback
// Lets add error feedback to our task.

// Above, we created the error stimulus. This creates a stimulus that displays a orange X at the bottom of the screen.

// Now that we have the error stimulus in place we can add the instruction how to display it.
// On incorrect responses we will display the error feedback, and trigger the end of the trial only after another 250 miliseconds.

/* Correct response actions */

{
conditions: [
{type:'inputEqualsStim',property:'correct_local'}
],
actions: [
{type:'setTrialAttr', setter:{score:1}},
{type:'setTrialAttr', setter:{message:'Correct response'}},
{type:'log'},
{type:'hideStim',handle:'cue'},
{type:'removeInput',handle:['left','right']},
{type:'removeInput',handle:'time'},
{type:'trigger', handle:'blankcorrect'}
]
},


/* Incorrect response actions */
{
conditions: [
{type:'inputEqualsStim',property:'correct_local',negate:true},
{type:'inputEquals',value:['left','right']}
],
actions: [
{type:'setTrialAttr', setter:{score:0}},
{type:'setTrialAttr', setter:{message:'Incorrect response'}},
{type:'log'},
{type:'removeInput',handle:['left','right']},
{type:'removeInput',handle:'time'},
{type:'hideStim',handle:'cue'},
{type:'trigger', handle:'blankerror'}
]
},
// . error feedback screen
{
conditions: [
{type:'inputEquals',value:'blankerror'},
{type:'trialEquals',property:'group',value:'practice_local'}
],
actions: [
{type:'showStim',handle:'error'},

{type:'trigger', handle:'end',on:'timeout',duration:1000}
]
},
// . correct feedback screen

{
conditions: [
{type:'inputEquals',value:'blankcorrect'},
{type:'trialEquals',property:'group',value:'practice_local'}
],
actions: [
{type:'showStim',handle:'correct'},
{type:'trigger', handle:'end',on:'timeout',duration:1000}
]
},

/* End trial */
{
conditions: [{type:'inputEquals', value:'end'}],
actions:[
{type:'hideStim',handle:'All'},
{type:'removeInput',handle:['left','right']},
{type:'endTrial'}
]
}


]
}]);


Elad Zlotnick

unread,
Jan 29, 2020, 8:20:09 AM1/29/20
to Minno.js
MinnoJS does not support live updates to templates, so you can do that manually.
In the stimulus create a place holder ({{latnecy}}).

{media: 'Correct!{{latency}} ms response time', handle:'correct'}

In the actions you can replace the place holder with the current latency:
(The data-handle attribute of the stimulus needs to be set according to the stimulus handle)
The requestAnimationFrame clause prevents us from losing a frame to a redraw here.
{type:'custom', fn:function(condition, inputData){
    var el = document.querySelector('[data-handle="correct"]');
    requestAnimationFrame(function(){
        el.innerHTML = el.innerHTML.replace('{{latency}}', Math.floor(inputData.latency));
    });
}}

And then simply show the stimulus:

{type:'showStim', handle:'correct'}

Snir Barzilay

unread,
Jan 29, 2020, 9:01:50 AM1/29/20
to Minno.js
Excellent! this worked perfectly!
thank you.

Yoav Bar-Anan

unread,
Sep 25, 2021, 1:13:55 AM9/25/21
to Minno.js
I have another question related to this topic: Is there a similar method to change a value passed to an action?

My action is:
{type:'trigger', handle:'Wait', duration:'<%=trialData.stimDur%>'}
However,  I change the stimDur within the trial. Is there any way to dynamically change the duration of the trigger after the trial starts?

Thanks,
Yoav

Elad Zlotnick

unread,
Sep 30, 2021, 8:27:08 AM9/30/21
to Minno.js
Hi Yoav,

Yes there is, though it is a bit more involved.
You can create a custom action by replacing the action by a function.
You can get an idea for how actions work by looking in this file: https://github.com/minnojs/minno-time/blob/0.5/src/app/trial/interactions/actionList.js

What you are trying to do, is to slightly change the trigger action.
I'd try swapping the whole action with the following function:

    function(action, eventData, trial){
        trial.input.add({handle:action.handle, on:'timeout', duration:+trial.data.stimDur});
    },

best of luck,
Elad

Yoav Bar-Anan

unread,
Oct 3, 2021, 3:04:08 AM10/3/21
to Minno.js
Thanks Elad,  It worked well. Specifically, this is the code I used for the action:

        {type:'custom',fn:function(action,eventData,trial){ //Using a custom function allows us to set the duration on the fly.
             trial.data.stimDur = trial.data.minDur+Math.round((Math.random()*current.randRange)); //Compute a wait duration specifically for this trial
             trial.input.add({handle:'Wait', on:'timeout', duration:trial.data.stimDur}); //We want to trigger the input 'Wait' after a duration of trial.data.stimDur ms
   }}

Note that 'Wait' is the handle for the input I want to be called after the timeout. 

Yoav

--
You received this message because you are subscribed to a topic in the Google Groups "Minno.js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/minnojs/QouhK_6v0B8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to minnojs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/minnojs/a883109a-e5d7-48f2-bc7b-678bda9b6c4fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages