From df61adb514d7e33819e3672eebf6fde279118d2c Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 26 Apr 2021 14:20:13 +0100 Subject: [PATCH] a quick hack to display total payments per milestone --- src/budget_sync/budget_graph.py | 18 +++++++++++------- src/budget_sync/main.py | 9 +++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/budget_sync/budget_graph.py b/src/budget_sync/budget_graph.py index a6de7a7..5a9542b 100644 --- a/src/budget_sync/budget_graph.py +++ b/src/budget_sync/budget_graph.py @@ -9,7 +9,7 @@ import sys import enum from collections import deque from datetime import date, time, datetime - +from collections import OrderedDict class BudgetGraphBaseError(Exception): pass @@ -296,7 +296,7 @@ class Node: new_err = BudgetGraphPayeesParseError( self.bug.id, f"TOML parse error: {e}") raise new_err.with_traceback(sys.exc_info()[2]) - retval = {} + retval = OrderedDict() for key, value in parsed.items(): if not isinstance(key, str): raise BudgetGraphPayeesParseError( @@ -503,7 +503,7 @@ class BudgetGraph: nodes: Dict[int, Node] def __init__(self, bugs: Iterable[Bug], config: Config): - self.nodes = {} + self.nodes = OrderedDict() self.config = config for bug in bugs: self.nodes[bug.id] = Node(self, bug) @@ -511,6 +511,7 @@ class BudgetGraph: if node.parent is None: continue node.parent.immediate_children.add(node) + self.milestone_payments = OrderedDict() # useful debug prints #for bug in bugs: # node = self.nodes[bug.id] @@ -578,7 +579,7 @@ class BudgetGraph: # childlist) payees_total = Money(0) - payee_payments = {} + payee_payments = OrderedDict() for payment in node.payments.values(): if payment.amount < 0: errors.append(BudgetGraphNegativePayeeMoney( @@ -737,16 +738,19 @@ class BudgetGraph: @cached_property def payments(self) -> Dict[Person, Dict[Milestone, List[Payment]]]: - retval = {} + retval = OrderedDict() for person in self.config.people.values(): - milestone_payments = {} + milestone_payments = OrderedDict() for milestone in self.config.milestones.values(): - milestone_payments[milestone] = [] + milestone_payments[milestone] = [] # per-person payments + self.milestone_payments[milestone] = [] # global payments retval[person] = milestone_payments for node in self.nodes.values(): if node.milestone is not None: for payment in node.payments.values(): retval[payment.payee][node.milestone].append(payment) + # add to global payments as well + self.milestone_payments[node.milestone].append(payment) return retval def __repr__(self): diff --git a/src/budget_sync/main.py b/src/budget_sync/main.py index 2726dbf..e18e072 100644 --- a/src/budget_sync/main.py +++ b/src/budget_sync/main.py @@ -37,6 +37,15 @@ def main(): if args.output_dir is not None: write_budget_markdown(budget_graph, args.output_dir) + # quick hack to display total payment amounts per-milestone + for milestone, payments in budget_graph.milestone_payments.items(): + print (milestone) + print () + total = 0 + for payment in payments: + print("\t", payment) + total += payment.amount + print ("\t", total) if __name__ == "__main__": main() -- 2.30.2