-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented processors for removing nonbillables and validating billa…
…ble PIs
- Loading branch information
Showing
6 changed files
with
134 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
process_report/processors/remove_nonbillables_processor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from dataclasses import dataclass | ||
|
||
import pandas | ||
|
||
from process_report.invoices import invoice | ||
from process_report.processors import processor | ||
|
||
|
||
@dataclass | ||
class RemoveNonbillables(processor.Processor): | ||
nonbillable_pis: list[str] | ||
nonbillable_projects: list[str] | ||
|
||
@staticmethod | ||
def _remove_nonbillables( | ||
data: pandas.DataFrame, | ||
nonbillable_pis: list[str], | ||
nonbillable_projects: list[str], | ||
): | ||
return data[ | ||
~data[invoice.PI_FIELD].isin(nonbillable_pis) | ||
& ~data[invoice.PROJECT_FIELD].isin(nonbillable_projects) | ||
] | ||
|
||
def _process(self): | ||
self.data = self._remove_nonbillables( | ||
self.data, self.nonbillable_pis, self.nonbillable_projects | ||
) |
25 changes: 25 additions & 0 deletions
25
process_report/processors/validate_billable_pi_processor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from dataclasses import dataclass | ||
import logging | ||
|
||
import pandas | ||
|
||
from process_report.invoices import invoice | ||
from process_report.processors import processor | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
@dataclass | ||
class ValidateBillablePIsProcessor(processor.Processor): | ||
@staticmethod | ||
def _validate_pi_names(data: pandas.DataFrame): | ||
invalid_pi_projects = data[pandas.isna(data[invoice.PI_FIELD])] | ||
for i, row in invalid_pi_projects.iterrows(): | ||
logger.warn( | ||
f"Billable project {row[invoice.PROJECT_FIELD]} has empty PI field" | ||
) | ||
return data[~pandas.isna(data[invoice.PI_FIELD])] | ||
|
||
def _process(self): | ||
self.data = self._validate_pi_names(self.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters