Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
test_gonogo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Laura Rodríguez
test_gonogo
Commits
25dc3da8
Commit
25dc3da8
authored
Jun 17, 2025
by
Laura Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
17 jun
parent
657966b4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
153 additions
and
100 deletions
+153
-100
test_final.py
+153
-100
No files found.
test_final.py
View file @
25dc3da8
...
@@ -103,7 +103,7 @@ def calibrate_tobii(self):
...
@@ -103,7 +103,7 @@ def calibrate_tobii(self):
# ============ TEST P
RO
/NOGO ======================
# ============ TEST P
S
/NOGO ======================
def
run_pro_nogo_test
(
self
):
def
run_pro_nogo_test
(
self
):
pygame
.
init
()
pygame
.
init
()
...
@@ -283,7 +283,7 @@ def run_pro_nogo_test(self):
...
@@ -283,7 +283,7 @@ def run_pro_nogo_test(self):
print
(
"Resultados guardados en 'gonogo_results.xlsx'."
)
print
(
"Resultados guardados en 'gonogo_results.xlsx'."
)
# ============ TEST P
R
/AS ===================
# ============ TEST P
S
/AS ===================
def
run_pr_as_test
(
self
):
def
run_pr_as_test
(
self
):
...
@@ -353,6 +353,7 @@ def run_pr_as_test(self):
...
@@ -353,6 +353,7 @@ def run_pr_as_test(self):
max_blocks
=
30
max_blocks
=
30
results
=
[]
results
=
[]
try
:
try
:
self
.
tracker
.
start_recording
()
for
block
in
range
(
max_blocks
):
for
block
in
range
(
max_blocks
):
trials
=
[
'PS'
,
'AS'
]
trials
=
[
'PS'
,
'AS'
]
fixation_duration
=
random
.
choice
([
1000
,
2000
,
3000
])
# milisegundos
fixation_duration
=
random
.
choice
([
1000
,
2000
,
3000
])
# milisegundos
...
@@ -367,7 +368,7 @@ def run_pr_as_test(self):
...
@@ -367,7 +368,7 @@ def run_pr_as_test(self):
# Mostrar cruz de fijación
# Mostrar cruz de fijación
self
.
disp
.
fill
(
fixscreen
)
self
.
disp
.
fill
(
fixscreen
)
self
.
disp
.
show
()
self
.
disp
.
show
()
libtime
.
pause
(
random
.
randint
(
750
,
1250
))
#
libtime.pause(random.randint(750, 1250))
libtime
.
pause
(
fixation_duration
)
# Usamos la duración fija del bloque
libtime
.
pause
(
fixation_duration
)
# Usamos la duración fija del bloque
# # Esperar que el usuario presione espacio
# # Esperar que el usuario presione espacio
...
@@ -382,7 +383,6 @@ def run_pr_as_test(self):
...
@@ -382,7 +383,6 @@ def run_pr_as_test(self):
time
.
sleep
(
0.2
)
time
.
sleep
(
0.2
)
self
.
tracker
.
start_recording
()
# Mostrar señal central de color
# Mostrar señal central de color
self
.
disp
.
fill
(
signal_screens
[
trialtype
])
self
.
disp
.
fill
(
signal_screens
[
trialtype
])
...
@@ -416,7 +416,6 @@ def run_pr_as_test(self):
...
@@ -416,7 +416,6 @@ def run_pr_as_test(self):
latency
=
(
t1
-
t0
)
/
1000
latency
=
(
t1
-
t0
)
/
1000
self
.
tracker
.
stop_recording
()
# midpoint = SCREEN_WIDTH / 2
# midpoint = SCREEN_WIDTH / 2
# margin = 100
# margin = 100
...
@@ -444,6 +443,7 @@ def run_pr_as_test(self):
...
@@ -444,6 +443,7 @@ def run_pr_as_test(self):
results
.
append
([
trialnr
,
trialtype
,
targetside
,
endpos
,
round
(
latency
,
3
),
correct
])
results
.
append
([
trialnr
,
trialtype
,
targetside
,
endpos
,
round
(
latency
,
3
),
correct
])
self
.
tracker
.
stop_recording
()
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
print
(
"Test interrumpido por el usuario con la tecla 'E'."
)
print
(
"Test interrumpido por el usuario con la tecla 'E'."
)
finally
:
finally
:
...
@@ -655,35 +655,23 @@ def open_results_file():
...
@@ -655,35 +655,23 @@ def open_results_file():
# ============ TEST BATERIA ===================
# ============ TEST BATERIA ===================
def
run_bateria_test
(
self
):
def
run_bateria_test
(
self
):
import
pygame
from
random
import
choice
from
pygaze
import
libscreen
,
liblog
from
pygaze.keyboard
import
Keyboard
import
constants
from
pygaze.display
import
Display
from
pygaze.eyetracker
import
EyeTracker
pygame
.
init
()
pygame
.
init
()
# self.test_window.disp = self.disp
while
True
:
self
.
disp
=
libscreen
.
Display
(
bgcolor
=
(
0
,
0
,
0
))
#abro display de nuevo
self
.
disp
=
libscreen
.
Display
(
bgcolor
=
(
0
,
0
,
0
))
# Abrir pantalla
# self.tracker = eyetracker.EyeTracker(self.disp)
log
=
liblog
.
Logfile
()
log
=
liblog
.
Logfile
()
log
.
write
([
"trialnr"
,
"trialtype"
,
"targetside"
,
"gaze_endpos"
,
"latency"
,
"correct"
])
log
.
write
([
"trialnr"
,
"trialtype"
,
"targetside"
,
"gaze_endpos"
,
"latency"
,
"correct"
])
kb
=
Keyboard
()
tracker
=
EyeTracker
(
self
.
disp
)
# Constantes
SCREEN_WIDTH
,
SCREEN_HEIGHT
=
constants
.
DISPSIZE
SCREEN_WIDTH
,
SCREEN_HEIGHT
=
constants
.
DISPSIZE
CENTER
=
(
SCREEN_WIDTH
//
2
,
SCREEN_HEIGHT
//
2
)
CENTER
=
(
SCREEN_WIDTH
//
2
,
SCREEN_HEIGHT
//
2
)
TARGET_OFFSET
=
382
TARGET_OFFSET
=
382
left_pos
=
(
CENTER
[
0
]
-
TARGET_OFFSET
,
CENTER
[
1
])
left_pos
=
(
CENTER
[
0
]
-
TARGET_OFFSET
,
CENTER
[
1
])
right_pos
=
(
CENTER
[
0
]
+
TARGET_OFFSET
,
CENTER
[
1
])
right_pos
=
(
CENTER
[
0
]
+
TARGET_OFFSET
,
CENTER
[
1
])
center
=
CENTER
arrow_length
=
100
arrow_color
=
(
255
,
255
,
255
)
n_trials
=
5
# Pantalla de instrucciones
blackscreen
=
libscreen
.
Screen
()
blackscreen
.
clear
(
colour
=
(
0
,
0
,
0
))
inscreen
=
libscreen
.
Screen
()
inscreen
=
libscreen
.
Screen
()
inscreen
.
clear
(
colour
=
(
0
,
0
,
0
))
inscreen
.
clear
(
colour
=
(
0
,
0
,
0
))
ins_text
=
(
ins_text
=
(
...
@@ -694,7 +682,31 @@ def run_bateria_test(self):
...
@@ -694,7 +682,31 @@ def run_bateria_test(self):
"Pulsa ESPACIO para comenzar la prueba.
\n
"
"Pulsa ESPACIO para comenzar la prueba.
\n
"
"Pulsa E para salir."
"Pulsa E para salir."
)
)
time
.
sleep
(
0.7
)
inscreen
.
draw_text
(
text
=
ins_text
,
fontsize
=
30
,
pos
=
CENTER
,
colour
=
(
255
,
255
,
255
),
center
=
True
)
inscreen
.
draw_text
(
text
=
ins_text
,
fontsize
=
30
,
pos
=
CENTER
,
colour
=
(
255
,
255
,
255
),
center
=
True
)
fixscreen
=
libscreen
.
Screen
()
fixscreen
.
clear
(
colour
=
(
0
,
0
,
0
))
fixscreen
.
draw_fixation
(
fixtype
=
'cross'
,
diameter
=
57
,
pos
=
CENTER
,
colour
=
(
255
,
255
,
255
))
signal_screens
=
{
'PS'
:
libscreen
.
Screen
(),
'AS'
:
libscreen
.
Screen
(),
'NoGo'
:
libscreen
.
Screen
()
}
for
key
,
color
in
[(
'PS'
,
(
0
,
255
,
0
)),
(
'AS'
,
(
255
,
0
,
0
)),
(
'NoGo'
,
(
255
,
165
,
0
))]:
signal_screens
[
key
]
.
clear
(
colour
=
(
0
,
0
,
0
))
signal_screens
[
key
]
.
draw_circle
(
pos
=
CENTER
,
r
=
38
,
fill
=
True
,
colour
=
color
)
feedbackscreens
=
{
1
:
libscreen
.
Screen
(),
0
:
libscreen
.
Screen
()
}
feedbackscreens
[
1
]
.
clear
(
colour
=
(
0
,
0
,
0
))
feedbackscreens
[
1
]
.
draw_text
(
text
=
'Correcto'
,
fontsize
=
30
,
pos
=
CENTER
,
colour
=
(
0
,
255
,
0
),
center
=
True
)
feedbackscreens
[
0
]
.
clear
(
colour
=
(
0
,
0
,
0
))
feedbackscreens
[
0
]
.
draw_text
(
text
=
'Incorrecto'
,
fontsize
=
30
,
pos
=
CENTER
,
colour
=
(
255
,
0
,
0
),
center
=
True
)
self
.
disp
.
fill
(
inscreen
)
self
.
disp
.
fill
(
inscreen
)
self
.
disp
.
show
()
self
.
disp
.
show
()
...
@@ -707,102 +719,143 @@ def run_bateria_test(self):
...
@@ -707,102 +719,143 @@ def run_bateria_test(self):
elif
event
.
key
==
pygame
.
K_e
:
elif
event
.
key
==
pygame
.
K_e
:
pygame
.
quit
()
pygame
.
quit
()
return
return
total_trials
=
5
results
=
[]
try
:
trials
=
[
'PS'
,
'AS'
,
'NoGo'
]
*
2
# Para asegurar que haya variedad
random
.
shuffle
(
trials
)
selected_trials
=
trials
[:
total_trials
]
screen
=
libscreen
.
Screen
()
for
trialnr
,
trialtype
in
enumerate
(
selected_trials
,
start
=
1
):
def
wait_with_exit
(
seconds
):
start
=
pygame
.
time
.
get_ticks
()
while
(
pygame
.
time
.
get_ticks
()
-
start
)
<
seconds
*
1000
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
KEYDOWN
and
event
.
key
==
pygame
.
K_e
:
if
event
.
type
==
pygame
.
KEYDOWN
and
event
.
key
==
pygame
.
K_e
:
pygame
.
quit
()
raise
KeyboardInterrupt
exit
()
# Mostrar cruz de fijación
for
trial
in
range
(
n_trials
):
self
.
disp
.
fill
(
fixscreen
)
# Mensaje previo
screen
.
clear
(
colour
=
(
0
,
0
,
0
))
screen
.
draw_text
(
f
"Trial {trial + 1} de {n_trials}
\n
Pulsa E para salir o espera para comenzar..."
,
fontsize
=
30
,
colour
=
(
255
,
255
,
255
))
self
.
disp
.
fill
(
screen
)
self
.
disp
.
show
()
self
.
disp
.
show
()
wait_with_exit
(
2.0
)
libtime
.
pause
(
random
.
randint
(
750
,
1250
))
# Esperar que el usuario presione espacio
# waiting = True
# while waiting:
# for event in pygame.event.get():
# if event.type == pygame.KEYDOWN:
# if event.key == pygame.K_SPACE:
# waiting = False
# elif event.key == pygame.K_e:
# raise KeyboardInterrupt
# Dirección y condición
time
.
sleep
(
0.2
)
direction
=
choice
([
"left"
,
"right"
])
condition
=
choice
([
"pro"
,
"anti"
,
"nogo"
])
if
condition
==
"pro"
:
self
.
tracker
.
start_recording
()
central_color
=
(
0
,
255
,
0
)
elif
condition
==
"anti"
:
central_color
=
(
255
,
0
,
0
)
else
:
central_color
=
(
255
,
165
,
0
)
# Estímulo central
# Mostrar señal central de color
screen
.
clear
(
colour
=
(
0
,
0
,
0
))
self
.
disp
.
fill
(
signal_screens
[
trialtype
])
screen
.
draw_circle
(
colour
=
central_color
,
pos
=
center
,
r
=
28
,
fill
=
True
)
self
.
disp
.
fill
(
screen
)
self
.
disp
.
show
()
self
.
disp
.
show
()
wait_with_exit
(
1.0
)
time
.
sleep
(
0.8
)
# Flechas y círculos
self
.
disp
.
fill
(
blackscreen
)
screen
.
clear
(
colour
=
(
0
,
0
,
0
)
)
self
.
disp
.
show
(
)
screen
.
draw_circle
(
colour
=
central_color
,
pos
=
center
,
r
=
28
,
fill
=
True
)
time
.
sleep
(
0.2
)
if
direction
==
"left"
:
targetside
=
random
.
choice
([
'left'
,
'right'
])
big_circle_pos
=
left_pos
target_pos
=
left_pos
if
targetside
==
'left'
else
right_pos
small_circle_pos
=
right_pos
nontarget_pos
=
right_pos
if
targetside
==
'left'
else
left_pos
else
:
# Mostrar flecha de dirección según la condición (PS, AS, NoGo)
big_circle_pos
=
right_pos
arrow_screen
=
libscreen
.
Screen
()
small_circle_pos
=
left_pos
arrow_screen
.
clear
(
colour
=
(
0
,
0
,
0
))
screen
.
draw_circle
(
colour
=
(
255
,
255
,
255
),
pos
=
big_circle_pos
,
r
=
52
,
fill
=
True
)
screen
.
draw_circle
(
colour
=
(
255
,
255
,
255
),
pos
=
small_circle_pos
,
r
=
38
,
fill
=
True
)
# Dibujar flecha
if
condition
!=
"nogo"
:
arrow_dir
=
direction
if
condition
==
"pro"
else
(
"left"
if
direction
==
"right"
else
"right"
)
if
arrow_dir
==
"right"
:
end
=
(
center
[
0
]
+
arrow_length
,
center
[
1
])
screen
.
draw_line
(
colour
=
arrow_color
,
spos
=
center
,
epos
=
end
,
pw
=
6
)
screen
.
draw_line
(
colour
=
arrow_color
,
spos
=
end
,
epos
=
(
end
[
0
]
-
30
,
end
[
1
]
-
30
),
pw
=
6
)
screen
.
draw_line
(
colour
=
arrow_color
,
spos
=
end
,
epos
=
(
end
[
0
]
-
30
,
end
[
1
]
+
30
),
pw
=
6
)
else
:
end
=
(
center
[
0
]
-
arrow_length
,
center
[
1
])
screen
.
draw_line
(
colour
=
arrow_color
,
spos
=
center
,
epos
=
end
,
pw
=
6
)
screen
.
draw_line
(
colour
=
arrow_color
,
spos
=
end
,
epos
=
(
end
[
0
]
+
30
,
end
[
1
]
-
30
),
pw
=
6
)
screen
.
draw_line
(
colour
=
arrow_color
,
spos
=
end
,
epos
=
(
end
[
0
]
+
30
,
end
[
1
]
+
30
),
pw
=
6
)
# Mostrar y grabar
arrow_offset
=
100
# desplazamiento vertical para colocar la flecha por encima
self
.
disp
.
fill
(
screen
)
arrow_color
=
(
255
,
255
,
255
)
tracker
.
start_recording
()
tracker
.
log
(
"TRIAL_
%
d_COND_
%
s_DIR_
%
s"
%
(
trial
+
1
,
condition
.
upper
(),
direction
.
upper
()))
if
trialtype
==
'PS'
:
arrow_pos
=
target_pos
elif
trialtype
==
'AS'
:
arrow_pos
=
nontarget_pos
else
:
# NoGo
arrow_pos
=
CENTER
arrow_pos_above
=
(
arrow_pos
[
0
],
arrow_pos
[
1
]
-
arrow_offset
)
arrow_screen
.
draw_text
(
text
=
'↑'
,
fontsize
=
60
,
pos
=
arrow_pos_above
,
colour
=
arrow_color
,
center
=
True
)
self
.
disp
.
fill
(
arrow_screen
)
self
.
disp
.
show
()
self
.
disp
.
show
()
wait_with_exit
(
1.5
)
time
.
sleep
(
0.8
)
tracker
.
stop_recording
()
dualstim_screen
=
libscreen
.
Screen
()
dualstim_screen
.
clear
(
colour
=
(
0
,
0
,
0
))
dualstim_screen
.
draw_circle
(
pos
=
nontarget_pos
,
r
=
28
,
fill
=
True
,
colour
=
(
255
,
255
,
255
))
dualstim_screen
.
draw_circle
(
pos
=
target_pos
,
r
=
38
,
fill
=
True
,
colour
=
(
255
,
255
,
255
))
dualstim_screen
.
draw_circle
(
pos
=
target_pos
,
r
=
32
,
fill
=
True
,
colour
=
(
0
,
0
,
0
))
dualstim_screen
.
draw_circle
(
pos
=
target_pos
,
r
=
28
,
fill
=
True
,
colour
=
(
255
,
255
,
255
))
# Cruz entre trials
self
.
disp
.
fill
(
dualstim_screen
)
screen
.
clear
(
colour
=
(
0
,
0
,
0
))
screen
.
draw_text
(
"+"
,
fontsize
=
40
)
self
.
disp
.
fill
(
screen
)
self
.
disp
.
show
()
self
.
disp
.
show
()
wait_with_exit
(
0.8
)
# Preguntar si repetir
t0
=
pygame
.
time
.
get_ticks
()
screen
.
clear
(
colour
=
(
0
,
0
,
0
))
self
.
tracker
.
log
(
f
"target {targetside}"
)
screen
.
draw_text
(
"Test completado. ¿Quieres volver a intentarlo?
\n\n
Pulsa S para repetir o N para salir."
,
fontsize
=
30
,
colour
=
(
255
,
255
,
255
))
# try:
self
.
disp
.
fill
(
screen
)
t1
,
startpos
=
self
.
tracker
.
wait_for_saccade_start
()
endtime
,
startpos
,
endpos
=
self
.
tracker
.
wait_for_saccade_end
()
latency
=
(
t1
-
t0
)
/
1000
self
.
tracker
.
stop_recording
()
# midpoint = SCREEN_WIDTH / 2
# margin = 100
# endpos=None
if
trialtype
==
'PS'
:
correct
=
int
(
(
targetside
==
'left'
and
endpos
[
0
]
<=
constants
.
DISPSIZE
[
0
]
/
2
)
or
(
targetside
==
'right'
and
endpos
[
0
]
>=
constants
.
DISPSIZE
[
0
]
/
2
)
)
print
(
correct
)
elif
trialtype
==
'AS'
:
correct
=
int
(
(
targetside
==
'left'
and
endpos
[
0
]
>=
constants
.
DISPSIZE
[
0
]
/
2
)
or
(
targetside
==
'right'
and
endpos
[
0
]
<=
constants
.
DISPSIZE
[
0
]
/
2
)
)
print
(
correct
)
elif
trialtype
==
'NoGo'
:
# En NoGo siempre se considera incorrecto
try
:
t1
,
startpos
=
self
.
tracker
.
wait_for_saccade_start
(
latency
=
200
)
endtime
,
_
,
endpos
=
self
.
tracker
.
wait_for_saccade_end
()
latency
=
(
t1
-
t0
)
/
1000
print
(
"Incorrecto - Sacada detectada"
)
except
Exception
:
latency
=
0
endpos
=
None
print
(
"Incorrecto - No se detectó sacada"
)
correct
=
0
self
.
disp
.
fill
(
feedbackscreens
[
correct
])
self
.
disp
.
show
()
self
.
disp
.
show
()
while
True
:
time
.
sleep
(
0.5
)
key
,
_
=
kb
.
get_key
(
keylist
=
[
's'
,
'n'
,
'e'
])
if
key
==
's'
:
break
# vuelve al inicio del while True
elif
key
in
[
'n'
,
'e'
]:
pygame
.
quit
()
return
results
.
append
([
trialnr
,
trialtype
,
targetside
,
endpos
,
round
(
latency
,
3
),
correct
])
except
KeyboardInterrupt
:
print
(
"Test interrumpido por el usuario con la tecla 'E'."
)
finally
:
log
.
close
()
self
.
tracker
.
close
()
self
.
disp
.
close
()
print
(
"Test Go/NoGo finalizado."
)
df
=
pd
.
DataFrame
(
results
,
columns
=
[
"trialnr"
,
"trialtype"
,
"targetside"
,
"gaze_endpos"
,
"latency"
,
"correct"
])
df
.
to_excel
(
"gonogo_results.xlsx"
,
index
=
False
)
print
(
"Resultados guardados en 'gonogo_results.xlsx'."
)
# ============ INTERFAZ PYQT ===================
# ============ INTERFAZ PYQT ===================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment