Skip to content

Commit

Permalink
Merge pull request #4 from CCI-MOC/generate-non-billed-csv
Browse files Browse the repository at this point in the history
Generate non billed csv
  • Loading branch information
naved001 authored Nov 1, 2023
2 parents deb0d45 + 033b078 commit aef9254
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
10 changes: 10 additions & 0 deletions process_report/process_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def main():
projects = list(set(projects + timed_projects_list))

remove_non_billables(merged_dataframe, pi, projects, args.output_file)
remove_billables(merged_dataframe, pi, projects, "non_billable.csv")


def merge_csv(files):
Expand Down Expand Up @@ -96,5 +97,14 @@ def remove_non_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 remove_billables(dataframe, pi, projects, output_file):
"""Removes projects and PIs that should be billed from the dataframe
So this *keeps* the projects/pis that should not be billed.
"""
filtered_dataframe = dataframe[dataframe['Manager (PI)'].isin(pi) | dataframe['Project - Allocation'].isin(projects)]
filtered_dataframe.to_csv(output_file, index=False)

if __name__ == "__main__":
main()
36 changes: 31 additions & 5 deletions process_report/tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ class TestRemoveNonBillables(TestCase):
def setUp(self):

data = {
'Manager (PI)': ['PI1', 'PI2', 'PI3', 'PI4'],
'Project - Allocation': ['ProjectA', 'ProjectB', 'ProjectC', 'ProjectD'],
'Untouch Data Column': ['DataA', 'DataB', 'DataC', 'DataD']
'Manager (PI)': ['PI1', 'PI2', 'PI3', 'PI4', 'PI5'],
'Project - Allocation': ['ProjectA', 'ProjectB', 'ProjectC', 'ProjectD', 'ProjectE'],
'Untouch Data Column': ['DataA', 'DataB', 'DataC', 'DataD', 'DataE']
}
self.dataframe = pandas.DataFrame(data)

self.pi_to_exclude = ['PI2', 'PI3']
self.projects_to_exclude = ['ProjectB', 'ProjectC']
self.projects_to_exclude = ['ProjectB', 'ProjectD']

self.output_file = tempfile.NamedTemporaryFile(delete=False)
self.output_file2 = tempfile.NamedTemporaryFile(delete=False)

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

def test_remove_non_billables(self):
process_report.remove_non_billables(self.dataframe, self.pi_to_exclude, self.projects_to_exclude, self.output_file.name)
Expand All @@ -74,8 +76,32 @@ def test_remove_non_billables(self):

self.assertNotIn('PI2', result_df['Manager (PI)'].tolist())
self.assertNotIn('PI3', result_df['Manager (PI)'].tolist())
self.assertNotIn('PI4', result_df['Manager (PI)'].tolist()) # indirect because ProjectD was removed
self.assertNotIn('ProjectB', result_df['Project - Allocation'].tolist())
self.assertNotIn('ProjectC', result_df['Project - Allocation'].tolist())
self.assertNotIn('ProjectC', result_df['Project - Allocation'].tolist()) # indirect because PI3 was removed
self.assertNotIn('ProjectD', result_df['Project - Allocation'].tolist())

self.assertIn('PI1', result_df['Manager (PI)'].tolist())
self.assertIn('PI5', result_df['Manager (PI)'].tolist())
self.assertIn('ProjectA', result_df['Project - Allocation'].tolist())
self.assertIn('ProjectE', result_df['Project - Allocation'].tolist())

def test_remove_billables(self):
process_report.remove_billables(self.dataframe, self.pi_to_exclude, self.projects_to_exclude, self.output_file2.name)

result_df = pandas.read_csv(self.output_file2.name)

self.assertIn('PI2', result_df['Manager (PI)'].tolist())
self.assertIn('PI3', result_df['Manager (PI)'].tolist())
self.assertIn('PI4', result_df['Manager (PI)'].tolist())
self.assertIn('ProjectB', result_df['Project - Allocation'].tolist())
self.assertIn('ProjectC', result_df['Project - Allocation'].tolist())
self.assertIn('ProjectD', result_df['Project - Allocation'].tolist())

self.assertNotIn('PI1', result_df['Manager (PI)'].tolist())
self.assertNotIn('PI5', result_df['Manager (PI)'].tolist())
self.assertNotIn('ProjectA', result_df['Project - Allocation'].tolist())
self.assertNotIn('ProjectE', result_df['Project - Allocation'].tolist())


class TestMergeCSV(TestCase):
Expand Down

0 comments on commit aef9254

Please sign in to comment.