Skip to content

Commit

Permalink
Merge pull request #1719 from wittejm/attempt-to-commit-has-traffic-q…
Browse files Browse the repository at this point in the history
…uestion

Add traffic question to all 'Attempt' charges
  • Loading branch information
wittejm authored Jan 12, 2024
2 parents b349cf3 + 9af3222 commit b98f772
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 17 deletions.
16 changes: 11 additions & 5 deletions src/backend/expungeservice/charge_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ def _other_criminal_charges(statute):
@staticmethod
def _attempt_to_commit(name, level, statute):
if (level == "misdemeanor class a" or level == "felony class c") and "attempt to commit" in name:
question_string = "Was the underlying conduct a sex crime?"
question_string = "Was the underlying conduct a sex crime or traffic offense?"
charge_type_by_level = ChargeClassifier._classification_by_level(level, statute).ambiguous_charge_type[0]
options = {"Yes": SexCrime(), "No": charge_type_by_level}
options = {"Yes; sex crime": SexCrime(), "Yes; traffic offense": TrafficOffense(), "No": charge_type_by_level}
return ChargeClassifier._build_ambiguous_charge_type_with_question(question_string, options)
if level == "felony class b" and "attempt to commit" in name:
question_string = "Was this a drug-related charge?"
question_string = "Was this a drug-related or traffic-related charge?"
drug_crime_question_string = "Was the underlying substance marijuana?"
drug_crime_options = {
"Yes": MarijuanaEligible(severity_level="Felony Class C"),
Expand All @@ -158,16 +158,22 @@ def _attempt_to_commit(name, level, statute):
)
drug_crime_question_id = f"{question_string}-Yes-{drug_crime_classification.question.question_id}" # type: ignore
drug_crime_question = replace(drug_crime_classification.question, question_id=drug_crime_question_id)
charge_types = drug_crime_classification.ambiguous_charge_type + [PersonFelonyClassB()]
charge_types = drug_crime_classification.ambiguous_charge_type + [PersonFelonyClassB(), TrafficOffense()]
question = Question(
question_string,
question_string,
{
"Yes": Answer(question=drug_crime_question),
"Yes; drug-related": Answer(question=drug_crime_question),
"Yes; traffic-related": Answer(edit={"charge_type": TrafficOffense.__name__}),
"No": Answer(edit={"charge_type": PersonFelonyClassB.__name__}),
},
)
return AmbiguousChargeTypeWithQuestion(charge_types, question)
if "attempt to commit" in name: # for any other severity level
question_string = "Was the underlying conduct a traffic crime?"
charge_type_by_level = ChargeClassifier._classification_by_level(level, statute).ambiguous_charge_type[0]
options = {"Yes": TrafficOffense(), "No": charge_type_by_level}
return ChargeClassifier._build_ambiguous_charge_type_with_question(question_string, options)

