-
Notifications
You must be signed in to change notification settings - Fork 590
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
C19 Sapphire - Linh Huynh #36
base: main
Are you sure you want to change the base?
Changes from all commits
ccd5164
4fc27cf
503209e
e143e94
8cd2714
d1cdea2
5cc4ba1
ba47b83
73a725a
e5912aa
836a168
8aa064c
364c122
184ec74
2fbf072
598caee
6c9967e
3a76846
7c309f4
556d0f0
40c6a75
a547d71
77024f5
e4577e8
dd3acb3
f3ce6c4
3dc5531
9cf474c
980bc49
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,14 @@ | ||
class Clothing: | ||
pass | ||
from .item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, id = None, fabric = "Unknown", condition = 0): | ||
super().__init__(id, condition) | ||
self.fabric = fabric | ||
|
||
# Initially wrote get_category instance method to return "Clothing". However, the code would be cleaner | ||
# if I removed this instance method altogether, referenced the __str__ method instance in the Item class, | ||
# and edited the return string in __str__ to remove any redundancy. | ||
|
||
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,14 @@ | ||
class Decor: | ||
pass | ||
from .item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, id = None, width = 0, length = 0, condition = 0): | ||
super().__init__(id, condition) | ||
self.width = width | ||
self.length = length | ||
|
||
# Initially wrote get_category instance method to return "Decor". However, the code would be cleaner | ||
# if I removed this instance method altogether, referenced the __str__ method instance in the Item class, | ||
# and edited the return string in __str__ to remove any redundancy. | ||
|
||
def __str__(self): | ||
return f"{super().__str__()} It takes up a {self.width} by {self.length} sized space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
class Electronics: | ||
pass | ||
from .item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, id = None, type = "Unknown", condition = 0): | ||
super().__init__(id, condition) | ||
self.type = type | ||
|
||
# Initially wrote get_category instance method to return "Electronics". However, the code would be cleaner | ||
# if I removed this instance method altogether, referenced the __str__ method instance in the Item class, | ||
# and edited the return string in __str__ to remove any redundancy. | ||
|
||
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,23 @@ | ||
import uuid | ||
|
||
class Item: | ||
pass | ||
def __init__(self, id = None, condition = 0): | ||
self.id = int(uuid.uuid4()) if id is None else id | ||
self.condition = condition | ||
|
||
def get_category(self): | ||
return type(self).__name__ | ||
|
||
def __str__(self): | ||
return f"An object of type {self.get_category()} with id {self.id}." | ||
|
||
def condition_description(self): | ||
condition_rating = { | ||
0: "Terrible: Unusable, broken, contaminated, or carries the possessed spirit of its previous owner. One might question why this was even considered sellable.", | ||
1: "Poor: High likelihood of abnormalities, defects, or irremovable stains you probably don't want to know about. Probably best to scavenge for parts.", | ||
2: "As-Is: Acceptable but of course, that's subjective. Consider at your own discretion.", | ||
3: "Good: Functional or wearable. What more could you ask for a discounted price?", | ||
4: "Gently worn: Practically like new. It's basically a steal. At least it's not cursed.", | ||
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. 👻 |
||
5: "New: Pretty much in pristine condition with the added bonus of preventing existential crises and attracting good luck." | ||
} | ||
return condition_rating[self.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. I like the use of the dictionary/map |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,60 @@ | ||
#from .item import Item | ||
|
||
class Vendor: | ||
pass | ||
def __init__(self, inventory = None): | ||
self.inventory = [] if inventory is None else inventory | ||
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 post-fix conditional! |
||
|
||
|
||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
|
||
def remove(self, item): | ||
if item not in self.inventory: | ||
return False | ||
else: | ||
self.inventory.remove(item) | ||
return item | ||
|
||
|
||
def get_by_id(self, id): | ||
for item in self.inventory: | ||
if id == item.id: | ||
return item | ||
return None | ||
|
||
|
||
def swap_items(self, other_vendor, my_item, their_item): | ||
if my_item in self.inventory and their_item in other_vendor.inventory: | ||
self.remove(my_item) | ||
self.add(their_item) | ||
other_vendor.remove(their_item) | ||
other_vendor.add(my_item) | ||
return True | ||
return False | ||
|
||
|
||
def swap_first_item(self, other_vendor): | ||
try: | ||
return self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) | ||
except IndexError: | ||
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 |
||
return False | ||
|
||
|
||
def get_by_category(self, category): | ||
return [item for item in self.inventory if item.get_category() == category] | ||
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!! |
||
|
||
|
||
def get_best_by_category(self, category): | ||
category_selection = self.get_by_category(category) | ||
try: | ||
return max(category_selection, key=lambda item: item.condition) | ||
except ValueError: | ||
return None | ||
|
||
|
||
def swap_best_by_category(self, other_vendor, my_priority, their_priority): | ||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other_vendor.get_best_by_category(my_priority) | ||
return self.swap_items(other_vendor, my_best_item, their_best_item) |
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.
I think this is a good decision for this project/context!