def __init__(self, seats=None, **kwargs): self.excess_votes = {} self.multiplier = 1 self.prior_winners = [] self.redistributed_votes = [] self.seats = seats self.threshold = None Election.__init__(self, **kwargs)
def test_dedupe(self): e = Election() e.data = [{ 'Email Address': '*****@*****.**', '[Black Sabbath]': 'First Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/3/2018 12:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Third Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'First Preference', 'Timestamp': '8/4/2018 11:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'First Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/5/2018 12:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Second Preference', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/5/2018 13:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': '', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': '', 'Timestamp': '8/4/2018 13:10:04' }] e.dedupe() self.maxDiff = None self.assertEqual(e.data, [{ 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Third Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'First Preference', 'Timestamp': '8/4/2018 11:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Second Preference', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/5/2018 13:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': '', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': '', 'Timestamp': '8/4/2018 13:10:04' }])
def test_preen_voter_ids(self): e = Election() e.data = [{ 'Email Address': '*****@*****.**', '[Black Sabbath]': 'First Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'Third Preference', '\ufeffTimestamp': '8/3/2018 12:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Second Preference', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': 'Third Preference', '\ufeffTimestamp': '8/4/2018 13:10:04' }, { 'Email Address': 5, '[Black Sabbath]': '', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': '', '\ufeffTimestamp': '8/4/2018 13:10:04' }] e.data = e.preen_voter_ids(e.data, e.voter_id_col) self.assertEqual([{ 'Email Address': '*****@*****.**', '[Black Sabbath]': 'First Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'Third Preference', '\ufeffTimestamp': '8/3/2018 12:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Second Preference', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': 'Third Preference', '\ufeffTimestamp': '8/4/2018 13:10:04' }, { 'Email Address': '5', '[Black Sabbath]': '', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': '', '\ufeffTimestamp': '8/4/2018 13:10:04' }], e.data)
def test_find_interlopers(self): e = Election() e.data = [{ 'Email Address': '*****@*****.**', '[Black Sabbath]': 'First Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/3/2018 12:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Third Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'First Preference', 'Timestamp': '8/4/2018 11:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'First Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/5/2018 12:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Second Preference', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/5/2018 13:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': '', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': '', 'Timestamp': '8/4/2018 13:10:04' }] e.registration_data = [{ 'email': '*****@*****.**', 'first_name': 'Glen', 'last_name': 'Campbell' }, { 'email': '*****@*****.**', 'first_name': 'Bobbie', 'last_name': 'Gentry' }] e.find_interlopers() self.assertEqual([{ 'Email Address': '*****@*****.**', '[Black Sabbath]': 'First Preference', '[Napalm Death]': 'Second Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/5/2018 12:10:04' }, { 'Email Address': '*****@*****.**', '[Black Sabbath]': 'Second Preference', '[Napalm Death]': 'First Preference', '[Cradle of Filth]': 'Third Preference', 'Timestamp': '8/5/2018 13:10:04' }], e.interlopers)
def test_swap_vote_cols(self): e = Election() e.data = [{ 'Email Address': '*****@*****.**', 'First Preference': 'Black Sabbath', 'Second Preference': 'Napalm Death', 'Third Preference': 'Cradle of Filth', 'Timestamp': '8/3/2018 12:10:04' }, { 'Email Address': '*****@*****.**', 'First Preference': 'Napalm Death', 'Second Preference': 'Black Sabbath', 'Third Preference': 'Cradle of Filth', 'Timestamp': '8/5/2018 13:10:04' }, { 'Email Address': '*****@*****.**', 'First Preference': 'Napalm Death', 'Second Preference': '', 'Third Preference': '', 'Timestamp': '8/4/2018 13:10:04' }] e.swap_cols = [ 'First Preference', 'Second Preference', 'Third Preference' ] e.swap_vote_cols() self.assertEqual([{ 'Email Address': '*****@*****.**', 'Black Sabbath': 'First Preference', 'Napalm Death': 'Second Preference', 'Cradle of Filth': 'Third Preference', 'Timestamp': '8/3/2018 12:10:04' }, { 'Email Address': '*****@*****.**', 'Napalm Death': 'First Preference', 'Black Sabbath': 'Second Preference', 'Cradle of Filth': 'Third Preference', 'Timestamp': '8/5/2018 13:10:04' }, { 'Email Address': '*****@*****.**', 'Napalm Death': 'First Preference', 'Timestamp': '8/4/2018 13:10:04' }], e.data)
def __init__(self, seats=None, **kwargs): Election.__init__(self, **kwargs)
def bootstrap(self, **kwargs): Election.bootstrap(self, **kwargs) self.derive_threshold()