def fillFields(self): k = 0 self.items = [] while (True): try: courier = Courier(k) print(type(courier.name)) self.items.append( str(courier.name) + " " + str(courier.surename)) k = k + 1 except KeyError: break self.Courier.addItems(self.items) dfn = pd.read_csv('data/products.csv', encoding='utf-8') del dfn['Unnamed: 0'] self.items = [] for i in range(len(dfn)): self.items.append(dfn.iloc[i, 0]) self.Product.addItems(self.items) k = 0 self.items = [] self.itemsAddress = [] while (True): try: client = Client(k) self.items.append( str(client.name) + " " + str(client.phone_number)) self.itemsAddress.append( str(client.street) + " " + str(client.house)) k = k + 1 except KeyError: break self.Client.addItems(self.items) self.Address.addItems(self.itemsAddress)
def __init__(self): '''Initializes bot class.''' self.scraper = Scraper() self.validator = Validator() self.courier = Courier() self.loopInterval = 300 # In seconds self.currentMode = Environment.TEST # This is set in self.ModeSelect() method in the run method. I have it set to Environment.TEST default incase someone removes self.modeSelect().
async def update_couriers(request): json = await request.json() id = request.match_info.get('id') incorrect = False courier = Courier(id, None, None, None, 0) for key, val in json.items(): if key == "courier_type" and type(val) is str and val in ('foot', 'bike', 'car'): courier.type = val elif key == "regions" and type(val) is list and all( type(x) is int and x > 0 for x in val): courier.regions = val elif key == "working_hours" and type(val) is list and all( type(x) is str for x in val) and len(val) <= 3: courier.working_hours = val else: incorrect = True if incorrect: return web.Response(status=400) courier = courier.update(request.app['db']) orders = courier.get_incompatible_orders(request.app['db']) for order in orders: order.remove_courier(request.app['db']) return web.json_response(status=200, data={ "courier_id": courier.id, "courier_type": courier.type, "regions": courier.regions, "working_hours": courier.working_hours })
def delCourier(self): index = self.tableWidget.row(self.tableWidget.currentItem()) if index == -1: return #Courier(index).removeCourier() Courier(index).removeCourier() self.fillTableCouriers()
def get_courier_by_id(connection, courier_id): with connection: element = connection.execute(GET_COURIER_BY_ID, courier_id).fetchall()[0] courier = Courier(element[0], element[1], json.loads(element[2]), json.loads(element[3]), json.loads(element[4])) return courier
def __init__(self): # self.sockfd = sockfd # 界面的创建以及动作执行 app = QtWidgets.QApplication(sys.argv) self.form = QtWidgets.QWidget() self.cur_dialog = QtWidgets.QDialog() self.reg_dialog = QtWidgets.QDialog() self.num_dialog = QtWidgets.QDialog() self.sel_dialog = QtWidgets.QDialog() self.usr_dialog = QtWidgets.QDialog() self.usr1_dialog = QtWidgets.QDialog() self.cur1_dialog = QtWidgets.QDialog() # 创建所有页面的对象 self.mf = MainInterface() # 主界面 self.cur = Courier() # 快递员登录界面 self.reg = Registered() # 快递员注册界面 self.num = Number() # 快递员输入用户信息界面 self.sel = SelectSize() # 快递员选择柜子大小界面 self.usr = User() # 用户输入验证码界面 self.usr1 = UsrSelect() # 用户选择寄件和取件界面 self.cur1 = CurSelect() # 快递员选择派件和取件界面 self.mf.main_inter(self.form) self.form.show() self.cur.c_interface(self.cur_dialog) self.reg.register_interface(self.reg_dialog) self.usr.user_interface(self.usr_dialog) self.num.number_inteface(self.num_dialog) self.sel.select_interface(self.sel_dialog) self.usr1.us_interface(self.usr1_dialog) self.cur1.cs_interface(self.cur1_dialog) # 调用动作函数 self.action() sys.exit(app.exec_())
async def test_deliver_order_success(self): ordinary_shelf = self.od.shelf_mapping['frozen'] overflow_shelf = self.od.shelf_mapping['overflow'] order, order_info = await self.setup_order_info([], ordinary_shelf, overflow_shelf) courier = Courier(delay_time=2, order_info=order_info) msg = await courier.deliver_order([]) print(msg) assert 'delivered: \x1b[32mTrue\x1b[0m' in msg
def get_couriers(self) -> dict: couriers = {} for courier in self.data['couriers']: new_courier = Courier() new_courier.courier_id = courier.get('courier_id') new_courier.location_x = courier.get('location_x') new_courier.location_y = courier.get('location_y') couriers[new_courier.courier_id] = new_courier return couriers
async def test_deliver_order_fail(self): ordinary_shelf = self.od.shelf_mapping['frozen'] overflow_shelf = self.od.shelf_mapping['overflow'] order, order_info = await self.setup_order_info([], ordinary_shelf, overflow_shelf) order_info.is_on_shelf = False courier = Courier(delay_time=2, order_info=order_info) msg = await courier.deliver_order(wasted_orders=[]) print(msg) assert 'not in shelf' in msg
def get_couriers(connection): with connection: data = connection.execute(GET_COURIERS_TABLE).fetchall() couriers = [] for element in data: courier = Courier(element[0], element[1], json.loads(element[2]), json.loads(element[3]), json.loads(element[4])) couriers.append(courier) return couriers
async def consumer(self): """ consume order from queue, terminated the program if all orders in queue have been processed, :return: """ try: while True: order_info = await self.order_queue.get() if not order_info: continue if order_info == 'finished': self.order_queue.task_done() break print('\n########## consume order queue #############') courier_delay_time = random.randint(self.deliver_time_range[0], self.deliver_time_range[1]) print( colored( 'consumer get {0} ,start dispatching to courier in: {1} seconds' .format(order_info.order['id'], courier_delay_time), 'green')) await asyncio.sleep(courier_delay_time) try: courier = Courier(delay_time=courier_delay_time, order_info=order_info) deliver_msg = await courier.deliver_order( wasted_orders=self.wasted_orders) print('\n&&&&&&&&&&&& deliver info &&&&&&&&&&&&') print(deliver_msg) self.delivered_orders.append(order_info) except Exception as e: print(colored("Catch Exception {0}".format(e)), 'red') raise finally: self.order_queue.task_done() except asyncio.CancelledError: print("worker is being cancelled") raise finally: print( '\n########## all orders have been processed,system terminated #############' )
def add_couriers(): elements, errors, conn = [], [], db.connect() ids = db.get_couriers_id(conn) for element in request.json['data']: try: if element['courier_id'] in ids: raise (ValueError, 'Такой id уже существует в базе данных') c = Courier(element['courier_id'], element['courier_type'], element['regions'], element['working_hours']) elements.append(c) except Exception: errors.append({'id': element['courier_id']}) # если в процессе добавления возникли ошибки if errors: return jsonify({'validation_error': {'couriers': errors}}), 400 db.insert_couriers(conn, elements) return jsonify({'couriers': [{'id': elem.courier_id} for elem in elements]}), 201
async def couriers(request): json = await request.json() objects = [] incorrect_objects = [] for k, v in json.items(): if k == "data": for obj in v: courier = Courier(obj.get("courier_id"), obj.get("courier_type"), obj.get("regions"), obj.get("working_hours"), 0) incorrect = False for key, val in obj.items(): if key == "courier_id" and type(val) is int and val > 0: courier.id = val elif key == "courier_type" and type( val) is str and val in ('foot', 'bike', 'car'): courier.type = val elif key == "regions" and type(val) is list and all( type(x) is int and x > 0 for x in val): courier.regions = val elif key == "working_hours" and type(val) is list and all( type(x) is str for x in val) and len(val) <= 3: courier.working_hours = val else: incorrect = True if incorrect or courier.regions is None or courier.working_hours is None or courier.type is None: incorrect_objects.append({"id": courier.id}) else: objects.append({"id": courier.id}) courier.save(request.app['db']) else: return web.Response(status=400) if len(incorrect_objects) > 0: return web.json_response( status=400, data={"validation_error": { "couriers": incorrect_objects }}) else: return web.json_response(status=201, data={"couriers": objects})
def setUp(self): self.o = Order({u'id' : u'a8cfcb76-7f24-4420-a5ba-d46dd77bdffd' , u'prepTime' : 4 , u'name' : u'Banana Split'}) cooking = MTList() cooking.put(self.o) self.c = Cook(MTList() , cooking) self.courier=Courier(self.o)
def addCourierButtonClicked(self): n = self.work.textName.toPlainText() s = self.work.textSurname.toPlainText() p = self.work.textPatr.toPlainText() c = self.work.carriageSize.toPlainText() Courier(self.i).changeCourier(n, s, p, c)