From 4dee7c3977ae17f67ed1976ee1cb42075e579780 Mon Sep 17 00:00:00 2001 From: Quan Pham Date: Fri, 29 Mar 2024 16:28:47 -0400 Subject: [PATCH] Revert "Added ability to group invoices by PIs" This reverts commit 52859c97b519be91427e45948e67e175de231db5. --- .gitignore | 4 +-- process_report/process_report.py | 24 +---------------- process_report/tests/unit_tests.py | 41 ------------------------------ 3 files changed, 2 insertions(+), 67 deletions(-) diff --git a/.gitignore b/.gitignore index 7248b74..16f2dc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -*.csv -__pycache__/ -*.py[cod] +*.csv \ No newline at end of file diff --git a/process_report/process_report.py b/process_report/process_report.py index 0ea7cfa..647e5b0 100644 --- a/process_report/process_report.py +++ b/process_report/process_report.py @@ -1,5 +1,4 @@ import argparse -import os import pandas @@ -35,12 +34,6 @@ def main(): default="filtered_output.csv", help="Name of output file", ) - parser.add_argument( - "--output-folder", - required=False, - default="pi_invoices", - help="Name of output folder containing pi-specific invoice csvs" - ) args = parser.parse_args() merged_dataframe = merge_csv(args.csv_files) @@ -60,9 +53,8 @@ def main(): projects = list(set(projects + timed_projects_list)) - billable_projects = remove_non_billables(merged_dataframe, pi, projects, args.output_file) + remove_non_billables(merged_dataframe, pi, projects, args.output_file) remove_billables(merged_dataframe, pi, projects, "non_billable.csv") - export_pi_billables(billable_projects, args.output_folder) def merge_csv(files): @@ -104,7 +96,6 @@ def remove_non_billables(dataframe, pi, projects, output_file): """Removes projects and PIs that should not be billed from the dataframe""" filtered_dataframe = dataframe[~dataframe['Manager (PI)'].isin(pi) & ~dataframe['Project - Allocation'].isin(projects)] filtered_dataframe.to_csv(output_file, index=False) - return filtered_dataframe def remove_billables(dataframe, pi, projects, output_file): @@ -115,18 +106,5 @@ def remove_billables(dataframe, pi, projects, output_file): filtered_dataframe = dataframe[dataframe['Manager (PI)'].isin(pi) | dataframe['Project - Allocation'].isin(projects)] filtered_dataframe.to_csv(output_file, index=False) -def export_pi_billables(dataframe: pandas.DataFrame, output_folder): - if not os.path.exists(output_folder): - os.mkdir(output_folder) - - invoice_month = dataframe['Invoice Month'][0] - pi_list = dataframe['Manager (PI)'].unique() - - for pi in pi_list: - pi_projects = dataframe[dataframe['Manager (PI)'] == pi] - pi_instituition = pi_projects['Institution'].unique()[0] - pi_projects.to_csv(output_folder + f"/{pi_instituition}_{pi}_{invoice_month}.csv") - - if __name__ == "__main__": main() diff --git a/process_report/tests/unit_tests.py b/process_report/tests/unit_tests.py index 15768d9..971577f 100644 --- a/process_report/tests/unit_tests.py +++ b/process_report/tests/unit_tests.py @@ -2,7 +2,6 @@ import tempfile import pandas import os -import shutil from textwrap import dedent from process_report import process_report @@ -135,43 +134,3 @@ def test_merge_csv(self): # Assert that the headers in the merged DataFrame match the expected headers self.assertListEqual(merged_dataframe.columns.tolist(), self.header) - -class TestExportPICSV(TestCase): - def setUp(self): - - data = { - 'Invoice Month': ['2023-01','2023-01','2023-01','2023-01','2023-01'], - 'Manager (PI)': ['PI1', 'PI1', 'PI1', 'PI2', 'PI2'], - 'Institution': ['BU', 'BU', 'BU', 'HU', 'HU'], - 'Project - Allocation': ['ProjectA', 'ProjectB', 'ProjectC', 'ProjectD', 'ProjectE'], - 'Untouch Data Column': ['DataA', 'DataB', 'DataC', 'DataD', 'DataE'] - } - self.dataframe = pandas.DataFrame(data) - - def test_export_pi(self): - output_dir = tempfile.TemporaryDirectory() - process_report.export_pi_billables(self.dataframe, output_dir.name) - - pi_csv_1 = f'{self.dataframe["Institution"][0]}_{self.dataframe["Manager (PI)"][0]}_{self.dataframe["Invoice Month"][0]}.csv' - pi_csv_2 = f'{self.dataframe["Institution"][3]}_{self.dataframe["Manager (PI)"][3]}_{self.dataframe["Invoice Month"][3]}.csv' - self.assertIn(pi_csv_1, os.listdir(output_dir.name)) - self.assertIn(pi_csv_2, os.listdir(output_dir.name)) - self.assertEqual(len(os.listdir(output_dir.name)), len(self.dataframe['Manager (PI)'].unique())) - - pi_df = pandas.read_csv(output_dir.name + '/' + pi_csv_1) - self.assertEqual(len(pi_df['Manager (PI)'].unique()), 1) - self.assertEqual(pi_df['Manager (PI)'].unique()[0], self.dataframe['Manager (PI)'][0]) - - self.assertIn('ProjectA', pi_df['Project - Allocation'].tolist()) - self.assertIn('ProjectB', pi_df['Project - Allocation'].tolist()) - self.assertIn('ProjectC', pi_df['Project - Allocation'].tolist()) - - pi_df = pandas.read_csv(output_dir.name + '/' + pi_csv_2) - self.assertEqual(len(pi_df['Manager (PI)'].unique()), 1) - self.assertEqual(pi_df['Manager (PI)'].unique()[0], self.dataframe['Manager (PI)'][3]) - - self.assertIn('ProjectD', pi_df['Project - Allocation'].tolist()) - self.assertIn('ProjectE', pi_df['Project - Allocation'].tolist()) - self.assertNotIn('ProjectA', pi_df['Project - Allocation'].tolist()) - self.assertNotIn('ProjectB', pi_df['Project - Allocation'].tolist()) - self.assertNotIn('ProjectC', pi_df['Project - Allocation'].tolist())