Skip to content

Commit

Permalink
Deuplicate project categories (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Anderson Banihirwe <13301940+andersy005@users.noreply.github.com>
Co-authored-by: Anderson Banihirwe <axbanihirwe@ualr.edu>
  • Loading branch information
3 people authored Nov 14, 2023
1 parent a4e0d55 commit 8f64fc8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions offsets_db_data/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,20 @@ def find_protocol(search_string: str, inverted_protocol_mapping: dict[str, list[

def get_protocol_category(protocol_strs: list[str] | str, protocol_mapping: dict) -> list[str]:
"""
Get category based on protocol string
Parameters
----------
protocol_strs : str or list
normalized protocol strings
protocol_mapping dict
metadata about normalized protocols
single protocol string or list of protocol strings
protocol_mapping: dict
metadata about normalized protocol strings
Returns
-------
list[str] :
list of category strings
categories : list[str]
list of category strings
"""

def _get_category(protocol_str, protocol_mapping):
Expand All @@ -352,14 +355,27 @@ def _get_category(protocol_str, protocol_mapping):

if isinstance(protocol_strs, str):
protocol_strs = [protocol_strs]
return [_get_category(protocol_str, protocol_mapping) for protocol_str in protocol_strs]
categories = [_get_category(protocol_str, protocol_mapping) for protocol_str in protocol_strs]
return list(
set(categories)
) # if multiple protocols have same category, just return category once


def harmonize_acr_status(row: pd.Series) -> str:
"""Derive single project status for CAR and ACR projects
Raw CAR and ACR data has two status columns -- one for compliance status, one for voluntary.
Handle and harmonize.
Parameters
----------
row : pd.Series
A row from a pandas DataFrame
Returns
-------
value : str
The status of the project
"""
if row['Compliance Program Status (ARB or Ecology)'] == 'Not ARB or Ecology Eligible':
return row['Voluntary Status'].lower()
Expand Down

0 comments on commit 8f64fc8

Please sign in to comment.