コード例 #1
0
    def test_ch_ap_cf_mk(self):
        apple = Product("AP1", "Apples", 6.00)
        coffee = Product("CF1", "Coffee", 11.23)
        chai = Product("CH1", "Chai", 3.11)
        milk = Product("MK1", "Milk", 4.75)

        self.assertIsInstance(apple, Product)
        self.assertIsInstance(coffee, Product)
        self.assertIsInstance(chai, Product)
        self.assertIsInstance(milk, Product)

        #cart object instantiation
        cart = Cart()
        self.assertIsInstance(cart, Cart)

        #add items to the cart
        cart.add_to_cart(apple)
        cart.add_to_cart(chai)
        cart.add_to_cart(coffee)
        cart.add_to_cart(milk)

        #promotions
        promos = Promotions()
        #apply the promotion rules to the cart
        promos.is_bogo(cart)
        promos.is_appl(cart)
        promos.is_chmk(cart)
        promos.is_apom(cart)

        cart.checkout()
        self.assertEqual(cart.total, 20.34)
コード例 #2
0
    def test_ap_ap_ch_ap(self):
        apple1 = Product("AP1", "Apples", 6.00)
        apple2 = Product("AP1", "Apples", 6.00)
        chai = Product("CH1", "Chai", 3.11)
        apple3 = Product("AP1", "Apples", 6.00)

        self.assertIsInstance(apple1, Product)
        self.assertIsInstance(apple2, Product)
        self.assertIsInstance(chai, Product)
        self.assertIsInstance(apple3, Product)

        #cart object instantiation
        cart = Cart()
        self.assertIsInstance(cart, Cart)

        #add items to the cart
        cart.add_to_cart(apple1)
        cart.add_to_cart(apple2)
        cart.add_to_cart(chai)
        cart.add_to_cart(apple3)

        #promotions
        promos = Promotions()
        #apply the promotion rules to the cart
        promos.is_bogo(cart)
        promos.is_appl(cart)
        promos.is_chmk(cart)
        promos.is_apom(cart)

        cart.checkout()
        self.assertEqual(cart.total, 16.61)
コード例 #3
0
    def test_ap_mk(self):
        apple = Product("AP1", "Apples", 6.00)
        milk = Product("MK1", "Milk", 4.75)

        self.assertIsInstance(apple, Product)
        self.assertIsInstance(milk, Product)

        #cart object instantiation
        cart = Cart()
        self.assertIsInstance(cart, Cart)

        #add items to the cart
        cart.add_to_cart(apple)
        cart.add_to_cart(milk)

        #promotions
        promos = Promotions()
        #apply the promotion rules to the cart
        promos.is_bogo(cart)
        promos.is_appl(cart)
        promos.is_chmk(cart)
        promos.is_apom(cart)

        cart.checkout()
        self.assertEqual(cart.total, 10.75)
コード例 #4
0
    def test_cf_cf(self):
        coffee1 = Product("CF1", "Coffee", 11.23)
        coffee2 = Product("CF1", "Coffee", 11.23)

        self.assertIsInstance(coffee1, Product)
        self.assertIsInstance(coffee2, Product)


        #cart object instantiation
        cart = Cart()
        self.assertIsInstance(cart, Cart)

        #add items to the cart
        cart.add_to_cart(coffee1)
        cart.add_to_cart(coffee2)


        #promotions
        promos = Promotions()
        #apply the promotion rules to the cart
        promos.is_bogo(cart)
        promos.is_appl(cart)
        promos.is_chmk(cart)
        promos.is_apom(cart)

        cart.checkout()
        self.assertEqual(cart.total, 11.23)
コード例 #5
0
def build_products(in_file):

        #create a list to hold the created objects
        product_list = []

        #read in the first line
        product = in_file.readline()
        try:
            #read in all the products until we hit the end
            while product != "":
                #split the string into a list of elements
                # [prod_code, prod_name, prod_price]
                product_details = product.split(",")

                #only attempt to create an object if there are three elements in the list
                #exception will be thrown if the 3rd object is not a number 
                # ie - you can't have a string as a price
                if len(product_details) == 3:
                    prod_code = product_details[0]
                    prod_name = product_details[1]
                    prod_price = product_details[2]
                    product_list.append(Product(prod_code, prod_name, prod_price))
                
                #read in the next line from the file
                product = in_file.readline()
        #general exception handling
        except Exception as err:
            print("Error found!: ", err)
            print()
        #return the valid objects to main
        return product_list
