예제 #1
0
def summary(pdf_summary: str, tempdir: str, redis_collect: str) -> None:
    """
    Analyze a single summary sheet for all sealings and expungements.
    """

    rec = CRecord()
    if pdf_summary is not None:
        rec.add_summary(parse_pdf_summary(pdf_summary, tempdir = tempdir))

    if redis_collect is not None:
        try:
            redis_options = redis_collect.split(":")
            rh = RedisHelper(host=redis_options[0], port=redis_options[1],
                             db=redis_options[2],env=redis_options[3])
            rh.sadd_crecord(rec)
        except Exception as e:
            logging.error("You supplied --redis-collect, but collection failed.")

    analysis = (
        Analysis(rec)
        .rule(expunge_deceased)
        .rule(expunge_over_70)
        .rule(expunge_nonconvictions)
        .rule(expunge_summary_convictions)
        .rule(seal_convictions)
    )

    print(json.dumps(analysis, indent=4, default=to_serializable)) #cls=DataClassJSONEncoder))
예제 #2
0
def dir(input_dir, output_json, output_html, email, log_level):
    """
    Analyze a record given a directory of dockets relating to a single person and write a plain-english 
    explanation of the analysis.
    """
    if not os.path.exists(input_dir):
        raise ValueError(f"Directory {input_dir} doesn't exist.")

    logger.setLevel(log_level)
    docket_files = [f for f in os.listdir(input_dir) if "docket_sheet" in f]

    source_records = []
    for df in docket_files:
        parser = pick_pdf_parser(df)
        if parser is None:
            continue
        source_records.append(
            SourceRecord(get_text_from_pdf(os.path.join(input_dir, df)),
                         parser))

    crecord = CRecord()
    for source_rec in source_records:
        crecord.add_sourcerecord(source_rec, override_person=True)

    analysis = (Analysis(crecord).rule(rd.expunge_deceased).rule(
        rd.expunge_over_70).rule(rd.expunge_nonconvictions).rule(
            rd.expunge_summary_convictions).rule(rd.seal_convictions))

    # email the results.
    communicate_results(source_records, analysis, output_json, output_html,
                        email)

    click.echo("Finished.")
예제 #3
0
def test_render_petitions(admin_user, admin_client, example_crecord,
                          example_attorney):
    with open("tests/templates/790ExpungementTemplate_usingpythonvars.docx",
              'rb') as tp:
        exp_petition = ExpungementPetitionTemplate.objects.create(
            name="790ExpungementTemplate.docx", file=File(tp))
    with open("tests/templates/791SealingTemplate.docx", 'rb') as tp:
        sealing_petition = SealingPetitionTemplate.objects.create(
            name="790SealingTemplate.docx", file=File(tp))

    admin_user.userprofile.expungement_petition_template = exp_petition
    admin_user.userprofile.sealing_petition_template = sealing_petition
    admin_user.userprofile.save()

    example_crecord.cases[0].charges[0].disposition = "Not Guilty"
    ans = Analysis(example_crecord).rule(expunge_nonconvictions)
    petitions = []
    for decision in ans.decisions:
        petitions.append(*decision.value)
    for p in petitions:
        p.attorney = example_attorney
    resp = admin_client.post("/record/petitions/",
                             json.dumps({"petitions": petitions},
                                        default=to_serializable),
                             content_type="application/json")
    assert resp.status_code == 200
예제 #4
0
    def post(self, request):
        """ Analyze a Criminal Record for expungeable and sealable cases and charges.
        
        POST body should be json-endoded CRecord object. 

        Return, if not an error, will be a json-encoded Decision that explains the expungements
        and sealings that can be generated for this record.

        """
        try:
            serializer = CRecordSerializer(data=request.data)
            if serializer.is_valid():
                rec = CRecord.from_dict(serializer.validated_data)
                analysis = (Analysis(rec).rule(expunge_deceased).rule(
                    expunge_over_70).rule(expunge_nonconvictions).rule(
                        expunge_summary_convictions).rule(seal_convictions))
                return Response(to_serializable(analysis))
            return Response(
                {"validation_errors": serializer.errors},
                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
            )
        except Exception as err:
            logger.error(err)
            return Response("Something went wrong",
                            status=status.HTTP_400_BAD_REQUEST)
