Esempio n. 1
0
def main(filename, zip_file, county, party):
    # Get absentee
    absentee = read_absentee_voter_file(filename)
    if county:
        absentee = absentee[absentee.county_desc == county]
        prefix = county
    else:
        prefix = 'state'
    # Only mail ballots
    absentee = absentee[absentee.ballot_req_type == 'MAIL']
    absentee.dropna(subset=['ballot_rtn_status'], inplace=True)
    absentee \
      = absentee[~absentee.ballot_rtn_status.str.contains('ACCEPTED') & (absentee.party == party)]

    reasons = {}
    for zip_code, group in absentee.groupby(by='voter_zip'):
        reasons[zip_code] = group.groupby(
            by='ballot_rtn_status').county_desc.count()
    reasons = pd.DataFrame(reasons).T.fillna(0)

    # Zipcodes
    count_by_zip_code = absentee.groupby(by='voter_zip').county_desc.count()
    zips = read_zip_codes(zip_file)
    zips['total'] = count_by_zip_code
    zips.dropna(subset=['total'], inplace=True)
    bins = [0, 5, 20, 40, 60, 200]
    zips['quantile'] \
      = pd.cut(zips['total'], bins, duplicates='drop').astype('str')

    zips = zips.join(reasons).fillna(0)
    ts = pd.Timestamp.now().isoformat()
    prefix = party.lower()
    out = zips[['total', 'quantile', 'geometry'] +
               list(reasons.columns.values)]
    to_kml(out, f'limbo/{prefix}_rejected_zip_{ts}.kml')
Esempio n. 2
0
def main(filename, zip_file, county, party):
    # Get absentee
    absentee = read_absentee_voter_file(filename)
    if county:
        absentee = absentee[absentee.county_desc == county]
        prefix = county
    else:
        prefix = 'state'
    zips = read_zip_codes(zip_file)
    plot_mail_cancels(zips, absentee, party)
    plot_mail_cancels_non_spoiled(zips, absentee, party)
    plot_one_stop(zips, absentee, party)
Esempio n. 3
0
def main(filename, registered_filename, party):
    absentee = read_absentee_voter_file(filename)
    accepted = absentee[(absentee.ballot_rtn_dt >= '2020-09-01')
                        & (absentee.ballot_rtn_status == 'ACCEPTED')
                        & (absentee.ballot_rtn_dt <= pd.datetime.now())]
    accepted = accepted[accepted.voter_party_code == party]
    by_precinct = get_accepted_by_precinct(accepted)
    precinct_shapes = load_precincts_shapes()
    registered = load_registered(registered_filename)
    ts = pd.Timestamp.now().isoformat()
    turnout = registered.join(by_precinct)
    turnout['ACTIVE+VOTED(%)'] = 100. * turnout['ACTIVE'] / turnout['TOTAL']
    ts = pd.Timestamp.now().isoformat()
    print(f'limbo/turnout-per-precinct-{ts}.csv')
    turnout.to_csv(f'limbo/turnout-per-precinct-{ts}.csv')
    print(f'limbo/turnout-per-precinct-latest.csv')
    turnout.to_csv(f'limbo/turnout-per-precinct-latest.csv')
Esempio n. 4
0
def main(filename):
    absentee = read_absentee_voter_file(filename)
    abm = absentee[(absentee.ballot_req_type == 'MAIL')
                   & (absentee['ballot_req_dt'] >= '2020-09-04')]
    abm['ballot_send_days'] = (abm['ballot_send_dt'] -
                               abm['ballot_req_dt']).dt.days

    plt.rcParams["figure.figsize"] = [16, 10]
    plt.rcParams["axes.titlesize"] = 16
    plt.rcParams["axes.labelsize"] = 16
    plt.rcParams["xtick.labelsize"] = 16
    plt.rcParams["ytick.labelsize"] = 16

    for county, results in abm.groupby(by='county_desc'):
        name = county.lower()
        figure = plot_request_send_latency(county, results)
        print(f'assets/images/abm-latency/request-to-mail/{name}.png')
        figure.savefig(f'assets/images/abm-latency/request-to-mail/{name}.png',
                       bbox_inches='tight')
        plt.close(figure)
Esempio n. 5
0
def main(filename):
    absentee = read_absentee_voter_file(filename)
    one_stop = absentee[absentee.ballot_req_type == 'ONE-STOP']
    plt.rcParams["figure.figsize"] = [16, 10]
    plt.rcParams["axes.titlesize"] = 16
    plt.rcParams["axes.labelsize"] = 16
    plt.rcParams["xtick.labelsize"] = 16
    plt.rcParams["ytick.labelsize"] = 16

    plot_state(one_stop)

    for county, results in one_stop.groupby(by='county_desc'):
        name = county.lower()

        figure = plot_by_party(county, results)
        print(f'assets/images/one-stop/county-party-totals/{name}.png')
        figure.savefig(
            f'assets/images/one-stop/county-party-totals/{name}.png',
            bbox_inches='tight')
        plt.close(figure)

        figure = plot_by_race(county, results)
        print(f'assets/images/one-stop/county-race-totals/{name}.png')
        figure.savefig(f'assets/images/one-stop/county-race-totals/{name}.png',
                       bbox_inches='tight')
        plt.close(figure)

        figure = plot_by_age_group(county, results)
        print(f'assets/images/one-stop/county-age-totals/{name}.png')
        figure.savefig(f'assets/images/one-stop/county-age-totals/{name}.png',
                       bbox_inches='tight')
        plt.close(figure)

        figure = plot_one_stop_counts_by_week(county, results)
        print(f'assets/images/one-stop/per-week-totals/{name}.png')
        figure.savefig(f'assets/images/one-stop/per-week-totals/{name}.png',
                       bbox_inches='tight')
        plt.close(figure)
Esempio n. 6
0
def main(filename):
    absentee = read_absentee_voter_file(filename)
    accepted = absentee[absentee.ballot_rtn_status == 'ACCEPTED']
    accepted = accepted[(accepted.ballot_rtn_dt >= '2020-09-01')
                        & (accepted.ballot_rtn_dt <= pd.datetime.now())]
    plt.rcParams["figure.figsize"] = [16, 10]
    plt.rcParams["axes.titlesize"] = 16
    plt.rcParams["axes.labelsize"] = 16
    plt.rcParams["xtick.labelsize"] = 16
    plt.rcParams["ytick.labelsize"] = 16

    plot_state(accepted)

    for county, results in accepted.groupby(by='county_desc'):
        name = county.lower()
        figure = plot_accepted_types_by_week(county, results)
        print(f'assets/images/accepted/type-per-week-totals/{name}.png')
        figure.savefig(
            f'assets/images/accepted/type-per-week-totals/{name}.png',
            bbox_inches='tight')
        plt.close(figure)

        figure = plot_accepted_demographics_by_week(county, results)
        print(f'assets/images/accepted/demographic-per-week-totals/{name}.png')
        figure.savefig(
            f'assets/images/accepted/demographic-per-week-totals/{name}.png',
            bbox_inches='tight')
        plt.close(figure)

        figure = plot_accepted_demographics_cumulative(county, results)
        print(
            f'assets/images/accepted/demographic-cumulative-totals/{name}.png')
        figure.savefig(
            f'assets/images/accepted/demographic-cumulative-totals/{name}.png',
            bbox_inches='tight')
        plt.close(figure)