Skip to content

Commit

Permalink
Simplify retrieve_data function
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S committed May 16, 2024
1 parent 21940ff commit 72271e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion usage_function/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = []
packages = [
{include = "usage"},
{include = "utils"},
# {include = "costmanagement"},
{include = "monthly_usage"},
# {include = "costmanagement"},
]

[tool.poetry.dependencies]
Expand Down
10 changes: 3 additions & 7 deletions usage_function/utils/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,15 @@ def retrieve_usage(usage_data):
else:
usage_item.amortised_cost = 0.0

if usage_item.id in all_items:
existing_item = all_items[usage_item.id]
# Add to the existing item
if existing_item := all_items.get(usage_item.id):
# Update the existing item
existing_item.quantity += usage_item.quantity
existing_item.effective_price += usage_item.effective_price
existing_item.cost += usage_item.cost
existing_item.amortised_cost += usage_item.amortised_cost
existing_item.total_cost += usage_item.total_cost
existing_item.unit_price += usage_item.unit_price

# Update the dict entry
all_items[usage_item.id] = existing_item

else:
all_items[usage_item.id] = usage_item

Expand All @@ -132,7 +128,7 @@ def retrieve_usage(usage_data):
datetime.now() - started_processing_at,
)

return list(all_items.values())
return all_item_list


def retrieve_and_send_usage(hostname_or_ip, usage_data):
Expand Down

0 comments on commit 72271e9

Please sign in to comment.