コード例 #6
0
    def test_bogo_2reg_2free(self):
        #instantiate products
        apple1 = Product("AP1", "Apples", 6.00)
        coffee1 = Product("CF1", "Coffee", 11.23)
        coffee2 = Product("CF1", "Coffee", 11.23)
        coffee3 = Product("CF1", "Coffee", 11.23)
        coffee4 = Product("CF1", "Coffee", 11.23)

        #make sure the products are actually Product objects
        self.assertIsInstance(apple1, Product)
        self.assertIsInstance(coffee1, Product)
        self.assertIsInstance(coffee2, Product)
        self.assertIsInstance(coffee3, Product)
        self.assertIsInstance(coffee4, Product)

        #cart object instantiation
        cart = Cart()
        self.assertIsInstance(cart, Cart)

        #add items to the cart
        cart.add_to_cart(coffee1)
        cart.add_to_cart(coffee2)
        cart.add_to_cart(coffee3)
        cart.add_to_cart(coffee4)
        cart.add_to_cart(apple1)

        #make sure no preexisting bogo deals exist in the products
        self.assertEqual(coffee1.discount.get("BOGO"), None)
        self.assertEqual(coffee2.discount.get("BOGO"), None)
        self.assertEqual(coffee3.discount.get("BOGO"), None)
        self.assertEqual(coffee4.discount.get("BOGO"), None)
        self.assertEqual(apple1.discount.get("BOGO"), None)

        #promotions
        promos = Promotions()
        #apply the promotion rules to the cart
        promos.is_bogo(cart)
        #verify that the correct products are adjusted
        self.assertEqual(coffee1.discount.get("BOGO"), None)
        self.assertEqual(list(coffee2.discount.keys())[0], "BOGO")
        self.assertEqual(coffee3.discount.get("BOGO"), None)
        self.assertEqual(list(coffee4.discount.keys())[0], "BOGO")
        self.assertEqual(apple1.discount.get("BOGO"), None)
        #make sure the discount prices are correct
        self.assertEqual(coffee2.discount.get("BOGO"), coffee2.price * -1)
        self.assertEqual(coffee4.discount.get("BOGO"), coffee4.price * -1)
コード例 #7
0
    def test_chmk(self):
        #instantiate the products
        chai1 = Product("CH1", "Chai", 3.11)
        chai2 = Product("CH1", "Chai", 3.11)
        milk1 = Product("MK1", "Milk", 4.75)
        milk2 = Product("MK1", "Milk", 4.75)

        #make sure they are type Product
        self.assertIsInstance(chai1, Product)
        self.assertIsInstance(chai2, Product)
        self.assertIsInstance(milk1, Product)
        self.assertIsInstance(milk2, Product)

        #cart object instantiation
        cart = Cart()
        self.assertIsInstance(cart, Cart)

        #add items to the cart
        cart.add_to_cart(chai1)
        cart.add_to_cart(chai2)
        cart.add_to_cart(milk1)
        cart.add_to_cart(milk2)

        #make sure no preexisting CHMK deal exists in the products
        self.assertEqual(chai1.discount.get("CHMK"), None)
        self.assertEqual(chai2.discount.get("CHMK"), None)
        self.assertEqual(milk1.discount.get("CHMK"), None)
        self.assertEqual(milk2.discount.get("CHMK"), None)

        #promotions
        promos = Promotions()
        #apply the promotion rules to the cart
        promos.is_chmk(cart)

        #verify that the correct products are adjusted
        self.assertDictContainsSubset(milk1.discount, {'CHMK': milk1.price * -1})
        self.assertEqual(milk2.discount.get('CHMK'), None)
        self.assertEqual(chai1.discount.get('CHMK'), None)
        self.assertEqual(chai2.discount.get('CHMK'), None)
コード例 #8
0
 def test_set_best_discount(self):
     apple = Product("AP1", "Apples", 6.00)
     self.assertIsInstance(apple, Product)
     apple.discount['BOGO'] = apple.price * - 1
     apple.discount['APOM'] = apple.price * - 0.5
     apple.set_greatest_discount()
     self.assertEqual(list(apple.best_discount.keys())[0], "BOGO")
     self.assertEqual(list(apple.best_discount.values())[0], -6.00)
     self.assertEqual(apple.greatest_discount_price, -6.00)
コード例 #9
0
 def test_price_as_string(self):
     apple = Product("AP1", "Apples", "6.00")
     self.assertIsInstance(apple, Product)
     self.assertEqual(apple.code, "AP1")
     self.assertEqual(apple.name, "Apples")
     self.assertEqual(apple.price, 6.00)
