diff --git a/README.md b/README.md index 848bbb05a..d901f41c4 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ $ source venv/bin/activate Verify that you're in a python3 virtual environment by running: - `$ python --version` should output a Python 3 version -- `$ pip --version` should output that it is working with Python 3 +- `$ python --version` should output that it is working with Python 3 6. Install dependencies once at the beginning of this project with @@ -84,7 +84,7 @@ Summary of one-time project setup: 1. When you want to begin work on this project, ensure that your virtual environment is activated: ```bash -$ source venv/bin/activate +$ e ``` 2. Find the test file that contains the test you want to run. diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..ce7393b5f --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,12 @@ +from swap_meet.item import Item +class Clothing(Item): + + def __init__(self,category = "", condition=0): + super().__init__("Clothing", condition) + + def __str__(self): + return "The finest clothing you could wear." + + + + diff --git a/swap_meet/decor.py b/swap_meet/decor.py new file mode 100644 index 000000000..609370b2b --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,10 @@ +from swap_meet.item import Item +class Decor(Item): + + def __init__(self,category = "", 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 new file mode 100644 index 000000000..2c5535c17 --- /dev/null +++ b/swap_meet/electronics.py @@ -0,0 +1,12 @@ +from swap_meet.item import Item +class Electronics(Item): + + def __init__(self,category = "", 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 new file mode 100644 index 000000000..392810133 --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,26 @@ +class Item: + def __init__(self, category = "", condition = 0): + self.category = category + self.condition = float(condition) + + def __str__(self): + return 'Hello World!' + def __repr__(self): + return "Item('{}')".format(self.category) + + def condition_description(self): + if self.condition == 5: + desc = "mint" + elif self.condition == 4: + desc = "excellent" + elif self.condition == 3: + desc = "good" + elif self.condition == 2: + desc = "well used" + elif self.condition == 1: + desc = "Might use a glove" + elif self.condition == 0: + desc = "Make sure you really want to do this!" + return desc + + \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..860a933fc --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,133 @@ +class Vendor: + def __init__(self, inventory = None): + if inventory == None: + self.inventory = [] + else: + self.inventory = inventory + + def add(self, item): + """ + function: adds Item to inventory + input: Item to add + output: Item (list) + """ + self.inventory.append(item) + return item + + def remove(self, item): + """ + function: removes Item from inventory + input: Item to remove + output: Item list if True, or False + """ + + try: + self.inventory.remove(item) + return item + except ValueError: + return False + + def get_by_category(self, category): + """ + function: groups the items by category passed in + """ + + by_category_list = [] + for item in self.inventory: + if item.category == category: + by_category_list.append(item) + return by_category_list + + + def swap_items(self, vendor,my_item,vendor_item ): + """ + function: checks Items are in inventory + input: Self, Vendor and Items to swap + output: Booleon (True for success) + """ + + if my_item in self.inventory and vendor_item in vendor.inventory: + self.add(vendor_item) + self.remove(my_item) + vendor.remove(vendor_item) + vendor.add(my_item) + return True + return False + + + def swap_first_item(self,vendor): + """ + function: swaps and removes item + input: vendor + output: True if successful, or False if empty list for vendor encountered + """ + if self.inventory == [] or vendor.inventory == []: + return False + + self_first_item = self.inventory[0] + vendor_first_item = vendor.inventory[0] + self.remove(self_first_item) + self.add(vendor_first_item) + vendor.remove(vendor_first_item) + vendor.add(self_first_item) + return True + + + def get_best_by_category(self,category): + """ + function: Gets all the items by category + input: category + output: True if successful, or False if empty list for vendor encountered + """ + if self.get_by_category == None: + return None + + best_item = None + for item in self.get_by_category(category): + if best_item == None or item.condition > best_item.condition: + best_item = item + return best_item + + def swap_best_by_category(self,other,my_priority,their_priority): + # my_priority is category that the Vendor wants to receive + # their_priority represents the category the other Vendor wants + """ + function: Best item in inventory that matches category is swapped with the best item in `other`'s inventory that matches `my_priority` + input: `their_priority`, my priority, other (the other vendor) + output: Boolean. + + False -- If the `Vendor` has no item that matches `their_priority` category, swapping does not happen, and it returns `False. - If `other` has no item that matches `my_priority` category, swapping does not happen, and it returns `False` + """ + + if other.get_by_category(my_priority) == None or self.get_by_category(their_priority)== None: + return False + + my_trade_to_other = self.get_best_by_category(their_priority) + their_trade_to_me = other.get_best_by_category(my_priority) + + result = self.swap_items(other,my_trade_to_other,their_trade_to_me) + return result + + + + + + + + + + + + + + + + + + + + + + + +