-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestant.py
More file actions
executable file
·140 lines (109 loc) · 4.25 KB
/
Copy pathtestant.py
File metadata and controls
executable file
·140 lines (109 loc) · 4.25 KB
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
"""
Example of how to use the ANT module
"""
import sys
import os
from psychopy import visual, core, event, monitors, tools, logging, gui, clock, data
import pyglet
import time
import numpy as np
import random as random
from ant import ANTExp
import threading
import itchat
friend = '言午'
try:
itchat.auto_login(True)
itchat.send('Hello',toUserName = 'filehelper')
except Exception:
print("error!!!")
################################
### Main program starts here
# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)
# Store info about the experiment session
psychopyVersion = '3.0.5'
expName = 'ANTSend' # from the Builder filename that created this script
expInfo = {'session': '01', 'participant': ''}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data' + os.sep + '%s_%s' % (expInfo['participant'], expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath='/downloads/ant-master/testant.py',
savePickle=True, saveWideText=True,
dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.WARNING)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for 'escape' or other condition => quit the exp
# Start Code - component code to be run before the window creation
# Prepare the window and stimulus
winsize = [1440, 900]
mon = monitors.Monitor('testMonitor', distance=60, width=28.5)
mon.setDistance(60)
mon.setWidth(28.5)
mon.setSizePix(winsize)
win = visual.Window(winsize, waitBlanking=True, winType='pyglet', fullscr=True,
color='white', units='deg', monitor=mon)
pw = visual.TextStim(win, alignHoriz='center', wrapWidth=12, height=0.01, color='black',
text="Please wait (checking screen timing)...")
pw.autoDraw = True
pw.draw()
win.flip()
refresh = win.getActualFrameRate(nIdentical=50, nMaxFrames=900, nWarmUpFrames=100, threshold=1)
pw.autoDraw = False
halted = False
win.flip()
globalClock = core.Clock()
startTime = time.time()
now = globalClock.getTime()
if now > 0.001:
sys.stderr.write("WARNING: Your machine seems a little slow; just looking at the watch takes more than 1 mS (%.3f)!\n" % t0)
else:
print("Internal initial timing offset is not to worry about (only %0.6f s)" % now)
endExperiment = False
exp = ANTExp(mon, win, winsize, refresh, globalClock, startTime, logFile)
noPractice = exp.displayInstructions()
allData = None
if noPractice:
sys.stderr.write("Skipped practice block on user's request\n")
else:
exp.displayText("Starting practice block in 2 seconds", noWait=True, showLine=False, time=2)
if not exp.practiceBlock():
sys.stderr.write("Shortened practice block on user's request\n")
clock = core.Clock()
for r in range(4):
if r%2 == 0:
if exp.displayText("Starting experimental block %d of 2\nHit any key when ready to start." % (r/2+1), showLine=False):
break
core.wait(1)
if r ==2:
exp.displayText("现在开始休息1分钟", noWait = True, time = 60)
block = exp.fullExperiment(friend)
if block == None:
break
if allData == None:
allData = block
else:
allData = np.concatenate((allData, block))
# do something with allData here!
endTime = time.time()
now = globalClock.getTime()
print("Real time was %0.3f and global clock counted %0.3f (compare %0.6f to initial timing offset to determine drift)" %
(endTime-startTime, now, now - (endTime-startTime)))
# these shouldn't be strictly necessary (should auto-save)
thisExp.saveAsWideText(filename+'.csv')
thisExp.saveAsPickle(filename)
logging.flush()
# make sure everything is closed down
thisExp.abort() # or data files will save again on exit
win.close()
core.quit()