Skip to content

Instantly share code, notes, and snippets.

@mw44118
Created May 11, 2015 19:01
Show Gist options
  • Save mw44118/c14d0a9e09b30ac28749 to your computer and use it in GitHub Desktop.
Save mw44118/c14d0a9e09b30ac28749 to your computer and use it in GitHub Desktop.
Cleveland Heights Levy votes
vim: set expandtab ts=4 sw=4 filetype=python fileencoding=utf8:
import re
# Data from
# http://boe.cuyahogacounty.us/pdf_boe/en-US/ElectionResults2015/May2015/05052015UnoffialResultsbyPrecinctTotal.HTM
raw = """
0022 CLEVELAND HEIGHTS -01-A 46 32 0 0
0023 CLEVELAND HEIGHTS -01-B 60 28 0 0
0024 CLEVELAND HEIGHTS -01-C 32 50 0 0
0025 CLEVELAND HEIGHTS -01-D 16 6 0 0
0026 CLEVELAND HEIGHTS -01-E 89 59 0 0
0027 CLEVELAND HEIGHTS -01-F 163 97 0 0
0028 CLEVELAND HEIGHTS -01-G 68 54 0 0
0029 CLEVELAND HEIGHTS -02-A 68 64 0 0
0030 CLEVELAND HEIGHTS -02-B 145 126 0 0
0031 CLEVELAND HEIGHTS -02-C 125 121 0 0
0032 CLEVELAND HEIGHTS -02-D 136 69 0 0
0033 CLEVELAND HEIGHTS -02-E 159 114 0 0
0034 CLEVELAND HEIGHTS -02-F 92 58 0 0
0035 CLEVELAND HEIGHTS -02-G 97 54 0 0
0036 CLEVELAND HEIGHTS -03-A 21 16 0 0
0037 CLEVELAND HEIGHTS -03-B 64 42 0 0
0038 CLEVELAND HEIGHTS -03-C 87 49 0 1
0039 CLEVELAND HEIGHTS -03-D 135 82 0 0
0040 CLEVELAND HEIGHTS -03-E 57 61 0 0
0041 CLEVELAND HEIGHTS -03-F 45 43 1 0
0042 CLEVELAND HEIGHTS -04-A 66 87 0 0
0043 CLEVELAND HEIGHTS -04-B 51 186 0 0
0044 CLEVELAND HEIGHTS -04-C 58 60 0 0
0045 CLEVELAND HEIGHTS -04-D 36 80 0 0
0046 CLEVELAND HEIGHTS -04-E 93 80 0 0
0047 CLEVELAND HEIGHTS -04-F 68 103 0 0
0048 CLEVELAND HEIGHTS -04-G 64 165 0 1
0049 CLEVELAND HEIGHTS -04-H 101 110 0 0
0050 CLEVELAND HEIGHTS -04-I 64 102 0 0
0051 CLEVELAND HEIGHTS -05-A 45 85 0 0
0052 CLEVELAND HEIGHTS -05-B 53 48 0 0
0053 CLEVELAND HEIGHTS -05-C 62 81 0 0
0054 CLEVELAND HEIGHTS -05-E 42 61 0 0
0055 CLEVELAND HEIGHTS -05-G 62 61 0 0
0094 SOUTH EUCLID -04-A 37 55 0 1
0095 UNIVERSITY HEIGHTS -00-A 41 75 0 0
0096 UNIVERSITY HEIGHTS -00-B 56 85 0 0
0097 UNIVERSITY HEIGHTS -00-C 42 87 0 0
0098 UNIVERSITY HEIGHTS -00-D 74 180 1 0
0099 UNIVERSITY HEIGHTS -00-E 41 109 0 0
0100 UNIVERSITY HEIGHTS -00-F 24 82 0 0
0101 UNIVERSITY HEIGHTS -00-G 38 232 0 0
0102 UNIVERSITY HEIGHTS -00-H 41 166 0 0
0103 UNIVERSITY HEIGHTS -00-I 12 66 0 0
0104 UNIVERSITY HEIGHTS -00-J 29 264 0 0
"""
class Precinct(object):
def __init__(self, precinct, yesvotes, novotes):
self.precinct = precinct
self.yesvotes = yesvotes
self.novotes = novotes
@classmethod
def parse_row(cls, row):
parts = re.split("\s\s+", row)
return cls(parts[0], int(parts[1]), int(parts[2]))
@property
def voted_yes(self):
return self.yesvotes > self.novotes
def __repr__(self):
return "<Precinct {0}: {1} to {2} ({3:.2f})>".format(
self.precinct,
self.yesvotes,
self.novotes,
self.pct_yes)
@property
def pct_yes(self):
return self.yesvotes / float(self.yesvotes + self.novotes)
@property
def city(self):
for c in ["CLEVELAND HEIGHTS", "SOUTH EUCLID", "UNIVERSITY HEIGHTS"]:
if c in self.precinct:
return c
else:
raise Exception("Could not extract city from {0}!".format(self.precinct))
if __name__ == "__main__":
rows = [row.strip() for row in raw.split("\n") if row]
precincts = [Precinct.parse_row(row) for row in rows]
heights = sorted(
(p for p in precincts if p.city == "CLEVELAND HEIGHTS"),
key=lambda p: p.pct_yes,
reverse=True)
for p in sorted(precincts, key=lambda p: p.pct_yes, reverse=True):
print "{0}: {1}".format(p, p.city)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment