forked from JulBenistant/SMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMS_experiment_v1Beta.asv
219 lines (168 loc) · 7.79 KB
/
SMS_experiment_v1Beta.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
function [data] = SMS_experiment_v1Beta(action,varargin)
action='run_exp';
try
data = run_exp();
catch ME
clean_exit()
sca
rethrow(ME)
end
end
function [data] = run_exp()
sca;
close all;
clearvars;
data.dbstack = dbstack; %For debug ?
data.time.start = now; % Get the time when the task begin
rng('shuffle'); % seed the rand
data.debug = 0; %-- not in debug mode
%% -- Prepare functions in memory
Screen('Screens');
KbName('UnifyKeyNames') %-- Unified key names across platforms
%% -- Task parameters
% load Matrix_test_oth_subj_data
data.parameters.task.ntrials = 3;
data.parameters.task.nruns = 1;
data.parameters.task.score_ratio = 1;
data.parameters.task.rank_mat = [1,2,3,4,5]; % Matrice contenant les rangs
data.parameters.task.Table_payoff = [10,8,6,4,2];
data.text.jump_line = {'\n'};
% Creates the score/rt matrix
a = 0.1:0.01:2;
b = 200:-1:10;
for xx = 1:191
data.fction_score(1,xx) = a(1,xx);
data.fction_score(2,xx) = b(1,xx);
end
% Creation bot (fake subjects)
[data] = botscore(data);
%% -- Participant code
if data.debug ; data.participant.code = ''; return ; end
data.participant.code=input('Participant code (leave empty for testing): ', 's');
if isempty(data.participant.code) ; data.debug = 1 ;end
if data.debug ; data.datafile = []; else data.datafile = datestr(data.time.start,30); end
data.task.monetary=input('Monetary part (Empty = No & 1 = Yes): ', 's');
data.task.social=input('Social part (Empty = No & 1 = Yes): ', 's');
%% -- Write .log
Write_log(sprintf('Participant: %s',data.participant.code),data.datafile);
Write_log(sprintf('Data files: %s',data.datafile),data.datafile);
%% -- Psychtoolbox Graphics
ListenChar(2); %-- "Ecouter le clavier ON" (0 = stop)
priorityLevel = 2; %-- Ideally : priorityLevel = MaxPriority(data.frame.ptr,'KbCheck');
Priority(priorityLevel);
% HideCursor; %-- Hide mouse cursor
% Display PTB
PsychDefaultSetup(2); % Here we call some default settings for setting up Psychtoolbox
screens = Screen('Screens'); % Get the screen numbers
screenNumber = max(screens); % Draw to the external screen if avaliable
% Define black and white
sc.white = WhiteIndex(screenNumber);
sc.black = BlackIndex(screenNumber);
% Screen('Preference', 'SkipSyncTests', 2);
[window, sc.windowRect] = PsychImaging('OpenWindow', screenNumber, sc.black); % Open an on screen window
[sc.screenXpixels, sc.screenYpixels] = Screen('WindowSize', window); % Get the size of the on screen window
sc.ifi = Screen('GetFlipInterval', window); % Query the frame duration
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA'); % Set up alpha-blending for smooth (anti-aliased) lines
%% -- Beginning of run : time
data.time.t0 = GetSecs;
%% -- Get ready
write_text(window,'.',sc.white);
write_text(window,'Nous allons demarrer...',sc.white);
if ~data.debug ; WaitSecs(2); end
intro_text={'As soon as the fixation cross become a square, press Enter \n\n Press Any Key To Begin'};
write_text(window,intro_text{1},sc.white);
if ~data.debug ; save(data.datafile,'data') ; else save('tmp.mat','data') ; end
%% -- Training real effort (in construction)
%% -- Monetary trials
dataM = [];
if ~isempty(data.task.monetary)
[data] = GetParams(data,sc,'monetary');
trialnb =0;
for i_run = 1 : data.parameters.task.nruns
run_text_Mon1 = {'Preparez vous !'};
run_text_Mon2 = sprintf('(Bloc numero #%d)',i_run);
run_text_Mon3 = {'Appuyer sur ENTREE pour commencer...'};
write_text(window,([run_text_Mon1{1},data.text.jump_line{1},...
run_text_Mon2,data.text.jump_line{1},run_text_Mon3{1},...
]),sc.white);
for i_trial = 1 : data.parameters.task.ntrials
trialnb = trialnb +1;
dataM(trialnb,1) = i_run;
dataM(trialnb,2) = trialnb;
datax2 = SMS_run_trial_monetary_V1Beta(window,data,sc,data.parameters.task.monetary,i_trial);
dataM(trialnb,3:12) = table2array(datax2);
if ~data.debug ; save(data.datafile,'data', 'dataM'); else save('tmp.mat','data', 'dataM'); end
end
end
% Random selection of one trial
data.Run_Mon = randi(data.parameters.task.nruns,1);
data.Trial_Mon = randi(data.parameters.task.ntrials,1);
data.Payoff_Mon_Final = dataM((data.Run_Mon*data.Trial_Mon),10);
%% -- Inter condition screen
run_text_Inter1 = {'Preparez vous !'};
run_text_Inter2 = {'Nous allons maintenant commencer la seconde partie'};
run_text_Inter3 = {'Appuyer sur ENTREE pour commencer...'};
write_text(window,([run_text_Inter1{1},data.text.jump_line{1},...
run_text_Inter2{1},data.text.jump_line{1},run_text_Inter3{1}]),...
sc.white);
end
%% -- Social trials (in construction)
dataS = [];
if ~isempty(data.task.social)
[data] = GetParams(data,sc,'social');
trialnb =0;
for i_run = 1 : data.parameters.task.nruns
run_text_Soc1 = {'Preparez vous !'};
run_text_Soc2 = sprintf('(Bloc numero #%d)',i_run);
run_text_Soc3 = {'Appuyer sur ENTREE pour commencer...'};
write_text(window,([run_text_Soc1{1},data.text.jump_line{1},...
run_text_Soc2,data.text.jump_line{1},run_text_Soc3{1},...
]),sc.white);
for i_trial = 1 : data.parameters.task.ntrials
trialnb = trialnb +1;
dataS(trialnb,1) = i_run;
dataS(trialnb,2) = trialnb;
datax3 = SMS_run_trial_social_V1Beta(window,data,sc,data.parameters.task.social,i_trial);
dataS(trialnb,3:12) = table2array(datax3);
if ~data.debug ; save(data.datafile,'data', 'dataS'); else save('tmp.mat','data', 'dataS'); end
end
end
data.Run_Soc = randi(data.parameters.task.nruns,1);
data.Trial_Mon = randi(data.parameters.task.ntrials,1);
data.Payoff_Social_Final = dataS((data.Run_Mon*data.Trial_Mon),10);
data.Rank_Social_Final = dataS((data.Run_Mon*data.Trial_Mon),7);
end
%% ***************** Final Feedback *****************
final_fbM = sprintf('Durant la partie A vous avez gagne %0.2f',data.Payoff_Mon_Final);
final_fbS = sprintf('Durant la partie B vous avez gagne %0.2f et vous êtes le numéro %s',data.Payoff_Social_Final,data.Rank_Social_Final);
%% *********End*******
if ~data.debug ; save(data.datafile,'data', 'dataM', 'dataS') ; else save('tmp.mat','data', 'dataM','dataS') ; end
% Wait for a key press
KbStrokeWait;
% Clear the screen
clean_exit();
sca;
end
function []=clean_exit()
Priority(0);
ListenChar(0);
ShowCursor
end
function [data] = botscore(data)
for ii = 1:4
for jj = 1:5
% data.run.score_oth(jj) = [];
test.Subj(ii).tr(jj).rt_square = 0.5 + (1.5-0.3).*rand(1,1); % create a random score for a given subj in a given trial
test.Subj(ii).tr(jj).rt_raw = test.Subj(ii).tr(jj).rt_square*data.parameters.task.score_ratio;
test.Subj(ii).tr(jj).rt_rounded = round(test.Subj(ii).tr(jj).rt_raw,2);
%transfo rt en score
[~,test.Subj(ii).tr(jj).column_fction_score] = ismembertol( test.Subj(ii).tr(jj).rt_rounded,data.fction_score(1,:),0.001); % Get column corresponding to the rt_rounded
test.Subj(ii).tr(jj).Score = data.fction_score(2,test.Subj(ii).tr(jj).column_fction_score); % Copy-paste from fction_score to Subj matrix
end
end
for jj = 1:5
data.run.trial(jj).score_oth = [test.Subj(1).tr(jj).Score,...
test.Subj(2).tr(jj).Score,test.Subj(3).tr(jj).Score,...
test.Subj(4).tr(jj).Score];
end
end