Beispiel #1
0
def test_add_summary_to_crecord():
    summary = parse_pdf(pdf="tests/data/CourtSummaryReport.pdf",
                        tempdir="tests/data/tmp")
    rec = CRecord(Person("John", "Smith", date(1998, 1, 1)))
    rec.add_summary(summary, override_person=True)
    assert len(rec.person.first_name) > 0
    assert rec.person.first_name != "John"
Beispiel #2
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))
Beispiel #3
0
def triage(directory, tempdir, output):
    """
    Read through a set of directories each containing records for a single person. Screen each person for obviously disqualifying elements in their record.
    """
    logging.basicConfig(level=logging.ERROR)
    if not os.path.exists(directory):
        logging.info(f"{directory} does not exist.")
        return
    subdirs = os.listdir(directory)
    recs = []
    logging.info(f"Constructing {len(subdirs)} records.")
    for sd in subdirs:
        rec = CRecord()
        pdfs = glob.glob(os.path.join(directory, sd, "*_Summary.pdf"))
        try:
            for pdf in pdfs: 
                try:
                    rec.add_summary(parse_pdf_summary(pdf, tempdir=tempdir))
                except:
                    try:
                        d, _ = Docket.from_pdf(pdf, tempdir=tempdir)
                        rec.add_docket(d)
                    except Exception as e:
                        raise e
            logging.info(f"Constructed a record for {rec.person.full_name()}, with {len(rec.cases)} cases.")
            recs.append((sd, rec))
        except Exception as e:
            logging.error(f"Error for {sd}: {str(e)}")
    logging.info(f"Now analyzing {len(recs)} records.")
    results = []
    for sd, rec in recs:
        
        res = {
                "dir": sd,
                "name": rec.person.full_name(),
                "cases": len(rec.cases),
                "felony_5_yrs": bool(any_felony_convictions_n_years(rec, 5)),
                "2plus_m1s_15yrs": bool(more_than_x_convictions_y_grade_z_years(rec, 2, "M1", 15)),
                "4plus_m2s_20yrs": bool(more_than_x_convictions_y_grade_z_years(rec, 4, "M2", 20)),
                "any_f1_convictions": not no_f1_convictions(rec),
        }
        res["any_disqualifiers"] = any([
            res["felony_5_yrs"],
            res["2plus_m1s_15yrs"],
            res["4plus_m2s_20yrs"],
            res["any_f1_convictions"],
        ])
        results.append(res)
    with open(output, 'w') as f:
        writer = csv.DictWriter(f, fieldnames=[
            "dir", "name", "cases", "felony_5_yrs", "2plus_m1s_15yrs", 
            "4plus_m2s_20yrs", "any_f1_convictions", "any_disqualifiers"])
        writer.writeheader()
        for res in results:
            writer.writerow(res)
    
    logging.info("Complete.")
Beispiel #4
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 ("*********************************")
Beispiel #5
0
def test_add_summary_merge_strategies(example_summary):
    summary2 = copy.deepcopy(example_summary)
    summary2.get_cases()[0].otn = "a_different_otn"
    # default merge_strategy is to ignore new duplicates or
    # new Person
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2)
    assert rec.cases[0].otn == example_summary.get_cases()[0].otn
    assert rec.person.first_name == "Dummy"

    # alternate merge strategy overwrites duplicates w/ new case
    # but doesn't touch the Person
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2, case_merge_strategy="overwrite_old")
    assert rec.cases[0].otn == summary2.get_cases()[0].otn
    assert rec.person.first_name == "Dummy"

    # override_person param provides for overwriting the Person with the new summary's
    # Person
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2, override_person=True)
    assert rec.cases[0].otn != summary2.get_cases()[0].otn
    assert rec.person.first_name == summary2.get_defendant().first_name
Beispiel #6
0
def test_add_summary_doesnt_add_duplicates(example_summary):
    summary2 = copy.deepcopy(example_summary)
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2)
    assert len(rec.cases) == len(example_summary.get_cases())
Beispiel #7
0
def test_add_summary(example_summary):
    rec = CRecord()
    rec.add_summary(example_summary)
    assert rec.person.first_name == example_summary.get_defendant().first_name
    assert ((len(rec.cases) == len(example_summary.get_cases())) and
            (len(rec.cases) > 0))