コード例 #10
0
    def test_appl_apom_3discounted_1halfoff(self):
        #instantiate products
        apple1 = Product("AP1", "Apples", 6.00)
        apple2 = Product("AP1", "Apples", 6.00)
        apple3 = Product("AP1", "Apples", 6.00)
        apple4 = Product("AP1", "Apples", 6.00)
        oatmeal1 = Product("OM1", "Oatmeal", 3.69)

        #make sure the products are actually Product objects
        self.assertIsInstance(apple1, Product)
        self.assertIsInstance(apple2, Product)
        self.assertIsInstance(apple3, Product)
        self.assertIsInstance(apple4, Product)
        self.assertIsInstance(oatmeal1, Product)

        #cart object instantiation
        cart = Cart()
        self.assertIsInstance(cart, Cart)

        #add items to the cart
        cart.add_to_cart(apple1)
        cart.add_to_cart(apple2)
        cart.add_to_cart(apple3)
        cart.add_to_cart(apple4)
        cart.add_to_cart(oatmeal1)

        #make sure no preexisting APPL or APOM deals exist in the products
        self.assertEqual(apple1.discount.get("APPL"), None)
        self.assertEqual(apple1.discount.get("APOM"), None)
        self.assertEqual(apple2.discount.get("APPL"), None)
        self.assertEqual(apple1.discount.get("APOM"), None)
        self.assertEqual(apple3.discount.get("APPL"), None)
        self.assertEqual(apple1.discount.get("APOM"), None)
        self.assertEqual(apple4.discount.get("APPL"), None)
        self.assertEqual(oatmeal1.discount.get("APPL"), None)
        self.assertEqual(oatmeal1.discount.get("APOM"), None)

        #promotions
        promos = Promotions()
        #apply the promotion rules to the cart
        promos.is_appl(cart)
        promos.is_apom(cart)

        #verify that the correct products are adjusted
        #only the first apple should have both discounts, the other 3 shouldn't
        self.assertDictContainsSubset(apple1.discount, {'APPL':-1.50,'APOM':apple1.price * -0.50})

        self.assertDictContainsSubset(apple2.discount, {'APPL': -1.50})
        self.assertEqual(apple2.discount.get('APOM'), None)

        self.assertDictContainsSubset(apple3.discount, {'APPL': -1.50})
        self.assertEqual(apple3.discount.get('APOM'), None)

        self.assertDictContainsSubset(apple4.discount, {'APPL': -1.50})
        self.assertEqual(apple4.discount.get('APOM'), None)

        #oatmeal remains unchanged
        self.assertEqual(oatmeal1.discount.get('APPL'), None)
        self.assertEqual(oatmeal1.discount.get('APOM'), None)

        #set the best discounts for each of the products
        for product in cart.cart:
            product.set_greatest_discount()
        #check that the best discounts are correct
        self.assertDictContainsSubset(apple1.best_discount, {'APOM': apple1.price * -0.50})
        self.assertDictContainsSubset(apple2.best_discount, {'APPL': -1.50})
        self.assertDictContainsSubset(apple3.best_discount, {'APPL': -1.50})
        self.assertDictContainsSubset(apple4.best_discount, {'APPL': -1.50})
        #oatmeal has no discounts
        self.assertEqual(len(oatmeal1.discount.keys()), 0)
コード例 #11
0
 def test_base(self):
     apple = Product("AP1", "Apples", 6.00)
     self.assertIsInstance(apple, Product)
     self.assertEqual(apple.code, "AP1" )
     self.assertEqual(apple.name, "Apples")
     self.assertEqual(apple.price, 6.00)
コード例 #12
0
import copy
from gendata import generator
from sorts import bubble_sort, cocktail_sort, merge_sort
from datetime import datetime
from product_class import Product

data_size = [100, 200, 500, 1000, 5000, 10000, 50000, 100000]

for size in data_size:
    data = []
    generator(size)  # создаем файл с данными
    with open(f'./data_{size}.txt', mode='r', encoding='UTF-8') as database:
        for one_data in database:
            data.append(Product(
                one_data.strip()))  # переносим данные из файла в массив

    data_bubble = copy.deepcopy(data)
    data_cocktail = copy.deepcopy(data)
    data_merge = copy.deepcopy(data)

    start1 = datetime.now()
    bubble_sort(data_bubble)  # сортировка пузырьком
    end1 = datetime.now()

    start2 = datetime.now()
    cocktail_sort(data_cocktail)  # шейкер-сортировка
    end2 = datetime.now()

    start3 = datetime.now()
    merge_sort(data_merge)  # сортировка слиянием
    end3 = datetime.now()
