accumulate payment info into rows by bug id
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 7 May 2021 14:08:28 +0000 (15:08 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 7 May 2021 14:08:28 +0000 (15:08 +0100)
src/budget_sync/main.py

index 3964134e7efe0cc30e209c83186b5910f2bdddea..5075603f308c7cd91b755e43dee9a7e77b0e0816 100644 (file)
@@ -91,12 +91,12 @@ def main():
     all_people = OrderedDict()
     # pre-initialise the CSV lists (to avoid overwrite)
     for milestone, payments in budget_graph.milestone_payments.items():
-        milestone_csvs[milestone] = [] # rows in the CSV file
+        milestone_csvs[milestone] = {} # rows in the CSV file
 
     for milestone, payments in budget_graph.milestone_payments.items():
         # first get the list of people, then create some columns
         people = milestones_people[milestone]
-        headings = []
+        headings = ['bug_id']
         for person in people:
             name = str(person).replace(" ", "_")
             all_people[person] = person
@@ -106,8 +106,11 @@ def main():
             headings.append(name+"_paid")
         milestone_headings[milestone] = headings
         # now we go through the whole "payments" thing again...
-        row = {}
         for payment in payments:
+            row = milestone_csvs[milestone].get(payment.node.id, None)
+            if row is None:
+                row = {'bug_id': payment.node.id}
+
             name = str(payment.payee.identifier).replace(" ", "_")
             row[name+"_amount"] = str(payment.amount)
             if payment.submitted is not None:
@@ -120,8 +123,9 @@ def main():
                 paid = ""
             row[name+"_req"] = requested
             row[name+"_paid"] = paid
+
             print (row)
-            milestone_csvs[milestone].append(row)
+            milestone_csvs[milestone][payment.node.id] = row
 
     if args.output_dir is not None:
         with open("%s/csvs.mdwn" % args.output_dir, "w") as f:
@@ -136,6 +140,7 @@ def main():
                 ident = milestone.identifier
                 header = milestone_headings[milestone]
                 fname = "%s/%s.csv" % (args.output_dir, ident)
+                rows = rows.values() # turn into list
                 write_csv(fname, rows, header)
                 f.write(mdwn_csv_template % (ident, fname))