def run(self):
        """
        Evaluates the expungement eligibility of a record.

        :return: True if there are no open cases; otherwise False
        """
        if self._open_cases():
            self._create_charge_list_from_closed_cases()
            self._type_analyzer.evaluate(self._charges)
            self.errors.append('Open cases exist')
            return False

        self._create_charge_list()
        self._categorize_charges()
        self._set_most_recent_dismissal()
        self._set_most_recent_convictions()
        self._set_num_acquittals()
        self._assign_most_recent_charge()
        self._type_analyzer.evaluate(self._charges)
        self._time_analyzer = TimeAnalyzer(most_recent_conviction=self._most_recent_conviction,
                                           second_most_recent_conviction=self._second_most_recent_conviction,
                                           most_recent_dismissal=self._most_recent_dismissal,
                                           num_acquittals=self._num_acquittals,
                                           class_b_felonies=self._type_analyzer.class_b_felonies,
                                           most_recent_charge=self._most_recent_charge)
        self._time_analyzer.evaluate(self._charges)
        return True
    def test_more_than_ten_year_old_conviction(self):
        charge = ChargeFactory.create(disposition=['Convicted', Time.TEN_YEARS_AGO])

        self.expunger.charges = [charge]
        TimeAnalyzer.evaluate(self.expunger)

        assert charge.expungement_result.time_eligibility.status is True
        assert charge.expungement_result.time_eligibility.reason == ''
        assert charge.expungement_result.time_eligibility.date_will_be_eligible is None
    def test_more_than_three_year_rule_conviction(self):
        charge = ChargeFactory.create(disposition=['Convicted', Time.THREE_YEARS_AGO])

        self.expunger.most_recent_conviction = charge
        self.expunger.charges = [charge]
        TimeAnalyzer.evaluate(self.expunger)

        assert charge.expungement_result.time_eligibility is True
        assert charge.expungement_result.time_eligibility_reason == ''
        assert charge.expungement_result.date_of_eligibility is None
    def test_more_than_ten_year_old_conviction(self):
        charge = ChargeFactory.create(
            disposition=["Convicted", Time.TEN_YEARS_AGO])

        charges_with_summary = ChargesWithSummary(charges=[charge])
        TimeAnalyzer.evaluate(charges_with_summary)

        assert charge.expungement_result.time_eligibility.status is EligibilityStatus.ELIGIBLE
        assert charge.expungement_result.time_eligibility.reason == ""
        assert charge.expungement_result.time_eligibility.date_will_be_eligible is None
    def test_less_than_three_year_rule_conviction(self):
        charge = ChargeFactory.create(disposition=['Convicted', Time.LESS_THAN_THREE_YEARS_AGO])

        self.expunger.most_recent_conviction = charge
        self.expunger.charges = [charge]
        TimeAnalyzer.evaluate(self.expunger)

        assert charge.expungement_result.time_eligibility.status is False
        assert charge.expungement_result.time_eligibility.reason == 'Most recent conviction is less than three years old'
        assert charge.expungement_result.time_eligibility.date_will_be_eligible == date.today() + relativedelta(days=+1)
    def test_less_than_three_year_rule_conviction(self):
        charge = ChargeFactory.create(
            disposition=["Convicted", Time.LESS_THAN_THREE_YEARS_AGO])

        charges_with_summary = ChargesWithSummary(
            charges=[charge], most_recent_conviction=charge)
        TimeAnalyzer.evaluate(charges_with_summary)

        assert charge.expungement_result.time_eligibility.status is EligibilityStatus.INELIGIBLE
        assert (charge.expungement_result.time_eligibility.reason ==
                "Most recent conviction is less than three years old")
        assert charge.expungement_result.time_eligibility.date_will_be_eligible == date.today(
        ) + relativedelta(days=+1)
    def test_time_eligibility_date_is_none_when_type_ineligible(self):
        charge = ChargeFactory.create(name='Assault in the first degree',
                                      statute='163.185',
                                      level='Felony Class A',
                                      date=Time.ONE_YEAR_AGO,
                                      disposition=['Convicted', Time.ONE_YEAR_AGO])

        self.expunger.most_recent_conviction = charge
        self.expunger.charges = [charge]
        TimeAnalyzer.evaluate(self.expunger)

        assert charge.expungement_result.time_eligibility.status is False
        assert charge.expungement_result.time_eligibility.reason == 'Most recent conviction is less than three years old'
        assert charge.expungement_result.time_eligibility.date_will_be_eligible is None
    def test_10_yr_old_conviction_with_less_than_3_yr_old_mrc(self):
        ten_yr_charge = ChargeFactory.create(disposition=['Convicted', Time.TEN_YEARS_AGO])
        less_than_three_yr_mrc = ChargeFactory.create(disposition=['Convicted', Time.LESS_THAN_THREE_YEARS_AGO])

        self.expunger.most_recent_conviction = less_than_three_yr_mrc
        self.expunger.charges = [ten_yr_charge, less_than_three_yr_mrc]
        TimeAnalyzer.evaluate(self.expunger)

        assert ten_yr_charge.expungement_result.time_eligibility.status is False
        assert ten_yr_charge.expungement_result.time_eligibility.reason == 'Time-ineligible under 137.225(7)(b)'
        assert ten_yr_charge.expungement_result.time_eligibility.date_will_be_eligible == less_than_three_yr_mrc.disposition.date + Time.TEN_YEARS

        assert less_than_three_yr_mrc.expungement_result.time_eligibility.status is False
        assert less_than_three_yr_mrc.expungement_result.time_eligibility.reason == 'Most recent conviction is less than three years old'
        assert less_than_three_yr_mrc.expungement_result.time_eligibility.date_will_be_eligible == date.today() + relativedelta(days=+1)
    def test_10_yr_old_conviction_with_3_yr_old_mrc(self):
        ten_yr_charge = ChargeFactory.create(disposition=['Convicted', Time.TEN_YEARS_AGO])
        three_yr_mrc = ChargeFactory.create(disposition=['Convicted', Time.THREE_YEARS_AGO])

        self.expunger.most_recent_conviction = three_yr_mrc
        self.expunger.charges = [ten_yr_charge, three_yr_mrc]
        TimeAnalyzer.evaluate(self.expunger)

        assert ten_yr_charge.expungement_result.time_eligibility.status is False
        assert ten_yr_charge.expungement_result.time_eligibility.reason == 'Time-ineligible under 137.225(7)(b)'
        assert ten_yr_charge.expungement_result.time_eligibility.date_will_be_eligible == three_yr_mrc.disposition.date + Time.TEN_YEARS

        assert three_yr_mrc.expungement_result.time_eligibility.status is True
        assert three_yr_mrc.expungement_result.time_eligibility.reason == ''
        assert three_yr_mrc.expungement_result.time_eligibility.date_will_be_eligible is None
    def test_felony_class_b_less_than_20yrs(self):
        charge = ChargeFactory.create(name='Aggravated theft in the first degree',
                                      statute='164.057',
                                      level='Felony Class B',
                                      date=Time.LESS_THAN_TWENTY_YEARS_AGO,
                                      disposition=['Convicted', Time.LESS_THAN_TWENTY_YEARS_AGO])

        self.expunger.class_b_felonies = [charge]
        self.expunger.most_recent_charge = charge

        self.expunger.charges = [charge]
        TimeAnalyzer.evaluate(self.expunger)

        assert charge.expungement_result.time_eligibility.status is False
        assert charge.expungement_result.time_eligibility.reason == 'Time-ineligible under 137.225(5)(a)(A)(i)'
        assert charge.expungement_result.time_eligibility.date_will_be_eligible == Time.TOMORROW
    def test_felony_class_b_greater_than_20yrs(self):
        charge = ChargeFactory.create(name='Aggravated theft in the first degree',
                                      statute='164.057',
                                      level='Felony Class B',
                                      date=Time.TWENTY_YEARS_AGO,
                                      disposition=['Convicted', Time.TWENTY_YEARS_AGO])

        self.expunger.class_b_felonies = [charge]
        self.expunger.most_recent_charge = charge

        self.expunger.charges = [charge]
        TimeAnalyzer.evaluate(self.expunger)

        assert charge.expungement_result.time_eligibility.status is True
        assert charge.expungement_result.time_eligibility.reason == ''
        assert charge.expungement_result.time_eligibility.date_will_be_eligible is None
    def test_time_eligibility_date_is_none_when_type_ineligible(self):
        charge = ChargeFactory.create(
            name="Assault in the first degree",
            statute="163.185",
            level="Felony Class A",
            date=Time.ONE_YEAR_AGO,
            disposition=["Convicted", Time.ONE_YEAR_AGO],
        )

        charges_with_summary = ChargesWithSummary(
            charges=[charge], most_recent_conviction=charge)
        TimeAnalyzer.evaluate(charges_with_summary)

        assert charge.expungement_result.time_eligibility.status is EligibilityStatus.INELIGIBLE
        assert (charge.expungement_result.time_eligibility.reason ==
                "Most recent conviction is less than three years old")
        assert charge.expungement_result.time_eligibility.date_will_be_eligible is None
