Skip to content

Commit c05231c

Browse files
authored
Merge pull request #197 from KelvinLinBU/clean-up
Removal of unused functions and variables
2 parents 38d7036 + 6fb4a83 commit c05231c

5 files changed

Lines changed: 9 additions & 116 deletions

File tree

process_report/process_report.py

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import sys
3-
import datetime
43
import logging
54
from decimal import Decimal
65
import os
@@ -11,6 +10,7 @@
1110

1211
from process_report import util
1312
from process_report.invoices import (
13+
invoice,
1414
lenovo_invoice,
1515
nonbillable_invoice,
1616
billable_invoice,
@@ -33,33 +33,6 @@
3333
validate_cluster_name_processor,
3434
)
3535

36-
### PI file field names
37-
PI_PI_FIELD = "PI"
38-
PI_FIRST_MONTH = "First Invoice Month"
39-
PI_INITIAL_CREDITS = "Initial Credits"
40-
PI_1ST_USED = "1st Month Used"
41-
PI_2ND_USED = "2nd Month Used"
42-
###
43-
44-
45-
### Invoice field names
46-
INVOICE_DATE_FIELD = "Invoice Month"
47-
PROJECT_FIELD = "Project - Allocation"
48-
PROJECT_ID_FIELD = "Project - Allocation ID"
49-
PI_FIELD = "Manager (PI)"
50-
INVOICE_EMAIL_FIELD = "Invoice Email"
51-
INVOICE_ADDRESS_FIELD = "Invoice Address"
52-
INSTITUTION_FIELD = "Institution"
53-
INSTITUTION_ID_FIELD = "Institution - Specific Code"
54-
SU_HOURS_FIELD = "SU Hours (GBhr or SUhr)"
55-
SU_TYPE_FIELD = "SU Type"
56-
RATE_FIELD = "Rate"
57-
COST_FIELD = "Cost"
58-
CREDIT_FIELD = "Credit"
59-
CREDIT_CODE_FIELD = "Credit Code"
60-
SUBSIDY_FIELD = "Subsidy"
61-
BALANCE_FIELD = "Balance"
62-
###
6336

6437
PI_S3_FILEPATH = "PIs/PI.csv"
6538
ALIAS_S3_FILEPATH = "PIs/alias.csv"
@@ -96,10 +69,6 @@ def load_prepay_csv(prepay_credits_path, prepay_projects_path, prepay_contacts_p
9669
)
9770

9871

