-
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 Two new fields, which are used internally by the scripts and never exported, have been added: - IS_BILLABLE_FIELD: Boolean field for whether the project is billable - MISSING_PI_FIELD: Boolean field that is True if PI name field is empty
- Loading branch information
Showing
7 changed files
with
129 additions
and
133 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
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
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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): | ||
nonbillable_pis: list[str] | ||
nonbillable_projects: list[str] | ||
|
||
@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(): | ||
if row[invoice.IS_BILLABLE_FIELD]: | ||
logger.warning( | ||
f"Billable project {row[invoice.PROJECT_FIELD]} has empty PI field" | ||
) | ||
return pandas.isna(data[invoice.PI_FIELD]) | ||
|
||
@staticmethod | ||
def _get_billables( | ||
data: pandas.DataFrame, | ||
nonbillable_pis: list[str], | ||
nonbillable_projects: list[str], | ||
): | ||
return ~data[invoice.PI_FIELD].isin(nonbillable_pis) & ~data[ | ||
invoice.PROJECT_FIELD | ||
].isin(nonbillable_projects) | ||
|
||
def _process(self): | ||
self.data[invoice.IS_BILLABLE_FIELD] = self._get_billables( | ||
self.data, self.nonbillable_pis, self.nonbillable_projects | ||
) | ||
self.data[invoice.MISSING_PI_FIELD] = 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