def getListOfFiles(filelist, manager_path): data_path = "%s/AnalysisDatasetManager/FileInfo" % manager_path data_info = UserInput.readAllJson("/".join([data_path, "%s.json" % "data/*"])) mc_info = UserInput.readAllJson("/".join([data_path, "%s.json" % "montecarlo/*"])) valid_names = data_info.keys() + mc_info.keys() names = [] for name in filelist: if "*" in name: names += fnmatch.filter(valid_names, name) else: if name.split("__")[0] not in valid_names: print "%s is not a valid name" % name continue names += [name] return names
def getInputFilesPath(sample_name, manager_path, selection, analysis): data_path = "%s/AnalysisDatasetManager/FileInfo" % manager_path input_file_name = "/".join([data_path, analysis, "%s.json" % selection]) input_files = UserInput.readJson(input_file_name) if sample_name not in input_files.keys(): raise ValueError("Invalid input file %s. Input file must correspond" " to a definition in %s" % (sample_name, input_file_name)) return input_files[sample_name]['file_path']
def getCutsJsonName(selection, analysis): definitions_json = UserInput.readJson("Cuts/definitions.json") if selection not in definitions_json.keys(): raise ValueError("Invalid selection %s. Selection must correspond " "to a definition in Cuts/definitions.json" % selection) if analysis not in definitions_json[selection]: raise ValueError("Invalid analysis %s. Analysis name must " "correspond to a definition in Cuts/definitions.json" % analysis) return definitions_json[selection][analysis]
def main(): try: params = UserInput.getUserInput('test') ExampleLoader.loadExamples(params) w = CacheObj.loadObject(params.modelFile) Performance.writePerformance(params, w, params.resultFile) Performance.printStrongAndWeakTrainError(params, w) utils.dumpCurrentLatentVariables(params, params.latentVariableFile) except Exception, e : import traceback traceback.print_exc(file=sys.stdout)
def playGame(board, p1, p2, uiRows): userSelectsSpaceOnBigBoard = True currPlayer = p1 while True: if userSelectsSpaceOnBigBoard: bigBoardSpace = UserInput.prompForBigBoardSpace( board.bigBoard, currPlayer) miniBoardSpace = UserInput.prompForMiniBoardSpace( board.miniBoards[bigBoardSpace], currPlayer, bigBoardSpace) performMiniBoardMove(board, p1, p2, uiRows, bigBoardSpace, miniBoardSpace, currPlayer) if isThreeInARow(board.miniBoards[bigBoardSpace], currPlayer.winThreshold): printDelayedMessage("Three in a row!") performBigBoardMove(board, p1, p2, uiRows, bigBoardSpace, currPlayer) if isThreeInARow(board.bigBoard, currPlayer.winThreshold): printDelayedMessage(f"{currPlayer.name} wins!") return elif isCatsGame(board.bigBoard): printDelayedMessage("It's a draw!") return elif isCatsGame(board.miniBoards[bigBoardSpace]): printDelayedMessage( f"Big board space #{bigBoardSpace} is a draw") board.bigBoard[bigBoardSpace] = CATS_GAME_VALUE currPlayer = p1 if not currPlayer.isP1 else p2 bigBoardSpace = miniBoardSpace bigBoardSpaceAlreadyOccupied = board.bigBoard[bigBoardSpace] > 0 userSelectsSpaceOnBigBoard = bigBoardSpaceAlreadyOccupied if bigBoardSpaceAlreadyOccupied: printDelayedMessage( "The big board space that you are forced to play in is already complete. Choose any unfinished big board space you want to play in." )
def getInputFilesPath(sample_name, selection, analysis): manager_path = getManagerPath() if ".root" in sample_name: logging.info("Using simple file %s" % sample_name) return sample_name data_path = "%s/%s/FileInfo" % (manager_path, getManagerName()) input_file_base_name = "/".join([data_path, analysis, selection]) input_file_name = getConfigFileName(input_file_base_name) input_files = UserInput.readInfo(input_file_name) if sample_name not in input_files.keys(): raise ValueError("Invalid input file %s. Input file must correspond" " to a definition in %s" % (sample_name, input_file_name)) filename = input_files[sample_name]['file_path'] return filename
def getInputFilesPath(sample_name, selection, analysis, manager_path=""): if manager_path is "": manager_path = getManagerPath() if ".root" in sample_name: print "INFO: using simple file %s" % sample_name return sample_name data_path = "%s/AnalysisDatasetManager/FileInfo" % manager_path input_file_base_name = "/".join([data_path, analysis, selection]) input_file_name = getConfigFileName(input_file_base_name) input_files = UserInput.readInfo(input_file_name) if sample_name not in input_files.keys(): raise ValueError("Invalid input file %s. Input file must correspond" " to a definition in %s" % (sample_name, input_file_name)) filename = input_files[sample_name]['file_path'] return filename
def buildCutString(state, selection, analysis, trigger): cut_string = CutString() selection_json = ConfigureJobs.getCutsJsonName(selection, analysis) cuts = UserInput.readJson(selection_json) cut_string.append(cuts["Event"]) cut_string.append(cuts["State"][state]) if trigger != "" and not cut_string.contains(trigger): cut_string.append(getTriggerCutString(trigger, analysis)) counts = dict((lep, state.count(lep)) for lep in state) current = dict((lep, 0) for lep in state) for lep in state: current[lep] += 1 lep_name = ''.join([lep, "" if counts[lep] == 1 else str(current[lep])]) for cut in cuts["Object"][lep]: cut_string.append(cut.format(object_name=lep_name)) return cut_string
def getListOfFilesWithXSec(filelist, manager_path=""): if manager_path is "": manager_path = getManagerPath() data_path = "%s/ZZ4lAnalysisDatasetManager/FileInfo" % manager_path files = getListOfFiles(filelist, "ntuples", manager_path) #files = getListOfFiles(filelist, "2018Data", manager_path) mc_info = UserInput.readAllJson("/".join( [data_path, "%s.json" % "montecarlo/*"])) info = {} for file_name in files: if "data" in file_name: info.update({file_name: 1}) else: file_info = mc_info[file_name.split("__")[0]] kfac = file_info["kfactor"] if "kfactor" in file_info.keys() else 1 info.update({file_name: file_info["cross_section"] * kfac}) return info
def getListOfFilesWithXSec(filelist, analysis="", input_tier=""): manager_path = getManagerPath() data_path = "%s/%s/FileInfo" % (manager_path, getManagerName()) files = getListOfFiles(filelist, analysis, input_tier) mc_info = UserInput.readAllInfo("/".join([data_path, "montecarlo/*"])) info = {} for file_name in files: if "data" in file_name.lower() or "nonprompt" in file_name.lower(): info.update({file_name: 1}) else: file_info = mc_info[file_name.split("__")[0].replace("-", "")] kfac = file_info["kfactor"] if "kfactor" in file_info.keys() else 1 # Intended to use for, e.g., nonprompt if file_name[0] == "-": kfac *= -1 info.update({file_name: file_info["cross_section"] * kfac}) return info
def __init__(self, dataset_manager_path, dataset_name): self.manager_path = dataset_manager_path self.dataset_name = dataset_name self.info = UserInput.readJson("/".join([self.manager_path, "FileInfo", "%s.json" % self.dataset_name])) self.config = config_object.ConfigObject(self.info) self.mc_info = UserInput.readJson("/".join([self.manager_path, "FileInfo", "montecarlo.json"])) self.data_info = UserInput.readJson("/".join([self.manager_path, "FileInfo", "data.json"])) self.styles = UserInput.readJson("/".join([self.manager_path, "Styles", "styles.json"])) base_name = self.dataset_name.split("/")[0] self.plot_groups = UserInput.readJson("/".join([self.manager_path, "PlotGroups", "%s.json" % base_name])) object_file = "/".join([self.manager_path, "PlotObjects", "%s.json" % base_name]) self.aliases = UserInput.readJson("/".join([self.manager_path, "Aliases", "%s.json" % base_name])) # Objects can be defined by the default dataset-wide file, # or by specific selection files if not os.path.isfile(object_file): object_file = object_file.replace(self.dataset_name, base_name) self.plot_objects = UserInput.readJson(object_file)
def mix(pilotInput): out = ui.RawInput() # Les gouvernes sont utilisés en priorité pour l'elevator, ce qu'il reste est utilisé pour le yaw pitch = pilotInput.getPitch() #[3D] #placeRestante = 1 - abs(pitch) #yaw = dm.constrain(pilotInput.getYaw(),-placeRestante, placeRestante) yaw = 0 out.setElevD(pitch + yaw) out.setElevG(pitch - yaw) out.setFlapsD(pilotInput.getFlaps()) out.setFlapsG(pilotInput.getFlaps()) out.setThrottle(pilotInput.getThrottle()) return out
def buildCutString(state, selections, analysis, trigger): cut_string = CutString() for selection in selections: selection_json = ConfigureJobs.getCutsJsonName(selection, analysis) cuts = UserInput.readJson(selection_json) cut_string.append(cuts["Event"]) cut_string.append(cuts["State"][state]) if trigger != "": trigger_string = getTriggerCutString(trigger, analysis) if not cut_string.contains(trigger_string): cut_string.append(trigger_string) counts = dict((lep, state.count(lep)) for lep in state) current = dict((lep, 0) for lep in state) for lep in state: current[lep] += 1 lep_name = ''.join( [lep, "" if counts[lep] == 1 else str(current[lep])]) for cut in cuts["Object"][lep]: cut_string.append(cut.format(object_name=lep_name)) return cut_string
def getListOfFilesWithXSec(filelist, manager_path="", selection="ntuples"): if manager_path is "": manager_path = getManagerPath() data_path = "%s/%s/FileInfo" % (manager_path, getManagerName()) files = getListOfFiles(filelist, selection, manager_path) mc_info = UserInput.readAllInfo("/".join([data_path, "montecarlo/*"])) info = {} for file_name in files: if "data" in file_name.lower() or "nonprompt" in file_name.lower(): info.update({file_name: 1}) else: label = file_name.split("__")[0] if label[0] == "-": label = label[1:] file_info = mc_info[label] kfac = file_info["kfactor"] if "kfactor" in file_info.keys() else 1 # Intended to use for, e.g., nonprompt if file_name[0] == "-": kfac *= -1 info.update({file_name: file_info["cross_section"] * kfac}) return info
def main(): try: params = UserInput.getUserInput('train') ExampleLoader.loadExamples(params) CommonApp.setExampleCosts(params) w = None if params.initialModelFile: w = CacheObj.loadObject(params.initialModelFile) else: w = CommonApp.PsiObject(params,False) globalSPLVars = SPLSelector.SPLVar() if params.splParams.splMode != 'CCCP': SPLSelector.setupSPL(params) w = LSSVM.optimize(w, globalSPLVars, params) CacheObj.cacheObject(params.modelFile,w) Performance.printStrongAndWeakTrainError(params, w) except Exception, e : import traceback traceback.print_exc(file=sys.stdout)
def getListOfFilesWithPath(filelist, analysis, input_tier, das=True): manager_path = getManagerPath() data_path = "%s/%s/FileInfo" % (manager_path, getManagerName()) files = getListOfFiles(filelist, analysis, input_tier) input_tier_info = UserInput.readInfo("/".join( [data_path, analysis, input_tier])) info = {} for file_name in files: if das and "DAS" not in input_tier_info[file_name].keys(): logging.error( "DAS path not defined for file %s in analysis %s/%s" % (file_name, analysis, input_tier)) continue elif not das and "file_path" not in input_tier_info[file_name].keys(): logging.error( "File_path not defined for file %s in analysis %s/%s" % (file_name, analysis, input_tier)) continue info.update({ file_name: input_tier_info[file_name]["DAS" if das else "file_path"] }) return info
def setAliases(tree, state, aliases_json): aliases = UserInput.readJson(aliases_json) for name, value in aliases["State"][state].iteritems(): print "Setting alias %s to %s" % (name, value) tree.SetAlias(name, value)
# Loading previous entries from params file paramsFile = 'params.csv' try: pFile = open(paramsFile, 'r+') params = next(csv.reader(pFile, delimiter=',')) lapsStr = params[0] ratStr = params[1] dayStr = params[2] dTheta0Str = params[3] dTheta1Str = params[4] except: pFile = open(paramsFile, 'w') # Create the file # Gets various fields from user (third argument specifies minimum input accepted) laps = UINPUT.genForm(lcd, 'Laps', lapsStr, 1) print('# of Laps: ' + str(laps)) goal = laps * 360 # Converting laps into goal degrees ratNum = UINPUT.genForm(lcd, 'Rat Num', ratStr, 0) print('Rat Num: ' + str(ratNum)) day = UINPUT.genForm(lcd, 'Day', dayStr, 0) print('Day: ' + str(day)) dTheta0 = UINPUT.genForm(lcd, 'dTheta0', dTheta0Str, 0) print('dTheta0: ' + str(dTheta0)) dTheta1 = UINPUT.genForm(lcd, 'dTheta1', dTheta1Str, 0) print('dTheta1: ' + str(dTheta1)) # Write new parameters to file pFile.seek(0) pFile.write('{:<5},{:<5},{:<5},{:<5},{:<5}'.format(str(laps), str(ratNum), str(day), str(dTheta0), str(dTheta1))) pFile.close()
valuecheck = sheets.cell(row= i , column= j) value1 = str(valuecheck.value) # print(data1) # print(value1) if value1 == str(data1): rownum = rownum + 1 mastercol =1 # print(data1) # print(value1) for k in range(4, wbMaxColumn+1): cellprintpos = sheets.cell(row= i, column=k) # print(cellprintpos) cellprintval = cellprintpos.value # print(cellprintval) currMassheet.cell(row= rownum, column= mastercol).value = sheets.cell(row=i, column= k).value mastercol = mastercol+1 # index = index + 1 masterbook.save(str(pathMasterWorkbook)) UserInput.user_selection() UserInput.user_choice_selection() UserInput.outputResult_path() writing_mastersheet() length0fpathlist = len(UserInput.pathList) for d in range(0, length0fpathlist): path = UserInput.pathList[d] check = DataFilter.validating_input(path) if check == 1: sending_data_master(path, UserInput.inputList)
def __init__(self, potential_params, config_params, teleop, predictor_type, robot_type, grasp, user_input_type, index_test, DH_params, name_user_test, dynamic_system, gripper_active, escape_active): self._potential_params = potential_params self._config_params = config_params self._vmax = self._config_params[1] self._teleop = teleop self._predictor_type = predictor_type self._robot_type = robot_type self._grasp = grasp self._user_input_type = user_input_type self._index_test = index_test self._DH_params = DH_params self._goal_radius = config_params[3] self._indexEE = len(self._DH_params[0]) self._gripper_active = gripper_active if (self._gripper_active): self._indexGripper = self._indexEE + 1 self._end_system = False self._distance_type = "distance" self._dynamic_system = dynamic_system self._escape_active = escape_active self._LEN_TWIST_VECTOR = 6 self._ZT = 1.20 #Variables for dynamic system: only obstacles can change, not goals if (self._dynamic_system): self._dynamic_first_lecture = True self._dynamic_goal = None self._dynamic_joints = None self._dynamic_obstacles = None self._dynamic_escape_points = None self._joints_target_positions = None self._dynamic_goal_msg = None self._dynamic_sub_objs = None #User Input, PrintFile and kinematics self._userinput = UserInput.UserInput(self._robot_type, self._user_input_type) self._print_file = None if (self._teleop): self._print_file = PrintFile.PrintFile("teleop", self._index_test, name_user_test, self._user_input_type) else: self._print_file = PrintFile.PrintFile(self._predictor_type, self._index_test, name_user_test, self._user_input_type) self._rob_kin = rk.RobotKinematics( self._DH_params[0], self._DH_params[1], self._DH_params[2], self._DH_params[3], self._robot_type, self._gripper_active) #Services self._service_obj = None self._service_move = None self._service_grasp = None self._service_init_pred_node = None self._service_predictor = None self._reset_myo_service = None
def getListOfFiles(filelist, selection, manager_path="", analysis=""): if manager_path == "": manager_path = getManagerPath() print("The main manager path = %s" % manager_path) data_path = "%s/%s/FileInfo" % (manager_path, getManagerName()) print("The data path = %s " % data_path) group_path = "%s/AnalysisDatasetManager/PlotGroups" % manager_path print("The group path = %s" % group_path) data_info = UserInput.readAllInfo("/".join([data_path, "data/*"])) #print(data_info) mc_info = UserInput.readAllInfo("/".join([data_path, "montecarlo/*"])) #print(mc_info) analysis_info = UserInput.readInfo("/".join([data_path, analysis, selection])) \ if analysis != "" else [] valid_names = (list(data_info.keys()) + list(mc_info.keys())) if not analysis_info else list( analysis_info.keys()) group_names = UserInput.readAllInfo( "%s/%s.py" % (group_path, analysis)) if analysis else dict() names = [] for name in filelist: if ".root" in name: names.append(name) # Allow negative contributions elif name[0] == "-": names.append(name) elif "WZxsec2016" in name: dataset_file = manager_path + \ "%s/FileInfo/WZxsec2016/%s.json" % (getManagerPath(), selection) allnames = list(json.load(open(dataset_file)).keys()) if "nodata" in name: nodata = [x for x in allnames if "data" not in x] names += nodata elif "data" in name: names += [x for x in allnames if "data" in x] else: names += allnames elif name in group_names: names += group_names[name]['Members'] elif "*" in name: anti = "NOT" in name[:3] name = name.replace("NOT", "") matching = fnmatch.filter(valid_names, name) if anti: names += filter(lambda x: x not in matching, valid_names) else: names += matching elif name not in valid_names and name.split( "__")[0] not in valid_names: logging.warning("%s is not a valid name" % name) logging.warning( "Valid names must be defined in AnalysisDatasetManager/FileInfo/(data/montecarlo)*" ) logging.debug("Vaid names are %s" % valid_names) continue else: names += [name] if not names or len(list(filter(lambda x: x != '', names))) == 0: raise RuntimeError("No processes found matching pattern '%s'" % filelist) return [str(i) for i in names]
def InjectTestInput(): # walk galaxy UserInput.queue_input(["w", "270", "2", "g"]) UserInput.queue_input( ["w", "90", "1", "L", "g", "w", "180", "3", "g", "l", "g"]) UserInput.queue_input([ "w", "270", "3", "L", "w", "270", "3", "L", "w", "270", "3", "L", "g" ]) UserInput.queue_input(["w", "20", "3", "L", "g"]) UserInput.queue_input(["w", "0", "3", "L", "g"]) UserInput.queue_input(["w", "0", "3", "L", "g"]) UserInput.queue_input(["w", "90", "3", "L", "g"]) UserInput.queue_input(["w", "90", "3", "L", "g"]) UserInput.queue_input(["w", "90", "1", "L", "g"]) # dock at close base UserInput.queue_input(["w", "180", "2", "i", "0", "6", "i", "90", "1"]) UserInput.queue_input(["W", "180", "2"]) # Globals.g_galaxy.unHideAll() pass
def getTriggerCutString(trigger, analysis): triggers = UserInput.readJson("Cuts/%s/triggers.json" % analysis) return triggers[trigger]
def setAliases(tree, state, aliases_json): aliases = UserInput.readJson(aliases_json) for name, value in aliases["State"][state].iteritems(): tree.SetAlias(name, value) for name, value in aliases["Event"].iteritems(): tree.SetAlias(name, value)
import UserInput as ui import DataManagement as dm class Mixer: @staticmethod def mix(pilotInput): out = ui.RawInput() # Les gouvernes sont utilisés en priorité pour l'elevator, ce qu'il reste est utilisé pour le yaw pitch = pilotInput.getPitch() #[3D] #placeRestante = 1 - abs(pitch) #yaw = dm.constrain(pilotInput.getYaw(),-placeRestante, placeRestante) yaw = 0 out.setElevD(pitch + yaw) out.setElevG(pitch - yaw) out.setFlapsD(pilotInput.getFlaps()) out.setFlapsG(pilotInput.getFlaps()) out.setThrottle(pilotInput.getThrottle()) return out if __name__ == "__main__": pilotInput = ui.PilotInput(1, 0.5, 0.8) rawInput = Mixer.mix(pilotInput) print(rawInput.__dict__)
import UserInput as ui import sqlite.recData.recup_data as rd import sqlite3 import reqDefs as sql conn = sqlite3.connect('sqlite/database.db') c = conn.cursor() s = ui.readInput() expression = None flag = [] expr = ui.analyseInput(s, expression, 0, flag, c) print("\n") print("Expression : " + str(expr)) try: expr.validation() res = expr.compute() print(sql.afficher(res, expr.c)) except Exception as e: print("Veuillez corriger votre expression.") conn.close()
def pressButton(self, x, y): print("You have pressed ",x,", ",y) row = self.buttonList[y] button = row[x] button['bg'] = '#8c8c8c' UI = UserInput.UserInput(self, x, y)
sheets = workbook1[workbooksheet[sheet]] storenextdata = [] for rows in range(2, sheets.max_row + 1): for col in range(1, 4): prevdata = sheets.cell(row=rows, column=col).value storenextdata.append(prevdata) storeprevdata.append(prevdata) lenoflist = len(storeprevdata) print(lenoflist) lenofinput = len(storenextdata) add = 0 i = 0 for j in range(0, lenoflist): if str(storenextdata[i]) == str(storeprevdata[j]): if i < 3: i = i + 1 add = add + 1 if add == lenofinput: print(storenextdata) storenextdata = [] # print(storenextdata) # print(storeprevdata) UserInput.user_selection() UserInput.user_choice_selection() if UserInput.Dict["Flag_showData"] == 1: search_by_input() elif UserInput.Dict["Flag_showData"] == 0: searchdata()
# be done all in one method to ensure that a step wouldn't be forgotten def performMiniBoardMove(board, p1, p2, uiRows, bigBoardSpace, miniBoardSpace, currPlayer): board.miniBoards[bigBoardSpace][miniBoardSpace] = currPlayer.moveValue BoardUI.setBoardUI(board, p1, p2, uiRows, bigBoardSpace) BoardUI.drawBoard(uiRows) def performBigBoardMove(board, p1, p2, uiRows, bigBoardSpace, currPlayer): board.bigBoard[bigBoardSpace] = currPlayer.moveValue BoardUI.setBoardUI(board, p1, p2, uiRows, bigBoardSpace) BoardUI.drawBoard(uiRows) if __name__ == "__main__": p1Name = UserInput.promptForName(isP1=True) p2Name = UserInput.promptForName(isP1=False) p1Character = UserInput.promptForCharacter(p1Name) if p1Character == "x": p1Draw = BoardUI.setXBoard p2Character = "o" p2Draw = BoardUI.setOBoard else: p1Draw = BoardUI.setOBoard p2Character = "x" p2Draw = BoardUI.setXBoard p1 = Player(p1Draw, p1Name, p1Character, isP1=True) p2 = Player(p2Draw, p2Name, p2Character, isP1=False) while True: