Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Regolith Grant Report Builder #523

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
75 changes: 61 additions & 14 deletions regolith/builders/grantreportbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


def subparser(subpi):
subpi.add_argument("authorFullName", help="full name of the author of this grant report")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very brittle. I doubt I will ever remember the full name of people and whether it is capitalized and spaces and whatnot. We have two choices here.

  1. require the person id (e.g., you would be vlin). This is easier to remember because we use a mostly standard naming scheme.
  2. allow anything that is in id, name or alias and then use fuzzy retrieval to get the person back.

(2) is probably better because (1) is also covered by (2)

subpi.add_argument("start_date", help="start date of the reporting period, formatted as YYYY-MM-DD",
default=None)
subpi.add_argument("end_date", help="end date of the reporting period, formatted as YYYY-MM-DD")
Expand All @@ -32,7 +33,7 @@ def subparser(subpi):
class GrantReportBuilder(LatexBuilderBase):
"""Build a proposal review from database entries"""
btype = "grantreport"
needed_dbs = ['presentations', 'projecta', 'people', 'grants', 'institutions', 'expenses', 'citations']
needed_dbs = ['presentations', 'projecta', 'people', 'grants', 'institutions', 'expenses', 'citations', 'contacts']

def construct_global_ctx(self):
"""Constructs the global context"""
Expand Down Expand Up @@ -100,32 +101,78 @@ def latex(self):
defended_theses.append(id)

# Products
# need rg-db-public's citation.yml... how to access that instead of the rg-db-group's citation.yml file
# need rg-db-public's citation.yml
publications = filter_publications(self.gtx["citations"], grant_people, since=rp_start_date, before=rp_end_date)

# Participants/Organizations
participants = {}
for person in grant_people:
p = self.gtx["people"].get(person)
months = 0
if p['active']:
difference = datetime.today() - rp_start_date
if difference.day > 15:
months = months + 1
months = difference.year * 12 + difference.month
else:
for name in grant_people:
person = self.gtx["people"].get(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to get things from a collection we use things like fuzzy_retrieval in tools.py or find_one etc. in fsclient and mongoclient You might also find get_person from tools.py to be useful.

months_on_grant, months_left = self.months_on(grant_name, person, rp_start_date, rp_end_date)
participants[name] = [person.get('position'), months_on_grant]

# Other Collaborators
collaborator_ids = []
for prum in grant_prums:
collabs = prum.get("collaborators")
if collabs:
for id in collabs:
collaborator_ids.append(id)
collaborator_ids = set(collaborator_ids)

collaborators = {}
for id in collaborator_ids:
contact = self.gtx["contacts"].get(id)
aka = contact.get("aka")
institution = contact.get("institution")
collaborators[id] = {
"aka": aka,
"institution": institution
}

# Impacts

end_date = datetime.date(p['year'])
info = [p.get('position'), months]
self.render(
"grantreport.txt",
"billinge_grant_report.txt",
authorFullName=rc.authorFullName,
beginYear=rp_start_date.year,
endYear=rp_end_date.year,
majorActivities=major_activities,
significantResults=significant_results,
trainingAndProfessionalDevelopment=training_and_professional_development,
defendedTheses=defended_theses,
products=publications,
grantPeople=grant_people
grantPeople=grant_people,
participants=participants,
collaborators=collaborators
)

def months_on(self, grant, person, since=datetime(1970, 1, 1), before=datetime.today()):
# print('Looking at months on grant {} in period since {} until {}'.format(
# grant, since, before), )
total_months = 0
appts = person.get('appointments')
if appts:
months = 0
for k1, v1 in appts.items():
if grant in v1.get('grant'):
dates = get_dates(v1)
startdate = dates.get('start_date')
enddate = dates.get('end_date')
loading = v1.get('loading')
if startdate >= since and enddate <= before:
months = months + (
enddate - startdate).days * loading / 30.4
elif startdate >= since and enddate > before:
months = months + (
before - startdate).days * loading / 30.4
elif startdate < since and enddate <= before:
months = months + (
enddate - since).days * loading / 30.4
elif startdate < since and enddate > before:
months = months + (before - since).days * loading / 30.4
if months > 0:
total_months = total_months + months
months_left = (before - datetime.today())
return total_months, months_left
24 changes: 8 additions & 16 deletions regolith/templates/grantreport.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NSF {{beginYear}}-{{endYear}} Annual Report
NSF {{beginYear}}-{{endYear}} Annual Report by {{authorFullName}}

Accomplishments
------------------------------------------------------------------------------
Expand Down Expand Up @@ -84,22 +84,14 @@ Participants/Organizations
What individuals have worked on the project?

Name, Most Senior Project Role, Nearest Person Month Worked
{%- for person in grantPeople %}
- {{person.get('_id')}}, {{person.get(''}}
{%- for person, info in participants.items() %}
- {{person}}: {{info[0]}}, {{info[1]}}
{% endfor -%}}

What other organizations have been involved as partners?/What other collaborators or contacts have been involved?
{%- for contact, info in collaborators.items() %}
- {{contact}}: aka: {{info["aka"]}}, institution: {{info["institution"]}}
{% endfor -%}}
Full details of individuals who have worked on the project:

Name:
Email:
Most Senior Project Role:
Nearest Person Month Worked:
Contribution to the Project:
Funding Support:
International Collaboration:
International Travel:

What other organizations have been involved as partners?
What other collaborators or contacts have been involved?

Impacts
------------------------------
Expand Down
16 changes: 2 additions & 14 deletions tests/outputs/grantreport/billinge_grant_report.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NSF 2019-2020 Annual Report
NSF 2019-2020 Annual Report by Simon J. L. Billinge

Accomplishments
------------------------------------------------------------------------------
Expand Down Expand Up @@ -69,19 +69,7 @@ What individuals have worked on the project?

Name, Most Senior Project Role, Nearest Person Month Worked

Full details of individuals who have worked on the project:

Name:
Email:
Most Senior Project Role:
Nearest Person Month Worked:
Contribution to the Project:
Funding Support:
International Collaboration:
International Travel:

What other organizations have been involved as partners?
What other collaborators or contacts have been involved?
What other organizations have been involved as partners?/What other collaborators or contacts have been involved?

Impacts
------------------------------
Expand Down