Skip to content

Commit

Permalink
Merge pull request #1057 from sbillinge/grants_lists_amts
Browse files Browse the repository at this point in the history
grants lister lists funds available
  • Loading branch information
sbillinge authored Feb 15, 2024
2 parents 35039d0 + ebfc8b3 commit 64b1d81
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
23 changes: 23 additions & 0 deletions news/grants_lists_amts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Grants lister helper now lists funding available when it is available

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
19 changes: 13 additions & 6 deletions regolith/helpers/l_grantshelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
"""
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
from regolith.fsclient import _id_key
from regolith.tools import (
all_docs_from_collection,
get_pi_id,
search_collection,
key_value_pair_filter,
collection_str,
merge_collections_superior
Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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
20 changes: 14 additions & 6 deletions regolith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
"grants": [
{
"_id": "SymPy-1.1",
"admin": "APAM",
"amount": 3000.0,
"alias": "sym",
"awardnr": "NF-1234",
Expand All @@ -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"
Expand Down Expand Up @@ -413,6 +414,7 @@
},
{
"_id": "SymPy-2.0",
"admin": "APAM",
"amount": 3000.0,
"alias": "sym2.0",
"awardnr": "NF-1234",
Expand All @@ -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",
Expand Down Expand Up @@ -465,6 +472,7 @@
"_id": "dmref15",
"alias": "dmref15",
"account": "GG012345",
"admin": "DSI",
"amount": 982785.0,
"awardnr": "DMR-0785462",
"funder": "NSF",
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 64b1d81

Please sign in to comment.