Skip to content

Commit

Permalink
Update recent conviction algorithm (#429)
Browse files Browse the repository at this point in the history
* Refactor MRC's method

Refactored so that MRC and 2MRC each have their own method.

* Refactor MRC tests

* added test_violation_is_not_most_recent, passed with Expunger change

* Add recent_convictions list to expunger

Done to make it easier to track recent convictions,
so we don't have to continually check if a charge is a recent_conviction.

Added test_recent_violation_and_nonrecent_misdemeanor to test if expunger is
correctly treating nonrecent charges.

* Add test for nonrecent misdemeanor and recent violation

The test is test_recent_violation_and_nonrecent_misdemeanor.

When there is a recent violation, test checks if nonrecent misdemeanor is set
as recent charge (it shouldn't be).

* Refactor: Extract Time class

This is being done to dry up the code since these date constants are
used in other classes.

* Remove dupliucate date constants

* Refactor: Use the Time data class

Using the new Time data class.

* Refactor test to dry out code

* Create run expunger method to dry out test code

* Add tests to handle new rule for considering violations

A single violation does not count as a recent conviction. It takes two
violations to count. See issue #382 for a detailed explanation.

* Update most recent convictions algorithm

Please see issue #382 for more details.

Fixes #382

* Update changelog
  • Loading branch information
NickSchimek authored Oct 2, 2019
1 parent 90b47a3 commit 0e7d7e6
Show file tree
Hide file tree
Showing 5 changed files with 344 additions and 152 deletions.
1 change: 1 addition & 0 deletions src/backend/expungeservice/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ v0.3.3
- The function to check if a case is closed now returns true when the term `Purgable` is encountered in the status. (386)
- Fixed issue where parking tickets that were acquitted were being tagged as type eligible. Parking tickets are never type eligible. (369)
- Fixed issue where some parking tickets were being missed due to the difference in reporting statute codes. Parking tickets are now created by case type `Municipal Parking` after statute creation fails. (#427)
- Fixed issue where a single violation would count as a recent conviction. Updated rules for MRC and second mrc to only apply a violation if there is a second violation. (429)


________________________________________________________________________________________________
Expand Down
43 changes: 33 additions & 10 deletions src/backend/expungeservice/expunger/expunger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Expunger:
"""

def __init__(self, record):
'''
"""
Constructor
most_recent_conviction: Most recent conviction if one exists from within the last ten years
second_most_recent_conviction: Second most recent conviction if one exists from within the last ten years
Expand All @@ -26,7 +26,7 @@ def __init__(self, record):
most_recent_charge: The most recent charge within the last 20yrs; excluding traffic violations
:param record: A Record object
'''
"""
self.record = record
self.charges = record.charges
self.errors = []
Expand All @@ -37,6 +37,7 @@ def __init__(self, record):
self.most_recent_charge = None
self.acquittals = []
self.convictions = []
self._recent_convictions = []
self.class_b_felonies = []

def run(self):
Expand All @@ -52,8 +53,10 @@ def run(self):
self._tag_skipped_charges()
self._remove_skipped_charges()
self._categorize_charges()
self._extract_most_recent_convictions()
self._set_most_recent_dismissal()
self._set_most_recent_convictions()
self._set_recent_conviction()
self._set_second_most_recent_conviction()
self._assign_most_recent_charge()
self._assign_class_b_felonies()
TimeAnalyzer.evaluate(self)
Expand Down Expand Up @@ -87,17 +90,37 @@ def _categorize_charges(self):
else:
self.convictions.append(charge)

def _extract_most_recent_convictions(self):
for charge in self.convictions:
if charge.recent_conviction():
self._recent_convictions.append(charge)

def _set_most_recent_dismissal(self):
self.acquittals.sort(key=lambda charge: charge.date)
if self.acquittals and self.acquittals[-1].recent_acquittal():
self.most_recent_dismissal = self.acquittals[-1]

def _set_most_recent_convictions(self):
self.convictions.sort(key=lambda charge: charge.disposition.date)
if len(self.convictions) > 0 and self.convictions[-1].recent_conviction():
self.most_recent_conviction = self.convictions[-1]
if len(self.convictions) > 1 and self.convictions[-2].recent_conviction():
self.second_most_recent_conviction = self.convictions[-2]
def _set_recent_conviction(self, set_mrc=True):
self._recent_convictions.sort(key=lambda charge: charge.disposition.date)
if len(self._recent_convictions) > 0:
if self._recent_convictions[-1].level != "Violation":
if set_mrc:
self.most_recent_conviction = self._recent_convictions[-1]
else:
self.second_most_recent_conviction = self._recent_convictions[-1]
elif len(self._recent_convictions) > 1:
if set_mrc:
self.most_recent_conviction = self._recent_convictions[-2]
else:
self.second_most_recent_conviction = self._recent_convictions[-2]

def _set_second_most_recent_conviction(self):
self._remove_mrc_from_recent_convictions()
self._set_recent_conviction(set_mrc=False)

def _remove_mrc_from_recent_convictions(self):
if self.most_recent_conviction:
self._recent_convictions.remove(self.most_recent_conviction)

def _assign_most_recent_charge(self):
self.charges.sort(key=lambda charge: charge.disposition.date, reverse=True)
Expand All @@ -106,5 +129,5 @@ def _assign_most_recent_charge(self):

def _assign_class_b_felonies(self):
for charge in self.charges:
if charge.__class__.__name__ == 'FelonyClassB':
if charge.__class__.__name__ == "FelonyClassB":
self.class_b_felonies.append(charge)
Loading

0 comments on commit 0e7d7e6

Please sign in to comment.