def group_res(cls, key_path , nameFile = None, allPrefix = 'res_', folderName = None, replace_func = None): """ return a dict <key:flags:list<str:>> Arguments --------- key_path: <list> Defines how to group results: given as a path in the dict structure of the results to get a value used for the grouping nameFile, allPrefix, folderName: cf. read_res() Output: ------- a dictionary where key is the concatenation of the unique set of keys found and value is a list of all the files corresponding to this key """ listFileName = ut.findFile(nameFile, allPrefix, folderName) results = [(f, cls.get_keys_from_onefile_safe(f, key_path, replace_func = replace_func)) for f in listFileName] nb_errors = np.sum([r[1] is None for r in results]) if (nb_errors > 0): print("{} files couldn't be read".format(nb_errors)) results = [r for r in results if r[1] is not None] groupped_res = collections.defaultdict(list) for k, v in results: groupped_res[v].append(k) return groupped_res
def read_res(cls, nameFile = None, allPrefix = 'res_', folderName = None, returnName = False, replace_func = None): """ Extract result(s) stored in a (several) txt file (s) and return them as a (list) of evaluated objects Arguments --------- nameFile: None or <str> If not None only read the file with this name If None will rely on folderName and allPrefix folderName: None or <str> In which folder should we look for the files allPrefix: None or <str> If not None enforce collecting only the results starting with this prefix returnName: bool if True returns also the name of the file(s) replace_func: <func> take the string extracted from the file and transform it Output ------ results: <list> each element is the evaluated string contained i the relevant file """ listFileName = ut.findFile(nameFile, allPrefix, folderName) results = [cls.eval_from_onefile(f, replace_func = replace_func) for f in listFileName] filter_none = [r is None for r in results] if np.any(filter_none): logger.warning('{} empty files'.format(np.sum(filter_none))) results = [r for r, f in zip(results, filter_none) if not(f) ] if returnName: return results, listFileName else: return results
def read_res_bug(cls, nameFile=None, allPrefix='res_', folderName=None): """ Extract result(s) stored in a (several) txt file (s) and return them in a (list) of evaluated objects Rules: +if nameFile is provided it will try to match it either in folderName if provided or in the current directory +if no nameFile is provided it will try to match the allPrefix or fetch everything if None (directory considered follow the same rules based on folderName as before) """ listFileName = ut.findFile(nameFile, allPrefix, folderName) results = [learner1DBH.eval_from_onefile_bug(f) for f in listFileName] #results = [ut.file_to_dico(f, evfunc = (lambda x: eval(x)) ) for f in listFileName] return results