@staticmethod
def _classification_by_level(level, statute):
Expand Down
93 changes: 93 additions & 0 deletions src/backend/expungeservice/demo_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,4 +614,97 @@ def build_search_results(
),
),
],
Alias("various", "attempts", "", ""): [
OeciCase(
summary=from_dict(
data_class=CaseSummary,
data={
**shared_case_data,
"current_status": "Closed",
"name": "John Notaperson",
"case_number": "123456",
"violation_type": "Offense Felony",
},
),
charges=(
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "123456-1",
"name": "Attempt to Commit a Class A Felony",
"statute": "161.405(2)(c)",
"level": "Felony Class B",
"date": date_class.today() - relativedelta(years=10),
"disposition": DispositionCreator.create(
date=date_class.today() - relativedelta(years=9, months=9), ruling="Convicted"
),
"balance_due_in_cents": 0,
},
),
),
),
OeciCase(
summary=from_dict(
data_class=CaseSummary,
data={
**shared_case_data,
"current_status": "Closed",
"name": "Jon Notaperson",
"case_number": "223456",
"violation_type": "Offense Felony",
"d"
"balance_due_in_cents": 0,
},
),
charges=(
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "223456-1",
"name": "Attempt to Commit a Class B Felony",
"statute": "161.405(2)(c)",
"level": "Felony Class C",
"date": date_class.today() - relativedelta(years=10),
"disposition": DispositionCreator.create(
date=date_class.today() - relativedelta(years=9, months=9), ruling="Convicted"
),
"balance_due_in_cents": 0,
},
),
),
),
OeciCase(
summary=from_dict(
data_class=CaseSummary,
data={
**shared_case_data,
"current_status": "Closed",
"name": "John Notaperson",
"case_number": "323456",
"violation_type": "Offense Misdemeanor",
"d"
"balance_due_in_cents": 0,
},
),
charges=(
from_dict(
data_class=OeciCharge,
data={
**shared_charge_data,
"ambiguous_charge_id": "323456-1",
"name": "Attempt to Commit a Class A Misdemeanor",
"statute": "161.405(2)(c)",
"level": "Misdemeanor Class B",
"date": date_class.today() - relativedelta(years=10),
"disposition": DispositionCreator.create(
date=date_class.today() - relativedelta(years=9, months=9), ruling="Convicted"
),
"balance_due_in_cents": 0,
},
),
),
),
],
}
45 changes: 45 additions & 0 deletions src/backend/tests/models/charge_types/test_attempt_to_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from expungeservice.models.charge_types.felony_class_c import FelonyClassC
from expungeservice.models.charge_types.sex_crimes import SexCrime
from expungeservice.models.charge_types.traffic_offense import TrafficOffense
from expungeservice.models.charge_types.misdemeanor_class_bc import MisdemeanorClassBC
from expungeservice.models.charge_types.marijuana_eligible import MarijuanaEligible
from expungeservice.models.charge_types.person_felony import PersonFelonyClassB
from expungeservice.models.charge_types.felony_class_b import FelonyClassB

from tests.factories.charge_factory import ChargeFactory
from tests.models.test_charge import Dispositions


def test_attempt_to_commit_felony_class_b_charge():
charge = ChargeFactory.create_ambiguous_charge(
name="Attempt to Commit a Class B Felony",
statute="161.405(2)(c)",
level="Felony Class C",
disposition=Dispositions.CONVICTED,
)
assert isinstance(charge[0].charge_type, SexCrime)
assert isinstance(charge[1].charge_type, TrafficOffense)
assert isinstance(charge[2].charge_type, FelonyClassC)

def test_attempt_to_commit_a_drug_crime():
charge = ChargeFactory.create_ambiguous_charge(
name="Attempt to Commit a Class A Felony",
statute="161.405(2)(c)",
level="Felony Class B",
disposition=Dispositions.CONVICTED,
)
assert isinstance(charge[0].charge_type, MarijuanaEligible)
assert isinstance(charge[1].charge_type, FelonyClassB)
assert isinstance(charge[2].charge_type, PersonFelonyClassB)
assert isinstance(charge[3].charge_type, TrafficOffense)

def test_attempt_to_commit_a_low_level_offense():
charge = ChargeFactory.create_ambiguous_charge(
name="Attempt to Commit a Class A Misdemeanor",
statute="161.405(2)(c)",
level="Misdemeanor Class B",
disposition=Dispositions.CONVICTED,
)
assert len(charge) == 2
assert isinstance(charge[0].charge_type, TrafficOffense)
assert isinstance(charge[1].charge_type, MisdemeanorClassBC)
12 changes: 0 additions & 12 deletions src/backend/tests/models/charge_types/test_felony_class_c.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from expungeservice.models.charge_types.dismissed_charge import DismissedCharge
from expungeservice.models.charge_types.felony_class_c import FelonyClassC
from expungeservice.models.charge_types.sex_crimes import SexCrime
from expungeservice.models.disposition import DispositionCreator
from expungeservice.models.expungement_result import EligibilityStatus

Expand Down Expand Up @@ -58,14 +57,3 @@ def test_felony_c_unrecognized_disposition():
charge.type_eligibility.reason
== "Eligible under 137.225(1)(b) for convictions or under 137.225(1)(d) for dismissals"
)


def test_attempt_to_commit_felony_class_b_charge():
charge = ChargeFactory.create_ambiguous_charge(
name="Attempt to Commit a Class B Felony",
statute="161.405(2)(c)",
level="Felony Class C",
disposition=Dispositions.CONVICTED,
)
assert isinstance(charge[0].charge_type, SexCrime)
assert isinstance(charge[1].charge_type, FelonyClassC)

0 comments on commit b98f772

Please sign in to comment.