<commit_before># Pylink wrapper for Psychopy
import pylink
import psychocal
import time
from psychopy.tools.monitorunittools import deg2pix
from psychopy import event

class eyeLinkFuns(object):
    """Provides functions for interacting with Pylink."""

    def __init__(self, window, edfname):
        # Pull out monitor info
        self.sres = window.size
        self.win = window
        
        # Make filename
        self.edfname = edfname + '.edf'
        
        # Initialize connection with eye-tracker
        self.tracker = pylink.EyeLink()
        
        # Make pylink accessible
        self.pylink = pylink
        
        # Open EDF
        self.tracker.openDataFile(self.edfname)		
        pylink.flushGetkeyQueue() 
        self.tracker.setOfflineMode()

        # Set content of edf file
        eftxt = 'LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON,INPUT'
        self.tracker.sendCommand('file_event_filter = ' + eftxt)
    
        lftxt = 'LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON'
        self.tracker.sendCommand('link_event_filter = ' + lftxt)
        
        lstxt = 'LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS,HTARGET'
        self.tracker.sendCommand('link_sample_data = ' + lstxt)
        
        fstxt ='LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS,HTARGET,INPUT'
        self.tracker.sendCommand('file_sample_data = ' + fstxt)
        
        # Set display coords for dataviewer
        disptxt = 'DISPLAY_COORDS 0 0 {} {}'.format(*self.sres)
        self.tracker.sendMessage(disptxt)

    def calibrate(self):
        '''Calibrates eye-tracker using psychopy stimuli.
        
        Parameters
            bgcolor -- background color of calibration display
            tcolout -- color of outer circle calibration target
            tcolin  -- color of inner circle calibration target
        '''
        
        # Generate custom calibration stimuli
        genv = psychocal.psychocal(self.sres[0], self.sres[1], self.tracker,
                                   self.win)
        pylink.openGraphicsEx(genv)
        
        # Calibrate and close window
        self.tracker.doTrackerSetup(self.sres[0], self.sres[1])
        
    def setStatus(self, message):
        '''Sets status message to appear while recording.
        
        Parameters
            message -- Text object to send, must < 80 char
        '''
        
        msg = "record_status_message '%s'" % message
        self.tracker.sendCommand(msg)
        
    def setTrialID(self):
        '''Sends message that indicates start of trial in EDF.'''
        
        self.tracker.sendMessage('TRIALID 1')
        
    def recordON(self):
        '''Starts recording, waits 50ms to allow eyelink to prepare.'''
        
        self.tracker.sendCommand('set_idle_mode')
        time.sleep(.05)
        self.tracker.startRecording(1, 1, 0, 0)

    def recordOFF(self):
        '''Stops recording.'''
        
        self.tracker.stopRecording()
        
    def drawIA(self, x, y, size, index, color, name):
        '''Draws square interest area in EDF and a  corresponding filled box on
           eye-tracker display.
        
        Parameters
            x, y  -- x and y coordinates in degrees visual angle
            size  -- length of one edge of square in degrees visual angle
            index -- number to assign interest area in EDF
            color -- color of box drawn on eye-tracker display (0 - 15)
            name  -- string to name interest area in EDF
        '''
            
        # Convert units to eyelink space
        elx = deg2pix(x, self.win.monitor) + (self.sres[0] / 2.0)
        ely = -(deg2pix(y, self.win.monitor) - (self.sres[1] / 2.0))
        elsz = deg2pix(size, self.win.monitor) / 2.0
    
        # Make top left / bottom right coordinates for square
        tplf = map(round, [elx - elsz, ely - elsz])
        btrh = map(round, [elx + elsz, ely + elsz])
    
        # Construct command strings
        flist = [index, name, color] + tplf + btrh
        iamsg = '!V IAREA RECTANGLE {0} {3} {4} {5} {6} {1}'.format(*flist)
        bxmsg = 'draw_filled_box {3} {4} {5} {6} {2}'.format(*flist)

        # Send commands
        self.tracker.sendMessage(iamsg)
        self.tracker.sendCommand(bxmsg)
        
    def sendVar(self, name, value):
        '''Sends trial variable to EDF file.
        
        Parameters
            name  -- string for name of variable.
            value -- string or number for variable value
        '''
        
        # Make string
        varmsg = '!V TRIAL_VAR {} {}'.format(name, value)
    
        # Send message
        self.tracker.sendMessage(varmsg)
        
    def setTrialResult(self):
        '''Sends trial result to indiciate trial end in EDF.'''
        
        self.tracker.sendMessage('TRIAL_RESULT 0')
        self.tracker.sendCommand('clear_screen 0')
        
    def endExperiment(self, spath):
        '''Closes and transfers the EDF file.
        
        Parameters
            spath -- File path of where to save EDF file. Include trailing \
        '''
        
        # File transfer and cleanup!
        self.tracker.setOfflineMode()
        time.sleep(.5)
        
        # Generate file path
        fpath = spath + self.edfname
        
        #Close the file and transfer it to Display PC
        self.tracker.closeDataFile()
        self.tracker.receiveDataFile(self.edfname, fpath)
        self.tracker.close()
        
    def fixcheck(self, size, ftime, button):
        '''Checks that fixation is maintained for certain time.
        
        Parameters
            size   -- length of one side of box in degrees visual angle
            ftime  -- length of time to check for fixation in seconds
            button -- key to press to recalibrate eye-tracker
        '''
        
        # Calculate Fix check borders
        cenX = self.sres[0] / 2.0
        cenY = self.sres[1] / 2.0
        size = deg2pix(size, self.win.monitor) / 2.0
        
        xbdr = [cenX - size, cenX + size]<commit_msg>added camelcase<commit_after># Pylink wrapper for Psychopy