Esempio n. 13
0
    def run(self):
        """
        Evaluates the expungement eligibility of a record.

        :return: True if there are no open cases; otherwise False
        """
        if self._open_cases():
            self.errors.append('Open cases exist')
            return False

        self._tag_skipped_charges()
        self._remove_skipped_charges()
        self._categorize_charges()
        self._set_most_recent_dismissal()
        self._set_most_recent_convictions()
        self._assign_most_recent_charge()
        self._assign_class_b_felonies()
        TimeAnalyzer.evaluate(self)
        return True
    def test_10_yr_old_conviction_with_3_yr_old_mrc(self):
        ten_yr_charge = ChargeFactory.create(
            disposition=["Convicted", Time.TEN_YEARS_AGO])
        three_yr_mrc = ChargeFactory.create(
            disposition=["Convicted", Time.THREE_YEARS_AGO])

        charges = [ten_yr_charge, three_yr_mrc]
        charges_with_summary = ChargesWithSummary(
            charges=charges, most_recent_conviction=three_yr_mrc)
        TimeAnalyzer.evaluate(charges_with_summary)

        assert ten_yr_charge.expungement_result.time_eligibility.status is EligibilityStatus.INELIGIBLE
        assert ten_yr_charge.expungement_result.time_eligibility.reason == "Time-ineligible under 137.225(7)(b)"
        assert (ten_yr_charge.expungement_result.time_eligibility.
                date_will_be_eligible == three_yr_mrc.disposition.date +
                Time.TEN_YEARS)

        assert three_yr_mrc.expungement_result.time_eligibility.status is EligibilityStatus.ELIGIBLE
        assert three_yr_mrc.expungement_result.time_eligibility.reason == ""
        assert three_yr_mrc.expungement_result.time_eligibility.date_will_be_eligible is None
    def test_10_yr_old_conviction_with_less_than_3_yr_old_mrc(self):
        ten_yr_charge = ChargeFactory.create(
            disposition=["Convicted", Time.TEN_YEARS_AGO])
        less_than_three_yr_mrc = ChargeFactory.create(
            disposition=["Convicted", Time.LESS_THAN_THREE_YEARS_AGO])

        charges_with_summary = ChargesWithSummary(
            charges=[ten_yr_charge, less_than_three_yr_mrc],
            most_recent_conviction=less_than_three_yr_mrc)
        TimeAnalyzer.evaluate(charges_with_summary)

        assert ten_yr_charge.expungement_result.time_eligibility.status is EligibilityStatus.INELIGIBLE
        assert ten_yr_charge.expungement_result.time_eligibility.reason == "Time-ineligible under 137.225(7)(b)"
        assert (
            ten_yr_charge.expungement_result.time_eligibility.
            date_will_be_eligible == less_than_three_yr_mrc.disposition.date +
            Time.TEN_YEARS)

        assert less_than_three_yr_mrc.expungement_result.time_eligibility.status is EligibilityStatus.INELIGIBLE
        assert (
            less_than_three_yr_mrc.expungement_result.time_eligibility.reason
            == "Most recent conviction is less than three years old")
        assert less_than_three_yr_mrc.expungement_result.time_eligibility.date_will_be_eligible == date.today(
        ) + relativedelta(days=+1)
 def run_expunger(self, mrc, second_mrc):
     charges_with_summary = ChargesWithSummary(
         charges=[mrc, second_mrc],
         most_recent_conviction=mrc,
         second_most_recent_conviction=second_mrc)
     TimeAnalyzer.evaluate(charges_with_summary)
