diff --git a/regolith/builder.py b/regolith/builder.py index a1a91f8ca..686220354 100644 --- a/regolith/builder.py +++ b/regolith/builder.py @@ -15,6 +15,7 @@ from regolith.builders.coabuilder import RecentCollaboratorsBuilder from regolith.builders.beamplanbuilder import BeamPlanBuilder from regolith.builders.activitylogbuilder import ActivitylogBuilder +from regolith.builders.grantreportbuilder import GrantReportBuilder BUILDERS = { @@ -34,6 +35,7 @@ "resume": ResumeBuilder, "review-man": ManRevBuilder, "review-prop": PropRevBuilder, + "grantreport": GrantReportBuilder } diff --git a/regolith/builders/grantreportbuilder.py b/regolith/builders/grantreportbuilder.py new file mode 100644 index 000000000..533c0ffb0 --- /dev/null +++ b/regolith/builders/grantreportbuilder.py @@ -0,0 +1,178 @@ +"""Builder for Proposal Reviews.""" +from datetime import datetime +import time +from nameparser import HumanName +import dateutil.parser as date_parser + +from regolith.builders.basebuilder import LatexBuilderBase +from regolith.dates import (month_to_int, + get_dates, + get_due_date, + is_current, + is_after, + is_before) +from regolith.fsclient import _id_key +from regolith.sorters import position_key +from regolith.tools import ( + all_docs_from_collection, + filter_grants, + filter_presentations, + fuzzy_retrieval, + filter_publications +) + + +def subparser(subpi): + subpi.add_argument("authorFullName", help="full name of the author of this grant report") + 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") + return subpi + + +class GrantReportBuilder(LatexBuilderBase): + """Build a proposal review from database entries""" + btype = "grantreport" + needed_dbs = ['presentations', 'projecta', 'people', 'grants', 'institutions', 'expenses', 'citations', 'contacts'] + + def construct_global_ctx(self): + """Constructs the global context""" + super().construct_global_ctx() + gtx = self.gtx + rc = self.rc + for dbs in rc.needed_dbs: + gtx[dbs] = sorted( + all_docs_from_collection(rc.client, dbs), key=_id_key + ) + gtx["all_docs_from_collection"] = all_docs_from_collection + gtx["float"] = float + gtx["str"] = str + gtx["zip"] = zip + + def latex(self): + """Render latex template""" + rc = self.rc + + # Convert Date Strings to Datetime Objects + rp_start_date = date_parser.parse(rc.start_date) + rp_end_date = date_parser.parse(rc.end_date) + + # NSF Grant _id + grant_name = "dmref" + + # Get prum associated to grant and active during reporting period + grant_prums = [] + for prum in self.gtx['projecta']: + if grant_name in prum['grants']: + begin_date = get_dates(prum).get('begin_date') + due_date = get_due_date(prum['deliverable']) + # if projectum was finished during reporting period or is still current + # some projectum don't have an "end date", but all projecta have a deliverable + # due_date + if (rp_start_date <= due_date <= rp_end_date and prum['status'] is "finished") or is_current(prum): + grant_prums.append(prum) + # Get people associated with grant + grant_people = list(set([prum['lead'] for prum in grant_prums])) + + # Accomplishments + major_activities = [] + significant_results = [] + for prum in grant_prums: + if prum['status'] is "finished": + significant_results.append(prum) + else: + major_activities.append(prum) + + # Opportunities for Training and Professional Development + training_and_professional_development = [] + # presentations + for id in grant_people: + training_and_professional_development.extend( + filter_presentations(self.gtx["people"], self.gtx["presentations"], self.gtx["institutions"], id, + types=["all"], since=rp_start_date, before=rp_end_date, statuses=["accepted"])) + # thesis defendings + # how do i access people.yml in rg-db-public vs the people.yml file in rg-db-group? + defended_theses = [] + for id in grant_people: + person = self.gtx['people'][id] + for education in person['education']: + if 'phd' in education['degree'].lower() and 'columbia' in education['institution'].lower() and \ + rp_start_date.year <= education['end_year'] <= rp_end_date.year: + defended_theses.append(id) + + # Products + # 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 name in grant_people: + person = self.gtx["people"].get(name) + 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 + + 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, + 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 diff --git a/regolith/templates/grantreport.txt b/regolith/templates/grantreport.txt new file mode 100644 index 000000000..3a4e10835 --- /dev/null +++ b/regolith/templates/grantreport.txt @@ -0,0 +1,126 @@ +NSF {{beginYear}}-{{endYear}} Annual Report by {{authorFullName}} + +Accomplishments +------------------------------------------------------------------------------ +* What are the major goals of the project? +In real-world applications, materials are rarely perfect crystals and their properties +depend sensitively on defects, nanoscale structures, interfaces, surfaces and multi-scale +heterogeneities. A major challenge is to gain a greater understanding of how such +"imperfect" materials operate, including on different length and time-scales. In situations +as complicated as this it is essential to validate theories against experiment, and vice versa. +A more tightly coupled partnership between experiment and theory is needed, having its roots +in information theory: the models need to capture all the physics of the problem become more +complicated, while at the same time the information content of experimental data is reduced, +due to lower resolution from finite size effects, defects, the presence of multiple components +with overlapping problems, which yield unreliable and non-unique solutions, a bottleneck to +predictive materials discovery. We will develop novel mathematical approaches to address this +problem. We will study as a test case the nanostructure inverse problem (NIP), a well defined +but generally ill-posed materials inverse problem; however, the methods that we develop will +have much broader applicability in the world of materials discovery. + +Goal 1: Develop databases of nanostructure data from model systems +Goal 2: Develop data analytic and stochastic optimization methodologies for robust +nanostructure solutions +Goal 3: Develop software infrastructure for nanostructure modeling that use the databases +and the new methodologies for nanostructure solution +Goal 4: Apply this to real scientific problems + +* What was accomplished under these goals (you must provide information for +at least one of the 4 categories below)? +------------------------------------------------------------------------------ +- Major Activities (currently worked on projecta): +PDF in the cloud (PDFitc): Development of a web-based service for determining +structures from measured PDFs given known structures in structural databases +xpdTools, xpdAcq, xpdAn, xpdView: Software tools for streaming data analysis +and visualization of diffraction data from the XPD diffractometer at NSLS-II +synchrotron. The tools can also be used to analyze data from other diffraction +beamlines. +{%- for prum in majorActivities %} + {{ prum.get('name') }}: {{ prum.get('description') }} +{% endfor -%} + +- Specific Objectives: +PDF in the cloud (PDFitc): Development of a web-based service for determining +structures from measured PDFs given known structures in structural databases + +- Significant Results (finished projecta): +{%- for prum in significantResults %} + {{ prum.get('name') }}: {{ prum.get('description') }} +{% endfor -%} + +Key outcomes or Other achievements: +* What opportunities for training and professional development has the project provided? +{%- for opportunity in trainingAndProfessionalDevelopment %} + - Authors: {{ opportunity.get('authors') }} + - Title: {{ opportunity.get('title') }} + - Location: {{ opportunity.get('meeting_name') }} +{% endfor -%}} +{%- for thesis in defendedTheses %} + {{thesis}} wrote and successfully defended their thesis. +{% endfor -%}} + +* How have the results been disseminated to communities of interest? +1. Publications +2. Software releases and deployment of software packages on conda-forge and pypi for ease of installation +3. Presentations at conferences and seminars + +* What do you plan to do during the next reporting period to accomplish the goals? +############################################################# +## ## +## ## +## FILL THIS PART IN !!! FILL THIS PART IN !!! ## +## ## +## ## +############################################################# + +Products +------------------------------ +{%- for doi in products %} + - {{doi.get('doi')}} +{% endfor -%}} + +Participants/Organizations +------------------------------ +What individuals have worked on the project? + +Name, Most Senior Project Role, Nearest Person Month Worked +{%- 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 -%}} + +Impacts +------------------------------ +What is the impact on the development of the principal discipline(s) of the project? + +What is the impact on other disciplines? + +What is the impact on the development of human resources? + +What is the impact on physical resources that form infrastructure? + +What is the impact on institutional resources that form infrastructure? + +What is the impact on information resources that form infrastructure? + +What is the impact on technology transfer? + +What is the impact on society beyond science and technology? + +Changes/Problems +------------------------------ +Changes in approach and reason for change + +Actual or Anticipated problems or delays and actions or plans to resolve them + +Changes that have a significant impact on expenditures + +Significant changes in use or care of human subjects + +Significant changes in use or care of vertebrate animals + +Significant changes in use or care of biohazards \ No newline at end of file diff --git a/tests/outputs/grantreport/billinge_grant_report.txt b/tests/outputs/grantreport/billinge_grant_report.txt new file mode 100644 index 000000000..ac6ee5baf --- /dev/null +++ b/tests/outputs/grantreport/billinge_grant_report.txt @@ -0,0 +1,104 @@ +NSF 2019-2020 Annual Report by Simon J. L. Billinge + +Accomplishments +------------------------------------------------------------------------------ +* What are the major goals of the project? +In real-world applications, materials are rarely perfect crystals and their properties +depend sensitively on defects, nanoscale structures, interfaces, surfaces and multi-scale +heterogeneities. A major challenge is to gain a greater understanding of how such +"imperfect" materials operate, including on different length and time-scales. In situations +as complicated as this it is essential to validate theories against experiment, and vice versa. +A more tightly coupled partnership between experiment and theory is needed, having its roots +in information theory: the models need to capture all the physics of the problem become more +complicated, while at the same time the information content of experimental data is reduced, +due to lower resolution from finite size effects, defects, the presence of multiple components +with overlapping problems, which yield unreliable and non-unique solutions, a bottleneck to +predictive materials discovery. We will develop novel mathematical approaches to address this +problem. We will study as a test case the nanostructure inverse problem (NIP), a well defined +but generally ill-posed materials inverse problem; however, the methods that we develop will +have much broader applicability in the world of materials discovery. + +Goal 1: Develop databases of nanostructure data from model systems +Goal 2: Develop data analytic and stochastic optimization methodologies for robust +nanostructure solutions +Goal 3: Develop software infrastructure for nanostructure modeling that use the databases +and the new methodologies for nanostructure solution +Goal 4: Apply this to real scientific problems + +* What was accomplished under these goals (you must provide information for +at least one of the 4 categories below)? +------------------------------------------------------------------------------ +- Major Activities (currently worked on projecta): +PDF in the cloud (PDFitc): Development of a web-based service for determining +structures from measured PDFs given known structures in structural databases +xpdTools, xpdAcq, xpdAn, xpdView: Software tools for streaming data analysis +and visualization of diffraction data from the XPD diffractometer at NSLS-II +synchrotron. The tools can also be used to analyze data from other diffraction +beamlines. + +- Specific Objectives: +PDF in the cloud (PDFitc): Development of a web-based service for determining +structures from measured PDFs given known structures in structural databases + +- Significant Results (finished projecta): + +Key outcomes or Other achievements: +* What opportunities for training and professional development has the project provided? + +* How have the results been disseminated to communities of interest? +1. Publications +2. Software releases and deployment of software packages on conda-forge and pypi for ease of installation +3. Presentations at conferences and seminars + +* What do you plan to do during the next reporting period to accomplish the goals? +############################################################# +## ## +## ## +## FILL THIS PART IN !!! FILL THIS PART IN !!! ## +## ## +## ## +############################################################# + +Products +------------------------------ + + +Participants/Organizations +------------------------------ +What individuals have worked on the project? + +Name, Most Senior Project Role, Nearest Person Month Worked + +What other organizations have been involved as partners?/What other collaborators or contacts have been involved? + +Impacts +------------------------------ +What is the impact on the development of the principal discipline(s) of the project? + +What is the impact on other disciplines? + +What is the impact on the development of human resources? + +What is the impact on physical resources that form infrastructure? + +What is the impact on institutional resources that form infrastructure? + +What is the impact on information resources that form infrastructure? + +What is the impact on technology transfer? + +What is the impact on society beyond science and technology? + +Changes/Problems +------------------------------ +Changes in approach and reason for change + +Actual or Anticipated problems or delays and actions or plans to resolve them + +Changes that have a significant impact on expenditures + +Significant changes in use or care of human subjects + +Significant changes in use or care of vertebrate animals + +Significant changes in use or care of biohazards \ No newline at end of file diff --git a/tests/test_builders.py b/tests/test_builders.py index 025097074..78c20585b 100644 --- a/tests/test_builders.py +++ b/tests/test_builders.py @@ -19,7 +19,8 @@ "reimb", "figure", "recent-collabs", - "beamplan" + "beamplan", + "grantreport" ] db_srcs = ["mongo", "fs"]