コード例 #13
0
def test_recalculate_olives():
    olives = Product("olives", 9)
    recalculate_quality(olives)
    assert olives.quality == 9
コード例 #14
0
def make_cart_item(code, product_list):
    for product in product_list:
        if product.code == code:
            return Product(code, product.name, product.price)
コード例 #15
0
def test_recalculate_potato():
    potato = Product("potato", 5)
    recalculate_quality(potato)
    assert potato.quality == 4.5
コード例 #16
0
def test_recalculate_maria():
    maria = Product("maria", 1)
    recalculate_quality(maria)
    assert maria.quality == -2
コード例 #17
0
def get_specifications():
    # get Specifications of new product and append them look like a dictonary
    print("we need some information about your product")

    while (True):  # FOR ERROR CONTROL code VALUE ERROR
        try:
            code = int(input('plese enter code: '))

        except ValueError:
            print("please enter a integer Value")

        else:
            break

    name = input('please enter name: '
                 )  # name is string and don't need error control value  error

    while (True):  # FOR ERROR CONTROL weight VALUE ERROR
        try:
            weight = input('please enter weight(kilo): ')

        except ValueError:
            print("please enter a integer Value")

        else:
            break

    while (True):  # FOR ERROR CONTROL hight VALUE ERROR
        try:
            hight = input('please enter hight(centimeter): ')

        except ValueError:
            print("please enter a integer Value")

        else:
            break

    while (True):  # FOR ERROR CONTROL width VALUE ERROR
        try:
            width = input('please enter width(centimeter): ')

        except ValueError:
            print("please enter a integer Value")

        else:
            break

    while (True):  # FOR ERROR CONTROL price VALUE ERROR
        try:
            price = int(input('please enter price(integer and toman): '))

        except ValueError:
            print("please enter a integer Value")

        else:
            break

    while (True):  # FOR ERROR CONTROL price VALUE ERROR
        try:
            price_of_bronze = int(
                input(
                    'please enter price of bronze of today:(if you dont know enter 0) '
                ))

        except ValueError:
            print("please enter a integer Value")

        else:
            break
    # print data for get user approval
    print(
        "\nyou\'r new product is :\nname = %s \nweight = %s \nhight = %s \nwidth = %s \nprice = %s"
        % (name, weight, hight, width, price))
    user_approval = input(
        "\nare all of the information that enter ,True??:(y/n) ")
    if user_approval == 'n':  # User approval
        final_dict = get_specifications()  # run again
    else:
        # make product object
        new_product = Product(name, code, weight, hight, width, price)

    return new_product.get_dict_data()
コード例 #18
0
def test_recalculate_milk():
    milk = Product("milk", 2)
    recalculate_quality(milk)
    assert milk.quality == -1
コード例 #19
0
def test_recalculate_bread():
    bread = Product("bread", 3)
    recalculate_quality(bread)
    assert bread.quality == 0
コード例 #20
0
def test_recalculate_ham():
    ham = Product("ham", 10)
    recalculate_quality(ham)
    assert ham.quality == 10
コード例 #21
0
            suffix = ("_%d" % i, "_%d" % (i + 1))
            prices_df = pd.merge_ordered(
                prices_df,
                product.df[['amazon_time', 'standardized_all'
                            ]][product.df['amazon_time'].dt.year == year],
                on='amazon_time',
                suffixes=suffix)
        prices_df = prices_df.set_index(['amazon_time'])
        prices_df = prices_df.mean(1)
        prices_df = prices_df.groupby(prices_df.index.month).mean()
        prices_df.index = [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
            'Oct', 'Nov', 'Dec'
        ]
        return prices_df


if __name__ == "__main__":
    products = list(
        np.load('product_electronics_sorted_ph.npy', allow_pickle=True))
    products = [Product(i) for i in products]
    cat = Category(products)
    # print(cat.average_price_per_month())
    print(cat.average_price_christmas())
    # print(cat.num_sales)
    # print(cat.sale_decrease_percentage)
    # cat.feature_correlation('rating','sale_percentage')
    # print(len(cat.product_list))
    # cat.holiday_correlation(2018, False)
    # b = cat.price_variation()
    # print(b)
コード例 #22
0
def test_recalculate_leila():
    leila = Product("leila",1)
    recalculate_quality(leila)
    assert leila.quality == -2
コード例 #23
0
 def test_code_as_int(self):
     apple = Product(111, "Apples", 6.00)
     self.assertIsInstance(apple, Product)
     self.assertEqual(apple.code, "111")
     self.assertEqual(apple.name, "Apples")
     self.assertEqual(apple.price, 6.00)
