def serial_read(serial_port="com22", debug=False): ser = serial.Serial(serial_port, 115200, timeout=0.001) ui("", "") while True: reading = str(ser.readline()) reading = reading.replace("b'", "") reading = reading.replace("'", "") if (reading in sw_object): before = timeit.default_timer() if (debug): print(reading) sw_object[reading].input_even() if (debug): print("time used " + str(timeit.default_timer() - before))
def input_even(self): stage = False if (self.debug): print("counter next button from : " + self.input) data = db.collection(self.Branch).document('Data').get().to_dict() data_queue = db.collection( self.Branch).document('Queue').get().to_dict() if (data["Last_" + self.type] in data_queue): db.collection(self.Branch).document('Queue').update( {data["Last_" + self.type]: firestore.DELETE_FIELD}) stage = True buffer = str(int((data["Last_" + self.type])[1:]) + 1) while (len(buffer) < 3): buffer = ("0" + buffer) if ((str(self.type[-1:]).upper() + str(buffer)) in data_queue): ui((str(self.type[-1:]).upper() + str(buffer)), self.name[-1:]) db.collection(self.Branch).document("Data").update({ "Last_" + self.type: (str(self.type[-1:]).upper() + str(buffer)) }) if (stage): Queue_Push = db.collection(self.Branch).document( "QueuePush").collection("ticket").document( data_queue[data["Last_" + self.type]]).get().to_dict() Estimated_Time = int(Queue_Push["Queue_Time"]) - int( Queue_Push["Stop_Time"]) Wait_time = int(Queue_Push["Start_Time"]) - int( Queue_Push["Queue_Time"]) db.collection(self.Branch).document('QueuePush').collection( "ticket").document(data_queue[data["Last_" + self.type]]).update({ 'Status': 1, 'Estimated_Time': Estimated_Time, 'Wait_Time': Wait_time })
#Redraw Function def redrawGameWindow(): win.blit(bg, (0, 0)) ui.draw(win) ai.draw(win) player.draw(win) for bullet in bullets: bullet.draw(win) pygame.display.update() #Game Loop player = player(100, 100, 32, 32) ui = ui(0, screenHeight - 100, 0) ai = enemy(250, 250, 32, 32, 100, 50) shootLoop = 0 ammo = 0 options = 0 reload = False bullets = [] run = True while run: clock.tick(15) if ammo == 5: reload = True if shootLoop > 0: shootLoop += 1
threshold_num=5 elif threshold_str=="10人": threshold_num=10 elif threshold_str=="20人": threshold_num=20 elif threshold_str=="30人": threshold_num=30 elif threshold_str=="50人": threshold_num=50 elif threshold_str=="100人": threshold_num=100 return threshold_num # 图形界面程序 application=ui() lock=Lock() file=None def screen_shot(file_path, screenshot_interval): global file get_img_from_camera_local(file_path, screenshot_interval,lock) def store_upload(file_path, threshold_value): global file write_to_json(file_path, threshold_value,lock)
def input_even(self): time_now = int(time.time()) stage = False if (self.debug): print("counter next button from : " + self.input) data = db.collection(self.Branch).document('Data').get().to_dict() data_queue = db.collection( self.Branch).document('Queue').get().to_dict() i = 1 while (int(data["Next_" + self.type][1:]) - int(data["Last_" + self.type][1:]) > 1): #chack queue buffer = str(int((data["Last_" + self.type])[1:]) + i) while (len(buffer) < 3): buffer = ("0" + buffer) if ((str(self.type[-1:]).upper() + str(buffer)) in data_queue): ui((str(self.type[-1:]).upper() + str(buffer)), self.name[-1:]) db.collection(self.Branch).document("Data").update({ "Last_" + self.type: (str(self.type[-1:]).upper() + str(buffer)) }) db.collection(self.Branch).document("QueuePush").collection( "ticket").document( data_queue[(str(self.type[-1:]).upper() + str(buffer))][0]).update( {"Queue_Time": time_now}) stage = True listin = [] diccc = {} Queue_Push = db.collection(self.Branch).document( "QueuePush").collection("ticket").document( data_queue[str(self.type[-1:]).upper() + str(buffer)][0]).get().to_dict() for i in data_queue: if (i[0:1] == Queue_Push["No"][0:1]): k = 1 listin.append(data_queue[i][0]) for j in data["counter_" + str(i[0:1]).lower()]: if Queue_Push["Type"] == j and int(i[1:]) >= int( self.Queue_now[1:]): if data_queue[i][k] - 1 >= 0: listin.append(data_queue[i][k] - 1) else: listin.append(data_queue[i][k]) elif (int(i[1:]) <= int(self.Queue_now[1:])): listin.append(0) else: listin.append(data_queue[i][k]) k += 1 diccc[i] = listin listin = [] if (diccc != {}): db.collection(self.Branch).document('Queue').update(diccc) break i += 1 if (self.Queue_now in data_queue): diccc = {self.Queue_now: firestore.DELETE_FIELD} Queue_Push = db.collection(self.Branch).document( "QueuePush").collection("ticket").document( data_queue[self.Queue_now][0]).get().to_dict() Estimated_Time = time_now - int(Queue_Push["Queue_Time"]) db.collection(self.Branch).document('Data').update({ "Avg_" + str(Queue_Push["Type"]): ((int(data["Avg_" + str(Queue_Push["Type"])]) * 9) + Estimated_Time) / 10, "Count_" + str(Queue_Push["Type"]): data["Count_" + str(Queue_Push["Type"])] - 1 }) Wait_time = int(Queue_Push["Queue_Time"]) - int( Queue_Push["Start_Time"]) db.collection(self.Branch).document('Queue').update(diccc) db.collection(self.Branch).document('QueuePush').collection( "ticket").document(data_queue[self.Queue_now][0]).update({ 'Status': 1, 'Estimated_Time': Estimated_Time, 'Wait_Time': Wait_time, 'Stop_Time': time_now }) if (stage): self.Queue_now = (str(self.type[-1:]).upper() + str(buffer)) print(self.Queue_now)