Пример #1
0
 def getConfigData(self, tag):
     """
     returns saved dictionary for given tag
     """
     return CAD.File_to_dict('mouse',
                             '{:013}'.format(int(tag)),
                             '.jsn',
                             dir=self.configPath)
Пример #2
0
 def configGenerator(self):
     """
     Each configuration file has config data for a single subject. This function loads data
     from all of them in turn, and returning each as a a tuple of(tagID, dictionary)
     """
     for fname in listdir(self.configPath):
         if fname.startswith('AHF_mouse_') and fname.endswith('.jsn'):
             tagStr = fname[10:len(fname) - 4]
             yield (int(tagStr),
                    CAD.File_to_dict('mouse',
                                     tagStr,
                                     '.jsn',
                                     dir=self.configPath))
Пример #3
0
    def setup(self):
        # hardware.json subject.json

        self.settingsTuple = ('HeadFixer', 'Rewarder', 'Stimulator')
        self.loadConfigs = self.settingsDict.get('loadMiceConfigs')
        self.jsonName = self.settingsDict.get('jsonName')
        self.inChamberTimeLimit = self.settingsDict.get('inChamberTimeLimit')
        self.miceDict = {}
        self.resultsDict = {}
        if self.loadConfigs == "database" and hasattr(
                self.task, 'DataLogger'
        ):  # try to load mice configuration from dataLogger
            dataLogger = self.task.DataLogger
            for configTuple in dataLogger.configGenerator("current_subjects"):
                self.miceDict.update(configTuple)
        elif self.loadConfigs == "provide_json":  #check file, if not existing or not correct provide a fillable json, then update miceDict when user is ready
            try:
                direc = ""
                if os.getcwd() == "/root":
                    with open("/home/pi/config.txt", "r") as file:
                        configs = file.readlines()
                        for config in configs:
                            config = config.split("=")
                            if config[0] == "path":
                                direc = config[1].rstrip("\n")
                self.miceDict = CAD.File_to_dict('mice', self.jsonName, '.jsn',
                                                 self.configPath)
                if self.check_miceDict(self.miceDict) == False:
                    raise Exception('Could not confirm dictionary')
            except Exception as e:
                print(
                    'Unable to open and fully load subjects configuration, we will create a fillable json for you.\n'
                    'This file will be named AHF_mice_fillable' +
                    self.jsonName + ".jsn\n")
                self.create_fillable_json()
            while self.check_miceDict(self.miceDict) == False:
                input(
                    'could not load json, please edit and try again. Press enter when done'
                )

            for tag in self.miceDict.keys():
                for source in self.miceDict.get(tag):
                    self.task.DataLogger.storeConfig(
                        int(tag),
                        self.miceDict.get(tag).get(source), source)
Пример #4
0
 def create_fillable_json(self):
     tags = self.miceDict.keys()
     self.miceDict = {}
     useOld = ""
     if len(tags) > 0:
         useOld = input("You have the following tags in your JSON: " +
                        str(tags) + " Would you like to use these?")
     addMore = True
     if len(useOld) > 0 and useOld[0].lower() == 'y':
         for tag in tags:
             self.add(int(tag))
         addMore = input("Add any more mice?")
         if len(addMore) > 0 and addMore[0].lower() == 'n':
             addMore = False
     if addMore:
         tempInput = input(
             'Add the mice for your task.\n'
             'Type A for adding a mouse with the tag number \n'
             'Type T for using the RFID Tag reader ')
         moreMice = True
         while moreMice:
             self.add(tempInput[0])
             stillmore = input('add another mouse? Y or N')
             if stillmore[0] == "n" or stillmore[0] == "N":
                 moreMice = False
     print(self.miceDict)
     CAD.Dict_to_file(self.miceDict,
                      "mice_fillable",
                      self.jsonName,
                      ".jsn",
                      dir=configPath)
     input("Please edit the values in AHF_mice_fillable_" + self.jsonName +
           '.jsn now. Do not modify the structure.\n' +
           "Press enter when done")
     os.system("sudo cp AHF_mice_fillable_" + self.jsonName + ".jsn" +
               " AHF_mice_" + self.jsonName + ".jsn")
     self.miceDict = CAD.File_to_dict('mice',
                                      self.jsonName,
                                      '.jsn',
                                      dir=configPath)