コード例 #1
0
 def run(self):
     """
     Main worker.
     """
     update_name = None  # Store update name, i.e: Eddy v0.9.1
     update_version = self.current  # Store update version, i.e: 0.9.1
     update_url = None  # Store update HTML url, i.e: http://github.com/...
     try:
         LOGGER.info(
             'Connecting to GitHub to retrieve update information (channel: %s)',
             self.channel.value)
         github = GitHub(token='6a417ccfe9a7c526598e77a74cbf1cba6e688f0e')
         repository = github.repository('danielepantaleone', 'eddy')
         for release in repository.releases():
             if self.channel is Channel.Beta or not release.prerelease:
                 try:
                     if NormalizedVersion(
                             release.tag_name[1:]) > NormalizedVersion(
                                 update_version):
                         update_name = release.name
                         update_version = release.tag_name[1:]
                         update_url = release.html_url
                 except IrrationalVersionError as e:
                     LOGGER.warning(
                         'Failed to parse version number from TAG: %s', e)
         if update_version != self.current:
             LOGGER.info('Update available: %s', update_name)
             self.sgnUpdateAvailable.emit(update_name, update_url)
         else:
             LOGGER.info('No update available')
             self.sgnNoUpdateAvailable.emit()
     except Exception as e:
         LOGGER.warning('Failed to retrieve update data: %s', e)
         self.sgnNoUpdateDataAvailable.emit()
     self.finished.emit()
コード例 #2
0
    def validate(self, **kwargs):
        if not (self.MIN_VERSION and self.MAX_VERSION):
            warnings.warn(
                "Capsule '%s' does not specify compatible which "
                "taskwarrior-capsule versions it is compatible with; you may "
                "encounter compatibility problems. " % (self.command_name))
        else:
            curr_version = self.get_taskwarrior_capsules_version()
            min_version = NormalizedVersion(self.MIN_VERSION)
            max_version = NormalizedVersion(self.MAX_VERSION)

            if not min_version <= curr_version <= max_version:
                warnings.warn(
                    "Capsule '%s' is not compatible with version %s of "
                    "taskwarrior-capsules; "
                    "minimum version: %s; "
                    "maximum version %s." % (
                        self.command_name,
                        __version__,
                        min_version,
                        max_version,
                    ), )

        if not self.TASKWARRIOR_VERSION_CHECK_NECESSARY:
            # Let's just continue on without checking taskwarrior
            # version compatibility.
            pass
        elif not (self.MAX_TASKWARRIOR_VERSION
                  and self.MIN_TASKWARRIOR_VERSION):
            warnings.warn(
                "Capsule '%s' does not specify which taskwarrior versions it "
                "is compatible with; you may encounter compatibility "
                "problems. " % (self.command_name))
        else:
            tw_version = self.get_taskwarrior_version()
            min_tw_version = NormalizedVersion(self.MIN_TASKWARRIOR_VERSION)
            max_tw_version = NormalizedVersion(self.MAX_TASKWARRIOR_VERSION)

            if not min_tw_version <= tw_version <= max_tw_version:
                warnings.warn(
                    "Capsule '%s' is not compatible with version %s of "
                    "taskwarrior; "
                    "minimum version: %s; "
                    "maximum version %s." % (
                        self.command_name,
                        tw_version,
                        min_tw_version,
                        max_tw_version,
                    ), )

        return True
コード例 #3
0
class NoTimeOff(SessionManager):
    notimeoff_version = Ver('0.0.1')

    def __init__(self, **kwargs):
        super(NoTimeOff, self).__init__(**kwargs)
        if not kwargs:
            pass
        elif 'data' in kwargs:
            self = self.load_from_dict(kwargs['data]'])
        else:
            pass

    def load_from_dict(self, data):
        self.notimeoff_version = Ver(data['notimeoff_version'])

    def save_to_dict(self):
        data = super(NoTimeOff, self).save_to_dict()
        data['notimeoff_version'] = self.notimeoff_version.__str__()
        return data

    def __repr__(self):
        return "NoTimeOff object"

    def check_schedule(self, **kwargs):
        # Returns keep_doing_trials, secs_remaining_until_state_flip
        keep_doing_trials = True
        secs_remaining_until_state_flip = 0
        return keep_doing_trials, secs_remaining_until_state_flip
コード例 #4
0
def ensure_default_settings(config):
    version = NormalizedVersion(__version__)
    if 'version' in config:
        config_version = NormalizedVersion(config['version'])
    else:
        config_version = NormalizedVersion('0.1')

    for section, values in DEFAULT_SETTINGS.items():
        if section not in config:
            config[section] = {}
        for key, value in values.items():
            if key not in config[section] or version > config_version:
                config[section][key] = value

    config['version'] = __version__
    return config
コード例 #5
0
class SessionManager(object):
    sessionmgr_version = Ver('0.0.1')
    name = ''

    def __init__(self, **kwargs):
        if not kwargs:
            pass
        elif 'data' in kwargs:
            self = self.load_from_dict(kwargs['data]'])
        else:
            pass

    def load_from_dict(self, data):
        self.sessionmgr_version = Ver(data['sessionmgr_version'])
        self.name = data['name']

    def save_to_dict(self):
        data = dict()
        data['sessionmgr_version'] = self.sessionmgr_version.__str__()
        data['name'] = self.name
        return data

    def __repr__(self):
        return "SessionManager object with name:%s" % (self.name)

    def check_schedule(self):
        return False
コード例 #6
0
class TimeRange(SessionManager):
    timerange_version = Ver('0.0.1')
    time_start = None
    time_stop = None

    def __init__(self, **kwargs):
        super(TimeRange, self).__init__(**kwargs)
        if not kwargs:
            pass
        elif 'data' in kwargs:
            self = self.load_from_dict(kwargs['data]'])
        else:
            pass

    def load_from_dict(self, data):
        self.timerange_version = Ver(data['timerange_version'])
        self.time_start = data['time_start']
        self.time_stop = data['time_stop']

    def save_to_dict(self):
        data = super(TimeRange, self).save_to_dict()
        data['timerange_version'] = self.timerange_version.__str__()
        data['time_start'] = self.time_start
        data['time_stop'] = self.time_stop
        return data

    def __repr__(self):
        return "TimeRange object"

    def check_schedule(self):
        return NotImplementedError()
コード例 #7
0
def get_git_version():
    result = subprocess.check_output(
        ['git', '--version'],
        stderr=subprocess.PIPE,
    ).decode('utf8')
    version_string = re.match('git version ([0-9.]+).*', result).group(1)
    return NormalizedVersion(version_string)
コード例 #8
0
class MinutesPerSession(SessionManager):
    minutespersession_version = Ver('0.0.1')
    minutes = None
    hours_between_sessions = None

    def __init__(self, **kwargs):
        super(MinutesPerSession, self).__init__(**kwargs)
        if not kwargs:
            pass
        elif 'data' in kwargs:
            self = self.load_from_dict(kwargs['data]'])
        else:
            pass

    def load_from_dict(self, data):
        self.minutespersession_version = Ver(data['minutespersession_version'])
        self.minutes = data['minutes']
        self.hours_between_sessions = data['hours_between_sessions']

    def save_to_dict(self):
        data = super(MinutesPerSession, self).save_to_dict()
        data[
            'minutespersession_version'] = self.minutespersession_version.__str__(
            )
        data['minutes'] = self.minutes
        data['hours_between_sessions'] = self.hours_between_sessions
        return data

    def __repr__(self):
        return "MinutesPerSession object, %s minutes with %s hrs between sessions" % (
            self.minutes, self.hours_between_sessions)

    def check_schedule(self):
        return NotImplementedError()