99-
def get_iso8601_time():
100-
return datetime.datetime.now().strftime("%Y%m%dT%H%M%SZ")
101-
102-
10372
def validate_required_env_vars(required_env_vars):
10473
for required_env_var in required_env_vars:
10574
if required_env_var not in os.environ:
@@ -116,11 +85,6 @@ def main():
11685
nargs="*",
11786
help="One or more CSV files that need to be processed",
11887
)
119-
parser.add_argument(
120-
"--fetch-from-s3",
121-
action="store_true",
122-
help="If set, fetches invoices from S3 storage. Requires environment variables for S3 authentication to be set",
123-
)
12488
parser.add_argument(
12589
"--upload-to-s3",
12690
action="store_true",
@@ -447,8 +411,8 @@ def merge_csv(files):
447411
dataframe = pandas.read_csv(
448412
file,
449413
dtype={
450-
COST_FIELD: pandas.ArrowDtype(pyarrow.decimal128(12, 2)),
451-
RATE_FIELD: str,
414+
invoice.COST_FIELD: pandas.ArrowDtype(pyarrow.decimal128(12, 2)),
415+
invoice.RATE_FIELD: str,
452416
},
453417
)
454418
dataframes.append(dataframe)
@@ -458,17 +422,6 @@ def merge_csv(files):
458422
return merged_dataframe
459423

460424

461-
def get_invoice_date(dataframe):
462-
"""Returns the invoice date as a pandas timestamp object
463-
464-
Note that it only checks the first entry because it should
465-
be the same for every row.
466-
"""
467-
invoice_date_str = dataframe[INVOICE_DATE_FIELD][0]
468-
invoice_date = pandas.to_datetime(invoice_date_str, format="%Y-%m")
469-
return invoice_date
470-
471-
472425
def timed_projects(timed_projects_file, invoice_date):
473426
"""Returns list of projects that should be excluded based on dates"""
474427
dataframe = pandas.read_csv(timed_projects_file)
@@ -487,11 +440,9 @@ def timed_projects(timed_projects_file, invoice_date):
487440

488441
def backup_to_s3_old_pi_file(old_pi_file):
489442
invoice_bucket = util.get_invoice_bucket()
490-
invoice_bucket.upload_file(old_pi_file, f"PIs/Archive/PI {get_iso8601_time()}.csv")
491-
492-
493-
def export_billables(dataframe, output_file):
494-
dataframe.to_csv(output_file, index=False)
443+
invoice_bucket.upload_file(
444+
old_pi_file, f"PIs/Archive/PI {util.get_iso8601_time()}.csv"
445+
)
495446

496447

497448
def get_lenovo_su_charge_info(invoice_month, rates_info):

process_report/tests/unit/processors/test_validate_billable_pi_processor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
class TestValidateBillablePIProcessor(TestCase):
1010
def test_remove_nonbillables(self):
11-
pis = [uuid.uuid4().hex for x in range(10)]
12-
projects = [uuid.uuid4().hex for x in range(10)]
13-
cluster_names = [uuid.uuid4().hex for x in range(10)]
11+
pis = [uuid.uuid4().hex for _ in range(10)]
12+
projects = [uuid.uuid4().hex for _ in range(10)]
13+
cluster_names = [uuid.uuid4().hex for _ in range(10)]
1414
cluster_names[6:8] = ["ocp-test"] * 2 # Test that ocp-test is not billable
1515
nonbillable_pis = pis[:3]
1616
nonbillable_projects = [

process_report/tests/unit/test_util.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,6 @@ def test_merge_csv(self):
5959
self.assertListEqual(merged_dataframe.columns.tolist(), self.header)
6060

6161

62-
class TestGetInvoiceDate(TestCase):
63-
def test_get_invoice_date(self):
64-
# The month in sample data is not the same
65-
data = {"Invoice Month": ["2023-01", "2023-02", "2023-03"]}
66-
dataframe = pandas.DataFrame(data)
67-
68-
invoice_date = process_report.get_invoice_date(dataframe)
69-
70-
self.assertIsInstance(invoice_date, pandas.Timestamp)
71-
72-
# Assert that the invoice_date is the first item
73-
expected_date = pandas.Timestamp("2023-01")
74-
self.assertEqual(invoice_date, expected_date)
75-
76-
7762
class TestTimedProjects(TestCase):
7863
def setUp(self):
7964
# Without the dedent method, our data will have leading spaces which

process_report/tests/util.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
from process_report.invoices import (
44
invoice,
5-
billable_invoice,
65
pi_specific_invoice,
76
prepay_credits_snapshot,
87
NERC_total_invoice,
98
)
109

1110
from process_report.processors import (
1211
coldfront_fetch_processor,
13-
add_institution_processor,
1412
validate_pi_alias_processor,
1513
lenovo_processor,
1614
validate_billable_pi_processor,
@@ -31,30 +29,6 @@ def new_base_invoice(
3129
return invoice.Invoice(name, invoice_month, data)
3230

3331

34-
def new_billable_invoice(
35-
name="",
36-
invoice_month="0000-00",
37-
data=None,
38-
nonbillable_pis=None,
39-
nonbillable_projects=None,
40-
old_pi_filepath="",
41-
updated_old_pi_df=pandas.DataFrame(),
42-
):
43-
if data is None:
44-
data = pandas.DataFrame()
45-
if nonbillable_pis is None:
46-
nonbillable_pis = []
47-
if nonbillable_projects is None:
48-
nonbillable_projects = []
49-
return billable_invoice.BillableInvoice(
50-
name,
51-
invoice_month,
52-
data,
53-
old_pi_filepath,
54-
updated_old_pi_df,
55-
)
56-
57-
5832
def new_pi_specific_invoice(
5933
name="",
6034
invoice_month="0000-00",
@@ -99,16 +73,6 @@ def new_coldfront_fetch_processor(
9973
)
10074

10175

102-
def new_add_institution_processor(
103-
name="",
104-
invoice_month="0000-00",
105-
data=None,
106-
):
107-
if data is None:
108-
data = pandas.DataFrame()
109-
return add_institution_processor.AddInstitutionProcessor(name, invoice_month, data)
110-
111-
11276
def new_validate_pi_alias_processor(
11377
name="", invoice_month="0000-00", data=None, alias_map=None
11478
):

process_report/util.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ def get_iso8601_time():
6565
return datetime.datetime.now().strftime("%Y%m%dT%H%M%SZ")
6666

6767

68-
def compare_invoice_month(month_1, month_2):
69-
"""Returns True if 1st date is later than 2nd date"""
70-
dt1 = datetime.datetime.strptime(month_1, "%Y-%m")
71-
dt2 = datetime.datetime.strptime(month_2, "%Y-%m")
72-
return dt1 > dt2
73-
74-
7568
def get_month_diff(month_1, month_2):
7669
"""Returns a positive integer if month_1 is ahead in time of month_2"""
7770
dt1 = datetime.datetime.strptime(month_1, "%Y-%m")

0 commit comments

Comments
 (0)