Skip to content

Commit

Permalink
python/mecha-munch-management: 3rd iteration - py3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 4, 2024
1 parent c75de44 commit 07a3bf8
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 187 deletions.
2 changes: 1 addition & 1 deletion python/mecha-munch-management/.coverage.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage version="7.4.0" timestamp="1712207618302" lines-valid="47" lines-covered="47" line-rate="1" branches-valid="8" branches-covered="8" branch-rate="1" complexity="0">
<coverage version="7.4.0" timestamp="1712208306828" lines-valid="47" lines-covered="47" line-rate="1" branches-valid="8" branches-covered="8" branch-rate="1" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.4.0 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
Expand Down
72 changes: 36 additions & 36 deletions python/mecha-munch-management/dict_methods.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
"""Functions to manage a users shopping cart items."""

# runners are still using py 3.11, can't use 3.12 type definitions
name_t = str
quantity_t = int
cart_t = dict[name_t, quantity_t]
items_t = list[name_t] | tuple[name_t]
recipes_t = dict[name_t, cart_t]
update_t = tuple[name_t, cart_t]
updates_t = list[update_t] | tuple[update_t]
refrigirate_t = bool
aisle_t = list[name_t | refrigirate_t]
aisle_map_t = dict[name_t, aisle_t]
inventory_entry_t = list[quantity_t | name_t | refrigirate_t]
fufillment_t = dict[name_t, inventory_entry_t]
message_t = str


def add_item(current_cart: cart_t, items_to_add: items_t) -> cart_t:
NameT = str
QuantityT = int
CartT = dict[NameT, QuantityT]
ItemsT = list[NameT] | tuple[NameT]
RecipesT = dict[NameT, CartT]
UpdateT = tuple[NameT, CartT]
UpdatesT = list[UpdateT] | tuple[UpdateT]
RefrigirateT = bool
AisleT = list[NameT | RefrigirateT]
AisleMapT = dict[NameT, AisleT]
InventoryEntryT = list[QuantityT | NameT | RefrigirateT]
FufillmentT = dict[NameT, InventoryEntryT]
MessageT = str


def add_item(current_cart: CartT, items_to_add: ItemsT) -> CartT:
"""Add items to shopping cart.
:param current_cart: dict - the current shopping cart.
Expand All @@ -31,31 +31,31 @@ def add_item(current_cart: cart_t, items_to_add: items_t) -> cart_t:
return current_cart


def read_notes(notes: items_t) -> cart_t:
def read_notes(notes: ItemsT) -> CartT:
"""Create user cart from an iterable notes entry.
:param notes: iterable of items to add to cart.
:return: dict - a user shopping cart dictionary.
"""

cart: cart_t = {}
cart: CartT = {}

return add_item(cart, notes)


def update_recipes(ideas: recipes_t, recipe_updates: updates_t) -> recipes_t:
def update_recipes(ideas: RecipesT, recipe_updates: UpdatesT) -> RecipesT:
"""Update the recipe ideas dictionary. Replaces the existing list of items with a new list, don't update/merge.
:param ideas: dict - The "recipe ideas" dict.
:param recipe_updates: dict - dictionary with updates for the ideas section.
:return: dict - updated "recipe ideas" dict.
"""

update: update_t
update: UpdateT

for update in recipe_updates:
recipe_name: name_t = update[0]
items: cart_t = update[1]
recipe_name: NameT = update[0]
items: CartT = update[1]

_ = ideas.setdefault(recipe_name, {})

Expand All @@ -64,7 +64,7 @@ def update_recipes(ideas: recipes_t, recipe_updates: updates_t) -> recipes_t:
return ideas


def sort_entries(cart: cart_t) -> cart_t:
def sort_entries(cart: CartT) -> CartT:
"""Sort a users shopping cart in alphabetically order.
:param cart: dict - a users shopping cart dictionary.
Expand All @@ -74,19 +74,19 @@ def sort_entries(cart: cart_t) -> cart_t:
return dict(sorted(cart.items()))


def send_to_store(cart: cart_t, aisle_mapping) -> fufillment_t:
def send_to_store(cart: CartT, aisle_mapping) -> FufillmentT:
"""Combine users order to aisle and refrigeration information.
:param cart: dict - users shopping cart dictionary.
:param aisle_mapping: dict - aisle and refrigeration information dictionary.
:return: dict - fulfillment dictionary ready to send to store.
"""

fufillment: fufillment_t = {}
fufillment: FufillmentT = {}

item_name: name_t
item_quantity: quantity_t
aisle: aisle_t
item_name: NameT
item_quantity: QuantityT
aisle: AisleT

for item_name, item_quantity in cart.items():
aisle = aisle_mapping.setdefault(item_name, ["Aisle 0", False])
Expand All @@ -96,22 +96,22 @@ def send_to_store(cart: cart_t, aisle_mapping) -> fufillment_t:


def update_store_inventory(
fulfillment_cart: fufillment_t, store_inventory: fufillment_t
) -> fufillment_t:
fulfillment_cart: FufillmentT, store_inventory: FufillmentT
) -> FufillmentT:
"""Update store inventory levels with user order.
:param fulfillment cart: dict - fulfillment cart to send to store.
:param store_inventory: dict - store available inventory
:return: dict - store_inventory updated.
"""

new_inventory: fufillment_t = store_inventory.copy()
new_inventory: FufillmentT = store_inventory.copy()