コード例 #9
0
ファイル: __init__.py プロジェクト: TCRichards/Insights
 def validate_version(version):
     rversion = suggest_normalized_version(version)
     if rversion is None:
         raise ValueError('Cannot work with "%s"' % version)
     if rversion != version:
         warnings.warn('"%s" is not a normalized version.\n'
                       'It has been transformed into "%s" '
                       'for interoperability.' % (version, rversion))
     return NormalizedVersion(rversion)
コード例 #10
0
ファイル: plugin.py プロジェクト: olivierh59500/jirafs
    def validate(self, **kwargs):
        if not self.MIN_VERSION or not self.MAX_VERSION:
            raise PluginValidationError(
                "Minimum and maximum version numbers not specified.")

        min_version = NormalizedVersion(self.MIN_VERSION)
        max_version = NormalizedVersion(self.MAX_VERSION)
        curr_version = NormalizedVersion(__version__)
        if not min_version <= curr_version <= max_version:
            raise PluginValidationError(
                "Plugin '%s' is not compatible with version %s of Jirafs; "
                "minimum version: %s; maximum version %s." % (
                    self.plugin_name,
                    __version__,
                    self.MIN_VERSION,
                    self.MAX_VERSION,
                ), )

        return True
コード例 #11
0
def versionCompared(netVersion):
    """
    Compare version number to check it whether or not need update.

    Parameters
    ----------
    netVersion : string
        the network version

    Returns
    -------
    bool 
        check program whether need update
    """

    currentVersion = NormalizedVersion(version.__version__)
    netVersion = NormalizedVersion(netVersion)
    flag = False
    if netVersion > currentVersion:
        flag = True
    return flag
コード例 #12
0
 def load_from_dict(self, data):
     self.version = Ver(data['version'])  # needed
     self.server_id = data['server_id']  # needed
     self.server_data_path = data['server_data_path']  # needed
     self.creation_time = datetime.datetime.strptime(
         data['creation_time'],
         DATETIME_TO_STR)  # Month-dd-YYYY::Hr:Min:Sec
     for sub in data['subjects']:
         self.subjects.append(Subject.load_from_dict(sub))
     for stn in data['stations']:
         self.stations.append(Station.load_from_dict(stn))
     self.assignments = data['assignemnts']
     return self
コード例 #13
0
ファイル: Station.py プロジェクト: yzerlaut/bcore
    def load_from_dict(self, data):
        self.station_version = Ver(data['station_version'])
        self.creation_time = datetime.datetime.strptime(
            data['creation_time'], DATETIME_TO_STR)
        self.station_id = data['station_id']
        self.station_name = data['station_name']
        self.station_path = os.path.join(get_base_path(), 'BCoreData',
                                         'StationData', str(self.station_id))
        self.station_location = data['station_location']

        self.mac_address = get_mac_address()
        self.ip_address = get_ip_addr()
        self.port = get_port()
        return self
コード例 #14
0
ファイル: Station.py プロジェクト: balajisriram/BCore
 def __init__(self,
              sound_on=False,
              station_id= 0,
              station_location=(0,0,0),
              parallel_port='standardVisionBehaviorDefault',
              parallel_port_address = '/dev/parport0'):
     self.ver = Ver('0.0.1')
     super(StandardVisionBehaviorStation, self).__init__(station_location=station_location)
     self.station_id = station_id
     self.station_name = "Station" + str(station_id)
     self.sound_on = sound_on
     self.parallel_port = parallel_port
     self.parallel_port_address = parallel_port_address
     self.display = self.get_display()
     self.parallel_port = self.get_parport_mappings()
コード例 #15
0
def comparable_version(version):
    """
    Given a version string (e.g. '1.3.0.dev234'), return an object which
    allows correct comparison. For example:
        comparable_version('1.3.10') > comparable_version('1.3.8')  # True
    whereas:
        '1.3.10' > '1.3.8'  # False
    """
    try:
        # This hack makes it possible to use 'rc' in the version, where
        # 'rc' must be followed by a single digit.
        ver = version.replace('rc', '.dev99999')
        return NormalizedVersion(ver)
    except IrrationalVersionError:
        # If obtaining the RationalVersion object fails (for example for
        # the version '2009j'), simply return the string, such that
        # a string comparison can be made.
        return version
コード例 #16
0
ファイル: Subject.py プロジェクト: balajisriram/BCore
 def __init__(self, subject_id, **kwargs):
     """
             Call as follows::
             subject(subjectID='demo')
             subjectID               - MANDATORY
             protocols               - EMPTY
     """
     self.ver = Ver('0.0.3')
     self.subject_id = subject_id
     self._protocol = []
     self._session_manager = []
     self.creation_date = time.time()
     self.iacuc_protocol_id = ''
     if 'reward' in kwargs:
         self._reward = kwargs['reward']
     else:
         self._reward = 0
     if 'timeout' in kwargs:
         self._timeout = kwargs['timeout']
     else:
         self._timeout = 0
     if 'iacuc_protocol_id' in kwargs:
         self.iacuc_protocol_id = kwargs['iacuc_protocol_id']
