示例#1
0
def sales():
    sales = spaza_shop.get_sales()

    cursor.execute("SELECT * FROM product_sold ORDER BY no_sold DESC")
    data = cursor.fetchall()
    if len(data) is 0:
        return render_template("sales.html", result=sales)

    return render_template("sales.html", result2=data)
示例#2
0
def popular_product():
    sales = spaza_shop.get_sales()
    most_pop = spaza_shop.get_most_pop_item(sales)

    cursor.execute("SELECT * FROM product_sold ORDER BY no_sold DESC LIMIT 0,1")
    data = cursor.fetchall()
    if len(data) is 0:
        return render_template("popular_product.html", result=most_pop)

    return render_template("popular_product.html", result2=data)
示例#3
0
def popular_category():
    sales = spaza_shop.get_sales()
    most_pop_cat = spaza_shop.get_most_pop_cat(sales)

    cursor.execute(
        "SELECT cat_name, SUM(no_sold) AS no_sold FROM sales_history INNER JOIN categories ON category_name=categories.cat_name GROUP BY cat_name ORDER BY no_sold DESC"
    )
    data = cursor.fetchall()
    if len(data) is 0:
        return render_template("popular_category.html", result=most_pop_cat)

    return render_template("popular_category.html", result=data)
示例#4
0
	def test_get_sales(self):
		sales = spaza_shop.get_sales("Nelisa.csv")

		expected = {"Milk 1l" : 30,
					"Imasi" : 1,
					"Bread" : 2,
					"Chakalaka Can" : 3,
					"Gold Dish Vegetable Curry Can" : 2,
					"Fanta 500ml" : 3,
					"Coke 500ml" : 2,
					"Cream Soda 500ml" : 2}
		self.assertEquals(sales, expected, "Got sales")
示例#5
0
	def test_get_most_pop_cat(self):
		sales = spaza_shop.get_sales("Nelisa.csv")
		most_pop_cat = spaza_shop.get_most_pop_cat(sales)
		expected = {"dairy" : 310}
		self.assertEquals(expected, most_pop_cat)		
示例#6
0
	def test_get_most_pop_item(self):
		sales = spaza_shop.get_sales("Nelisa.csv")
		most_pop = spaza_shop.get_most_pop_item(sales)
		expected = {"Milk 1l" : 30}
		self.assertEquals(expected, most_pop)