-
Notifications
You must be signed in to change notification settings - Fork 103
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
Sapphire - Sophia Tran #71
base: main
Are you sure you want to change the base?
Changes from all commits
e078066
c017f59
ac142db
5052082
0abff7f
e766440
701f134
540e256
5f893f9
8fbd05a
d84bfb3
8b9e23c
c249393
42f2520
88be6b1
4c54b28
24ad341
e983a0d
eee6a6d
502e9f4
ac7e52e
957c23b
7ecbbb0
2674624
e08874b
9b75e93
08ec327
25b7825
11fe273
3ac50cf
d5d6812
2b3abd7
3226318
cf4f071
43a7d2e
618c8d3
090f94a
55f9676
8c3108e
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,3 +1,4 @@ | ||
# Testing git push | ||
# Swap Meet | ||
|
||
## Skills Assessed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, id=None, condition=0, fabric="Unknown"): | ||
super().__init__(id, condition) | ||
self.fabric = fabric | ||
|
||
def get_category(self): | ||
return "Clothing" | ||
|
||
def __str__(self): | ||
return f"An object of type Clothing with id {self.id}. It is made from {self.fabric} fabric." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, id=None, condition=0, width=0, length=0): | ||
super().__init__(id, condition) | ||
self.width = width | ||
self.length = length | ||
|
||
def get_category(self): | ||
return "Decor" | ||
|
||
def __str__(self): | ||
return f"An object of type Decor with id {self.id}. It takes up a {self.width} by {self.length} sized space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, id=None, condition=0, type="Unknown"): | ||
super().__init__(id, condition) | ||
self.type = type | ||
|
||
def get_category(self): | ||
return "Electronics" | ||
|
||
def __str__(self): | ||
return f"An object of type Electronics with id {self.id}. This is a {self.type} device." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,27 @@ | ||
import uuid | ||
|
||
class Item: | ||
pass | ||
def __init__(self, id=None, condition=0): | ||
if id is None: | ||
id = uuid.uuid4().int | ||
self.id = id | ||
self.condition = condition | ||
|
||
def get_category(self): | ||
return "Item" | ||
|
||
def __str__(self): | ||
return f"An object of type Item with id {self.id}." | ||
|
||
def condition_description(self): | ||
condition_dict = { | ||
0: "Trash", | ||
1: "Yikes", | ||
2: "Meh", | ||
3: "Okay", | ||
4: "Pretty good", | ||
5: "Brilliant, incredible, amazing, show stopping, spectacular, never the same, totally unique, completely not ever been done before" | ||
} | ||
|
||
if self.condition in condition_dict: | ||
return condition_dict[self.condition] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,71 @@ | ||
class Vendor: | ||
pass | ||
def __init__(self, inventory = None): | ||
if inventory is None: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
|
||
return False | ||
|
||
def get_by_id(self, item_id): | ||
for item in self.inventory: | ||
if item.id == item_id: | ||
return item | ||
|
||
return None | ||
|
||
def swap_items(self, other_vendor, my_item, their_item): | ||
if my_item not in self.inventory or their_item not in other_vendor.inventory: | ||
return False | ||
|
||
self.remove(my_item) | ||
other_vendor.add(my_item) | ||
|
||
other_vendor.remove(their_item) | ||
self.add(their_item) | ||
Comment on lines
+29
to
+33
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 work using |
||
|
||
return True | ||
|
||
def swap_first_item(self, other_vendor): | ||
if not self.inventory or not other_vendor.inventory: | ||
return False | ||
|
||
self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) | ||
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 work using |
||
return True | ||
|
||
def get_by_category(self, category): | ||
category_items = [] | ||
|
||
for item in self.inventory: | ||
if item.get_category() == category: | ||
category_items.append(item) | ||
|
||
return category_items | ||
|
||
def get_best_by_category(self, category): | ||
best_item = None | ||
condition = 0 | ||
|
||
for item in self.inventory: | ||
if item.get_category() == category and item.condition > condition: | ||
condition = item.condition | ||
best_item = item | ||
return best_item | ||
Comment on lines
+54
to
+61
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. Your solution works, and it's a good solution especially since it only loops through |
||
|
||
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) | ||
|
||
if my_best_item and their_best_item: | ||
self.swap_items(other_vendor, my_best_item, their_best_item) | ||
return True | ||
return False | ||
|
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.
💥 💥 💥 💥 💥 💥