def read_product_rate(cls, product_id): try: pdt_ratings = session.query(func.count(cls.rate), cls.rate)\ .group_by(cls.rate).filter_by(product_id=product_id).all() numerator = 0 denomenator = 0 for rate in pdt_ratings: denomenator += rate[0] if rate[1] == 5: numerator += rate[0] * 100 elif rate[1] == 4: numerator += rate[0] * 80 elif rate[1] == 3: numerator += rate[0] * 60 elif rate[1] == 2: numerator += rate[0] * 40 elif rate[1] == 1: numerator += rate[0] * 20 if pdt_ratings: return int(((numerator / denomenator) / 100) * 5) else: return 0 except: session.rollback()
def customer_order_count(cls, customer_id): try: count = session.query(func.count(cls.id)).filter_by( is_paid=True, is_terminated=False).scalar() return count except: session.rollback()
def read_customer_count(cls): try: return session.query(func.count(cls.id)).scalar() except: session.rollback()
def read_orders_not_prepared_count(cls): try: return session.query(func.count(cls.id))\ .filter( and_( cls.is_prepared==False, cls.is_terminated == False ) ).scalar() except: session.rollback()
def index(self): customer_number = session.query(func.count(db.Customer.id)).scalar() resturant_number = session.query(func.count(db.Resturant.id)).scalar() sales_amount = session.query(func.count(db.Sales.amount)).scalar() products_sold = session.query(func.sum(db.Sales.quantity)).scalar() if customer_number is None: customer_number = 0 if resturant_number is None: resturant_number = 0 if sales_amount is None: sales_amount = 0 if products_sold is None: products_sold = 0 return self.render("admin/index.html", customer_number=customer_number, resturant_number=resturant_number, sales_amount=sales_amount, products_sold=products_sold)
def read_orders_count(cls): try: return session.query(func.count(cls.id)).filter_by( is_paid=False, is_terminated=False).scalar() except: session.rollback()
def read_products_count(cls): try: return session.query(func.count(cls.product_id)).scalar() except: session.rollback()
def read_restaurants_count(cls): try: return session.query(func.count(cls.id)).scalar() except: session.rollback()
def suspended_products_count(self): total = session.query(func.count(pdts.Products.product_id))\ .filter(pdts.Products.resturant_id==self.id, pdts.Products.suspend==True).scalar() return total if total else 0
def not_approved_products_count(self): total = session.query(func.count(pdts.Products.product_id))\ .filter(pdts.Products.resturant_id==self.id, pdts.Products.approved==False).scalar() return total if total else 0
def read_rest_total_products_count(self): total = session.query(func.count(pdts.Products.product_id))\ .filter(pdts.Products.resturant_id==self.id).scalar() return total if total else 0
def deliveries_count(self): count = session.query(func.count(dd.DeliveryDetails.id))\ .filter(dd.DeliveryDetails.courier_id == self.id).scalar() return count if count else 0