-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.py
82 lines (69 loc) · 3.13 KB
/
task.py
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
#--- Day 2 ---#
# Import necessary libraries
from psychopy import visual, core,gui,event
import pandas as pd
import os
import datetime
# Import run_task function
from task_runner import run_task
from utils import get_random_walk_path
# Get participant number and session number using the dialog
info = {'subject_number': '', 'session_number': '', 'type_s': ''} # Define the dialog box dictionary
order = ['subject_number', 'session_number','type_s'] # Define the desired order
dlg = gui.DlgFromDict(info, title='INFO', order=order)
if not dlg.OK: # If the user cancels the dialog
core.quit()
if not info['subject_number'] or not info['session_number'] or not info['type_s']:
raise ValueError("Participant details not provided.")
# Access the values from the 'info' dictionary
subject_number = int(info['subject_number']) # Get and convert the subject number
session_number = int(info['session_number']) # Get the session number as a string
type_s = info['type_s']
# Initialize Window
win = visual.Window([800, 600], fullscr=True, color="white", colorSpace="rgb")
win.mouseVisible = False
# Setup Data
random_walk_practice = pd.read_csv("random_walk/practice/random_walk_practice.csv", header=None) #transpose rows and columns
random_walk_exp=get_random_walk_path(subject_number, session_number)
#Start practice
start_practice_text = "כעת נתחיל באימון. לחץ על כל מקש כדי להתחיל."[::-1]
# Display the message
start_practice = visual.TextStim(win, text=start_practice_text, pos=(0, 0), color="black",height=0.05)
start_practice.draw()
win.flip()
# Wait for any key to proceed
event.waitKeys()
# Practice Task
practice_trials_data = []
run_task(win,subject_number,type_s,session_number, num_trials=1, phase="practice", random_walk_data=random_walk_practice, trial_data_list=practice_trials_data)
# Save Practice Data
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
practice_file=os.path.join(
"results",
f"practice_data_subject_{subject_number}_session_{session_number}_type_{type_s}_{timestamp}.csv"
)
pd.DataFrame(practice_trials_data).to_csv(practice_file, index=False)
#End practice
end_practice_text = "האימון הסתיים. לחץ על כל מקש כדי להתחיל בניסוי."[::-1]
# Display the message
end_practice = visual.TextStim(win, text=end_practice_text, pos=(0, 0), color="black",height=0.05)
end_practice.draw()
win.flip()
# Wait for any key to proceed
event.waitKeys()
# Main Experiment Task
experiment_trials_data = []
run_task(win,subject_number,type_s,session_number ,num_trials=1, phase="experiment", random_walk_data=random_walk_exp, trial_data_list=experiment_trials_data,block_size=50)
# Save Experiment Data
experiment_file = os.path.join(
"results",
f"experiment_data_subject_{subject_number}_session_{session_number}_type_{type_s}_{timestamp}.csv"
)
pd.DataFrame(experiment_trials_data).to_csv(experiment_file, index=False)
#End experiment
end_practice_text = "הניסוי הסתיים."[::-1]
# Display the message
end_practice = visual.TextStim(win, text=end_practice_text, pos=(0, 0), color="black",height=0.05)
end_practice.draw()
win.flip()
event.waitKeys()