a quick hack to display total payments per milestone
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 26 Apr 2021 13:20:13 +0000 (14:20 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 26 Apr 2021 13:20:13 +0000 (14:20 +0100)
src/budget_sync/budget_graph.py
src/budget_sync/main.py

index a6de7a734feb17e5e9cdf27687986d5db5774097..5a9542b3edeb1d3b7026fa40075643a7609d9040 100644 (file)
@@ -9,7 +9,7 @@ import sys
 import enum
 from collections import deque
 from datetime import date, time, datetime
 import enum
 from collections import deque
 from datetime import date, time, datetime
-
+from collections import OrderedDict
 
 class BudgetGraphBaseError(Exception):
     pass
 
 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])
             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(
         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):
     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)
         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)
             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]
         # useful debug prints
         #for bug in bugs:
         #    node = self.nodes[bug.id]
@@ -578,7 +579,7 @@ class BudgetGraph:
         #                        childlist)
 
         payees_total = Money(0)
         #                        childlist)
 
         payees_total = Money(0)
-        payee_payments = {}
+        payee_payments = OrderedDict()
         for payment in node.payments.values():
             if payment.amount < 0:
                 errors.append(BudgetGraphNegativePayeeMoney(
         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]]]:
 
     @cached_property
     def payments(self) -> Dict[Person, Dict[Milestone, List[Payment]]]:
-        retval = {}
+        retval = OrderedDict()
         for person in self.config.people.values():
         for person in self.config.people.values():
-            milestone_payments = {}
+            milestone_payments = OrderedDict()
             for milestone in self.config.milestones.values():
             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)
             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):
         return retval
 
     def __repr__(self):
index 2726dbf0457bcf289b056213431c21a625a862f5..e18e07208473f6200edbfaebec6cd03284e5544a 100644 (file)
@@ -37,6 +37,15 @@ def main():
     if args.output_dir is not None:
         write_budget_markdown(budget_graph, args.output_dir)
 
     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()
 
 if __name__ == "__main__":
     main()