Пример #1
0
 def on_start(self):
     si = {}
     si['first_name'] = ''.join(self.items['firstname']._value).strip()
     si['last_name'] = ''.join(self.items['lastname']._value).strip()
     si['rin'] = ''.join(self.items['rin']._value)
     si['encrypted_rin'], si['cipher'] = rin2id(si['rin'])
     si['timestamp'] = getDateTimeStamp()
     director.settings['si'] = si
     filebase = "WilliamsSearch_%s_%s" % (si['timestamp'], si['encrypted_rin'][:8])
     director.settings['filebase'] = filebase
     writeHistoryFile("data/%s.history" % filebase, si)
     director.scene.dispatch_event('start_task')
Пример #2
0
 def mainbutton_clicked(self, button):
     if button == self.ok:
         self.values = {}
         for field in self.field_widgets:
             self.values[field.lower().replace(
                 " ", "_")] = self.field_widgets[field].text()
         self.values['encrypted_rin'], self.values['cipher'] = rin2id(
             self.values['rin'])
         self.setResult(True)
         self.done(True)
     elif button == self.cancel:
         self.setResult(False)
         self.done(True)
Пример #3
0
    def __init__( self, args, subjectInfo ):
        super( World, self ).__init__()

        self.args = args

        self.modifier = pygame.KMOD_CTRL
        if platform.system() == 'Darwin':
            self.modifier = pygame.KMOD_META

        self.lc = None
        self.fix_data = None
        self.eye_position = None
        self.fixating = False
        self.ret = 0

        self.colors = [( 204, 255, 102 ), ( 255, 153, 255 )]
        if args.color:
            self.colors = self.colors[::-1]
        self.bgcolor = ( 0, 0, 0 )
        self.fix_shape = u'\u25CB'

        self.replicates = 10
        self.trialPool = self.generateTrialPool( self.replicates )
        self.blockLength = len( self.trialPool )
        self.lastTrial = self.blockLength * int( self.args.blocks )
        self.colorSetup = 1
        if self.args.color:
            self.colorSetup = 2

        self.subjectInfo = subjectInfo

        self.screenshot = 1

        if self.subjectInfo:
            eid = rin2id( subjectInfo['rin'] )
            subjectInfo['encrypted_rin'] = eid
            subjectInfo['cipher'] = 'AES/CBC (RIJNDAEL) - 16Byte Key'
            self.log_basename = cwsubject.makeLogFileBase( 'SaccadeTask_' + eid[:8] )

        self.logdir = args.logdir
        if self.args.subdir:
            self.logdir = os.path.join(self.logdir, eid[:8])
        if not os.path.exists( self.logdir ):
            os.makedirs( self.logdir )

        self.log_filename = None
        if self.subjectInfo:
            cwsubject.writeHistoryFile( os.path.join( self.logdir, self.log_basename ), self.subjectInfo )
            self.log_filename = os.path.join( self.logdir, self.log_basename + '.txt.incomplete')
            self.output = open( self.log_filename, 'w' )
        else:
            if self.args.logfile:
                self.log_filename = os.path.join( self.logdir, args.logfile + '.incomplete')
                self.output = open( self.log_filename, 'w' )
            else:
                self.output = sys.stdout

        pygame.mouse.set_visible( False )
        if self.args.fullscreen:
            self.screen = pygame.display.set_mode( ( 0, 0 ), pygame.FULLSCREEN )
        else:
            self.screen = pygame.display.set_mode( ( 1024, 768 ), 0 )
        self.width, self.height = self.screen.get_size()
        self.center_x = int( self.width / 2 )
        self.center_y = int( self.height / 2 )
        self.offset = int( self.width / 3 )
        self.offsets = [int( self.center_x - self.offset ), int( self.center_x + self.offset )]
        self.worldsurf = self.screen.copy()
        self.worldsurf_rect = self.worldsurf.get_rect()
        obj_width = int( self.center_y * self.args.arrowsize )
        self.fontname = 'DejaVuSansMono.ttf'
        self.obj_widths = [obj_width, int( math.ceil( obj_width * 1.5 ) ), int( math.ceil( obj_width * 2 ) )]
        self.arrow_font = pygame.font.Font( self.fontname, self.obj_widths[0] )
        self.mask_font = pygame.font.Font( self.fontname, int( self.obj_widths[2] * 1.5 ) )
        self.demo_font = pygame.font.Font( self.fontname, int( self.obj_widths[2] * 4 ) )
        self.cue_fonts = [pygame.font.Font( self.fontname, self.obj_widths[0] ),
                          pygame.font.Font( self.fontname, self.obj_widths[1] ),
                          pygame.font.Font( self.fontname, self.obj_widths[2] )]
        self.arrows = ['', u'\u25B6', u'\u25B2', u'\u25C0']
        self.arrow_text = ['', '>', '^', '<']
        self.clock = pygame.time.Clock()
        self.accuracy = []

        self.EVENT_SHOW_CUE = pygame.USEREVENT + 1
        self.EVENT_SHOW_ARROW = pygame.USEREVENT + 2
        self.EVENT_SHOW_MASK = pygame.USEREVENT + 3
        self.EVENT_HIDE_FIX = pygame.USEREVENT + 4

        self.mode_text = ''

        self.trial = 0
        self.size = self.cue_side = self.fix_delay = -1
        self.answer = self.mask_time = self.cue_time = self.trial_stop = self.trial_start = 0

        if self.args.eyetracker and self.args.fullscreen:
            self.client = iViewXClient( self.args.eyetracker, 4444 )
            self.client.addDispatcher( self.d )
            self.fp = VelocityFP(self.width, self.height, 473.76, 296.1, 500, 23, 45)
            self.calibrator = Calibrator( self.client, self.screen, reactor = reactor)
Пример #4
0
 from twisted.internet import reactor
 from twisted.internet.task import LoopingCall
 from autobahn.websocket import listenWS
 from pycogworks.crypto import rin2id
 import argparse
 import random
 import names
 import time
 
 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
 parser.add_argument('-p', '--port', type=int, default=7000, help='the port spook will broadcast on')
 args = parser.parse_args()
 
 defaults = {'experiment': random.choice(["Williams","Tetris","FarBack","Dual N-Back"]),
             'subject_name': names.get_full_name(),
             'subject_eid': rin2id(str(random.randint(100000000, 999999999)))[0],
             'trial': [1,random.randint(50,200)],
             'status': random.choice([-1,0,1]),
             'timestamp': time.time()}# + random.randint(0, 60*60*3)}
     
 def broadcast(spook, status):
     if status['trial'][0] > status['trial'][1]:
         reactor.stop()
         return
     status['status'] = random.choice([-1,0,1])
     spook.broadcast(json.dumps(status))
     status['trial'][0] += 1
 
 spook = SpookServerFactory("ws://localhost:%d" % args.port)
 listenWS(spook)
 lc = LoopingCall(broadcast, spook, defaults)