Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More ineligibility categories #1678

Merged
merged 10 commits into from
Mar 16, 2023
62 changes: 40 additions & 22 deletions src/backend/expungeservice/charges_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def build_charges_for_summary_panel(record: Record) -> ChargesForSummaryPanel:
sorted(visible_charges, key=ChargesSummarizer._secondary_sort, reverse=True),
key=lambda charge: ChargesSummarizer._primary_sort(charge, record),
)
for label, charges in groupby(sorted_charges, key=lambda charge: ChargesSummarizer._get_label(charge, record)):

for label, charges in groupby(
sorted_charges, key=lambda charge: ChargesSummarizer._primary_sort(charge, record)[1]
):
charges_in_section: List[Tuple[str, List[Tuple[str, str]]]] = []
for case_number, case_charges in groupby(charges, key=lambda charge: charge.case_number):
case = ChargesSummarizer._get_case_by_case_number(record, case_number)
Expand All @@ -36,10 +39,25 @@ def build_charges_for_summary_panel(record: Record) -> ChargesForSummaryPanel:
def _primary_sort(charge: Charge, record: Record):
charge_eligibility = charge.expungement_result.charge_eligibility
if charge_eligibility:
this_case = ChargesSummarizer._get_case_by_case_number(record, charge.case_number)
case_has_ineligible_charge = ChargesSummarizer._get_case_has_ineligible_charge(this_case)
future_eligibility_label_on_case = ChargesSummarizer._get_future_eligibility_label_on_case(this_case)
label = charge_eligibility.label
no_balance = (
ChargesSummarizer._get_case_by_case_number(record, charge.case_number).summary.balance_due_in_cents == 0
)
no_balance = this_case.summary.balance_due_in_cents == 0

if label == "Eligible Now" and case_has_ineligible_charge:
if no_balance:
return 8, "Eligible on case with Ineligible charge"
else:
return 9, "Eligible If Balance Paid on case with Ineligible charge"

if label == "Eligible Now" and future_eligibility_label_on_case:
label = "Eligible on case with charge " + future_eligibility_label_on_case
if no_balance:
return 10, label
else:
return 11, label + " If Balance Paid"

if label == "Needs More Analysis":
return 0, label
elif label == "Ineligible":
Expand Down Expand Up @@ -70,24 +88,6 @@ def _secondary_sort(charge: Charge):
else:
return date.max()

@staticmethod
def _get_label(charge: Charge, record: Record):
no_balance = (
ChargesSummarizer._get_case_by_case_number(record, charge.case_number).summary.balance_due_in_cents == 0
)
charge_eligibility = charge.expungement_result.charge_eligibility
if charge_eligibility:
if (
charge_eligibility.label == "Needs More Analysis"
or charge_eligibility.label == "Ineligible"
or no_balance
):
return charge_eligibility.label
else:
return charge_eligibility.label + " If Balance Paid"
else:
return "" # TODO: Add error logging because this should be logged as an error

@staticmethod
def _get_case_by_case_number(record, case_number):
for case in record.cases:
Expand All @@ -100,3 +100,21 @@ def _get_case_balance_header_info_for_case(case, label):
return ""
else:
return f"{case.summary.location} {case.summary.case_number} – ${round(case.summary.get_balance_due(),2)}"

@staticmethod
def _get_case_has_ineligible_charge(case: Record):
for charge in case.charges:
if charge.expungement_result.charge_eligibility.label == "Ineligible":
return True
return False