コード例 #17
0
class BServer(object):
    """
        BSERVER  keeps track of all the stations that it commands,
        which subjects are allowed in which station and data storage locations.
            version             : string identifier
            server_id           : string Identifier
            server_data_path    : allowed data storage location
            server_ip           : IPV4 value
            creation_time       : time.time()
            stations            : list of stations
            subjects            : list of subjects
            assignments         : dictionary with keys being subjectID
                                  and values being list of stationIDs
    """
    version = Ver('0.0.1')  # Feb 5, 2014
    server_id = ''
    server_ip = ''
    server_data_path = ''
    creation_time = None
    stations = []
    subjects = []
    assignments = dict()
    server_connection = []
    station_connections = []

    def __init__(self, **kwargs):
        if not kwargs:
            self.creation_time = datetime.datetime.now()
        elif 'data' in kwargs:
            self = self.load_from_dict(kwargs['data'], convert=False)
        else:
            pass

    def load_from_dict(self, data):
        self.version = Ver(data['version'])  # needed
        self.server_id = data['server_id']  # needed
        self.server_data_path = data['server_data_path']  # needed
        self.creation_time = datetime.datetime.strptime(
            data['creation_time'],
            DATETIME_TO_STR)  # Month-dd-YYYY::Hr:Min:Sec
        for sub in data['subjects']:
            self.subjects.append(Subject.load_from_dict(sub))
        for stn in data['stations']:
            self.stations.append(Station.load_from_dict(stn))
        self.assignments = data['assignemnts']
        return self

    def save_to_dict(self):
        data = dict()
        data['version'] = self.version.__str__()
        data['server_id'] = self.server_id
        data['server_data_path'] = self.server_data_path
        data['creation_time'] = datetime.datetime.strftime(
            self.creation_time, DATETIME_TO_STR)

        subjects = []
        for sub in self.subjects:
            subjects.append(sub.save_to_dict())
        data['subjects'] = subjects

        stations = []
        for stn in self.stations:
            stations.append(stn.save_to_dict())
        data['stations'] = stations

        data['assignments'] = self.assignments

    def __repr__(self):
        return "BServer with id:%s, name:%s, created on:%s)" % (
            self.server_id, self.server_name,
            time.strftime("%b-%d-%Y", self.creation_time))

    def run(server, **kwargs):
        # should expose the ZMQ context. and allow connections
        raise NotImplementedError()

    @staticmethod
    def load():
        """
            Alias for server.loadServer
        """
        return BServer.load_server()

    @staticmethod
    def load_server():
        # use standard location for path,
        # make sure to never modify server here:
        dbLoc = os.path.join(get_base_path(), 'BCoreData', 'ServerData',
                             'db.BServer')
        if os.path.isfile(dbLoc):
            with open(dbLoc, 'rb') as f:
                server = json.load(f)
            print('BServer loaded')
        else:
            raise RuntimeError(
                'db.Server not found. Ensure it exists before calling loadServer'
            )
        return server

    def save(self):
        """
            Alias for server.saveServer
        """
        self.save_server()

    def save_server(self):
        srcDir = os.path.join(get_base_path(), 'BCoreData', 'ServerData')
        desDir = os.path.join(get_base_path(), 'BCoreData', 'ServerData',
                              'backupDBs')

        if not os.path.isdir(self.server_data_path):
            # assume that these are never made alone...
            self._setup_paths()

        if os.path.isfile(os.path.join(srcDir, 'db.BServer')):  # old db exists
            print(('Old db.Bserver found. moving to backup'))
            old = BServer()  # standardLoad to old
            des_name = 'db_' + get_time_stamp(old.creation_time) + '.BServer'
            shutil.copyfile(os.path.join(srcDir, 'db.BServer'),
                            os.path.join(desDir, des_name))
            print(('Moved to backup... deleting old copy'))
            os.remove(os.path.join(srcDir, 'db.BServer'))

        # there might be some attributes that need to be deleted
        # delete them here before continuing
        print(('Cleaning and pickling object'))
        cleanedBServer = copy.deepcopy(self)
        cleanedBServer.station_connections = {}
        with open(os.path.join(srcDir, 'db.BServer'), 'wb') as f:
            pickle.dump(cleanedBServer, f)

    def load_backup(self):
        """
            Use this only if you specifically require the deletion of current
            db.BServer and replacement with an older backup. Only the latest
            back up is used.
        """
        desDir = os.path.join(get_base_path(), 'BCoreData', 'ServerData')
        srcDir = os.path.join(get_base_path(), 'BCoreData', 'ServerData',
                              'backupDBs')
        # delete the original database
        os.remove(os.path.join(desDir, 'db.BServer'))
        # find the latest file in the backupDBs
        newestBkup = max(os.listdir(srcDir), key=os.path.getctime)
        shutil.copyfile(
            os.path.join(srcDir, newestBkup),  # source
            os.path.join(desDir, 'db.BServer')  # destination
        )
        # delete the newest backup
        os.remove(os.path.join(srcDir, newestBkup))

    def _setup_paths(server):
        # create 'BServerData'
        os.mkdir(os.path.join(get_base_path(), 'BCoreData'))
        # create 'ServerData','Stations','PermanentTrialRecordStore' in
        # BServerData
        os.mkdir(os.path.join(get_base_path(), 'BCoreData', 'ServerData'))
        os.mkdir(os.path.join(get_base_path(), 'BCoreData', 'StationData'))
        os.mkdir(os.path.join(get_base_path(), 'BCoreData', 'SubjectData'))
        os.mkdir(os.path.join(get_base_path(), 'BCoreData', 'ChangeParams'))
        # create 'replacedDBs' in 'ServerData'
        os.mkdir(
            os.path.join(get_base_path(), 'BCoreData', 'ServerData',
                         'backupDBs'))
        # create 'Full' and 'Compiled' in 'SubjectData'
        os.mkdir(
            os.path.join(get_base_path(), 'BCoreData', 'SubjectData',
                         'SessionRecords'))
        os.mkdir(
            os.path.join(get_base_path(), 'BCoreData', 'SubjectData',
                         'CompiledTrialRecords'))

    def add_station(self, new_station):
        if (new_station.station_id in self.get_station_ids()
                or new_station.station_name in self.get_station_names()):
            raise ValueError('Station IDs and Station Names have to be unique')
        self.stations.append(new_station)
        # now enable station specific data
        self.save()

    def add_subject(self, new_subject):
        if new_subject in self.subjects:
            raise ValueError('Cannot add replica of subjects to BServer')
        self.subjects.append(new_subject)
        self.save()

    def change_assignment(self, subject, new_assignment):
        if subject not in self.subjects:
            raise ValueError('Cannot change assignment on a subject \
            that is not on Bserver')
        if not (any(new_assignment in self.get_station_ids())):
            raise ValueError('Cannot assign subject to non existent stations')
        self.assignments[subject.subject_id] = new_assignment
        self.save()

    def get_station_ids(self):
        station_ids = []
        for station in self.stations:
            station_ids.append(station.station_id)
        return station_ids

    def get_station_names(self):
        station_names = []
        for station in self.stations:
            station_names.append(station.station_name)
        return station_names

    def get_subject_ids(self):
        subject_ids = []
        for subject in self.subjects:
            subject_ids.append(subject.subject_id)
        return subject_ids
コード例 #18
0
ファイル: test_utils.py プロジェクト: to-json/jirafs
    def test_parse_linux_git_version(self, git_version_output):
        git_version_output.return_value = b"git version 1.9.1"

        actual_version = utils.get_git_version()

        self.assertEqual(actual_version, NormalizedVersion("1.9.1"))
コード例 #19
0
ファイル: test_utils.py プロジェクト: to-json/jirafs
    def test_parse_osx_git_version(self, git_version_output):
        git_version_output.return_value = b"git version 1.8.5.2 (Apple Git-48)"

        actual_version = utils.get_git_version()

        self.assertEqual(actual_version, NormalizedVersion("1.8.5.2"))
コード例 #20
0
 def load_from_dict(self, data):
     self.minutespersession_version = Ver(data['minutespersession_version'])
     self.minutes = data['minutes']
     self.hours_between_sessions = data['hours_between_sessions']