import pylink
import psychocal
import time
from psychopy.tools.monitorunittools import deg2pix
from psychopy import event

class eyeLinkFuns(object):
    """Provides functions for interacting with Pylink."""

    def __init__(self, window, edfname):
        # Pull out monitor info
        self.sres = window.size
        self.win = window
        
        # Make filename
        self.edfname = edfname + '.edf'
        
        # Initialize connection with eye-tracker
        self.tracker = pylink.EyeLink()
        
        # Make pylink accessible
        self.pylink = pylink
        
        # Open EDF
        self.tracker.openDataFile(self.edfname)		
        pylink.flushGetkeyQueue() 
        self.tracker.setOfflineMode()

        # Set content of edf file
        eftxt = 'LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON,INPUT'
        self.tracker.sendCommand('file_event_filter = ' + eftxt)
    
        lftxt = 'LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON'
        self.tracker.sendCommand('link_event_filter = ' + lftxt)
        
        lstxt = 'LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS,HTARGET'
        self.tracker.sendCommand('link_sample_data = ' + lstxt)
        
        fstxt ='LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS,HTARGET,INPUT'
        self.tracker.sendCommand('file_sample_data = ' + fstxt)
        
        # Set display coords for dataviewer
        disptxt = 'DISPLAY_COORDS 0 0 {} {}'.format(*self.sres)
        self.tracker.sendMessage(disptxt)

    def calibrate(self):
        '''Calibrates eye-tracker using psychopy stimuli.
        
        Parameters
            bgcolor -- background color of calibration display
            tcolout -- color of outer circle calibration target
            tcolin  -- color of inner circle calibration target
        '''
        
        # Generate custom calibration stimuli
        genv = psychocal.psychocal(self.sres[0], self.sres[1], self.tracker,
                                   self.win)
        pylink.openGraphicsEx(genv)
        
        # Calibrate and close window
        self.tracker.doTrackerSetup(self.sres[0], self.sres[1])
        
    def setStatus(self, message):
        '''Sets status message to appear while recording.
        
        Parameters
            message -- Text object to send, must < 80 char
        '''
        
        msg = "record_status_message '%s'" % message
        self.tracker.sendCommand(msg)
        
    def setTrialID(self):
        '''Sends message that indicates start of trial in EDF.'''
        
        self.tracker.sendMessage('TRIALID 1')
        
    def recordON(self):
        '''Starts recording, waits 50ms to allow eyelink to prepare.'''
        
        self.tracker.sendCommand('set_idle_mode')
        time.sleep(.05)
        self.tracker.startRecording(1, 1, 0, 0)

    def recordOFF(self):
        '''Stops recording.'''
        
        self.tracker.stopRecording()
        
    def drawIA(self, x, y, size, index, color, name):
        '''Draws square interest area in EDF and a  corresponding filled box on
           eye-tracker display.
        
        Parameters
            x, y  -- x and y coordinates in degrees visual angle
            size  -- length of one edge of square in degrees visual angle
            index -- number to assign interest area in EDF
            color -- color of box drawn on eye-tracker display (0 - 15)
            name  -- string to name interest area in EDF
        '''
            
        # Convert units to eyelink space
        elx = deg2pix(x, self.win.monitor) + (self.sres[0] / 2.0)
        ely = -(deg2pix(y, self.win.monitor) - (self.sres[1] / 2.0))
        elsz = deg2pix(size, self.win.monitor) / 2.0
    
        # Make top left / bottom right coordinates for square
        tplf = map(round, [elx - elsz, ely - elsz])
        btrh = map(round, [elx + elsz, ely + elsz])
    
        # Construct command strings
        flist = [index, name, color] + tplf + btrh
        iamsg = '!V IAREA RECTANGLE {0} {3} {4} {5} {6} {1}'.format(*flist)
        bxmsg = 'draw_filled_box {3} {4} {5} {6} {2}'.format(*flist)

        # Send commands
        self.tracker.sendMessage(iamsg)
        self.tracker.sendCommand(bxmsg)
        
    def sendVar(self, name, value):
        '''Sends trial variable to EDF file.
        
        Parameters
            name  -- string for name of variable.
            value -- string or number for variable value
        '''
        
        # Make string
        varmsg = '!V TRIAL_VAR {} {}'.format(name, value)
    
        # Send message
        self.tracker.sendMessage(varmsg)
        
    def setTrialResult(self):
        '''Sends trial result to indiciate trial end in EDF.'''
        
        self.tracker.sendMessage('TRIAL_RESULT 0')
        self.tracker.sendCommand('clear_screen 0')
        
    def endExperiment(self, spath):
        '''Closes and transfers the EDF file.
        
        Parameters
            spath -- File path of where to save EDF file. Include trailing \
        '''
        
        # File transfer and cleanup!
        self.tracker.setOfflineMode()
        time.sleep(.5)
        
        # Generate file path
        fpath = spath + self.edfname
        
        #Close the file and transfer it to Display PC
        self.tracker.closeDataFile()
        self.tracker.receiveDataFile(self.edfname, fpath)
        self.tracker.close()
        
    def fixCheck(self, size, ftime, button):
        '''Checks that fixation is maintained for certain time.
        
        Parameters
            size   -- length of one side of box in degrees visual angle
            ftime  -- length of time to check for fixation in seconds
            button -- key to press to recalibrate eye-tracker
        '''
        
        # Calculate Fix check borders
        cenX = self.sres[0] / 2.0
        cenY = self.sres[1] / 2.0
        size = deg2pix(size, self.win.monitor) / 2.0
        
        xbdr = [cenX - size, cenX + size]
{'fraction_non_alphanumeric': 0.0946372239747634, 'fraction_numerical': 0.00913166196247717, 'mean_word_length': 1.83993399339934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6092216', 'n_tokens_mistral': 3649, 'n_tokens_neox': 3535, 'n_words': 980}