예제 #5
0
def test_rule_chaining(example_crecord):
    ans = Analysis(example_crecord)
    try:
        (ans
         .rule(expunge_over_70)
         .rule(expunge_summary_convictions)
        )
    except:
        pytest.fail("Could not chain analysis rule operations.")
예제 #6
0
def dir(directory, archive, expungement_template, sealing_template, atty_name, atty_org, atty_org_addr, atty_org_phone, atty_bar_id, tempdir):
    if not os.path.exists(directory):
        print(f"The directory {directory} does not exist.")
        return
    files = [os.path.join(directory, f) for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
    summaries = []
    dockets = []
    atty = Attorney(full_name=atty_name, organization=atty_org, organization_address=atty_org_addr, organization_phone=atty_org_phone, bar_id=atty_bar_id)
    for f in files:
        print(f"  Processing {f}")
        try:
            dk = Docket.from_pdf(f, tempdir=tempdir)
            print(f"    It looks like {f} is a docket.")
            dockets.append(dk)
        except:
            try:
                sm = parse_pdf(f, tempdir=tempdir)
                print(f"    It looks like {f} is a summary.")
                summaries.append(sm)
            except:
                print(f"    It seems {f} is neither a summary nor a docket.")
    
    crec = CRecord()
    [crec.add_summary(summary) for summary in summaries]
    [crec.add_docket(docket) for docket in dockets]

    analysis = (
        Analysis(crec)
        .rule(expunge_deceased)
        .rule(expunge_over_70)
        .rule(expunge_nonconvictions)
        .rule(expunge_summary_convictions)
        .rule(seal_convictions)
    )

    petitions = [petition for decision in analysis.decisions for petition in decision.value] 
    for petition in petitions: petition.attorney = atty
    with open(sealing_template, "rb") as doc:
        for petition in petitions:
            if petition.petition_type == "Sealing":
                petition.set_template(doc)

    with open(expungement_template, "rb") as doc:
        for petition in petitions:
            if petition.petition_type == "Expungement":
                petition.set_template(doc)


    petition_tuples = []
    for pt in petitions:
        petition_tuples.append((pt.file_name(), pt.render()))
    pkg = Compressor(archive, petition_tuples, tempdir=tempdir)
    pkg.save()
    print ("*********************************")
    print ("****** COMPLETE *****************")
    print ("*********************************")
예제 #7
0
def test_unsealable_until_date(example_crecord):
    example_crecord.cases[0].disposition_date = date(2020, 1,1)
    analysis = Analysis(example_crecord).rule(seal_convictions)
    eb = EmailBuilder([], analysis)
    assert eb.get_unsealable_until_date(example_crecord.cases[0]) is not None
예제 #8
0
def test_init(example_crecord):
    try:
        ans = Analysis(example_crecord)
    except:
        pytest.fail("Could not create analysis object")
예제 #9
0
def test_rule(example_crecord):
    ans = Analysis(example_crecord)
    try:
        ans.rule(expunge_summary_convictions)
    except:
        pytest.fail("Could not apply rule to record.")
예제 #10
0
    for case in search_results:
        parser = pick_pdf_parser(case["docket_number"])
        if parser is None:
            continue
        sr = SourceRecord(case["docket_sheet_text"], parser)
        sourcerecords.append(sr)
        crecord.add_sourcerecord(sr, case_merge_strategy="overwrite_old")

    logger.info("Built CRecord.")
    logger.info(f"   -time so far:{(datetime.now() - starttime).seconds}")
    # Create and Analysis using the CRecord. This Analysis will explain
    # what charges and cases are expungeable, what will be automatically sealed,
    # what could be sealed by petition.

    analysis = (Analysis(crecord).rule(rd.expunge_deceased).rule(
        rd.expunge_over_70).rule(rd.expunge_nonconvictions).rule(
            rd.expunge_summary_convictions).rule(rd.seal_convictions))

    # email the results.
    communicate_results(sourcerecords, analysis, output_json, output_html,
                        email)

    endtime = datetime.now()
    elapsed = endtime - starttime
    click.echo(f"Completed csscreen in {elapsed.seconds} seconds.")


@cli.command()
@click.option(
    "--input-dir",
    "-i",