コード例 #24
0
 def savePdct(self, pdctParms):
     readyParms = []
     for i in pdctParms:
         readyParms.append(i.get())
     newProd = Product(readyParms)
     newProd.setProductDb()
コード例 #25
0
    def add_costs(self):
        self.add_costs = []
        for item in self.container:
            self.add_costs.append(item.base_price)
        self.add_costs = float(sum(self.add_costs))

    def add_costs_tax(self):
        self.add_costs_tax = []
        for item in self.container:
            after_tax = item.base_price * (1 + item.tax)
            self.add_costs_tax.append(after_tax)
        self.add_costs_tax = float(sum(self.add_costs_tax))


apple = Product("Apple", 0.85, 0.15)
cucumber = Product("Cucumber", 1.20, 0.15)
orange = Product("Orange", 1.00, 0.13)

cart1 = Cart("cart1", [apple, cucumber])

cart1.add_product(orange)

for item in cart1.container:
    print(item.name)

# cart1.rm_product(orange)
#
for item in cart1.container:
    print(item.name)
コード例 #26
0
def test_recalculate_cheese():
    cheese = Product("cheese", 5)
    recalculate_quality(cheese)
    assert cheese.quality == 3
コード例 #27
0
 def test_name_as_int(self):
     apple = Product("AP1", 111, 6.00)
     self.assertIsInstance(apple, Product)
     self.assertEqual(apple.code, "AP1")
     self.assertEqual(apple.name, "111")
     self.assertEqual(apple.price, 6.00)
コード例 #28
0
    appm1 = cat1.average_price_per_month()
    appm2 = cat2.average_price_per_month()
    appm3 = cat3.average_price_per_month()
    appm4 = cat4.average_price_per_month()
    
    frame = {'Office Products': appm1, 'Software': appm2, 'Electronics': appm3, 'Toys': appm4}
    appm_df = pd.DataFrame(frame)
    plot_average_price_per_month(data = appm_df)


if __name__ == "__main__":
    products1 = list(np.load('office_products_sorted_ph.npy', allow_pickle=True))
    products2 = list(np.load('product_software_sorted_ph.npy', allow_pickle=True))
    products3 = list(np.load('product_electronics_sorted_ph.npy', allow_pickle=True))
    products4 = list(np.load('toy_products_sorted_ph.npy', allow_pickle=True))

    products1 = [Product(i) for i in products1]
    products2 = [Product(i) for i in products2]
    products3 = [Product(i) for i in products3]
    products4 = [Product(i) for i in products4]

    cat1 = Category(products1)
    cat2 = Category(products2)
    cat3 = Category(products3)
    cat4 = Category(products4)

    # plot_holiday(cat1, cat2, cat3, cat4)
    time_price(cat1, cat2, cat3, cat4)
    # average_derivative_prices(cat1, cat2, cat3, cat4)
    # average_price_per_month_price(cat1, cat2, cat3, cat4)
コード例 #29
0
def main_menu():
    """ The main loop, running the program from start to the
     end. Handles Database and Product objects and takes user inputs. """

    while True:

        for elt in welcome:
            print(elt)
        choose = input('Votre choix: ')
        if choose == '1':
            cursor = db.search_category()
            res = []
            for elt in cursor:
                res += elt
            print("\n", categorie, "\n")
            for idx, elt in enumerate(res):
                print(" {}/ {}".format(idx + 1, elt))
            print("\n", bar, "\n")
            choose = input(" Votre choix: ")
            while choose not in [str(i) for i in range(1, len(res) + 1)]:
                choose = input(" Votre choix: ")
            choose = res[int(choose) - 1]
            cursor = db.ten_random_prod(choose)
            prod = Product(cursor)
            prod.print_product()
            food = 0
            while food not in [str(i) for i in range(1, 11)]:
                food = input('Votre choix: ')
            cursor = db.search_a_substitute(choose)
            prod = Product(cursor)
            prod.print_substitute()
            substitute = ""
            while substitute.lower() != 'q':
                print("\n", sub_menu)
                substitute = input("\nVotre choix: ")
                if substitute == '1':
                    db.save_a_product(prod.product)
                elif substitute == '2':
                    prod.search_internet(choose)
                    prod.print_substitute()
        elif choose == '2':
            cursor = db.search_already_saved()
            prod = Product(cursor)
            prod.print_saved()
            print("\n\n")
            input(back)
        elif choose == '3':
            break
    db.close_cnx()
コード例 #30
0
def test_recalculate_fish():
    fish = Product("fish",1.5)
    recalculate_quality(fish)
    assert fish.quality == -1.5