def restore(self): filename = filedialog.askdirectory( ) # show an "Open" dialog box and return the path to the selected file length = len(filename) file = filename[length - 17:length] path = filename[0:length - len(file)] output = str( File_Transfer.paste(SOURCE_FILE_PATH=path, SOURCE_FILE_NAME=file, DEST_FILE_PATH="/home/smst/", DEST_FILE_NAME="")) #print(output) output = str( Commander.main(COMMAND_PATH="/home/smst/", COMMAND_NAME="Restore_Backup_DB", ARGUMENTS="-p " + "/home/smst/ " + "-n " + file, SUDO=True)) #print(output) output = str( Commander.main(COMMAND_PATH="/home/smst/", COMMAND_NAME="Switch_DB", ARGUMENTS="-n " + file, SUDO=True)) #print(output) output = str( Commander.main( COMMAND_PATH="", # make Backup COMMAND_NAME="rm", ARGUMENTS="-r " + "/home/smst/influxdb/share/" + file, SUDO=True))
def __init__(self): OpenLogger() self.running = False self.reseting = False self.connected = False self.stepThrough = False self.step = False self.worldState = WorldState.WorldState() self.controlInterface = ControlInterface.ControlInterface() self.visionInterface = VisionInterface.VisionInterface() self.command_list = [] self.commander = Commander.Commander(self.controlInterface) self.strategyClass = Strategies.MetaStrategy self.strategy = self.strategyClass() self.lastStrategyChange = os.stat("./Strategies.py").st_mtime self.visionUpdateTimer = 0.0 self.ballVelocities = [] self.strategyThread = threading.Thread( name = "RunLoop", target = self.run ) self.strategyThread.start()
def backup(self, start_date, start_time, end_date, end_time): if(start_time < 10): start_time = "0" + str(start_time) start_time = str(start_time) + ":00:00" if(end_time < 10): end_time = "0" + str(end_time) end_time = str(end_time) + ":00:00" output = str(Commander.main(COMMAND_PATH="/home/smst/", #make Backup COMMAND_NAME="Create_Backup_DB", ARGUMENTS="-s " + (start_date) + " -t " + (start_time) +" -e " + (end_date) + " -z " + (end_time) + " -d " + "dss", SUDO=True)) if output.find("[sudo] password for smst: ")!= -1: output = output.split("[sudo] password for smst:", 2)[1] Count = output.find("meta.00") Name = output[Count-18: Count-1] if (os.path.exists("backup/")) == False: os.mkdir("backup/") output = File_Transfer.copy( DEST_FILE_PATH="/home/smst/influxdb/share/", DEST_FILE_NAME=Name, SOURCE_FILE_PATH="backup/", SOURCE_FILE_NAME="", arg="-r ") #print(output) output = str(Commander.main(COMMAND_PATH="", # make Backup COMMAND_NAME="rm", ARGUMENTS="-r " + "/home/smst/influxdb/share/" + Name, SUDO=True)) print("Exported database: " + Name + " -> " + "Start: " + start_date + "_" + start_time + " End: " + end_date + "_" + end_time)
def FTP(self, path, command, arguments, sudo): print(arguments) self.arguments = arguments output = str( Commander.main(COMMAND_PATH=path, COMMAND_NAME=command, ARGUMENTS=arguments, SUDO=sudo)) if output.find("[sudo] password for smst: ") != -1: output = output.split("[sudo] password for smst:", 2)[1] return output
def deCoder(transCommandList, ForS, map, player2, player1, mapDetail): ## ,player2,player1 ##我方會將對方視為player2,因此player2變成主要攻擊者 transCommandList = transCommandList["action"] for i in range(len(transCommandList)): TorF = Commander.inputCommand(player2, player1, ForS, transCommandList[i], map, mapDetail) TorF = winOrLose.wOrL(player1) ##判斷我方是否輸了 if TorF == True: print("你輸了") return True else: print("下一回合") for i in range(len(player1.army)): if (player1.army[i].moved == 0): ##扣除油或體力 player1.army[i].fuel = player1.army[i].fuel - 5 if (player1.army[i].fuel <= 0): player1.army[i].hp = 0 player1.army[i].moved = 0 player1.army[i].atked = 0 return TorF
from Commander import * # <-- IP_ADRESS: Your raspberry IP address (You can check it by using 'ifconfig' command on raspberry) # <-- PORT_NR: Port number. Change it to 60xx where xx is the number of your SD card following the 'R' (use 0x for 1-digit numbers (use 04 for R4)) IP_ADDRESS = "your.pi.ip.addr" # for example "192.168.15.23" PORT_NR = 6666 if __name__ == "__main__": commander = Commander(IP_ADDRESS, PORT_NR) try: while True: command = input( "Enter command (F - forward, B - backward, S - stop, Q - quit) :" ) if command.strip() == 'Q': break commander.sendCommand(command) finally: commander.closeSocket()
def compose_response_os(self, data, raw_input): return c.Commander(data, raw_input).wrapper()
"""" this is main commander of a program""" import Commander commander = Commander.Commander(path_folder="train", winlen=0.015) commander.eval_test() commander.write_to_csv_else('results.csv') print("program ended")
def game_newgame(): # 都是 TextBox 的東西 By Chin - Head# n = 0 y = 0 x = 0 global myTurn global enemyAction global take myTurn = False take = 0 # open room By Paco a = net.send({'event': 1, 'player': place - 1}) b = net.recv( ) # get dic {'room': value, 'turn': value} turn = 1 is player1, = 2 player2 rm = json.loads(b) room = rm['room'] if rm['turn'] == 1: myTurn = True # open room By Paco textinput = GUINewGamePageTextBox.TextInput() # 建立一個Textinput 的地方 ResponseArea = pygame.Surface((600, 150)) ResponseArea.fill(black) # 都是 TextBox 的東西 By Chin - Foot# # 呢邊是 Button 的東西 By Chin - Head # SendBtn = GUINewGamePageButtonClick.button( blue, 750, 590, 170, 120, "GO") # color , x, y, width, height , text GOBtn = pygame.image.load("../img/GoBtn.png") GOBtn = pygame.transform.scale(GOBtn, (320, 320)) GOBtn2 = pygame.image.load("../img/GoBtn2.png") GOBtn2 = pygame.transform.scale(GOBtn2, (320, 320)) token = True # 模仿回合的結束 用來不給玩家在不是自己的回合中輸入 Pass = False # Pause 專用 # 呢邊是 Button 的東西 By Chin - Foot # # player conn server select By Paco net.send({'event': 7, 'room': room, 'player': place - 1}) player = net.recv() ##1在這邊要接收 server告訴本地適用哪的玩家 player1 = Constructer.constructPlayer(player) player1.playerID = place - 1 ##server give us - By Dan player2 = Constructer.constructPlayer(player) player2.playerID = None ##server give us - By Dan # player conn server select By Paco # server get map By Paco net.send({'event': 5, 'player': place - 1, 'room': room}) mapInfor = net.recv() mapInfor = json.loads(mapInfor) print('mapInfor : ', mapInfor) map = Constructer.constructMap(mapInfor) print("Map number is ", mapInfor['Id']) # print(mapInfor) # server get map By Paco if rm["turn"] == 1: player1.hq = Headquarter.Headquarter( hp=20, x=mapInfor["Player1_HQ"]["x"], y=mapInfor["Player1_HQ"]["y"]) ##建構玩家1物件 player2.hq = Headquarter.Headquarter(hp=20, x=mapInfor["Player2_HQ"]["x"], y=mapInfor["Player2_HQ"]["y"]) else: player1.hq = Headquarter.Headquarter( hp=20, x=mapInfor["Player2_HQ"]["x"], y=mapInfor["Player2_HQ"]["y"]) ##建構玩家2物件 player2.hq = Headquarter.Headquarter(hp=20, x=mapInfor["Player1_HQ"]["x"], y=mapInfor["Player1_HQ"]["y"]) head_font = medfont ##建立文字物件 by Dan Changed : pygame.font.SysFont(None, 60) -> smallfont (By Chin) text_surface = head_font.render('Illegal instruction', True, (255, 255, 255)) ##宣告文字物件的格式by Dan Sx = None # Set up Army position x Default Value - By Chin Sy = None # Set up Army position y Default Value - By Chin msg = medfont # 用於顯示不是目前玩家的回合 MSGColor = red MSG = msg.render("Not Your Turn", True, MSGColor) thread = threading.Thread(target=recieve) thread.start() RankBtn = pygame.image.load("../img/RankBtn.png") RankBtn2 = pygame.image.load("../img/RankBtn2.png") print(player1.hq.hp, player2.hq.hp) while True: gameDisplay.fill(yellow) pygame.display.set_caption("Game Start") # message_to_screen("Game Start", black, 1000, -340, size='large') gameDisplay.blit(ResponseArea, (80, 580)) SendBtn.draw(gameDisplay) BTN(680, 490, 740, 940, 600, 700, GOBtn, GOBtn2) # Infantry id 編號是? - By Chin # Infantry = pygame.image.load("../img/Infantry-self.png") Infantry = pygame.transform.scale(Infantry, (50, 50)) # InfantryBTN = GUINewGamePageButtonClick.button(white, 5, 70, 190, 150, "") #用於按下Button 顯示可移動及生成位置(運用pause page 原理) # InfantryBTN.draw(gameDisplay) gameDisplay.blit(Infantry, (20, 80)) message_to_screen("NO. 0", navy, 250, -275, size="medium") message_to_screen("Move : 3 px", navy, 120, -230) message_to_screen("ATK : 1 px", navy, 120, -190) # Mech id 編號是? - By Chin # Mech = pygame.image.load("../img/Mech-self.png") Mech = pygame.transform.scale(Mech, (50, 50)) gameDisplay.blit(Mech, (20, 230)) message_to_screen("NO. 1", navy, 250, -130, size="medium") message_to_screen("Move : 2 px", navy, 120, -90) message_to_screen("ATK : 1 px", navy, 120, -50) # Reco id 編號是? - By Chin # Reco = pygame.image.load("../img/Reco-self.png") Reco = pygame.transform.scale(Reco, (50, 50)) gameDisplay.blit(Reco, (20, 380)) message_to_screen("NO. 2", navy, 250, 30, size="medium") message_to_screen("Move : 2 px", navy, 120, 70) message_to_screen("ATK : 1 px", navy, 120, 110) GUINewGamePageMap.Map(gameDisplay, map, mapInfor, rm['turn']) DisplayArmy(player1, player2, Sx, Sy, rm['turn']) gameDisplay.blit(textinput.get_surface(), (90, 585)) # TextInput position By Chin events = pygame.event.get() for event in events: pos = pygame.mouse.get_pos() if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.MOUSEBUTTONDOWN: if SendBtn.isOver(pos) and myTurn: net.send({ 'event': 3, 'room': room, 'player': place - 1, 'action': transComman }) TorF = winOrLose.wOrL(player2) ##判斷對方是否輸了 if TorF == True: print("Player 1 win") net.send({ 'event': 8, 'player': place - 1, 'name': name }) thread.join() WinPage(gameDisplay, 1) else: myTurn = False for i in range(len(player1.army)): if (player1.army[i].moved == 0): ##扣除油或體力 player1.army[i].fuel = player1.army[i].fuel - 5 if (player1.army[i].fuel <= 0): player1.army[i].hp = 0 player1.army[i].moved = 0 player1.army[i].atked = 0 print("下一回合") print("TextBox Locked!") # token = False # 還未做出下一回合, 回恢權限 By Chin if event.type == pygame.MOUSEMOTION: if SendBtn.isOver(pos): SendBtn.color = light_blue else: SendBtn.color = blue if event.type == pygame.KEYDOWN: #當按下Enter 後重新畫出ResponseArea By Chin if event.key == pygame.K_RETURN: print(player1.hq.hp, player2.hq.hp) ResponseArea = pygame.Surface((600, 150)) ResponseArea.fill(black) gameDisplay.blit(ResponseArea, (80, 580)) if myTurn: y = 60 if textinput.update(events): # 輸入指令的地方 By Chin command = textinput.get_text() # print(command) # 透過get_text() 取得輸入的資訊 By Chin TorF = Commander.inputCommand( player1, player2, rm['turn'], command, map, mapInfor) ##呼叫commander來解析指令 by Dan if TorF == True: ##如果回傳值是true 就要記錄下來 by Dan text_surface = head_font.render('Construction Success', True, (255, 255, 255)) transComman.append(command) else: ##指令有問題 text_surface = head_font.render('Illegal Instruction', True, (255, 255, 255)) # By Chin ResponseArea.blit(text_surface, (10, y)) ##顯示文字物件 by Dan else: # 如不是玩家回合則顯示MSG - By Chin gameDisplay.blit(MSG, (730, 715)) if take == 1: print(enemyAction) # ---------------bug------------------ transComman.clear() for i in range(len(player1.army)): player2.army[i].moved = 0 # ---------------bug------------------ Lose = DeCoder.deCoder(enemyAction, (rm['turn'] % 2) + 1, map, player2, player1, mapInfor) DisplayArmy(player1, player2, 0, 0, rm['turn']) myTurn = True take = 0 if Lose == True: print("Lose") WinPage(gameDisplay, 0) pygame.display.update() clock.tick(30)
# DeCoder.deCoder(transCommandList,1,map,player2,player1) while True: print("HQ:",player1.hq.hp,"X: ",player1.hq.x,"Y: ",player1.hq.y) for i in range (len(player1.army)): print("ID: ",i," HP:",player1.army[i].hp," X: ",player1.army[i].x," Y: ",player1.army[i].y) command = input("plz input ur command :\n") if (command == "leave"): ##button按下去要做的事情 for i in range(len(player1.army)): if(player1.army[i].moved == 0):##扣除油或體力 player1.army[i].fuel = player1.army[i].fuel - 5 if(player1.army[i].fuel <=0): player1.army[i].hp = 0 player1.army[i].moved = 0 player1.army[i].atked = 0 tmpDic = {"action":transComman} transCommandList.update(tmpDic) TorF = winOrLose.wOrL(player2)##判斷對方是否輸了 if TorF ==True: print("對方輸了") else: print("下一回合") break else: TorF = Commander.inputCommand(player1, player2, 1, command,map) ##這裡應該使GUI呼叫我的地方,我會回傳true or false if TorF == True: print("記錄下來") transComman.append(command) else: print("不紀錄") print(transCommandList)
from task3_field import * from task4_path import * from task5_command import * cap = cv2.VideoCapture(1) ret, frame = cap.read() # <-- Change the robot id number to the one written on the tag you're using robotID = 1 # <-- Find the markers from the frame and calculate the shortest path # drive = Drive(path) commander = Commander(IP_ADDRESS, PORT_NR) try: while True: # read the image from the camera ret, frame = cap.read() markers = detect(frame) # Display the resulting image with markers cv2.imshow('markers', frame) # <-- Find the coordinates of the front and back of the robot, get the next command from the drive object and pass it on to the commander # Quit the program when Q is pressed if cv2.waitKey(1) & 0xFF == ord('q'):
""" initializating program from here""" import Commander GameCommander = Commander.Commander() GameCommander.game_run()
def report(self, start_date, start_time, end_date, end_time): #start_time = str(start_time) + ":00:00" #if start_time < 10: #start_time = "0" + start_time #end_time = str(end_time) + ":00:00" #if e_time < 10: # end_time = "0" + end_time start_date = date(int(start_date[0:4]), int(start_date[6:7]), int(start_date[9:10])) end_date = date(int(end_date[0:4]), int(end_date[6:7]), int(end_date[9:10])) now = str(datetime.now()) now_time = now[11:16] now_date = date(int(now[0:4]), int(now[6:7]), int(now[9:10])) start_time_delta = str(int(now_time[0:2]) - start_time) + ":" + str( int(now_time[3:5])) end_time_delta = str(int(now_time[0:2]) - end_time) + ":" + str( int(now_time[3:5])) start_date_delta = str(now_date - start_date) start_date_delta = start_date_delta.split("0:00:00", 2)[0] start_date_delta = start_date_delta.split("days,", 2)[0] end_date_delta = str(now_date - end_date) end_date_delta = end_date_delta.split("0:00:00", 2)[0] end_date_delta = end_date_delta.split("days,", 2)[0] start = str(start_date_delta)[:-1] + 'd' end = str(end_date_delta)[:-1] TimeSpan = "'from=now-" + start TimeSpan += "&to=now" if (end != ""): TimeSpan += "-" + end + 'd' + "'" else: TimeSpan += "'" filename = str(start_date) + ".pdf" filename = filename.replace('-', '') Dashboard = "oBjEVCPGz" API = "eyJrIjoieUNXNzdZZDB4aFV5MklkRFF3MDVFaTZHOTE1cEtqWVEiLCJuIjoiS2V5IiwiaWQiOjF9" IP = Params.IP + ':' + str(Params.Report_Port) output = str( Commander.main(COMMAND_PATH="/home/smst/go/bin/", COMMAND_NAME="grafana-reporter", ARGUMENTS="-cmd_enable=1 -cmd_apiKey " + Params.API_KEY + " -ip " + IP + " -cmd_dashboard " + Dashboard + " -cmd_ts " + TimeSpan + " -cmd_o " + filename, SUDO=True)) print(output) if (os.path.exists("report/")) == False: os.mkdir("report/") output = File_Transfer.copy(DEST_FILE_PATH="/home/smst/", DEST_FILE_NAME=filename, SOURCE_FILE_PATH="report/", SOURCE_FILE_NAME="", arg="") print(output) output = str( Commander.main( COMMAND_PATH="", # make Backup COMMAND_NAME="rm", ARGUMENTS="/home/smst/" + filename, SUDO=True)) print(output)