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
2 changes: 2 additions & 0 deletions regolith/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -34,6 +35,7 @@
"resume": ResumeBuilder,
"review-man": ManRevBuilder,
"review-prop": PropRevBuilder,
"grantreport": GrantReportBuilder
}


Expand Down
131 changes: 131 additions & 0 deletions regolith/builders/grantreportbuilder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""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("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']

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

so pretty! 👍

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

since you will be doing something like this a lot I guess, you may want to use a function. Can you use is_current which has already been written? I would probably try and use get_dates to get dates and then is_current.

It may not work, but using functions that are well tested and can handle edge cases well will save time later.

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
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't be lazy with variable names, it makes the code hard to read. What is p?

Here I think the logic is that p contains the person document for the person of name person, so I would pick variable names like this:

for name in grant_people:
    person = self.gtx["people"].get(person)

I think this logic assumes that the names in grant_people are valid id's is that right? This might be a bit brittle.

months = 0
if p['active']:
difference = datetime.today() - rp_start_date
Copy link
Contributor

Choose a reason for hiding this comment

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

is it correct to do this calculation from today?

if difference.day > 15:
months = months + 1
months = difference.year * 12 + difference.month
else:

end_date = datetime.date(p['year'])
info = [p.get('position'), months]
self.render(
"grantreport.txt",
"billinge_grant_report.txt",
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
)
134 changes: 134 additions & 0 deletions regolith/templates/grantreport.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
NSF {{beginYear}}-{{endYear}} Annual Report
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you want a name here (just not my name hard-coded)


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):
Copy link
Contributor

Choose a reason for hiding this comment

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

again, can't have me hard-coded in here.

If there is something that is "me" specific that doesn't change often it should probably be in people. However, since this is a grant-specific thing it might better be in grants? If it is mostly me-specific but will be described in the grant report of multiple grants, this should probably be in people but have a field that is grant. This is how we discover how the world is organized!

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
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 an interesting one. It should probably be in people too so any user of Regolith can decide for themselves.

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 in grantPeople %}
- {{person.get('_id')}}, {{person.get(''}}
{% 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
------------------------------
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
Loading