コード例 #21
0
ファイル: Station.py プロジェクト: balajisriram/BCore
class StandardVisionBehaviorStation(Station):
    """
        STANDARDVISIONBEHAVIORSTATION(SVBS) defines a subclass of STATION.
        It defines a station with a standard display, a parallel port for i/o
        with standard pin-out settings, sounds settings which can only be
        turned on or off, three valve pins, three sensor pins. Only allows
        stand alone running
        Attributes allowed are:
            station_id       : numeric ID to be sent to STATION
            station_path     : DO NOT SEND - STATION WILL SET IT
            display          : dictionary containing details about the
                               display unit
            soundOn          : True/False
            parallelPort     : dictionary containing details about the parallel
                               port

        For the StandardVisualBehaviorStation, with Rev 2/3 breakout boards
        ("The Bomb"), only certain ports are used and for specific purposes:
            Pin 2            :            Right Reward Valve
            Pin 3            :            Center Reward Valve
            Pin 4            :            Left Reward Valve
            Pin 5            :            LED1
            Pin 6            :            eyePuff
            Pin 7            :            LED2
            Pin 8            :            indexPulse
            Pin 9            :            framePulse
            Pin 10           :            Center Response Sensor
            Pin 12           :            Right Response Sensor
            Pin 13           :            Left Response Sensor
        While, these values are not hard coded here, use these values if you
        want your system to work :)

        Use these defaults unless you know what you are doing
        parallel_port = {}
        parallel_port['right_valve'] = 2
        parallel_port['center_valve'] = 3
        parallel_port['left_valve'] = 4
        parallel_port['valve_pins'] = (2, 3, 4)
        parallel_port['center_port'] = 10
        parallel_port['right_port'] = 12
        parallel_port['left_port'] = 13
        parallel_port['port_pins'] = (12, 10, 13)
        parallel_port['index_pin'] = 8
        parallel_port['frame_pin'] = 9
        parallel_port['led_0'] = 5
        parallel_port['led_1'] = 7
    """
    _window = None
    _session = None
    _server_conn = None

    def __init__(self,
                 sound_on=False,
                 station_id= 0,
                 station_location=(0,0,0),
                 parallel_port='standardVisionBehaviorDefault',
                 parallel_port_address = '/dev/parport0'):
        self.ver = Ver('0.0.1')
        super(StandardVisionBehaviorStation, self).__init__(station_location=station_location)
        self.station_id = station_id
        self.station_name = "Station" + str(station_id)
        self.sound_on = sound_on
        self.parallel_port = parallel_port
        self.parallel_port_address = parallel_port_address
        self.display = self.get_display()
        self.parallel_port = self.get_parport_mappings()

    def __repr__(self):
        return "StandardVisionBehaviorStation object with id:%s, location:%s and ip:%s" %(self.station_id, self.station_location, self.ip_address)

    def get_display(self):
        return StandardDisplay()

    def get_parport_mappings(self):
        if self.parallel_port == 'standardVisionBehaviorDefault':
            print('STANDARDVISIONBEHAVIORSTATION:INITIALIZE_PARALLEL_PORT::setting parallelport to standardVisionBehaviorDefault')
            pPort = {}
            pPort['right_valve'] = 2
            pPort['center_valve'] = 3
            pPort['left_valve'] = 4
            pPort['valve_pins'] = [2, 3, 4]
            pPort['center_port'] = 10
            pPort['right_port'] = 12
            pPort['left_port'] = 13
            pPort['port_pins'] = [13, 10, 12]
            pPort['index_pin'] = 8
            pPort['frame_pin'] = 9
            pPort['trial_pin'] = 6
            pPort['led_0'] = 5
            pPort['led_1'] = 7
            return pPort
        elif self.parallel_port == 'standardHeadfixBehaviorDefault':
            print('STANDARDVISIONBEHAVIORSTATION:INITIALIZE_PARALLEL_PORT::setting parallelport to standardVisionHeadfixDefault')
            pPort = {}
            pPort['reward_valve'] = 3
            pPort['valve_pins'] = [3,]
            pPort['response_port'] = 10
            pPort['running_port'] = 13
            pPort['port_pins'] = [10,]
            pPort['index_pin'] = 8
            pPort['frame_pin'] = 9
            pPort['trial_pin'] = 6
            pPort['led_0'] = 5
            pPort['led_1'] = 7
            return pPort
        else:
            return None # need to write code that checks if allowable

    def initialize(self):
        self.initialize_display(display=self.display)
        self.initialize_sounds()
        self.initialize_parallel_port()
        self.close_all_valves()

    def run(self):
        self.connect_to_server()
        run_trials = False
        while True:
            # look for data from server
            msg = self.get_server_msg()
            quit = False
            if run_trials and ~quit:
                # get info anout session
                self.get_session()

                sub = self._session['subject']
                tR = self._session['trial_record']
                cR = self._session['compiled_record']
                prot = self._session['protocol']
                trial_num = self._session['trial_num']

    def initialize_display(self, display = StandardDisplay()):
        self._window = psychopy.visual.Window(color=(0.,0.,0.), fullscr=True, winType='pyglet', allowGUI=False, units='deg', screen=0, viewScale=None, waitBlanking=True, allowStencil=True,monitor = display)
        self._window.flip()

    def initialize_parallel_port(self):
        self._parallel_port_conn = psychopy.parallel.ParallelPort(address=self.parallel_port_address)
        self.close_all_valves()

    def connect_to_server(self):
        """
            This is a somewhat complicated handshake. Initially, the
            station acts as a server exposing its IP::port to the server.
            Since the server knows this IP::port it can create a client
            connection easily. Upon connection, BServer(currently client)
            sends a connection info for a separate connection(BServer will
            reserve the space for this connection) to the station and the
            station will connect to the BServer now as a client. This way
            new stations can be added to the server without any
            station-side code modification. BServer can dynamically manage
            its resources. Along with threaded TCP server connections on
            the server side, this should provide scalable, TCP communications
            with the server
        """
        self._server_conn = TCPServerConnection(ipaddr=self.ip_address,
            port=self.port)
        self._server_conn.start()
        server_connection_details = self._server_conn.recvData()
        # use server_connection_details to connect to the BServer as a client
        print('STANDARDVISIONBEHAVIORSTATION:CONNECT_TO_SERVER::Closing connection as server...')
        self._server_conn.stop()
        self._server_conn = BehaviorClientConnection(
            ipaddr=server_connection_details['ipaddr'],
            port=server_connection_details['port'])
        print('STANDARDVISIONBEHAVIORSTATION:CONNECT_TO_SERVER::Starting connection as client...')
        self._server_conn.start()

    @property
    def subject(self):
        return self._subject

    @subject.setter
    def subject(self,value):
        self._subject = value

    @property
    def session(self):
        return self._session

    @session.setter
    def session(self,value):
        self._session = value

    def get_ports(self):
        return np.asarray(['left_port','center_port','right_port'])

    @property
    def num_ports(self):
        if self.parallel_port:
            return len(self.parallel_port['port_pins'])
        else:
            return 0

    def add_subject(self, sub):
        self.subject = sub
            #if sub.subject_id in self.get_subjects():
            #    RuntimeError("STATION:STANDARDVISIONBEHAVIORSTATION:ADD_SUBJECT:Subject "+ sub.subject_id + " already in station. Cannot add twice")
            #
            #print("STATION:STANDARDVISIONBEHAVIORSTATION:ADD_SUBJECT: Adding subject_id " + sub.subject_id +" to station_id " + str(self.station_id))
            #self.subjects.append(sub)

    def remove_subject(self,sub):
        self.subject = None
            #if sub.subject_id not in self.get_subjects():
            #    RuntimeError("STATION:STANDARDVISIONBEHAVIORSTATION:ADD_SUBJECT:Subject "+ sub.subject_id + " not in station. Cannot remove.")
            #print("STATION:STANDARDVISIONBEHAVIORSTATION:REMOVE_SUBJECT: Removing subject_id " + sub.subject_id +" from station_id " + str(self.station_id))
            #idx = [i for (i,x) in enumerate(self.get_subjects()) if x==sub.subject_id]
            #self.subjects = self.subjects[:idx[0]]+self.subjects[idx[0]+1:]

    def close_all_valves(self):
        val = list('{0:08b}'.format(self._parallel_port_conn.readData()))
        for valve in self.parallel_port['valve_pins']:
            val[1-valve] = '0'
        self._parallel_port_conn.setData(int(''.join(val),2))

    def read_ports(self):
        out = [False, False, False]
        port_names = ['left_port','center_port','right_port']
        for i,port in enumerate(self.parallel_port['port_pins']):
            out[i] = self._parallel_port_conn.readPin(port)
        active_ports = [x for x,y in zip(port_names,out) if not y]
        return active_ports

    def open_valve(self, valve):
        valve_pin = self.parallel_port[valve]
        self.set_pin_on(valve_pin)

    def close_valve(self, valve):
        valve_pin = self.parallel_port[valve]
        self.set_pin_off(valve_pin)

    def flush_valves(self, dur=1):
        val = list('{0:08b}'.format(self._parallel_port_conn.readData()))
        for valve in self.parallel_port['valve_pins']:
            val[1-valve] = '1'
        self._parallel_port_conn.setData(int(''.join(val),2))

        time.sleep(dur)

        for valve in self.parallel_port['valve_pins']:
            val[1-valve] = '0'
        self._parallel_port_conn.setData(int(''.join(val),2))

    def set_index_pin_on(self):
        index_pin = self.parallel_port['index_pin']
        self.set_pin_on(index_pin)

    def set_index_pin_off(self):
        index_pin = self.parallel_port['index_pin']
        self.set_pin_off(index_pin)

    def set_frame_pin_on(self):
        frame_pin = self.parallel_port['frame_pin']
        self.set_pin_on(frame_pin)

    def set_frame_pin_off(self):
        frame_pin = self.parallel_port['frame_pin']
        self.set_pin_off(frame_pin)

    def set_trial_pin_on(self):
        trial_pin = self.parallel_port['trial_pin']
        self.set_pin_on(trial_pin)

    def set_trial_pin_off(self):
        trial_pin = self.parallel_port['trial_pin']
        self.set_pin_off(trial_pin)

    def set_pin_on(self,pin):
        if pin<2 or pin>9:
            ValueError('Cannot deal with this')
        val = list('{0:08b}'.format(self._parallel_port_conn.readData()))
        val[1-pin] = '1'
        self._parallel_port_conn.setData(int(''.join(val),2))

    def set_pin_off(self,pin):
        if pin<2 or pin>9:
            ValueError('Cannot deal with this')
        val = list('{0:08b}'.format(self._parallel_port_conn.readData()))
        val[1-pin] = '0'
        self._parallel_port_conn.setData(int(''.join(val),2))

    def get_display_size(self):
        pass

    def get_session(self):
        """
            Connect to BServer and request session details to be loaded
        """
        self._session = self._server_conn.client_to_server(self._server_conn.SESSION_REQUESTED)

    def decache(self):
        """
            Remove session specific details. ideal for pickling
        """
        self._window = None
        self._session = None
        self._server_conn = None
        self._parallel_port_conn = None
        self._clocks = None

    def do_trials(self, **kwargs):
        # first step in the running of trials. called directly by station
        # or through the BServer
        if __debug__:
            pass
        self.initialize()
        # get the compiled_records for the animal. Compiled records will contain all the information that will be used in
        # the course of running the experiment. If some stimulus parameter for a given trial is dependent on something in
        # the previous trial, please add it to compiled records
        compiled_record = self.subject.load_compiled_records()
        quit = False

        # session starts here
        session_record = []  # just a list of tRs
        session_number = compiled_record["session_number"][-1] + 1

        # setup the clocks
        self._clocks['session_clock'] = psychopy.core.MonotonicClock()
        self._clocks['trial_clock'] = psychopy.core.Clock()
        session_start_time = psychopy.core.getAbsTime()

        while not quit:
            # it loops in here every trial
            trial_record = {}
            # just assign relevant details here
            trial_record["session_start_time"] = session_start_time
            trial_record["trial_number"] = compiled_record["trial_number"][-1] + 1
            trial_record["session_number"] = session_number
            trial_record["station_id"] = self.station_id
            trial_record["station_version_number"] = self.ver.__str__()
            trial_record["station_name"]= self.station_name
            trial_record["num_ports_in_station"] = self.num_ports
            trial_record["trial_start_time"] = self._clocks['session_clock'].getTime()
            # doTrial - only trial_record will be returned as its type will be changed
            trial_record, quit = self.subject.do_trial(station=self, trial_record=trial_record, compiled_record=compiled_record, quit=quit)

            trial_record["trial_stop_time"] = self._clocks['session_clock'].getTime()
            # update sessionRecord and compiledRecord
            compiled_record = compile_records(compiled_record,trial_record)
            session_record.append(trial_record)

        # save session records
        self.subject.save_session_records(session_record)
        # save compiled records
        self.subject.save_compiled_records(compiled_record)

        self.decache()

    def close_session(self, **kwargs):
        print("STANDARDVISIONBEHAVIORSTATION:CLOSE_SESSION::Closing Session")

    def close_window(self):
        self._window.close()

    def check_manual_quit(self):
        key = psychopy.event.getKeys(keyList=['k','q'])
        if key:
            if not key[0] in self._key_pressed: self._key_pressed.append(key[0])
        if 'k' in self._key_pressed and 'q' in self._key_pressed:
            psychopy.event.clearEvents()
            return True
        else:
            return False

    def read_kb(self):
        key,modifier = event.getKeys(keyList=['1','2','3','k'],modifier=True)
        ports = np.asarray([False,False,False])
        if key:
            if not key[0] in self._key_pressed: self._key_pressed.append(key[0])
        if 'k' in self._key_pressed and '1' in self._key_pressed:
            self._key_pressed.remove('k')
            self._key_pressed.remove('1')
        if 'k' in self._key_pressed and '2' in self._key_pressed:
            ports = np.bitwise_or(ports,[False,True,False])
            psychopy.event.clearEvents()
            print(self._key_pressed)
            self._key_pressed.remove('k')
            self._key_pressed.remove('2')
        if 'k' in self._key_pressed and '3' in self._key_pressed:
            ports = np.bitwise_or(ports,[False,False,True])
            psychopy.event.clearEvents()
            print(self._key_pressed)
            self._key_pressed.remove('k')
            self._key_pressed.remove('3')

        return self.get_ports()[ports]