class Expunger:
    """
    This is more or less a wrapper for the time_analyzer and type_analyzer.
    After running this method the results can be extracted from the cases
    attribute. The errors attribute will list the reasons why the run
    method failed to evaluate in which case the run method will return
    False; otherwise there were no errors and it returns True.

    Most of the algorithms in this class can be replaced with database
    query's if/when we start persisting the model objects to the db.
    """

    def __init__(self, cases):
        '''
        Constructor

        :param cases: A list of cases
        '''
        self.cases = cases
        self.errors = []
        self._charges = []
        self._most_recent_dismissal = None
        self._most_recent_conviction = None
        self._second_most_recent_conviction = None
        self._most_recent_charge = None
        self._num_acquittals = 0
        self._acquittals = []
        self._convictions = []
        self._time_analyzer = None
        self._type_analyzer = TypeAnalyzer()

    def run(self):
        """
        Evaluates the expungement eligibility of a record.

        :return: True if there are no open cases; otherwise False
        """
        if self._open_cases():
            self._create_charge_list_from_closed_cases()
            self._type_analyzer.evaluate(self._charges)
            self.errors.append('Open cases exist')
            return False

        self._create_charge_list()
        self._categorize_charges()
        self._set_most_recent_dismissal()
        self._set_most_recent_convictions()
        self._set_num_acquittals()
        self._assign_most_recent_charge()
        self._type_analyzer.evaluate(self._charges)
        self._time_analyzer = TimeAnalyzer(most_recent_conviction=self._most_recent_conviction,
                                           second_most_recent_conviction=self._second_most_recent_conviction,
                                           most_recent_dismissal=self._most_recent_dismissal,
                                           num_acquittals=self._num_acquittals,
                                           class_b_felonies=self._type_analyzer.class_b_felonies,
                                           most_recent_charge=self._most_recent_charge)
        self._time_analyzer.evaluate(self._charges)
        return True

    def _open_cases(self):
        for case in self.cases:
            if not case.closed():
                return True
        return False
 def run_expunger(self, mrc, second_mrc):
     self.expunger.most_recent_conviction = mrc
     self.expunger.second_most_recent_conviction = second_mrc
     self.expunger.charges = [mrc, second_mrc]
     TimeAnalyzer.evaluate(self.expunger)