diff --git a/news/grants_lists_amts.rst b/news/grants_lists_amts.rst new file mode 100644 index 000000000..9a7b0ae8f --- /dev/null +++ b/news/grants_lists_amts.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* Grants lister helper now lists funding available when it is available + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/regolith/helpers/l_grantshelper.py b/regolith/helpers/l_grantshelper.py index f3028a0ee..64fb8681c 100644 --- a/regolith/helpers/l_grantshelper.py +++ b/regolith/helpers/l_grantshelper.py @@ -3,8 +3,7 @@ """ import datetime as dt import dateutil.parser as date_parser -from dateutil.relativedelta import relativedelta -import sys +from operator import itemgetter from regolith.dates import get_dates, is_current from regolith.helpers.basehelper import SoutHelperBase @@ -12,7 +11,6 @@ from regolith.tools import ( all_docs_from_collection, get_pi_id, - search_collection, key_value_pair_filter, collection_str, merge_collections_superior @@ -30,7 +28,9 @@ def subparser(subpi): date_kwargs['widget'] = 'DateChooser' subpi.add_argument("-c", "--current", action="store_true", help='outputs only the current grants') - subpi.add_argument("-v", "--verbose", action="store_true", + subpi.add_argument("-v", "--verbose", action="store_true", default=False, + help='if set, additional information will be printed about each grant') + subpi.add_argument("-r", "--reveal-hidden", action="store_true", help='if set, outputs also hidden grants such as TA, ' 'matches etc.') subpi.add_argument("-f", "--filter", nargs="+", help="Search this collection by giving key element pairs") @@ -88,7 +88,7 @@ def sout(self): for grant in collection: if rc.current and not is_current(grant, now=desired_date): continue - if not rc.verbose: + if not rc.reveal_hidden: if grant.get("alias") not in BLACKLIST: grants.append(grant) else: @@ -105,11 +105,18 @@ def sout(self): 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}") + print(f"\nAdministered 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')}") + if rc.verbose: + funds_entries = g.get('funds_available') + if funds_entries: + funds_entries.sort(key=lambda k: get_dates(k).get('date', get_dates(k).get("end_date")), reverse=True) + if funds_entries[0].get('funds_available'): + print(f" funds available: ${funds_entries[0].get('funds_available'):,.0f} on " + f"{get_dates(funds_entries[0]).get('date').isoformat()}") return diff --git a/regolith/schemas.py b/regolith/schemas.py index 99eb75bc8..7cd1123e0 100644 --- a/regolith/schemas.py +++ b/regolith/schemas.py @@ -350,6 +350,7 @@ "grants": [ { "_id": "SymPy-1.1", + "admin": "APAM", "amount": 3000.0, "alias": "sym", "awardnr": "NF-1234", @@ -363,9 +364,9 @@ "end_year": 2030, "funder": "NumFOCUS", "funds_available": [ - {"quarter": "2020-Q2", "funds_available": 2800.00}, - {"quarter": "2020-Q3", "funds_available": 2600.00}, - {"quarter": "2021-Q1", "funds_available": 2100.00} + {"date": "2020-04-01", "funds_available": 2800.00}, + {"date": "2021-01-03", "funds_available": 2100.00}, + {"date": "2020-07-21", "funds_available": 2600.00} ], "narrative": "https://docs.google.com/document/d/1nZxqoL" "-Ucni_aXLWmXtRDd3IWqW0mZBO65CEvDrsXZM/edit?usp" @@ -413,6 +414,7 @@ }, { "_id": "SymPy-2.0", + "admin": "APAM", "amount": 3000.0, "alias": "sym2.0", "awardnr": "NF-1234", @@ -425,6 +427,11 @@ "end_month": "December", "end_year": 2030, "funder": "NumFOCUS", + "funds_available": [ + {"date": "2020-04-01", "funds_available": 2800.00}, + {"date": "2021-01-03", "funds_available": 2100.00}, + {"date": "2020-07-21", "funds_available": 2600.00} + ], "narrative": "https://docs.google.com/document/d/1nZxqoL" "-Ucni_aXLWmXtRDd3IWqW0mZBO65CEvDrsXZM/edit?usp" "=sharing", @@ -465,6 +472,7 @@ "_id": "dmref15", "alias": "dmref15", "account": "GG012345", + "admin": "DSI", "amount": 982785.0, "awardnr": "DMR-0785462", "funder": "NSF", @@ -2772,7 +2780,7 @@ "type": "string", }, "admin": { - "description": "the group administering the grant", + "description": "the unit or group administering the grant", "type": "string", "required": False, }, @@ -2850,11 +2858,11 @@ "type": "string", }, "funds_available": { - "description": "funds available by quarter", + "description": "funds available on date", "required": False, "schema": { "schema": { - "quarter": {"required": False, "type": "string"}, + "date": {"required": False,"anyof_type": ["string", "date"]}, "funds_available": {"required": False, "type": ("integer", "float")} }, "type": "dict", diff --git a/tests/test_helpers.py b/tests/test_helpers.py index ec0d68571..6fedbb85c 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -191,9 +191,18 @@ "\nNo projecta finished within the 7 days leading up to 2020-06-02\n" ), (["helper", "l_grants", "--current", "--date", "2020-05-25"], - "Administered by: missing\n" + "\nAdministered by: apam\n" " sym2.0 \t awardnr: NF-1234 \t acctn: n/a \t 2019-06-01 to 2030-12-31\n" ), + (["helper", "l_grants", "--current", "--date", "2020-05-25", "--reveal-hidden"], + "\nAdministered by: apam\n" + " sym2.0 \t awardnr: NF-1234 \t acctn: n/a \t 2019-06-01 to 2030-12-31\n" + ), + (["helper", "l_grants", "--current", "--date", "2020-05-25", "--verbose"], + "\nAdministered by: apam\n" + " sym2.0 \t awardnr: NF-1234 \t acctn: n/a \t 2019-06-01 to 2030-12-31\n" + " funds available: $2,100 on 2021-01-03\n" + ), (["helper", "l_members", "--current", "-v"], " -- Assistant Scientists --\n" "Simon J. L. Billinge, professor\n"