Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Update usage output (#364)
Browse files Browse the repository at this point in the history
* Only add/remove SUs to total (not current) on investments

* Add current totals to floating and investment SU table output

* make last investment row a dividier

* Pull duplicate header items from investment output
  • Loading branch information
Comeani committed Mar 5, 2024
1 parent 467e563 commit 9f6e333
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions bank/account_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def add_sus(self, inv_id: Optional[int], sus: int) -> None:
with DBConnection.session() as session:
investment = session.execute(query).scalars().first()
investment.service_units += sus
investment.current_sus += sus

session.commit()

Expand Down Expand Up @@ -573,7 +572,6 @@ def subtract_sus(self, inv_id: Optional[int], sus: int) -> None:
f'Cannot subtract {sus}. Investment {inv_id} only has {investment.current_sus} available.')

investment.service_units -= sus
investment.current_sus -= sus

session.commit()

Expand Down Expand Up @@ -794,28 +792,33 @@ def _build_usage_table(self) -> PrettyTable:
usage_percentage = self._calculate_percentage(aggregate_usage_total, allocation_total)

floating_su_percent = self._calculate_percentage(floating_su_usage, floating_su_total)
output_table.add_row(['Floating SUs', "SUs Remaining", "% Used"], divider=True)
output_table.add_row([f'*Floating SUs', "", ""])
output_table.add_row([f'are applied on', "", ""])
output_table.add_row([f'any cluster to', str(floating_su_remaining)+'*', floating_su_percent])
output_table.add_row([f'cover usage above', "", ""])
output_table.add_row([f'Total SUs', "", ""], divider=True)
output_table.add_row(["Floating SUs", "", ""], divider=True)
output_table.add_row(["Floating SUs", "", ""])
output_table.add_row(["are applied on", "", ""])
output_table.add_row(["any cluster to", "", ""])
output_table.add_row(["cover usage above", "", ""])
output_table.add_row(["Total Proposal SUs", "", ""])
output_table.add_row(["Total", "SUs Remaining", "% Used"])
output_table.add_row([floating_su_total, floating_su_remaining, floating_su_percent], divider=True)

# Add another inner table describing aggregate usage
if not investments:
output_table.add_row(['Aggregate Usage', usage_percentage, ""], divider=True)
else:
investment_total = sum(inv.service_units for inv in investments)
investment_remaining = sum(inv.current_sus for inv in investments)
investment_remaining = sum(inv.current_sus for inv in investments)
investment_used = investment_total - investment_remaining
investment_percentage = self._calculate_percentage(investment_used, investment_total)

output_table.add_row(['Investment SUs', "SUs Remaining", "% Used"], divider=True)
output_table.add_row([f'**Investment SUs', "",""])
output_table.add_row([f'are applied on', "", ""])
output_table.add_row([f'any cluster to', str(investment_remaining)+"**", investment_percentage])
output_table.add_row([f'cover usage above',"",""])
output_table.add_row([f'Total SUs', "", ""], divider=True)
output_table.add_row(["Investment SUs", "", ""], divider=True)
output_table.add_row(["Investment SUs", "", ""])
output_table.add_row(["are applied on", "", ""])
output_table.add_row(["any cluster to", "", ""])
output_table.add_row(["cover usage above", "", ""])
output_table.add_row(["Total Proposal SUs", "", ""])
output_table.add_row(["Total", "SUs Remaining", "% Used"])
output_table.add_row([investment_total, investment_remaining, investment_percentage], divider=True)

output_table.add_row(['Aggregate Usage', usage_percentage, ""])
output_table.add_row(['(no investments)', "", ""])

Expand Down

0 comments on commit 9f6e333

Please sign in to comment.