コード例 #22
0
def main():
    term = Terminal()
    if sys.version_info < (2, 7):
        raise RuntimeError(
            "Jirafs requires minimally version 2.7 of Python 2, or "
            "any version of Python 3.  Please upgrade your version of "
            "python before using Jirafs.")
    if utils.get_git_version() < NormalizedVersion('1.8'):
        raise RuntimeError(
            "Jirafs requires minimally version 1.8 of Git.  Please "
            "upgrade your version of git before using Jirafs.")

    commands = utils.get_installed_commands()

    parser = argparse.ArgumentParser(
        description='Edit Jira issues locally from your filesystem',
        add_help=False,
    )
    parser.add_argument('command', type=six.text_type, choices=commands.keys())
    parser.add_argument('--subtasks', action='store_true', default=False)
    parser.add_argument(
        '--log-level',
        default=None,
        dest='log_level',
    )
    parser.add_argument('--folder', default=os.getcwd())
    parser.add_argument(
        '--no-subfolders',
        action='store_true',
        default=False,
    )
    parser.add_argument(
        '--traceback',
        action='store_true',
        default=False,
    )
    args, extra = parser.parse_known_args()

    if args.log_level is not None:
        logging.basicConfig(level=logging.getLevelName(args.log_level))

    command_name = args.command
    cmd_class = commands[command_name]

    # Subtasks
    if args.subtasks:
        cmd_class.RUN_FOR_SUBTASKS = True

    started = time.time()
    logger.debug('Command %s(%s) started', command_name, extra)
    jira = utils.lazy_get_jira()
    try:
        value = cmd_class.execute_command(extra,
                                          jira=jira,
                                          path=args.folder,
                                          command_name=command_name)
        logger.debug('Command %s(%s) finished in %s seconds', command_name,
                     extra, (time.time() - started))
        if value:
            value.echo()
        sys.exit(value.return_code)
    except GitCommandError as e:
        print(u"{t.red}Error (code: {code}) while running git "
              u"command.{t.normal}".format(t=term, code=e.returncode))
        print("")
        print(u"{t.red}Command:{t.normal}{t.red}{t.bold}".format(t=term))
        print(u"    {cmd}".format(cmd=e.command))
        print(u"{t.normal}".format(t=term))
        print(u"{t.red}Output:{t.normal}{t.red}{t.bold}".format(t=term))
        for line in e.output.decode('utf8').split('\n'):
            print(u"    %s" % line)
        print(u"{t.normal}".format(t=term))
        if args.traceback:
            traceback.print_exc()
        sys.exit(10)
    except NotTicketFolderException:
        if not getattr(cmd_class, 'TRY_SUBFOLDERS', False):
            print(u"{t.red}The command '{cmd}' must be ran from "
                  u"within an issue folder.{t.normal}".format(
                      t=term, cmd=command_name))
            sys.exit(20)
        elif args.no_subfolders:
            sys.exit(20)

        count_runs = 0
        for folder in os.listdir(os.getcwd()):
            full_path = os.path.join(
                os.getcwd(),
                folder,
            )
            if not os.path.isdir(full_path):
                continue

            try:
                full_args = copy.copy(sys.argv)
                if '--no-subfolders' not in full_args:
                    full_args.append('--no-subfolders')
                result = subprocess.call(' '.join(
                    [shlex_quote(a) for a in full_args]),
                                         cwd=full_path,
                                         shell=True)
                if result == 0:
                    count_runs += 1
            except NotTicketFolderException:
                pass
        if count_runs == 0:
            if args.traceback:
                traceback.print_exc()
            sys.exit(21)
    except JIRAError as e:
        print(u"{t.red}Jirafs encountered an error while interacting with "
              u"your JIRA instance: {t.normal}{t.red}{t.bold}{error}"
              u"{t.normal}".format(t=term, error=str(e)))
        if args.traceback:
            traceback.print_exc()
        sys.exit(70)
    except JiraInteractionFailed as e:
        print(u"{t.red}JIRA was unable to satisfy your "
              u"request: {t.normal}{t.red}{t.bold}{error}{t.normal}".format(
                  t=term, error=str(e)))
        if args.traceback:
            traceback.print_exc()
        sys.exit(80)
    except JirafsError as e:
        print(u"{t.red}Jirafs encountered an error processing your "
              u"request: {t.normal}{t.red}{t.bold}{error}{t.normal}".format(
                  t=term, error=str(e)))
        if args.traceback:
            traceback.print_exc()
        sys.exit(90)
