Skip to content

Commit

Permalink
Merge pull request #1028 from sbillinge/clean_attestations
Browse files Browse the repository at this point in the history
formatting numbers to 2 sig figs in attestations
  • Loading branch information
sbillinge authored Jul 20, 2023
2 parents c5c2695 + b7a2888 commit 83c79ea
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
24 changes: 24 additions & 0 deletions news/clean_attestations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**Added:**

* <news item>

**Changed:**

* grants lister prints in columns and is grouped by the unit that administers the grant
* amounts in attestations are limited to 2-sig-figs

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
2 changes: 1 addition & 1 deletion regolith/helpers/attestationshelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def db_updater(self):
for amt, dte in zip(all_reimb_amts, all_reimb_dates):
if month.year == dte.year and month.month == dte.month:
month_spend += amt
print(f"{month}: expenses monthly total = {month_spend}")
print(f"{month}: expenses monthly total = {month_spend:.2f}")

print(f"Total spend = {round(total_spend, 2)}")

Expand Down
18 changes: 13 additions & 5 deletions regolith/helpers/l_grantshelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,22 @@ def sout(self):
else:
grants.append(grant)

# Sort the grants by end date in reverse chronological order
grants.sort(key=lambda k: get_dates(k).get('end_date'), reverse=True)
if rc.keys:
results = (collection_str(grants, rc.keys))
print(results, end="")
return
for g in grants:
print("{}, awardnr: {}, acctn: {}, {} to {}".format(g.get('alias', ''), g.get('awardnr', ''),
g.get('account', ''), get_dates(g).get('begin_date'),
get_dates(g).get('end_date')))
if g.get('admin') is None:
g['admin'] = 'missing'
g['admin'] = g.get('admin').casefold()
grants.sort(key=lambda x: x['admin'])
admins = list(set([g.get('admin') for g in grants]))
for admin in admins:
print(f"Administered by: {admin}")
sub_grants = [grant for grant in grants if grant.get('admin').strip() == admin.strip()]
sub_grants.sort(key=lambda k: get_dates(k).get('end_date'), reverse=True)
for g in sub_grants:
print(f" {g.get('alias', '').ljust(15)}\t awardnr: {g.get('awardnr', '').ljust(15)}\t "
f"acctn: {g.get('account', 'n/a').ljust(20)}\t {get_dates(g).get('begin_date')} "
f"to {get_dates(g).get('end_date')}")
return
29 changes: 15 additions & 14 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
'2018-01-10 (reimb date), 2018-01-10 (expense date): amount: 500, \n'
'2019-02-15 (reimb date), 2018-01-10 (expense date): amount: 1000, \n'
' payee: scopatz purpose: testing the databallectionsse\n'
'2018-05-01: expenses monthly total = 0\n'
'2018-06-01: expenses monthly total = 0\n'
'2018-07-01: expenses monthly total = 0\n'
'2018-08-01: expenses monthly total = 0\n'
'2018-09-01: expenses monthly total = 0\n'
'2018-10-01: expenses monthly total = 0\n'
'2018-11-01: expenses monthly total = 0\n'
'2018-12-01: expenses monthly total = 0\n'
'2019-01-01: expenses monthly total = 0\n'
"2019-02-01: expenses monthly total = 1000\n"
'2019-03-01: expenses monthly total = 0\n'
'2019-04-01: expenses monthly total = 0\n'
'2019-05-01: expenses monthly total = 0\n'
'2018-05-01: expenses monthly total = 0.00\n'
'2018-06-01: expenses monthly total = 0.00\n'
'2018-07-01: expenses monthly total = 0.00\n'
'2018-08-01: expenses monthly total = 0.00\n'
'2018-09-01: expenses monthly total = 0.00\n'
'2018-10-01: expenses monthly total = 0.00\n'
'2018-11-01: expenses monthly total = 0.00\n'
'2018-12-01: expenses monthly total = 0.00\n'
'2019-01-01: expenses monthly total = 0.00\n'
"2019-02-01: expenses monthly total = 1000.00\n"
'2019-03-01: expenses monthly total = 0.00\n'
'2019-04-01: expenses monthly total = 0.00\n'
'2019-05-01: expenses monthly total = 0.00\n'
"Total spend = 1500\n"),
(["helper", "attestations", "--begin-date", "2019-01-01", "--end-date", "2019-05-30", "--effort-reporting", "--no-plot"],
",, 2019-01-01, 2019-02-01, 2019-03-01, 2019-04-01, 2019-05-01\n"
Expand Down Expand Up @@ -191,7 +191,8 @@
"\nNo projecta finished within the 7 days leading up to 2020-06-02\n"
),
(["helper", "l_grants", "--current", "--date", "2020-05-25"],
"sym2.0, awardnr: , acctn: , 2019-06-01 to 2030-12-31\n"
"Administered by: missing\n"
" sym2.0 \t awardnr: \t acctn: n/a \t 2019-06-01 to 2030-12-31\n"
),
(["helper", "l_members", "--current", "-v"],
" -- Assistant Scientists --\n"
Expand Down

0 comments on commit 83c79ea

Please sign in to comment.