From 5e2179672d34fb0ffdb75409c003c1d7a4682bb7 Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Wed, 3 May 2023 14:41:18 +0100 Subject: [PATCH 1/4] formatting numbers to 2 sig figs in attestations --- regolith/helpers/attestationshelper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regolith/helpers/attestationshelper.py b/regolith/helpers/attestationshelper.py index b5793f04d..c51cd4593 100644 --- a/regolith/helpers/attestationshelper.py +++ b/regolith/helpers/attestationshelper.py @@ -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)}") From 0b6706f40605c302df311aea63ce037997d3b717 Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Wed, 3 May 2023 15:20:20 +0100 Subject: [PATCH 2/4] grant lister now prints in columns --- regolith/helpers/l_grantshelper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/regolith/helpers/l_grantshelper.py b/regolith/helpers/l_grantshelper.py index 6a5e7ff90..f3028a0ee 100644 --- a/regolith/helpers/l_grantshelper.py +++ b/regolith/helpers/l_grantshelper.py @@ -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 From f5246b95ca6f0afd5ce20a7705e322831f77e278 Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Wed, 3 May 2023 15:23:24 +0100 Subject: [PATCH 3/4] news --- news/clean_attestations.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 news/clean_attestations.rst diff --git a/news/clean_attestations.rst b/news/clean_attestations.rst new file mode 100644 index 000000000..c4bc1c71a --- /dev/null +++ b/news/clean_attestations.rst @@ -0,0 +1,24 @@ +**Added:** + +* + +**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:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* From bd11ff77c50fb19cbf4646dfb88dcc7c5ba6f839 Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Thu, 4 May 2023 11:43:50 +0100 Subject: [PATCH 4/4] passing helper tests --- tests/test_helpers.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 21cf0c153..a8e83f63e 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -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" @@ -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"