コード例 #23
0
ファイル: reasoner.py プロジェクト: Njrob/eddy
 def version(self):
     """
     Returns the version of the reasoner.
     :rtype: NormalizedVersion
     """
     return NormalizedVersion(self.spec.get('reasoner', 'version'))
コード例 #24
0
 def version(self):
     """
     Returns the version of the plugin.
     :rtype: NormalizedVersion
     """
     return NormalizedVersion(self.spec.get('plugin', 'version'))
コード例 #25
0
 def load_from_dict(self, data):
     self.timerange_version = Ver(data['timerange_version'])
     self.time_start = data['time_start']
     self.time_stop = data['time_stop']
コード例 #26
0
 def load_from_dict(self, data):
     self.sessionmgr_version = Ver(data['sessionmgr_version'])
     self.name = data['name']
コード例 #27
0
ファイル: Station.py プロジェクト: yzerlaut/bcore
class Station(object):
    """
        STATION contains all the relevant details and interfaces to run
        trials from a particular station. This is an abstract class.
        Do not instantiate.
        stationID       : numeric ID
        stationPath     : string path to data storage location
        MACAddress      : unique mac address for the processor/ethernet
                          card. string identifier
    """
    _subject = None
    _key_pressed = []
    _sounds = {}
    _stims = {}
    _clocks = {}
    _parallel_port_conn = None
    creation_time = ''
    station_version = Ver('0.0.1')
    station_id = None
    station_name = ''
    station_path = ''
    station_location = None

    def __init__(self, **kwargs):
        if not kwargs:
            pass
        elif 'data' in kwargs:
            self = self.load_from_dict(kwargs['data'])
        else:
            pass

    def load_from_dict(self, data):
        self.station_version = Ver(data['station_version'])
        self.creation_time = datetime.datetime.strptime(
            data['creation_time'], DATETIME_TO_STR)
        self.station_id = data['station_id']
        self.station_name = data['station_name']
        self.station_path = os.path.join(get_base_path(), 'BCoreData',
                                         'StationData', str(self.station_id))
        self.station_location = data['station_location']

        self.mac_address = get_mac_address()
        self.ip_address = get_ip_addr()
        self.port = get_port()
        return self

    def save_to_dict(self):
        data = dict()
        data['station_version'] = self.station_version.__str__()
        data['station_id'] = self.station_id
        data['station_name'] = self.station_name
        data['station_location'] = self.station_location
        data['creation_time'] = datetime.datetime.strftime(
            self.creation_time, DATETIME_TO_STR)
        return data

    def __repr__(self):
        return "Station object with id:%s, location:%s and ip:%s" % (
            self.station_id, self.station_location, self.ip_address)

    def register(self):
        #
        pass

    def _setup_paths(self):
        if not os.path.isdir(self.station_path):
            os.makedirs(self.station_path)

    def do_trials(self, **kwargs):
        raise NotImplementedError('Run doTrials() on a subclass')

    def initialize_sounds(self):
        self._sounds['trial_start_sound'] = psychopy.sound.Sound(440,
                                                                 stereo=0,
                                                                 secs=1.,
                                                                 hamming=True)

        self._sounds['request_sound'] = psychopy.sound.Sound(493.88,
                                                             stereo=0,
                                                             secs=1.,
                                                             hamming=True)
        self._sounds['stim_start_sound'] = psychopy.sound.Sound(493.88,
                                                                stereo=0,
                                                                secs=1.,
                                                                hamming=True)
        self._sounds['go_sound'] = psychopy.sound.Sound(493.88,
                                                        stereo=0,
                                                        secs=1.,
                                                        hamming=True)
        self._sounds['keep_going_sound'] = psychopy.sound.Sound(493.88,
                                                                stereo=0,
                                                                secs=1.,
                                                                hamming=True)
        self._sounds['request_sound'] = psychopy.sound.Sound(493.88,
                                                             stereo=0,
                                                             secs=1.,
                                                             hamming=True)

        self._sounds['correct_sound'] = psychopy.sound.Sound(523.25,
                                                             stereo=0,
                                                             secs=1.,
                                                             hamming=True)
        self._sounds['reward_sound'] = psychopy.sound.Sound(523.25,
                                                            stereo=0,
                                                            secs=1.,
                                                            hamming=True)
        self._sounds['trial_end_sound'] = psychopy.sound.Sound(523.25,
                                                               stereo=0,
                                                               secs=1.,
                                                               hamming=True)

        sampleRate, secs, f_punishment = (44100, 2, [370, 440])
        nSamples = int(secs * sampleRate)
        phase = 2 * np.pi * np.linspace(0.0, 1.0, nSamples)
        val = np.full_like(phase, 0.)
        for f in f_punishment:
            val += np.sin(f * phase)
        val = np.matlib.repmat(val, 2, 1)
        self._sounds['punishment_sound'] = psychopy.sound.Sound(val.T,
                                                                hamming=True)

        val = 0.5 * np.random.randn(1, nSamples)
        val = np.matlib.repmat(val, 2, 1)
        self._sounds['try_something_else'] = psychopy.sound.Sound(val.T,
                                                                  hamming=True)

        self._sounds['trial_end_sound'] = psychopy.sound.Sound(587.33,
                                                               stereo=0,
                                                               secs=1.,
                                                               hamming=True)

    def _rewind_sounds(self, time=0.):
        for sound in self._sounds:
            self._sounds[sound].seek(time)

    def decache(self):
        """
            Remove session specific details. ideal for pickling
        """
        self._key_pressed = None
        self._sounds = None
        self._stims = None
        self._clocks = None
