-
Notifications
You must be signed in to change notification settings - Fork 21
#Ocelots Megan Maple #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,15 @@ | ||
| class Clothing: | ||
| pass | ||
| #import parent class | ||
| from swap_meet.item import Item | ||
|
|
||
| class Clothing(Item): | ||
|
|
||
| #apply parent class in constructor | ||
| def __init__(self, id=None, fabric="Unknown", condition=None): | ||
| super().__init__(id, condition) | ||
| self.fabric=fabric | ||
|
|
||
| #here I return the string from the parent contstructer inside of an f string with additional changes | ||
| #Aka Override | ||
| def __str__(self): | ||
| return (f"{super().__str__()}. It is made from {self.fabric} fabric.") | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,15 @@ | ||
| class Decor: | ||
| pass | ||
| #import parent class | ||
| from swap_meet.item import Item | ||
|
|
||
| class Decor(Item): | ||
|
|
||
| #parent constructor with additional attributes | ||
| def __init__(self, id=None, width=0, length=0, condition=None): | ||
| super().__init__(id, condition) | ||
| self.width = width | ||
| self.length=length | ||
|
|
||
| #override that string from parent | ||
| def __str__(self): | ||
| return (f"{super().__str__()}. It takes up a {self.width} by " | ||
| f"{self.length} sized space.") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| class Electronics: | ||
| pass | ||
|
|
||
| #import parent class | ||
| from swap_meet.item import Item | ||
| class Electronics(Item): | ||
|
|
||
| def __init__(self, id=None, type=None, condition=None): | ||
| super().__init__(id, condition) | ||
| self.type = type if type is not None else "Unknown" | ||
|
|
||
| def __str__(self): | ||
| return (f"{super().__str__()}. This is a {self.type} device.") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,26 @@ | ||
| import uuid | ||
| class Item: | ||
| pass | ||
|
|
||
| #Instantiate with id, allowing custom or using UUID Int auto generate | ||
| def __init__(self, id=None, condition=None): | ||
| self.id = id if id is not None else uuid.uuid1().int | ||
| self.condition = condition if condition is not None else 0 | ||
| #get the class name | ||
| def get_category(self): | ||
| return str(type(self).__name__) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice use of python introspection! |
||
|
|
||
| #here I am overriding the __str__ method. | ||
| def __str__(self): | ||
| return (f"An object of type {self.get_category()} with id {self.id}") | ||
|
|
||
| #adding a condition description class to describe condition based on value of condition | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo. "function", not "class" |
||
| def condition_description(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clever, but unnecessarily so here. A |
||
| case = lambda x: self.condition < x | ||
| if case(1): item_condition_desc = "Very Poor Indeed" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love the descriptions, though! :D |
||
| elif case(2): item_condition_desc = "This will likely be part of a DIY" | ||
| elif case(3): item_condition_desc = "Not To Shabby, not to great" | ||
| elif case(4): item_condition_desc = "Hey now, this is a tad swanky" | ||
| elif case(5): item_condition_desc = "You find yourself a right treasure you did!" | ||
| else : item_condition_desc = "This is so pristine its obscene!" | ||
| return item_condition_desc | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,91 @@ | ||
| class Vendor: | ||
| pass | ||
| #constructor for vendor | ||
| def __init__(self, inventory = None): | ||
| self.inventory = inventory if inventory is not None else [] | ||
|
|
||
| #function to add new item to inventory list. | ||
| def add(self, new_item): | ||
| self.inventory.append(new_item) | ||
| return new_item | ||
|
|
||
| #function to remove a given item from inventory | ||
| def remove(self, item_to_remove): | ||
| if item_to_remove not in self.inventory: | ||
| return None | ||
| self.inventory.remove(item_to_remove) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great use of |
||
| return item_to_remove | ||
|
|
||
| #function to retreive item based on custom Id | ||
| def get_by_id(self, id): | ||
|
|
||
| for item in self.inventory: | ||
| if item.id==id: | ||
| return item | ||
| return None | ||
|
|
||
| #Making a method to swap items | ||
|
|
||
| def swap_items(self, vendor_friend, item_to_give, item_to_get): | ||
|
|
||
| #since the items are returned from their functions | ||
| #I can add and remove at the same time | ||
| if item_to_give not in self.inventory or item_to_get not in vendor_friend.inventory: | ||
| return False | ||
|
|
||
| vendor_friend.add(self.remove(item_to_give)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. concise! for debugging and maintenance, this could be on different lines. That said, you did do error checking above, so that ameliorates some of the chances that you'll hit an error here. |
||
| self.add(vendor_friend.remove(item_to_get)) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| def swap_first_item(self, vendor_friend): | ||
|
|
||
| if not self.inventory or not vendor_friend.inventory: | ||
| return False | ||
| return self.swap_items(vendor_friend, self.inventory[0], vendor_friend.inventory[0]) | ||
|
|
||
| #get items from inventory by catagory | ||
| def get_by_category(self, category_string): | ||
|
|
||
| return [item for item in self.inventory if item.get_category() == category_string] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent use of list comprehension |
||
|
|
||
|
|
||
| # getting best by for catagory | ||
|
|
||
| def get_best_by_category(self, category_string): | ||
| if self.get_by_category(category_string): | ||
| return max(self.get_by_category(category_string), key=lambda item: item.condition) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay, using |
||
| return None | ||
|
|
||
| #swap best by catagory | ||
| def swap_best_by_category(self, other_vendor, my_priority, their_priority): | ||
| if not self.get_by_category(their_priority) or not other_vendor.get_by_category(my_priority): | ||
| return False | ||
| return self.swap_items(other_vendor, self.get_best_by_category(their_priority), other_vendor.get_best_by_category(my_priority)) | ||
|
|
||
| #create a function to display inventory. | ||
| def display_inventory(self, category = None): | ||
| #create a list based on catagory or no | ||
| inventory = self.get_by_category(category) if category else self.inventory | ||
| if not inventory: | ||
| print ("No inventory to display.") | ||
|
|
||
| counter = 1 | ||
| for item in inventory: | ||
| print (f"{counter}. " + str(item)) | ||
| counter += 1 | ||
|
|
||
| #swapping by id. | ||
| def swap_by_id(self, other_vendor, my_item_id, their_item_id): | ||
| if not self.get_by_id(my_item_id) or not other_vendor.get_by_id(their_item_id): | ||
| return False | ||
| return self.swap_items(other_vendor,self.get_by_id(my_item_id), other_vendor.get_by_id(their_item_id)) | ||
|
|
||
| #choose and swap items! | ||
| def choose_and_swap_items(self, other_vendor, category = None): | ||
| self.display_inventory(category) | ||
| other_vendor.display_inventory(category) | ||
| my_item_id = input("Please enter the id of the item from the first vendor to swap") | ||
| their_item_id = input("Please input item of other vendor item you wish you swap") | ||
| return self.swap_by_id(other_vendor, int(my_item_id), int(their_item_id)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of ternary operator