Esempio n. 1
0
def fill_pcts(data):
  for level in data:
    for code in data[level]:
      data[level][code]['gov_pct'] = utils.rounded_pct(data[level][code]['gov'],
                                                       data[level][code]['valid'])
      data[level][code]['cap_pct'] = utils.rounded_pct(data[level][code]['cap'],
                                                       data[level][code]['valid'])
Esempio n. 2
0
def fill_participation(data, apr14=True):
  for level in data:
    for code in data[level]:
      if apr14:
        data[level][code]['particip'] = \
          utils.rounded_pct(data[level][code]['scrut_voters'],
                            data[level][code]['voters'])
      else: # 7o
        data[level][code]['particip'] = \
          utils.rounded_pct(data[level][code]['voting_voters'],
                      data[level][code]['scrut_voters'])
def plot_pct_vs_cum_valid(votes, level, year):
    codes_by_valid = sorted(votes, key=lambda code: votes[code]["valid"])
    cumsums = cumsum_all(votes, codes_by_valid)

    tuple_rounded_pct = lambda (n, d): utils.rounded_pct(n, d)
    cumsum_gov_pct = map(tuple_rounded_pct, zip(cumsums["gov"], cumsums["valid"]))
    cumsum_cap_pct = map(tuple_rounded_pct, zip(cumsums["cap"], cumsums["valid"]))
    cumsum_null_pct = map(tuple_rounded_pct, zip(cumsums["null"], cumsums["valid"]))

    utils.plot_wrap(
        (
            cumsums["valid"],
            cumsum_gov_pct,
            "r",
            cumsums["valid"],
            cumsum_cap_pct,
            "b",
            cumsums["valid"],
            cumsum_null_pct,
            "k",
        ),
        title="Candidate %% vs cumulative valid votes, by %s" % level,
        xlabel="Cumulative valid votes (by %s)" % level,
        ylabel="Candidate % of votes",
        filename="candidate_pct_vs_cum_valid_by_%s_%d.png" % (level, year),
    )