コード例 #28
0
ファイル: version.py プロジェクト: dd/Meringue
def get_version(version):
    try:
        return str(NormalizedVersion.from_parts(*version))
    except NameError:
        logging.info(u'for better install verlib' )
        return '.'.join([str(j) for i in version for j in i])
コード例 #29
0
def main():
    term = Terminal()
    if sys.version_info < (2, 7):
        raise RuntimeError(
            "Jirafs requires minimally version 2.7 of Python 2, or "
            "any version of Python 3.  Please upgrade your version of "
            "python before using Jirafs.")
    if utils.get_git_version() < NormalizedVersion('1.8'):
        raise RuntimeError(
            "Jirafs requires minimally version 1.8 of Git.  Please "
            "upgrade your version of git before using Jirafs.")

    commands = utils.get_installed_commands()

    parser = argparse.ArgumentParser(
        description='Edit Jira issues locally from your filesystem',
        add_help=False,
    )
    parser.add_argument('command', type=six.text_type, choices=commands.keys())
    parser.add_argument('--subtasks', action='store_true', default=False)
    args, extra = parser.parse_known_args()

    command_name = args.command
    cmd_class = commands[command_name]

    # Subtasks
    if args.subtasks:
        cmd_class.RUN_FOR_SUBTASKS = True

    started = time.time()
    logger.debug('Command %s(%s) started', command_name, extra)
    jira = utils.lazy_get_jira()
    try:
        cmd_class.execute_command(extra,
                                  jira=jira,
                                  path=os.getcwd(),
                                  command_name=command_name)
    except GitCommandError as e:
        print("{t.red}Error (code: {code}) while running git "
              "command.{t.normal}".format(t=term, code=e.returncode))
        print("")
        print("{t.red}Command:{t.normal}{t.red}{t.bold}".format(t=term))
        print("    {cmd}".format(cmd=e.command))
        print("{t.normal}".format(t=term))
        print("{t.red}Output:{t.normal}{t.red}{t.bold}".format(t=term))
        for line in e.output.decode('utf8').split('\n'):
            print("    %s" % line)
        print("{t.normal}".format(t=term))
        sys.exit(10)
    except NotTicketFolderException:
        if not getattr(cmd_class, 'TRY_SUBFOLDERS', False):
            print("{t.red}The command '{cmd}' must be ran from "
                  "within an issue folder.{t.normal}".format(t=term,
                                                             cmd=command_name))
            sys.exit(20)
        count_runs = 0
        for folder in os.listdir(os.getcwd()):
            try:
                cmd_class.execute_command(
                    extra,
                    jira=jira,
                    path=os.path.join(
                        os.getcwd(),
                        folder,
                    ),
                    command_name=command_name,
                )
                count_runs += 1
            except NotTicketFolderException:
                pass
        if count_runs == 0:
            print("{t.red}The command '{cmd}' must be ran from "
                  "within an issue folder or from within a folder containing "
                  "issue folders.{t.normal}".format(t=term, cmd=command_name))
            sys.exit(21)
    except JiraInteractionFailed as e:
        print("{t.red}JIRA was unable to satisfy your "
              "request: {t.normal}{t.red}{t.bold}{error}{t.normal}".format(
                  t=term, error=str(e)))
        sys.exit(80)
    except JirafsError as e:
        print("{t.red}Jirafs encountered an error processing your "
              "request: {t.normal}{t.red}{t.bold}{error}{t.normal}".format(
                  t=term, error=str(e)))
        sys.exit(90)

    logger.debug('Command %s(%s) finished in %s seconds', command_name, extra,
                 (time.time() - started))