@staticmethod
def _get_future_eligibility_label_on_case(case: Record):
date_sorted_charges = sorted(
case.charges,
key=lambda charge: charge.expungement_result.charge_eligibility.date_to_sort_label_by or date.max(),
)
if date_sorted_charges[0].expungement_result.charge_eligibility.date_to_sort_label_by:
return date_sorted_charges[0].expungement_result.charge_eligibility.label
else:
return None
135 changes: 58 additions & 77 deletions src/backend/expungeservice/demo_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,83 +360,6 @@ def build_search_results(
),
),
],
Alias("portland", "protester", "", ""): [
OeciCase(
summary=from_dict(
data_class=CaseSummary,
data={
**shared_case_data,
"current_status": "Open",
"name": "DEFUND POLICE",
"case_number": "100000",
"violation_type": "Offense Misdemeanor",
},
),
charges=(
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "100000-1",
"name": "Assaulting a Public Safety Officer",
"statute": "163.208",
"level": "Felony Class C",
},
),
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "100000-3",
"name": "Interfering w/ Peace/Parole and Probation Officer",
"statute": "162.247",
"level": "Misdemeanor Class A",
"date": date_class.today() + relativedelta(days=1),
},
),
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "100000-4",
"name": "Disorderly Conduct in the First Degree",
"statute": "166.0232A",
"level": "Misdemeanor Class A",
},
),
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "100000-5",
"name": "Resisting Arrest",
"statute": "162.315",
"level": "Misdemeanor Class A",
},
),
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "100000-6",
"name": "Riot",
"statute": "166.015",
"level": "Felony Class C",
},
),
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "100000-7",
"name": "Riot While Masked",
"statute": "166.015A",
"level": "Felony Class B",
},
),
),
),
],
Alias("more", "categories", "", ""): [
OeciCase(
summary=from_dict(
Expand Down Expand Up @@ -509,6 +432,20 @@ def build_search_results(
),
},
),
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "234567-2",
"name": "Assaulting a Public Safety Officer",
"statute": "163.208",
"level": "Felony Class C",
"date": date_class.today() - relativedelta(years=5),
"disposition": DispositionCreator.create(
date=date_class.today() - relativedelta(years=4, months=9), ruling="Dismissed"
),
},
),
),
),
OeciCase(
Expand Down Expand Up @@ -569,5 +506,49 @@ def build_search_results(
),
),
),
# Has an eligible and an ineligible charge
OeciCase(
summary=from_dict(
data_class=CaseSummary,
data={
**shared_case_data,
"current_status": "Closed",
"name": "John Notaperson",
"case_number": "555555",
"violation_type": "Offense Felony",
},
),
charges=(
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "555555-1",
"name": "Assault in the First Degree",
"statute": "999999",
"level": "Felony Class A",
"date": date_class.today() - relativedelta(years=5),
"disposition": DispositionCreator.create(
date=date_class.today() - relativedelta(years=4, months=9), ruling="Convicted"
),
"balance_due_in_cents": 0,
},
),
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "555555-2",
"name": "Harassment",
"statute": "163.208",
"level": "Felony Class C",
"date": date_class.today() - relativedelta(years=5),
"disposition": DispositionCreator.create(
date=date_class.today() - relativedelta(years=4, months=9), ruling="Dismissed"
),
},
),
),
),
],
}
12 changes: 7 additions & 5 deletions src/backend/tests/models/test_record_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,21 @@ def test_record_summarizer_multiple_cases():
],
),
(
"Clackamas 2 – $200.0",
"Baker 3 – $300.0",
[
(
case_partially_eligible.charges[0].ambiguous_charge_id,
case_possibly_eligible.charges[0].ambiguous_charge_id,
"Theft of services (CONVICTED) Charged Jan 1, 2010",
)
],
),
(
"Baker 3 – $300.0",
],
"Eligible If Balance Paid on case with Ineligible charge": [
(
"Clackamas 2 – $200.0",
[
(
case_possibly_eligible.charges[0].ambiguous_charge_id,
case_partially_eligible.charges[0].ambiguous_charge_id,
"Theft of services (CONVICTED) Charged Jan 1, 2010",
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function getEligibilityColor(eligibility: string) {
{
"Eligible Now": "green",
Ineligible: "red",
"Eligible on case with Ineligible charge": "red",
"Needs More Analysis": "purple",
}[eligibility] ?? "dark-blue"
);
Expand Down