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

Allow limiting New-PI credit to partner institutions #96

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

QuanMPhm
Copy link
Contributor

@QuanMPhm QuanMPhm commented Sep 12, 2024

Closes #94, process_report.py will now use nerc_rates to determine if the New-PI credit is limited to institutions that are MGHPCC partners for the given invoice month.

The script determines whether an institution's MGHPCC partnership is active by first seeing if the mghpcc_partnership_start_date field is set in institute_list.yaml, then checks if the start date is within or before the invoice month.

@joachimweyl To mark an institution as an MGHPCC partner, you will need to set the field mghpcc_partnership_start_date in institute_list.yaml to the start date of the partnership in YYYY-MM format.

I.e for Boston University, their current entry looks like this:

-   display_name: Boston University
    domains:
    - bu.edu
    - robbaron

To mark them as a partner, change their entry like so:

-   display_name: Boston University
    domains:
    - bu.edu
    - robbaron
    mghpcc_partnership_start_date: "2024-10"

Copy link
Contributor

@knikolla knikolla left a comment

Choose a reason for hiding this comment

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

Not a full review yet, just one comment related to the data in the file.

- display_name: Boston University
domains:
- bu.edu
- robbaron
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we've fully transitioned to using email addresses rather than username (and also have a aliasin system in place), I feel it's safe to remove everything that is an username from this file.

Copy link
Collaborator

@naved001 naved001 left a comment

Choose a reason for hiding this comment

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

Looks great!, just some questions and comments. Thanks @QuanMPhm !

process_report/invoices/billable_invoice.py Show resolved Hide resolved
"mghpcc_partnership_start_date", None
):
if (
util.get_month_diff(self.invoice_month, partnership_start_date[:-3])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Usually I'd add a comment when you need to access some very specific indexes of a string.

In this case, however, I think we should convert it to a datetime object and then get the month and year.

>>> "{:%Y-%m}".format(datetime.strptime("2024-09-01", "%Y-%m-%d"))
'2024-09'

This would also work in the case where someone writes the date as "2024-9-1" in institute_list.yaml because nothing is enforcing that a zero is added.

>>> "{:%Y-%m}".format(datetime.strptime("2024-9-1", "%Y-%m-%d"))
'2024-09'

as opposed to

>>> "2024-9-1"[:-3]
'2024-'

process_report/invoices/billable_invoice.py Show resolved Hide resolved
process_report/util.py Outdated Show resolved Hide resolved
@QuanMPhm QuanMPhm force-pushed the 94/limit_credits branch 2 times, most recently from 745ecff to 0cf4f8f Compare September 19, 2024 15:03
process_report/institute_list.yaml Outdated Show resolved Hide resolved
process_report/invoices/billable_invoice.py Show resolved Hide resolved
As prerequisite to adding metadata about our list of institutions,
such as whether MGHPCC has a partnership with them, and to make the
file more human-friendly, `institute.json` has been converted to a YAML
and formatted as a list. Each element of the YAML list must be a dict with
2 attributes:
- `display_name`: The name of the institute, as will appear on invoices
- `domains`: A list containing domains for that institute

Additional metadata can be freely added to each institute dict as our
billing needs change.

There is also some small cleanup. Namely, some functions in `process_report.py`
that have been moved to `util.py` were not removed during refactoring.
Copy link
Contributor

@knikolla knikolla left a comment

Choose a reason for hiding this comment

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

One comment regarding the format of the partnership start date, otherwise looks good.

Also please note that since no institutions in this list have a partnership start date, in the current cycle no one would receive a credit unless we introduce those dates in a subsequent PR.

"mghpcc_partnership_start_date"
):
partnership_year_month = "{:%Y-%m}".format(
datetime.strptime(partnership_start_date, "%Y-%m-%d")
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand you're following my suggestion of the partnership start date being YYYY-MM-DD, but considering that we're working with YYYY-MM in every other aspect of the billing pipeline (including nerc-rates) I think it's reasonable to just use YYYY-MM here too. So no need to format, just pass the value from the yaml to get_month_diff

Copy link
Collaborator

Choose a reason for hiding this comment

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

@knikolla I think that was because of my concerns described in this comment: #96 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

but yeah, if it's just year and month then it could probably be passed directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The date format of the partnership start date will now be YYYY-MM. I've updated the PR message accordingly.

`process_report.py` will now use `nerc_rates` to determine if
the New-PI credit is limited to institutions that are MGHPCC
partners for the given invoice month.

The script determines whether an institution's MGHPCC partnership
is active by first seeing if the `mghpcc_partnership_start_date` field
is set in `institute_list.yaml`, then checks if the start date is
within or before the invoice month.

Also removed usernames from `institute_list.yaml`, as they are no
longer nessecary given the alias validation step.
Copy link
Collaborator

@naved001 naved001 left a comment

Choose a reason for hiding this comment

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

looks fine to me.

There is also some small cleanup. Namely, some functions in process_report.py
that have been moved to util.py were not removed during refactoring.

What was the small cleanup? whatever was moved from process_report.py to util.py in this PR seemed to be relevant?

@QuanMPhm
Copy link
Contributor Author

QuanMPhm commented Sep 30, 2024

@naved001 During the first refactor PR (#54) when the Invoice class was created, I moved get_institution_from_pi and ``load_institute_list to utils.py but forgot to remove the functions `process_report.py`, and also forgot to update the references to the function.

Functionally, this didn't change anything. Stylistically, it wasn't a big deal until this PR, since more references to these functions were added. While writing this PR, I just decided the two functions should be placed in utils.py, and so did the cleanup that I forgot to do when I made the initial refactor PR.

@naved001
Copy link
Collaborator

While writing this PR, I just decided the two functions should be placed in utils.py,

In the future I'd recommend separate commits for tangentially related cleanups.

@naved001 naved001 merged commit bc4f599 into CCI-MOC:main Sep 30, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sure Credit Code 0002 is only for MGHPCC Partners
4 participants