コード例 #30
0
ファイル: __init__.py プロジェクト: Rethought/cfn-pyplates
- https://aws.amazon.com/cloudformation/
- https://cfn-pyplates.readthedocs.org/ (you might already be here)
- https://github.com/seandst/cfn-pyplates/
'''

# Friendly PEP-386 version string
# The fourth number used for third-party fork versions
__version__ = '0.2.1.1'

import warnings

try:
    from verlib import NormalizedVersion
    # Validates the version above, exposing the version parts for anyone
    # that might want to make decisions based on a normalized version tuple
    version_parts = NormalizedVersion(__version__).parts
except ImportError:
    verlib_errormsg = '''
    Failed to import verlib, version_parts will not be available

    This should only happen during install, before dependencies are evaluated
    and installed.
    '''
    warnings.warn(verlib_errormsg, ImportWarning)

# Protocol numbers, used in setting up security group rules as documented
# in:
# https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
#
# The CloudFormation template requires the protocol number, but the name
# TCP, UDP etc is easier to remember. This mapping therefore helps.
コード例 #31
0
ファイル: Subject.py プロジェクト: balajisriram/BCore
class Subject(object):
    """
        SUBJECT contains all relevant details about the subject.
                subject_id              : string identifier
                protocol                : protocol object
                session_manager         : session manager
                creation_time           : time
                iacuc_protocol_id      : string Identifier
        Changes::
            Ver 0.0.2 - Added iacuc_protocol_id to the object
            Ver 0.0.3 - Added  _property_changed and made getters and setters
    """
    _subject_changed = False
    def __init__(self, subject_id, **kwargs):
        """
                Call as follows::
                subject(subjectID='demo')
                subjectID               - MANDATORY
                protocols               - EMPTY
        """
        self.ver = Ver('0.0.3')
        self.subject_id = subject_id
        self._protocol = []
        self._session_manager = []
        self.creation_date = time.time()
        self.iacuc_protocol_id = ''
        if 'reward' in kwargs:
            self._reward = kwargs['reward']
        else:
            self._reward = 0
        if 'timeout' in kwargs:
            self._timeout = kwargs['timeout']
        else:
            self._timeout = 0
        if 'iacuc_protocol_id' in kwargs:
            self.iacuc_protocol_id = kwargs['iacuc_protocol_id']

    def __repr__(self):
        return "Subject with id:%s, rewarded at %s ms and punishment at %s ms" % (self.subject_id, self.reward, self.timeout)

    def _clean(self):
        pass

    def __eq__(self, other):
        # if this method is called, then clearly
        return False
        
    ### getters
    @property
    def protocol(self):
        return self._protocol
        
    @property
    def session_manager(self):
        return self._session_manager
    
    @property
    def reward(self):
        return self._reward
        
    @property
    def timeout(self):
        return self._timeout
    
    ### setters
    @protocol.setter
    def protocol(self, value):
        self._protocol = value
        _subject_changed = True
        
    @session_manager.setter
    def session_manager(self, value):
        self._session_manager = value
        _subject_changed = True
    
    @reward.setter
    def reward(self,value):
        self._reward = value
        _subject_changed = True
        
    @timeout.setter
    def timeout(self, value):
        self._timeout = value
        _subject_changed = True
        
    
    
    
    def add_protocol(self, new_protocol):
        if not self.protocol:
            self.protocol = new_protocol
        else:
            raise ValueError('cannot add new_protocol. protocol is not empty. \
            Maybe you meant replace_protocol()?')

    def add_session_manager(self, new_session_manager):
        if not self.session_manager:
            self.session_manager = new_session_manager
        else:
            raise ValueError('cannot add new_session_manager. session_manager is not empty. \
            Maybe you meant replace_session_manager()?')

    def replace_protocol(self, new_protocol):
        self.protocol = new_protocol

    def replace_session_manager(self, new_session_manager):
        self.session_manager = new_session_manager

    def allowed_genders(self):
        return None

    def allowed_strains(self):
        return None

    def allowed_gene_bkgd(self):
        return None

    def do_trial(self, station, trial_record, compiled_record, quit):
        # Called by station.do_trials()
        if not self.protocol:
            raise ValueError('Protocol Unavailable: cannot run subject without \
            a protocol')

        # new consideration in  protocol and training step
        graduate = False

        # some basic info about the subject
        trial_record['subject_id'] = self.subject_id
        trial_record['subject_version_number'] = self.ver.__str__()

        # figure out the protocol, and the trainingStep details
        trial_record['protocol_name'] = self.protocol.name
        trial_record['protocol_version_number'] = self.protocol.ver.__str__()
        trial_record['current_step'] = self.protocol.current_step
        trial_record['current_step_name'] = self.protocol.step(compiled_record=compiled_record,trial_record=trial_record).name
        trial_record['num_steps'] = self.protocol.num_steps

        current_step = self.protocol.step(compiled_record=compiled_record,trial_record=trial_record)
        trial_record,quit = current_step.do_trial(subject=self, station=station, trial_record=trial_record, compiled_record=compiled_record,quit = quit)
        if trial_record['graduate']:
            trial_record['criterion_met'] = True
            self.protocol.graduate()
        else:
            trial_record['criterion_met'] = False

        return trial_record, quit

    def load_compiled_records(self):
        # location is get_base_directory->BCoreData->CompiledTrialRecords->subject_id.compiled_record
        compiled_file_loc = os.path.join(get_base_directory(),"BCoreData","SubjectData","CompiledTrialRecords")
        files = [i for i in os.listdir(compiled_file_loc) if \
                 os.path.isfile(os.path.join(compiled_file_loc,i)) and self.subject_id in i]
        print(self.subject_id)
        print(files)
        if len(files)>1:
            RuntimeError("SUBJECT:SUBJECT:LOAD_COMPILED_RECORDS:Too many records")
        elif len(files)==1:
            with open(os.path.join(compiled_file_loc,files[0]),"rb") as f:
                cR = pickle.load(f)
        else:
            cR = None

        return cR

    def save_compiled_records(self, cR):
        # location is get_base_directory->BCoreData->SubjectData->CompiledTrialRecords->subject_id.compiled_record
        from BCore import get_base_directory
        import os
        import pickle
        compiled_file_loc = os.path.join(get_base_directory(), "BCoreData", "SubjectData", "CompiledTrialRecords")
        files = [i for i in os.listdir(compiled_file_loc) if \
                 os.path.isfile(os.path.join(compiled_file_loc, i)) and self.subject_id in i]

        if len(files)>1:
            pass
        elif len(files)==1:
            os.remove(os.path.join(compiled_file_loc,files[0]))
        else:
            pass

        tNum = cR["trial_number"][-1]
        sid = self.subject_id
        cR_name = '{0}.1-{1}.compiled_record'.format(sid,tNum)
        with open(os.path.join(compiled_file_loc,cR_name), "wb") as f:
            pickle.dump(cR,f)

    def save_session_records(self,sR):
        # location is get_base_directory->BCoreData->PermanentTrialRecords->subject_id->trialRecord.1-N.session_record
        from BCore import get_base_directory
        import os
        import pickle
        session_file_loc = os.path.join(get_base_directory(), "BCoreData", "SubjectData", "SessionRecords",self.subject_id)
        if not os.path.exists(session_file_loc):
            os.makedirs(session_file_loc)
        tnum_lo = sR[0]["trial_number"]
        tnum_hi = sR[-1]["trial_number"]

        sR_name = "trialRecords.{0}-{1}.session_record".format(tnum_lo,tnum_hi)
        with open(os.path.join(session_file_loc, sR_name), "wb") as f:
            pickle.dump(sR, f)
コード例 #32
0
 def get_taskwarrior_version(self):
     taskwarrior_version = subprocess.Popen(
         ['task', '--version'], stdout=subprocess.PIPE).communicate()[0]
     return NormalizedVersion(taskwarrior_version)
コード例 #33
0
 def load_from_dict(self, data):
     self.notimeoff_version = Ver(data['notimeoff_version'])
コード例 #34
0
 def get_taskwarrior_capsules_version(self):
     return NormalizedVersion(__version__)
コード例 #35
0
ファイル: __init__.py プロジェクト: warriorsong/Meringue
# -*- coding: utf-8 -*-

__VERSION__ = (
    (0, 3, 3),
    # ('a', 1),
    # ('dev', 1)
)

try:
    from verlib import NormalizedVersion
    version = str(NormalizedVersion.from_parts(*__VERSION__))
except ImportError:
    version = '.'.join([str(j) for i in __VERSION__ for j in i])