Skip to content

Ocelots - Ya-Juan Ruan#15

Open
ryjpink wants to merge 36 commits intoada-ac2:mainfrom
ryjpink:main
Open

Ocelots - Ya-Juan Ruan#15
ryjpink wants to merge 36 commits intoada-ac2:mainfrom
ryjpink:main

Conversation

@ryjpink
Copy link
Copy Markdown

@ryjpink ryjpink commented Dec 9, 2022

No description provided.

Comment thread swap_meet/item.py
class Item:
pass No newline at end of file
def __init__(self, id=None, condition=0):
self.id = id if id else uuid.uuid4().int
Copy link
Copy Markdown

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

Comment thread swap_meet/item.py
def condition_description(self) :
# Make sure condition is a integer between zero and five
condition = max(0, min(5, math.floor(self.condition)))
description_dict = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great use of a dict here. And if/else block would take O(n) worse case to fall through to the last condition!

Plus, nice formatting of the contents of the dict here

Comment thread swap_meet/vendor.py
cur_best_condition = None
for item in self.inventory:
if item.get_category() == category:
if cur_best_item is None or item.condition > cur_best_condition:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is clean code that only loops through the whole thing once. In a more complex project, you can probably see how we could use things like filter to pull specific sets out of the inventory. Well done, though!

Comment thread swap_meet/vendor.py
def display_inventory(self, category=""):
# When there is no assigned category, it should display all inventory
assigned_category_inventory = list(filter(
lambda item: item.get_category() == category if category else True,
Copy link
Copy Markdown

@ilana-adadev ilana-adadev Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice use of a lambda. with a ternary operator, too!

Comment thread swap_meet/vendor.py

return self.swap_by_id(other_vendor, my_item_id, their_item_id)

def swap_similar_items(self, other_vendor, my_item):
Copy link
Copy Markdown

@ilana-adadev ilana-adadev Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of OOP-based similarity enhancement!

Comment thread swap_meet/vendor.py
def swap_similar_items(self, other_vendor, my_item):
their_inventory = other_vendor.get_by_category(my_item.get_category())

final_candidates = list(filter(lambda item: my_item.is_similar(item), their_inventory))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, and there's filter. Good use of it here!


assert one_condition_description != five_condition_description

def test_item_condition_higher_than_five_return_five():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice extra testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants