avg_election_votes = np.array(avg_election_voteshares) total_dem_votes = np.array(total_dem_votes) total_rep_votes = np.array(total_rep_votes) dem_voteshares_elections = total_dem_votes / (total_dem_votes + total_rep_votes) dem_voteshare = np.average(dem_voteshares_elections, axis=0) # ---- Partisan Fairness Metrics ---- dem_voteshares = avg_election_votes[avg_election_votes > 0.5] rep_voteshares = avg_election_votes[avg_election_votes < 0.5] avg_dem_win = np.average(dem_voteshares) avg_rep_win = 1 - np.average(rep_voteshares) # EG assumes equal turnout -- gets a different result than gerrychain EG = gm.EG(avg_election_votes) partisan_bias = gm.partisan_bias(avg_election_votes) mean_median = gm.mean_median(avg_election_votes) avgactWins = subset_list(avg_election_votes, 0.5, 1) # ---- Competitiveness ----- competitive_vote_shares = avg_election_dict avgactcomp = subset_list(avg_election_votes, comp_lower, comp_higher) # ---- Export to JSON ------ plan = { "state": state, "planName": district_assignment_col,
# ---- Racial Fairness Metrics ----- num_vra_districts = prop_partition["num_vra_districts"] num_opp_districts = prop_partition["num_opp_districts"] # AVG Election vote shares vote_shares = [ np.array(sorted(prop_partition[election_names[i]].percents("Dem"))) for i in range(num_elections) ] avg_election = np.average(vote_shares, axis=0) # ---- Partisan Fairness Metrics ---- # EG assumes equal turnout -- gets a different result than gerrychain EG = gm.EG(avg_election) partisan_bias = gm.partisan_bias(avg_election) mean_median = gm.mean_median(avg_election) # ---- Competitiveness ----- competitive_vote_shares = avg_election # ---- Export to JSON ------ chain_obj = { "numDists": num_dist, "countySplits": num_county_splits, "lowerBoundCountySplits": lower_county, "upperBoundCountySplits": upper_county,