Skip to content

Commit

Permalink
Added processing and exporting for Lenovo SU Types
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanMPhm committed Apr 5, 2024
1 parent 12dbf39 commit ce3fbe0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions process_report/process_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def main():
export_pi_billables(billable_projects, args.output_folder)
export_HU_only(billable_projects, args.HU_only)
export_HU_BU(billable_projects, args.HU_BU)
export_lenovo(billable_projects)


def merge_csv(files):
Expand Down Expand Up @@ -275,5 +276,25 @@ def export_HU_BU(dataframe, output_file):
HU_BU_projects.to_csv(output_file)


def export_lenovo(dataframe: pandas.DataFrame, output_file=None):

lenovo_file_name = output_file or f'Lenovo_{dataframe[INVOICE_DATE_FIELD].iat[0]}.csv'

LENOVO_SU_TYPES = ['OpenShift GPUA100SXM4', 'OpenStack GPUA100SXM4']
SU_CHARGE_MULTIPLIER = 1

lenovo_df = dataframe[dataframe[SU_TYPE_FIELD].isin(LENOVO_SU_TYPES)][[
INVOICE_DATE_FIELD,
PROJECT_FIELD,
INSTITUTION_FIELD,
SU_HOURS_FIELD,
SU_TYPE_FIELD]]

lenovo_df.rename(columns={SU_HOURS_FIELD: 'SU Hours'}, inplace=True)
lenovo_df.insert(len(lenovo_df.columns), 'SU Charge', SU_CHARGE_MULTIPLIER)
lenovo_df['Charge'] = lenovo_df['SU Hours'] * lenovo_df['SU Charge']
lenovo_df.to_csv(lenovo_file_name)


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions process_report/tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,40 @@ def test_apply_credit_0002(self):
self.assertEqual(0, credited_projects[credited_projects['Project - Allocation'] == 'ProjectE']['Balance'].iloc[0])
self.assertEqual(800, credited_projects[credited_projects['Project - Allocation'] == 'ProjectF']['Balance'].iloc[0])


class TestExportLenovo(TestCase):
def setUp(self):

data = {
'Invoice Month': ['2023-01','2023-01','2023-01','2023-01','2023-01', '2023-01'],
'Project - Allocation': ['ProjectA', 'ProjectB', 'ProjectC', 'ProjectD', 'ProjectE', 'ProjectF'],
'Institution': ['A', 'B', 'C', 'D', 'E', 'F'],
'SU Hours (GBhr or SUhr)': [1, 10, 100, 4, 432, 10],
'SU Type': ['OpenShift GPUA100SXM4', 'CPU', 'OpenShift GPUA100SXM4', 'OpenStack GPUA100SXM4', 'CPU', 'GPU']
}
self.dataframe = pandas.DataFrame(data)

output_file = tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.csv')
self.output_file = output_file.name

def tearDown(self):
os.remove(self.output_file)


def test_apply_credit_0002(self):
process_report.export_lenovo(self.dataframe, self.output_file)
output_df = pandas.read_csv(self.output_file)

self.assertTrue(set([
process_report.INVOICE_DATE_FIELD,
process_report.PROJECT_FIELD,
process_report.INSTITUTION_FIELD,
process_report.SU_TYPE_FIELD,
'SU Hours',
'SU Charge',
'Charge',
]).issubset(output_df))

for i, row in output_df.iterrows():
self.assertIn(row[process_report.SU_TYPE_FIELD], ['OpenShift GPUA100SXM4', 'OpenStack GPUA100SXM4'])
self.assertEqual(row['Charge'], row['SU Charge'] * row['SU Hours'])

0 comments on commit ce3fbe0

Please sign in to comment.