def main(restaurant, order, show_count, token): restaurant_id = restaurant fig = get_statistics_per_restaurant(restaurant_id, Orders.all(token), order, int(show_count)) output = io.BytesIO() FigureCanvasSVG(fig).print_svg(output) return output.getvalue()
def test_recommendation_output(self): token = TestConstants.REST_FOOD_RECOMM_TOKEN orders = Orders.all(token) decoded = decode(token, Constants.SECRET) customer_id = decoded['_id'] restaurant_id = "5ebcf11126e32517c46effff" self.assertEqual(TestConstants.REST_FOOD_RECOMM_OUTPUT, final(customer_id, restaurant_id, orders))
def test_recommendation_output(self): token = TestConstants.REST_FOOD_FOR_REST_TOKEN orders = Orders.all(token) restaurant_id =Restaurants.by_id("5ebcf11126e32517c46effff", token) self.assertEqual(TestConstants.REST_FOOD_FOR_REST_OUTPUT, final(restaurant_id, orders)) #127.0.0.1:5000/recommendations/food/5ebcf11126e32517c46effff #token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIxNmZkZjRhZmJmNjU0OTY2Y2I2OGQiLCJpYXQiOjE1ODgyMzc0NTZ9.OG3o5XPIDDGlyFusinKVN11w27b5JYCSwLMl9XhYHeI
def test_recommendation_output1(self): token = TestConstants.SEARCH_BY_REST_TOKEN decoded = decode(token, Constants.SECRET) customer_id = decoded['_id'] restaurant_prefix = "Ram" orders = Orders.all(token) reviews= Reviews.by_customer_id(customer_id, token) restaurants = Restaurants.all(token) self.assertEqual("5ebcf11126e32517c46effff", final(reviews, restaurants, orders, customer_id, restaurant_prefix, token)[0]["id"])
def recommendForRestaurant(restaurant_id, customer_id, token): try: foods_ids = final(customer_id, restaurant_id, Orders.all(token)) foods_data = map(lambda e: Foods.by_id(e, token), foods_ids) except Exception as error: answer = dict({ Constants.SUCCESS: "false", Constants.ERROR: error.__str__() }) return answer answer = dict({Constants.SUCCESS: "true", Constants.DATA: foods_data}) return answer
def main(customer_id, restaurant_prefix, token): try: restaurants_data = final(Reviews.by_customer_id(customer_id, token), Restaurants.all(token), Orders.all(token), customer_id, restaurant_prefix, token) except Exception as error: answer = dict({ Constants.SUCCESS: "false", Constants.ERROR: error.__str__() }) return answer answer = dict({ Constants.SUCCESS: "true", Constants.DATA: restaurants_data }) return answer
def map_to_object(row): if row is not None and type(row) is dict: orderid = OrdersRepository.check_column(row, "OrderID") orderid = int(orderid) if orderid is not None else None klantnummer = OrdersRepository.check_column(row, "Klantnummer") klantnummer = int(klantnummer) if klantnummer is not None else None werknemerid = OrdersRepository.check_column(row, "WerknemerID") werknemerid = int(werknemerid) if werknemerid is not None else None verzendid = OrdersRepository.check_column(row, "VerzendID") verzendid = int(verzendid) if verzendid is not None else None orderdatum = OrdersRepository.check_column(row, "Orderdatum") vervaldatum = OrdersRepository.check_column(row, "Vervaldatum") leverdatum = OrdersRepository.check_column(row, "Leverdatum") vrachtkosten = OrdersRepository.check_column(row, "Vrachtkosten") vrachtkosten = float( vrachtkosten) if vrachtkosten is not None else None return Orders(orderid, klantnummer, werknemerid, verzendid, orderdatum, vervaldatum, leverdatum, vrachtkosten)
def addorder(pid): if request.method == "GET": return render_template("addorder.html") else: order_time = time.strftime('%Y-%m-%d %H:%M:%S') quantity = request.form['quantity'] product = Products.query.filter_by(ProductId=pid).first() vid = product.VendorId status = "pending" order = Orders(VendorId=vid, ProductId=pid, UserId=session['UserId'], Status=status, Quantity=quantity, OrderAt=order_time) db.session.add(order) db.session.commit() db.session.close() return redirect(url_for('userprofile', uid=session['UserId']))
def main(restaurant_id, token): try: orders = Orders.all(token) orders_with_userid = [] for order in orders: if 'userId' in order: orders_with_userid.append(order) foods_ids = final(Restaurants.by_id(id=restaurant_id, token=token), orders_with_userid) foods_data = map(lambda e: Foods.by_id(e, token), foods_ids) except Exception as error: answer = dict({ Constants.SUCCESS: "false", Constants.ERROR: error.__str__() }) return answer answer = dict({Constants.SUCCESS: "true", Constants.DATA: foods_data}) return answer
def number_of_orders(token): fig = main_hours(Orders.all(token)) output = io.BytesIO() FigureCanvasSVG(fig).print_svg(output) return output.getvalue()
def number_of_orders_by_restaurant(restaurant_id, token): fig = main_hours(Orders.by_res_id(restaurant_id, token)) output = io.BytesIO() FigureCanvasSVG(fig).print_svg(output) return output.getvalue()
def test_raise_exception(self): self.assertRaises(ValueError, final, {"_id": "abcdef"}, Orders.all("1234") )
def test_recommendation_output(self): token = TestConstants.REST_FOOD_RECOMM_TOKEN orders = Orders.all(token) customer_id = "5eb16fdf4afbf654966cb68d" restaurant_id = "5e9494aadd757435187a6dbd" self.assertNotEqual({}, final(customer_id, restaurant_id, orders))
def test_raise_exception(self): self.assertRaises(ValueError, final, "12345", "abcdef", Orders.all("1234")) self.assertRaises(ValueError, final, "1234", "5eb16fdf4afbf654966cb68d", Orders.all("1234"))