def _build_case( oeci_case: OeciCase) -> Tuple[AmbiguousCase, List[Question]]: ambiguous_charges: List[AmbiguousCharge] = [] questions: List[Question] = [] for oeci_charge in oeci_case.charges: ambiguous_charge_id = oeci_charge.ambiguous_charge_id charge_dict = { "name": oeci_charge.name, "statute": oeci_charge.statute, "level": oeci_charge.level, "date": oeci_charge.date, "disposition": oeci_charge.disposition, "probation_revoked": oeci_charge.probation_revoked, "case_number": oeci_case.summary.case_number, "violation_type": oeci_case.summary.violation_type, "birth_year": oeci_case.summary.birth_year, } ambiguous_charge, question = ChargeCreator.create( ambiguous_charge_id, **charge_dict) ambiguous_charges.append(ambiguous_charge) if question: questions.append(question) ambiguous_case: AmbiguousCase = [] for charges in product(*ambiguous_charges): possible_case = Case(oeci_case.summary, charges=tuple(charges)) ambiguous_case.append(possible_case) return ambiguous_case, questions
def _build_case_strategy(draw: Callable[[SearchStrategy], Any], min_charges_size=0) -> Case: case_summary = draw(builds(CaseSummary)) charge_classes = get_charge_classes() charge_strategy_choices = list( map(lambda charge_class: _build_charge_strategy(charge_class, case_summary), charge_classes) ) charge_strategy = one_of(charge_strategy_choices) charges = draw(lists(charge_strategy, min_charges_size)) return Case(case_summary, charges=tuple(charges))
def create(info=['John Doe', '1990'], case_number='C0000', citation_number=None, date_location=['1/1/1995', 'Multnomah'], type_status=['Offense Misdemeanor', 'Closed'], charges=[], case_detail_link='?404'): return Case(info, case_number, citation_number, date_location, type_status, charges, case_detail_link)
class CaseFactory: @staticmethod def create(info=['John Doe', '1990'], case_number='C0000', citation_number=None, date_location=['1/1/1995', 'Multnomah'], type_status=['Offense Misdemeanor', 'Closed'], charges=[], case_detail_link='?404', balance='0'): case = Case(info, case_number, citation_number, date_location, type_status, charges, case_detail_link) case.set_balance_due(balance) return case
def create( info=["John Doe", "1990"], case_number="1", citation_number=None, date_location=["1/1/1995", "Multnomah"], type_status=["Offense Misdemeanor", "Closed"], charges=[], case_detail_link="?404", balance="0", ) -> Case: case_summary = CaseSummaryFactory.create(info, case_number, citation_number, date_location, type_status, case_detail_link, balance) return Case(case_summary, tuple(charges))
def setUp(self): self.case = Case(("John Doe", "1990"), "", "", ("1/1/2019", ""), ("", ""), "", "")
def __record_case(self): self.cases.append(Case(self.info, self.case_number, self.citation_number, self.date_location, self.type_status, [], self.case_detail_link))
def _build_case( oeci_case: OeciCase, new_charges: List[Charge] ) -> Tuple[AmbiguousCase, List[QuestionSummary]]: ambiguous_charges: List[AmbiguousCharge] = [] questions: List[QuestionSummary] = [] for oeci_charge in oeci_case.charges: ambiguous_charge_id = oeci_charge.ambiguous_charge_id charge_dict = { "name": oeci_charge.name, "statute": oeci_charge.statute, "level": oeci_charge.level, "date": oeci_charge.date, "disposition": oeci_charge.disposition, "probation_revoked": oeci_charge.probation_revoked, "balance_due_in_cents": oeci_charge.balance_due_in_cents, "case_number": oeci_case.summary.case_number, "violation_type": oeci_case.summary.violation_type, "birth_year": oeci_case.summary.birth_year, "edit_status": EditStatus(oeci_charge.edit_status), } if oeci_charge.disposition.status == DispositionStatus.UNKNOWN: charge_dict.pop("disposition") ambiguous_charge_dismissed, question_dismissed = ChargeCreator.create( ambiguous_charge_id, **charge_dict, disposition=DispositionCreator.create( date_class.today(), "dismissed"), ) ambiguous_charge_convicted, question_convicted = ChargeCreator.create( ambiguous_charge_id, **charge_dict, disposition=DispositionCreator.create( date_class.future(), "convicted"), ) if RecordCreator._disposition_question_is_irrelevant( ambiguous_charge_convicted, ambiguous_charge_dismissed): ambiguous_charges.append(ambiguous_charge_dismissed) question = RecordCreator._append_ambiguous_charge_id_to_question_id( question_dismissed, ambiguous_charge_id ) if question_dismissed else None # type: ignore # TODO: Fix type else: ambiguous_charges.append(ambiguous_charge_dismissed + ambiguous_charge_convicted) disposition_question_text = "Choose the disposition" question_id_prefix = ambiguous_charge_id + disposition_question_text dismissed_option = RecordCreator._build_option( question_dismissed, "Dismissed", f"{question_id_prefix}-dismissed") convicted_option = RecordCreator._build_option( question_convicted, "Convicted", f"{question_id_prefix}-convicted") probation_revoked_option = RecordCreator._build_probation_revoked_option( question_convicted, f"{question_id_prefix}-revoked") unknown_option = {"Unknown": Answer()} question = Question( question_id_prefix, disposition_question_text, { **dismissed_option, **convicted_option, **probation_revoked_option, **unknown_option }, ) else: ambiguous_charge, maybe_question = ChargeCreator.create( ambiguous_charge_id, **charge_dict) ambiguous_charges.append(ambiguous_charge) question = RecordCreator._append_ambiguous_charge_id_to_question_id( maybe_question, ambiguous_charge_id ) if maybe_question else None # type: ignore # TODO: Fix type if question: question_summary = QuestionSummary( ambiguous_charge_id, oeci_case.summary.case_number, question) questions.append(question_summary) ambiguous_charges += [[charge] for charge in new_charges] ambiguous_case: AmbiguousCase = [] for charges in product(*ambiguous_charges): possible_case = Case(oeci_case.summary, charges=tuple(charges)) ambiguous_case.append(possible_case) return ambiguous_case, questions
def save(case): return Case(**case)