From bea7f088d58bc583bf2c8bf13135e8874c6df40a Mon Sep 17 00:00:00 2001 From: Raquel Mena Date: Wed, 31 Mar 2021 20:18:17 -0500 Subject: [PATCH 1/6] all tests passed wave 1 --- swap_meet/vendor.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 swap_meet/vendor.py diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..62173ecc0 --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,18 @@ +class Vendor: + def __init__(self, inventory=None): #needs to be optional keyword arg + #inventory is a list + if inventory == None: + self.inventory = [] + else: + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): #can this function be called remove? + if item not in self.inventory: + return False + if item in self.inventory: + self.inventory.remove(item)#if I use the remove method + return item \ No newline at end of file From a92d32eedd2063d392e3bce5f4f32c397aeca08c Mon Sep 17 00:00:00 2001 From: Raquel Mena Date: Fri, 2 Apr 2021 10:05:48 -0500 Subject: [PATCH 2/6] implemented new vendor instance 'swap_items' --- swap_meet/clothing.py | 2 ++ swap_meet/decor.py | 2 ++ swap_meet/electronics.py | 2 ++ swap_meet/item.py | 8 ++++++++ swap_meet/vendor.py | 40 ++++++++++++++++++++++++++++++++++++++-- 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 swap_meet/clothing.py create mode 100644 swap_meet/decor.py create mode 100644 swap_meet/electronics.py create mode 100644 swap_meet/item.py diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..b8afdeb1e --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,2 @@ +class Clothing: + pass \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py new file mode 100644 index 000000000..eab7a9dbe --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,2 @@ +class Decor: + pass \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py new file mode 100644 index 000000000..33e054fd1 --- /dev/null +++ b/swap_meet/electronics.py @@ -0,0 +1,2 @@ +class Electronics: + pass \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py new file mode 100644 index 000000000..9872b7101 --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,8 @@ + +class Item: + def __init__(self, category=""): #an inventory has to be passed in + + self.category = category + #self.get_by_category + def __str__(self): + return 'Hello World!' diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 62173ecc0..fad3e53da 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,3 +1,5 @@ + + class Vendor: def __init__(self, inventory=None): #needs to be optional keyword arg #inventory is a list @@ -14,5 +16,39 @@ def remove(self, item): #can this function be called remove? if item not in self.inventory: return False if item in self.inventory: - self.inventory.remove(item)#if I use the remove method - return item \ No newline at end of file + self.inventory.remove(item)#if I use the remove method + return item + + def get_by_category(self, types_of_items): + matching_items = [] #this method returns a list of Items in inventory w that catego + for item in self.inventory: + if types_of_items == item.category: + matching_items.append(item) + + return matching_items + + def swap_items(self, friend, my_item, friends_item): + if my_item in self.inventory and friends_item in friend.inventory: + friend.add(self.remove(my_item)) + self.add(friend.remove(friends_item)) + # self.inventory.remove(my_item) + # friend.inventory.add(my_item) + # friend.inventory.remove(friends_item) + # self.inventory.add(friends_item) + return True + else: + return False + + + # add my_item to friends inventory (and friend is just another Vendor instance) + # remove friends_item from friends inventory, and add to my inventory + # return True if it does all this + # else False + # def swap_first_item(self, friend): + # if not self.inventory or not friend.inventory: + # return False + # look at the first item in self.inventory and look at the first in friend.inventory + # remove the first item [0] from self.inventory and add that item to friend.inventory + # remove the first item from friend inventory and add self inventory first item + # return True + # else false \ No newline at end of file From fa756356c32663c157c7fce2897ffede168116ca Mon Sep 17 00:00:00 2001 From: Raquel Mena Date: Sat, 3 Apr 2021 13:14:39 -0500 Subject: [PATCH 3/6] implemented swap_first_item method, refactored swap_items --- swap_meet/vendor.py | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index fad3e53da..73a09f47d 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,4 +1,5 @@ - +#from .item import Item +#from item import Item class Vendor: def __init__(self, inventory=None): #needs to be optional keyword arg @@ -29,12 +30,12 @@ def get_by_category(self, types_of_items): def swap_items(self, friend, my_item, friends_item): if my_item in self.inventory and friends_item in friend.inventory: - friend.add(self.remove(my_item)) - self.add(friend.remove(friends_item)) - # self.inventory.remove(my_item) - # friend.inventory.add(my_item) - # friend.inventory.remove(friends_item) - # self.inventory.add(friends_item) + # friend.add(self.remove(my_item)) + # self.add(friend.remove(friends_item)) + self.remove(my_item) + friend.add(my_item) + friend.remove(friends_item) + self.add(friends_item) return True else: return False @@ -44,11 +45,26 @@ def swap_items(self, friend, my_item, friends_item): # remove friends_item from friends inventory, and add to my inventory # return True if it does all this # else False - # def swap_first_item(self, friend): + + + def swap_first_item(self, friend): # if not self.inventory or not friend.inventory: - # return False - # look at the first item in self.inventory and look at the first in friend.inventory - # remove the first item [0] from self.inventory and add that item to friend.inventory - # remove the first item from friend inventory and add self inventory first item - # return True - # else false \ No newline at end of file + + if len(self.inventory) == 0 or len(friend.inventory) == 0: + return False + else: + self.swap_items(friend, self.inventory[0], friend.inventory[0]) + return True + + + # if self.inventory and friend.inventory: + # print(self) + # print(friend) + # friend.add(self.remove([0])) + # print(friend.inventory) + # self.add(friend.remove([0])) + # print(friend.add(self.remove([0]))) + # return True + + + \ No newline at end of file From 520b7261019a9ceaf115b69ce797d7c18888cae6 Mon Sep 17 00:00:00 2001 From: Raquel Mena Date: Sat, 3 Apr 2021 15:37:42 -0500 Subject: [PATCH 4/6] "updated decor, clothing, electronic class modules, created condition_description method" --- swap_meet/clothing.py | 10 ++++++++-- swap_meet/decor.py | 10 ++++++++-- swap_meet/electronics.py | 10 ++++++++-- swap_meet/item.py | 22 ++++++++++++++++++++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..f1f5a97e1 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,8 @@ -class Clothing: - pass \ No newline at end of file +from .item import Item + +class Clothing(Item): + def __init__(self, condition=0): + super().__init__("Clothing", condition) + + def __str__(self): + return "The finest clothing you could wear." \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..0c1957737 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,8 @@ -class Decor: - pass \ No newline at end of file +from .item import Item + +class Decor(Item): + def __init__(self, condition=0): + super().__init__("Decor", condition) + + def __str__(self): + return "Something to decorate your space." \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 33e054fd1..f98578be4 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,8 @@ -class Electronics: - pass \ No newline at end of file +from .item import Item + +class Electronics(Item): + def __init__(self, condition=0): + super().__init__("Electronics", condition) + + def __str__(self): + return "A gadget full of buttons and secrets." \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py index 9872b7101..50b95e104 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,8 +1,26 @@ class Item: - def __init__(self, category=""): #an inventory has to be passed in - + def __init__(self, category='', condition=0): #an inventory has to be passed in self.category = category + self.condition = condition #self.get_by_category def __str__(self): return 'Hello World!' + + def condition_description(self): + # for items in self.category: + if self.condition == 0: + return "You probably want to use a glove for this one" + if self.condition == 1: + return "Heavily used." + if self.condition == 2: + return "Heavily used." + if self.condition == 3: + return "Standard wear and tear." + if self.condition == 4: + return "*Almost* like new." + if self.condition == 5: + return "Like new" + else: + return "nope" + From d6ad7c3cf9f9aedd9f2c6dedd1347c09923b3161 Mon Sep 17 00:00:00 2001 From: Raquel Mena Date: Mon, 5 Apr 2021 15:17:29 -0500 Subject: [PATCH 5/6] implemented get_best_by_category method --- swap_meet/vendor.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 73a09f47d..ca72a461e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -20,10 +20,10 @@ def remove(self, item): #can this function be called remove? self.inventory.remove(item)#if I use the remove method return item - def get_by_category(self, types_of_items): + def get_by_category(self, category): matching_items = [] #this method returns a list of Items in inventory w that catego for item in self.inventory: - if types_of_items == item.category: + if category == item.category: matching_items.append(item) return matching_items @@ -41,14 +41,10 @@ def swap_items(self, friend, my_item, friends_item): return False - # add my_item to friends inventory (and friend is just another Vendor instance) - # remove friends_item from friends inventory, and add to my inventory - # return True if it does all this - # else False + def swap_first_item(self, friend): - # if not self.inventory or not friend.inventory: if len(self.inventory) == 0 or len(friend.inventory) == 0: return False @@ -56,15 +52,25 @@ def swap_first_item(self, friend): self.swap_items(friend, self.inventory[0], friend.inventory[0]) return True - - # if self.inventory and friend.inventory: - # print(self) - # print(friend) - # friend.add(self.remove([0])) - # print(friend.inventory) - # self.add(friend.remove([0])) - # print(friend.add(self.remove([0]))) - # return True + def get_best_by_category(self, category): + list_of_categorys = self.get_by_category(category) + #if no items in inventory matched the passed in category, return none + if len(list_of_categorys) == 0: #if not list_of categorys + return None + top_condition = -1 + top_item = None + for item in list_of_categorys: + if item.condition > top_condition: + top_condition = item.condition + top_item = item + return top_item + + + #Look through self.inventory. for items with matching category.If item is highest value, like 5 + #account for duplicate items + # return a single item. + + \ No newline at end of file From e4684652e1fbcfe61babfb7feba19fb7d921b7f4 Mon Sep 17 00:00:00 2001 From: Raquel Mena Date: Mon, 5 Apr 2021 19:38:38 -0500 Subject: [PATCH 6/6] swap_best_by_categoy method implemented, program meeting set requirements --- swap_meet/vendor.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index ca72a461e..00c54626e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,9 +1,7 @@ -#from .item import Item -#from item import Item class Vendor: - def __init__(self, inventory=None): #needs to be optional keyword arg - #inventory is a list + def __init__(self, inventory=None): + if inventory == None: self.inventory = [] else: @@ -13,15 +11,15 @@ def add(self, item): self.inventory.append(item) return item - def remove(self, item): #can this function be called remove? + def remove(self, item): if item not in self.inventory: return False if item in self.inventory: - self.inventory.remove(item)#if I use the remove method + self.inventory.remove(item) return item def get_by_category(self, category): - matching_items = [] #this method returns a list of Items in inventory w that catego + matching_items = [] for item in self.inventory: if category == item.category: matching_items.append(item) @@ -41,8 +39,6 @@ def swap_items(self, friend, my_item, friends_item): return False - - def swap_first_item(self, friend): @@ -54,8 +50,7 @@ def swap_first_item(self, friend): def get_best_by_category(self, category): list_of_categorys = self.get_by_category(category) - #if no items in inventory matched the passed in category, return none - if len(list_of_categorys) == 0: #if not list_of categorys + if not list_of_categorys: return None top_condition = -1 top_item = None @@ -65,12 +60,12 @@ def get_best_by_category(self, category): top_item = item return top_item - - #Look through self.inventory. for items with matching category.If item is highest value, like 5 - #account for duplicate items - # return a single item. - - - - - \ No newline at end of file + def swap_best_by_category(self, other, my_priority, their_priority): + item_for_other = self.get_best_by_category(their_priority) + item_for_self = other.get_best_by_category(my_priority) + if item_for_other and item_for_self: + self.swap_items(other, item_for_other, item_for_self) + return True + else: + return False + \ No newline at end of file