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

Added processing and exporting for Lenovo SU Types #14

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions process_report/process_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def main():
export_pi_billables(billable_projects, args.output_folder)
export_HU_only(billable_projects, args.HU_invoice_file)
export_HU_BU(billable_projects, args.HU_BU_invoice_file)
export_lenovo(billable_projects)


def merge_csv(files):
Expand Down Expand Up @@ -295,5 +296,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']
joachimweyl marked this conversation as resolved.
Show resolved Hide resolved
SU_CHARGE_MULTIPLIER = 1
knikolla marked this conversation as resolved.
Show resolved Hide resolved

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()
38 changes: 38 additions & 0 deletions process_report/tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,41 @@ def test_validate_billables(self):
self.assertEqual(1, len(self.dataframe[pandas.isna(self.dataframe['Manager (PI)'])]))
validated_df = process_report.validate_pi_names(self.dataframe)
self.assertEqual(0, len(validated_df[pandas.isna(validated_df['Manager (PI)'])]))


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', 'OpenShift GPUA100', 'OpenShift GPUA100SXM4', 'OpenStack GPUA100SXM4', 'OpenStack CPU', 'OpenStack GPUK80']
}
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'])
Loading