item_name: name_t
order_quantity: quantity_t
inventory_quantity: quantity_t
new_quantity: quantity_t | message_t
data: inventory_entry_t
item_name: NameT
order_quantity: QuantityT
inventory_quantity: QuantityT
new_quantity: QuantityT | MessageT
data: InventoryEntryT

for item_name in fulfillment_cart:
order_quantity = int(
Expand Down
72 changes: 36 additions & 36 deletions python/mecha-munch-management/dict_methods.py,cover
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
> """Functions to manage a users shopping cart items."""

# runners are still using py 3.11, can't use 3.12 type definitions
> name_t = str
> quantity_t = int
> cart_t = dict[name_t, quantity_t]
> items_t = list[name_t] | tuple[name_t]
> recipes_t = dict[name_t, cart_t]
> update_t = tuple[name_t, cart_t]
> updates_t = list[update_t] | tuple[update_t]
> refrigirate_t = bool
> aisle_t = list[name_t | refrigirate_t]
> aisle_map_t = dict[name_t, aisle_t]
> inventory_entry_t = list[quantity_t | name_t | refrigirate_t]
> fufillment_t = dict[name_t, inventory_entry_t]
> message_t = str


> def add_item(current_cart: cart_t, items_to_add: items_t) -> cart_t:
> NameT = str
> QuantityT = int
> CartT = dict[NameT, QuantityT]
> ItemsT = list[NameT] | tuple[NameT]
> RecipesT = dict[NameT, CartT]
> UpdateT = tuple[NameT, CartT]
> UpdatesT = list[UpdateT] | tuple[UpdateT]
> RefrigirateT = bool
> AisleT = list[NameT | RefrigirateT]
> AisleMapT = dict[NameT, AisleT]
> InventoryEntryT = list[QuantityT | NameT | RefrigirateT]
> FufillmentT = dict[NameT, InventoryEntryT]
> MessageT = str


> def add_item(current_cart: CartT, items_to_add: ItemsT) -> CartT:
> """Add items to shopping cart.

> :param current_cart: dict - the current shopping cart.
Expand All @@ -31,31 +31,31 @@
> return current_cart


> def read_notes(notes: items_t) -> cart_t:
> def read_notes(notes: ItemsT) -> CartT:
> """Create user cart from an iterable notes entry.

> :param notes: iterable of items to add to cart.
> :return: dict - a user shopping cart dictionary.
> """

> cart: cart_t = {}
> cart: CartT = {}

> return add_item(cart, notes)


> def update_recipes(ideas: recipes_t, recipe_updates: updates_t) -> recipes_t:
> def update_recipes(ideas: RecipesT, recipe_updates: UpdatesT) -> RecipesT:
> """Update the recipe ideas dictionary. Replaces the existing list of items with a new list, don't update/merge.

> :param ideas: dict - The "recipe ideas" dict.
> :param recipe_updates: dict - dictionary with updates for the ideas section.
> :return: dict - updated "recipe ideas" dict.
> """

> update: update_t
> update: UpdateT

> for update in recipe_updates:
> recipe_name: name_t = update[0]
> items: cart_t = update[1]
> recipe_name: NameT = update[0]
> items: CartT = update[1]

> _ = ideas.setdefault(recipe_name, {})

Expand All @@ -64,7 +64,7 @@
> return ideas


> def sort_entries(cart: cart_t) -> cart_t:
> def sort_entries(cart: CartT) -> CartT:
> """Sort a users shopping cart in alphabetically order.

> :param cart: dict - a users shopping cart dictionary.
Expand All @@ -74,19 +74,19 @@
> return dict(sorted(cart.items()))


> def send_to_store(cart: cart_t, aisle_mapping) -> fufillment_t:
> def send_to_store(cart: CartT, aisle_mapping) -> FufillmentT:
> """Combine users order to aisle and refrigeration information.

> :param cart: dict - users shopping cart dictionary.
> :param aisle_mapping: dict - aisle and refrigeration information dictionary.
> :return: dict - fulfillment dictionary ready to send to store.
> """

> fufillment: fufillment_t = {}
> fufillment: FufillmentT = {}

> item_name: name_t
> item_quantity: quantity_t
> aisle: aisle_t
> item_name: NameT
> item_quantity: QuantityT
> aisle: AisleT

> for item_name, item_quantity in cart.items():
> aisle = aisle_mapping.setdefault(item_name, ["Aisle 0", False])
Expand All @@ -96,22 +96,22 @@


> def update_store_inventory(
> fulfillment_cart: fufillment_t, store_inventory: fufillment_t
> ) -> fufillment_t:
> fulfillment_cart: FufillmentT, store_inventory: FufillmentT
> ) -> FufillmentT:
> """Update store inventory levels with user order.

> :param fulfillment cart: dict - fulfillment cart to send to store.
> :param store_inventory: dict - store available inventory
> :return: dict - store_inventory updated.
> """

> new_inventory: fufillment_t = store_inventory.copy()
> new_inventory: FufillmentT = store_inventory.copy()

> item_name: name_t
> order_quantity: quantity_t
> inventory_quantity: quantity_t
> new_quantity: quantity_t | message_t
> data: inventory_entry_t
> item_name: NameT
> order_quantity: QuantityT
> inventory_quantity: QuantityT
> new_quantity: QuantityT | MessageT
> data: InventoryEntryT

> for item_name in fulfillment_cart:
> order_quantity = int(
Expand Down
Loading

0 comments on commit 07a3bf8

Please sign in to comment.