1class Currency:
2 def __init__(self, name, required_for_one_vote):
3 self.name = name
4 self.required_for_one_vote = required_for_one_vote
5
6 def __eq__(self, other):
7 return (
8 False
9 if other is None
10 else (self.name == other.name and self.required_for_one_vote == other.required_for_one_vote)
11 )
12
13 def __hash__(self):
14 return hash(self.name)
15
16 def convert_to_voters(self, amount):
17 return int(amount / self.required_for_one_vote)
18
19
20class PoliticalParty:
21 def __init__(self, name, motto, members=None, preferred_currency=None):
22 self.name = name
23 self._motto = motto
24 self.members = members[:] if members else [] # Check for mutating in tests
25 self.preferred_currency = preferred_currency
26
27 def __str__(self):
28 return self.name
29
30 @property
31 def motto(self):
32 return self._motto
33
34 def convert_currency_to_voters(self, amount, currency):
35 multiplier = 2 if currency == self.preferred_currency else 1
36 return currency.convert_to_voters(amount) * multiplier
37
38 def __add__(self, other_party):
39 return Coalition(self, other_party)
40
41
42class Coalition:
43 def __init__(self, *parties):
44 self.parties = list(parties)
45
46 def __str__(self):
47 return "-".join(str(party) for party in self.parties)
48
49 @property
50 def members(self):
51 return {str(party): party.members for party in self.parties}
52
53 def __add__(self, coalition_or_party):
54 parties_to_append = (
55 [coalition_or_party] if isinstance(coalition_or_party, PoliticalParty) else coalition_or_party.parties
56 )
57 return self.__class__(*self.parties, *parties_to_append)
58
59 def convert_currency_to_voters(self, amount, currency):
60 preferred_currencies = {party.preferred_currency: party for party in self.parties}
61 return preferred_currencies.get(currency, self.parties[0]).convert_currency_to_voters(amount, currency)
62
63
64class Elections:
65 ELECTIONS_HISTORY = {}
66
67 def __init__(self, year):
68 self.year = year
69 self.__votes = {}
70 self.ELECTIONS_HISTORY[year] = self
71
72 @classmethod
73 def get_results_by_year(cls, year):
74 return cls.ELECTIONS_HISTORY[year].get_results()
75
76 def register_party_or_coalition(self, *parties_or_coalitions):
77 self.__votes |= {str(party_or_coallition): 0 for party_or_coallition in parties_or_coalitions}
78
79 def rig_elections(self, party_or_coalition, amount, currency):
80 self.__votes[str(party_or_coalition)] += party_or_coalition.convert_currency_to_voters(amount, currency)
81
82 def get_results(self):
83 return self.__votes
84
85 def vote(self, party_or_coalition):
86 self.__votes[str(party_or_coalition)] += 1
.....................
----------------------------------------------------------------------
Ran 21 tests in 0.001s
OK
| f | 1 | class Currency: | f | 1 | class Currency: |
| 2 | def __init__(self, name, required_for_one_vote): | 2 | def __init__(self, name, required_for_one_vote): | ||
| 3 | self.name = name | 3 | self.name = name | ||
| 4 | self.required_for_one_vote = required_for_one_vote | 4 | self.required_for_one_vote = required_for_one_vote | ||
| 5 | 5 | ||||
| 6 | def __eq__(self, other): | 6 | def __eq__(self, other): | ||
| 7 | return ( | 7 | return ( | ||
| 8 | False | 8 | False | ||
| 9 | if other is None | 9 | if other is None | ||
| 10 | else (self.name == other.name and self.required_for_one_vote == other.required_for_one_vote) | 10 | else (self.name == other.name and self.required_for_one_vote == other.required_for_one_vote) | ||
| 11 | ) | 11 | ) | ||
| 12 | 12 | ||||
| 13 | def __hash__(self): | 13 | def __hash__(self): | ||
| 14 | return hash(self.name) | 14 | return hash(self.name) | ||
| 15 | 15 | ||||
| 16 | def convert_to_voters(self, amount): | 16 | def convert_to_voters(self, amount): | ||
| 17 | return int(amount / self.required_for_one_vote) | 17 | return int(amount / self.required_for_one_vote) | ||
| 18 | 18 | ||||
| 19 | 19 | ||||
| 20 | class PoliticalParty: | 20 | class PoliticalParty: | ||
| 21 | def __init__(self, name, motto, members=None, preferred_currency=None): | 21 | def __init__(self, name, motto, members=None, preferred_currency=None): | ||
| 22 | self.name = name | 22 | self.name = name | ||
| 23 | self._motto = motto | 23 | self._motto = motto | ||
| 24 | self.members = members[:] if members else [] # Check for mutating in tests | 24 | self.members = members[:] if members else [] # Check for mutating in tests | ||
| 25 | self.preferred_currency = preferred_currency | 25 | self.preferred_currency = preferred_currency | ||
| 26 | 26 | ||||
| 27 | def __str__(self): | 27 | def __str__(self): | ||
| 28 | return self.name | 28 | return self.name | ||
| 29 | 29 | ||||
| 30 | @property | 30 | @property | ||
| 31 | def motto(self): | 31 | def motto(self): | ||
| 32 | return self._motto | 32 | return self._motto | ||
| 33 | 33 | ||||
| 34 | def convert_currency_to_voters(self, amount, currency): | 34 | def convert_currency_to_voters(self, amount, currency): | ||
| 35 | multiplier = 2 if currency == self.preferred_currency else 1 | 35 | multiplier = 2 if currency == self.preferred_currency else 1 | ||
| 36 | return currency.convert_to_voters(amount) * multiplier | 36 | return currency.convert_to_voters(amount) * multiplier | ||
| 37 | 37 | ||||
| 38 | def __add__(self, other_party): | 38 | def __add__(self, other_party): | ||
| 39 | return Coalition(self, other_party) | 39 | return Coalition(self, other_party) | ||
| 40 | 40 | ||||
| 41 | 41 | ||||
| 42 | class Coalition: | 42 | class Coalition: | ||
| 43 | def __init__(self, *parties): | 43 | def __init__(self, *parties): | ||
| 44 | self.parties = list(parties) | 44 | self.parties = list(parties) | ||
| 45 | 45 | ||||
| 46 | def __str__(self): | 46 | def __str__(self): | ||
| 47 | return "-".join(str(party) for party in self.parties) | 47 | return "-".join(str(party) for party in self.parties) | ||
| 48 | 48 | ||||
| 49 | @property | 49 | @property | ||
| 50 | def members(self): | 50 | def members(self): | ||
| 51 | return {str(party): party.members for party in self.parties} | 51 | return {str(party): party.members for party in self.parties} | ||
| 52 | 52 | ||||
| 53 | def __add__(self, coalition_or_party): | 53 | def __add__(self, coalition_or_party): | ||
| 54 | parties_to_append = ( | 54 | parties_to_append = ( | ||
| 55 | [coalition_or_party] if isinstance(coalition_or_party, PoliticalParty) else coalition_or_party.parties | 55 | [coalition_or_party] if isinstance(coalition_or_party, PoliticalParty) else coalition_or_party.parties | ||
| 56 | ) | 56 | ) | ||
| 57 | return self.__class__(*self.parties, *parties_to_append) | 57 | return self.__class__(*self.parties, *parties_to_append) | ||
| 58 | 58 | ||||
| 59 | def convert_currency_to_voters(self, amount, currency): | 59 | def convert_currency_to_voters(self, amount, currency): | ||
| 60 | preferred_currencies = {party.preferred_currency: party for party in self.parties} | 60 | preferred_currencies = {party.preferred_currency: party for party in self.parties} | ||
| 61 | return preferred_currencies.get(currency, self.parties[0]).convert_currency_to_voters(amount, currency) | 61 | return preferred_currencies.get(currency, self.parties[0]).convert_currency_to_voters(amount, currency) | ||
| 62 | 62 | ||||
| 63 | 63 | ||||
| 64 | class Elections: | 64 | class Elections: | ||
| 65 | ELECTIONS_HISTORY = {} | 65 | ELECTIONS_HISTORY = {} | ||
| 66 | 66 | ||||
| 67 | def __init__(self, year): | 67 | def __init__(self, year): | ||
| 68 | self.year = year | 68 | self.year = year | ||
| 69 | self.__votes = {} | 69 | self.__votes = {} | ||
| 70 | self.ELECTIONS_HISTORY[year] = self | 70 | self.ELECTIONS_HISTORY[year] = self | ||
| 71 | 71 | ||||
| 72 | @classmethod | 72 | @classmethod | ||
| 73 | def get_results_by_year(cls, year): | 73 | def get_results_by_year(cls, year): | ||
| 74 | return cls.ELECTIONS_HISTORY[year].get_results() | 74 | return cls.ELECTIONS_HISTORY[year].get_results() | ||
| 75 | 75 | ||||
| 76 | def register_party_or_coalition(self, *parties_or_coalitions): | 76 | def register_party_or_coalition(self, *parties_or_coalitions): | ||
| 77 | self.__votes |= {str(party_or_coallition): 0 for party_or_coallition in parties_or_coalitions} | 77 | self.__votes |= {str(party_or_coallition): 0 for party_or_coallition in parties_or_coalitions} | ||
| 78 | 78 | ||||
| 79 | def rig_elections(self, party_or_coalition, amount, currency): | 79 | def rig_elections(self, party_or_coalition, amount, currency): | ||
| 80 | self.__votes[str(party_or_coalition)] += party_or_coalition.convert_currency_to_voters(amount, currency) | 80 | self.__votes[str(party_or_coalition)] += party_or_coalition.convert_currency_to_voters(amount, currency) | ||
| 81 | 81 | ||||
| 82 | def get_results(self): | 82 | def get_results(self): | ||
| 83 | return self.__votes | 83 | return self.__votes | ||
| 84 | 84 | ||||
| 85 | def vote(self, party_or_coalition): | 85 | def vote(self, party_or_coalition): | ||
| 86 | self.__votes[str(party_or_coalition)] += 1 | 86 | self.__votes[str(party_or_coalition)] += 1 | ||
| t | 87 | t | |||
| 88 | |||||
| 89 | elections_2026 = Elections(2026) | ||||
| 90 | |||||
| 91 | BSP = PoliticalParty( | ||||
| 92 | "БСП", "Ще вдигнем пенсиите и тази година!", members=["Крум Еди-Кой-Си", "Атанас Еди-Кой-Си", "Онзи другия"] | ||||
| 93 | ) | ||||
| 94 | |||||
| 95 | elections_2026.register_party_or_coalition(BSP) | ||||
| 96 | |||||
| 97 | |||||
| 98 | gold_bars = Currency("мини-златни кюлчета", 0.2) | ||||
| 99 | GERB = PoliticalParty("ГЕРБ", "Ту-тууу!", members=["Бат'", "Бойко", "и", "сам", "стига"], preferred_currency=gold_bars) | ||||
| 100 | SDS = PoliticalParty("СДС", "Ние също сме шокирани, че все още съществуваме...", members=["Румен, ама не Радев"]) | ||||
| 101 | GERB_SDS = GERB + SDS | ||||
| 102 | |||||
| 103 | elections_2026.register_party_or_coalition(GERB_SDS) | ||||
| 104 | elections_2026.vote(BSP) | ||||
| 105 | elections_2026.rig_elections(GERB_SDS, 1, gold_bars) | ||||
| 106 | |||||
| 107 | print(elections_2026.get_results()) # {"БСП": 1, "ГЕРБ-СДС": 5} |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | class Currency: | f | 1 | class Currency: |
| 2 | def __init__(self, name, required_for_one_vote): | 2 | def __init__(self, name, required_for_one_vote): | ||
| 3 | self.name = name | 3 | self.name = name | ||
| 4 | self.required_for_one_vote = required_for_one_vote | 4 | self.required_for_one_vote = required_for_one_vote | ||
| 5 | 5 | ||||
| 6 | def __eq__(self, other): | 6 | def __eq__(self, other): | ||
| 7 | return ( | 7 | return ( | ||
| 8 | False | 8 | False | ||
| 9 | if other is None | 9 | if other is None | ||
| 10 | else (self.name == other.name and self.required_for_one_vote == other.required_for_one_vote) | 10 | else (self.name == other.name and self.required_for_one_vote == other.required_for_one_vote) | ||
| 11 | ) | 11 | ) | ||
| 12 | 12 | ||||
| 13 | def __hash__(self): | 13 | def __hash__(self): | ||
| 14 | return hash(self.name) | 14 | return hash(self.name) | ||
| 15 | 15 | ||||
| 16 | def convert_to_voters(self, amount): | 16 | def convert_to_voters(self, amount): | ||
| n | 17 | return amount // self.required_for_one_vote | n | 17 | return int(amount / self.required_for_one_vote) |
| 18 | 18 | ||||
| 19 | 19 | ||||
| 20 | class PoliticalParty: | 20 | class PoliticalParty: | ||
| 21 | def __init__(self, name, motto, members=None, preferred_currency=None): | 21 | def __init__(self, name, motto, members=None, preferred_currency=None): | ||
| 22 | self.name = name | 22 | self.name = name | ||
| 23 | self._motto = motto | 23 | self._motto = motto | ||
| 24 | self.members = members[:] if members else [] # Check for mutating in tests | 24 | self.members = members[:] if members else [] # Check for mutating in tests | ||
| 25 | self.preferred_currency = preferred_currency | 25 | self.preferred_currency = preferred_currency | ||
| 26 | 26 | ||||
| 27 | def __str__(self): | 27 | def __str__(self): | ||
| 28 | return self.name | 28 | return self.name | ||
| 29 | 29 | ||||
| 30 | @property | 30 | @property | ||
| 31 | def motto(self): | 31 | def motto(self): | ||
| 32 | return self._motto | 32 | return self._motto | ||
| 33 | 33 | ||||
| 34 | def convert_currency_to_voters(self, amount, currency): | 34 | def convert_currency_to_voters(self, amount, currency): | ||
| 35 | multiplier = 2 if currency == self.preferred_currency else 1 | 35 | multiplier = 2 if currency == self.preferred_currency else 1 | ||
| 36 | return currency.convert_to_voters(amount) * multiplier | 36 | return currency.convert_to_voters(amount) * multiplier | ||
| 37 | 37 | ||||
| 38 | def __add__(self, other_party): | 38 | def __add__(self, other_party): | ||
| 39 | return Coalition(self, other_party) | 39 | return Coalition(self, other_party) | ||
| 40 | 40 | ||||
| 41 | 41 | ||||
| 42 | class Coalition: | 42 | class Coalition: | ||
| 43 | def __init__(self, *parties): | 43 | def __init__(self, *parties): | ||
| 44 | self.parties = list(parties) | 44 | self.parties = list(parties) | ||
| 45 | 45 | ||||
| 46 | def __str__(self): | 46 | def __str__(self): | ||
| 47 | return "-".join(str(party) for party in self.parties) | 47 | return "-".join(str(party) for party in self.parties) | ||
| 48 | 48 | ||||
| 49 | @property | 49 | @property | ||
| 50 | def members(self): | 50 | def members(self): | ||
| 51 | return {str(party): party.members for party in self.parties} | 51 | return {str(party): party.members for party in self.parties} | ||
| 52 | 52 | ||||
| 53 | def __add__(self, coalition_or_party): | 53 | def __add__(self, coalition_or_party): | ||
| 54 | parties_to_append = ( | 54 | parties_to_append = ( | ||
| 55 | [coalition_or_party] if isinstance(coalition_or_party, PoliticalParty) else coalition_or_party.parties | 55 | [coalition_or_party] if isinstance(coalition_or_party, PoliticalParty) else coalition_or_party.parties | ||
| 56 | ) | 56 | ) | ||
| 57 | return self.__class__(*self.parties, *parties_to_append) | 57 | return self.__class__(*self.parties, *parties_to_append) | ||
| 58 | 58 | ||||
| 59 | def convert_currency_to_voters(self, amount, currency): | 59 | def convert_currency_to_voters(self, amount, currency): | ||
| 60 | preferred_currencies = {party.preferred_currency: party for party in self.parties} | 60 | preferred_currencies = {party.preferred_currency: party for party in self.parties} | ||
| 61 | return preferred_currencies.get(currency, self.parties[0]).convert_currency_to_voters(amount, currency) | 61 | return preferred_currencies.get(currency, self.parties[0]).convert_currency_to_voters(amount, currency) | ||
| 62 | 62 | ||||
| 63 | 63 | ||||
| 64 | class Elections: | 64 | class Elections: | ||
| 65 | ELECTIONS_HISTORY = {} | 65 | ELECTIONS_HISTORY = {} | ||
| 66 | 66 | ||||
| 67 | def __init__(self, year): | 67 | def __init__(self, year): | ||
| 68 | self.year = year | 68 | self.year = year | ||
| 69 | self.__votes = {} | 69 | self.__votes = {} | ||
| 70 | self.ELECTIONS_HISTORY[year] = self | 70 | self.ELECTIONS_HISTORY[year] = self | ||
| 71 | 71 | ||||
| 72 | @classmethod | 72 | @classmethod | ||
| 73 | def get_results_by_year(cls, year): | 73 | def get_results_by_year(cls, year): | ||
| 74 | return cls.ELECTIONS_HISTORY[year].get_results() | 74 | return cls.ELECTIONS_HISTORY[year].get_results() | ||
| 75 | 75 | ||||
| 76 | def register_party_or_coalition(self, *parties_or_coalitions): | 76 | def register_party_or_coalition(self, *parties_or_coalitions): | ||
| 77 | self.__votes |= {str(party_or_coallition): 0 for party_or_coallition in parties_or_coalitions} | 77 | self.__votes |= {str(party_or_coallition): 0 for party_or_coallition in parties_or_coalitions} | ||
| 78 | 78 | ||||
| 79 | def rig_elections(self, party_or_coalition, amount, currency): | 79 | def rig_elections(self, party_or_coalition, amount, currency): | ||
| 80 | self.__votes[str(party_or_coalition)] += party_or_coalition.convert_currency_to_voters(amount, currency) | 80 | self.__votes[str(party_or_coalition)] += party_or_coalition.convert_currency_to_voters(amount, currency) | ||
| 81 | 81 | ||||
| 82 | def get_results(self): | 82 | def get_results(self): | ||
| 83 | return self.__votes | 83 | return self.__votes | ||
| 84 | 84 | ||||
| 85 | def vote(self, party_or_coalition): | 85 | def vote(self, party_or_coalition): | ||
| 86 | self.__votes[str(party_or_coalition)] += 1 | 86 | self.__votes[str(party_or_coalition)] += 1 | ||
| t | t | 87 | |||
| 88 | |||||
| 89 | elections_2026 = Elections(2026) | ||||
| 90 | |||||
| 91 | BSP = PoliticalParty( | ||||
| 92 | "БСП", "Ще вдигнем пенсиите и тази година!", members=["Крум Еди-Кой-Си", "Атанас Еди-Кой-Си", "Онзи другия"] | ||||
| 93 | ) | ||||
| 94 | |||||
| 95 | elections_2026.register_party_or_coalition(BSP) | ||||
| 96 | |||||
| 97 | |||||
| 98 | gold_bars = Currency("мини-златни кюлчета", 0.2) | ||||
| 99 | GERB = PoliticalParty("ГЕРБ", "Ту-тууу!", members=["Бат'", "Бойко", "и", "сам", "стига"], preferred_currency=gold_bars) | ||||
| 100 | SDS = PoliticalParty("СДС", "Ние също сме шокирани, че все още съществуваме...", members=["Румен, ама не Радев"]) | ||||
| 101 | GERB_SDS = GERB + SDS | ||||
| 102 | |||||
| 103 | elections_2026.register_party_or_coalition(GERB_SDS) | ||||
| 104 | elections_2026.vote(BSP) | ||||
| 105 | elections_2026.rig_elections(GERB_SDS, 1, gold_bars) | ||||
| 106 | |||||
| 107 | print(elections_2026.get_results()) # {"БСП": 1, "ГЕРБ-СДС": 5} |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | class Currency: | f | 1 | class Currency: |
| 2 | def __init__(self, name, required_for_one_vote): | 2 | def __init__(self, name, required_for_one_vote): | ||
| 3 | self.name = name | 3 | self.name = name | ||
| 4 | self.required_for_one_vote = required_for_one_vote | 4 | self.required_for_one_vote = required_for_one_vote | ||
| 5 | 5 | ||||
| 6 | def __eq__(self, other): | 6 | def __eq__(self, other): | ||
| n | 7 | return self.name == other.name | n | 7 | return ( |
| 8 | False | ||||
| 9 | if other is None | ||||
| 10 | else (self.name == other.name and self.required_for_one_vote == other.required_for_one_vote) | ||||
| 11 | ) | ||||
| 12 | |||||
| 13 | def __hash__(self): | ||||
| 14 | return hash(self.name) | ||||
| 8 | 15 | ||||
| 9 | def convert_to_voters(self, amount): | 16 | def convert_to_voters(self, amount): | ||
| 10 | return amount // self.required_for_one_vote | 17 | return amount // self.required_for_one_vote | ||
| 11 | 18 | ||||
| 12 | 19 | ||||
| 13 | class PoliticalParty: | 20 | class PoliticalParty: | ||
| 14 | def __init__(self, name, motto, members=None, preferred_currency=None): | 21 | def __init__(self, name, motto, members=None, preferred_currency=None): | ||
| 15 | self.name = name | 22 | self.name = name | ||
| n | 16 | self.motto = motto | n | 23 | self._motto = motto |
| 17 | self.members = members[:] # Check for mutating in tests | 24 | self.members = members[:] if members else [] # Check for mutating in tests | ||
| 18 | self.preferred_currency = preferred_currency | 25 | self.preferred_currency = preferred_currency | ||
| n | n | 26 | |||
| 27 | def __str__(self): | ||||
| 28 | return self.name | ||||
| 19 | 29 | ||||
| 20 | @property | 30 | @property | ||
| 21 | def motto(self): | 31 | def motto(self): | ||
| 22 | return self._motto | 32 | return self._motto | ||
| 23 | 33 | ||||
| 24 | def convert_currency_to_voters(self, amount, currency): | 34 | def convert_currency_to_voters(self, amount, currency): | ||
| 25 | multiplier = 2 if currency == self.preferred_currency else 1 | 35 | multiplier = 2 if currency == self.preferred_currency else 1 | ||
| 26 | return currency.convert_to_voters(amount) * multiplier | 36 | return currency.convert_to_voters(amount) * multiplier | ||
| 27 | 37 | ||||
| 28 | def __add__(self, other_party): | 38 | def __add__(self, other_party): | ||
| n | 29 | return Coallition(self, other_party) | n | 39 | return Coalition(self, other_party) |
| 30 | 40 | ||||
| 31 | 41 | ||||
| n | 32 | class Coallition: | n | 42 | class Coalition: |
| 33 | def __init__(self, *parties): | 43 | def __init__(self, *parties): | ||
| n | 34 | self.parties = parties | n | 44 | self.parties = list(parties) |
| 45 | |||||
| 46 | def __str__(self): | ||||
| 47 | return "-".join(str(party) for party in self.parties) | ||||
| 35 | 48 | ||||
| 36 | @property | 49 | @property | ||
| 37 | def members(self): | 50 | def members(self): | ||
| n | 38 | return {party.name: party.members for party in self.parties} | n | 51 | return {str(party): party.members for party in self.parties} |
| 39 | 52 | ||||
| n | 40 | def __add__(self, coallition_or_party): | n | 53 | def __add__(self, coalition_or_party): |
| 41 | if isinstance(PoliticalParty): | 54 | parties_to_append = ( | ||
| 42 | self.parties.append(PoliticalParty) | 55 | [coalition_or_party] if isinstance(coalition_or_party, PoliticalParty) else coalition_or_party.parties | ||
| 43 | return self | 56 | ) | ||
| 44 | 57 | return self.__class__(*self.parties, *parties_to_append) | |||
| 45 | return Coallition(*self.parties, *coallition_or_party.parties) | ||||
| 46 | 58 | ||||
| 47 | def convert_currency_to_voters(self, amount, currency): | 59 | def convert_currency_to_voters(self, amount, currency): | ||
| n | 48 | preferred_currencies = { | n | ||
| 49 | party.preferred_currency: party for party in self.parties | 60 | preferred_currencies = {party.preferred_currency: party for party in self.parties} | ||
| 50 | } | 61 | return preferred_currencies.get(currency, self.parties[0]).convert_currency_to_voters(amount, currency) | ||
| 51 | return preferred_currencies.get( | ||||
| 52 | currency, self.parties[0] | ||||
| 53 | ).convert_currency_to_voters(amount, currency) | ||||
| 54 | 62 | ||||
| 55 | 63 | ||||
| 56 | class Elections: | 64 | class Elections: | ||
| 57 | ELECTIONS_HISTORY = {} | 65 | ELECTIONS_HISTORY = {} | ||
| 58 | 66 | ||||
| 59 | def __init__(self, year): | 67 | def __init__(self, year): | ||
| 60 | self.year = year | 68 | self.year = year | ||
| 61 | self.__votes = {} | 69 | self.__votes = {} | ||
| 62 | self.ELECTIONS_HISTORY[year] = self | 70 | self.ELECTIONS_HISTORY[year] = self | ||
| 63 | 71 | ||||
| 64 | @classmethod | 72 | @classmethod | ||
| 65 | def get_results_by_year(cls, year): | 73 | def get_results_by_year(cls, year): | ||
| 66 | return cls.ELECTIONS_HISTORY[year].get_results() | 74 | return cls.ELECTIONS_HISTORY[year].get_results() | ||
| 67 | 75 | ||||
| n | 68 | def register_party_or_coallition(self, *parties_or_coallitions): | n | 76 | def register_party_or_coalition(self, *parties_or_coalitions): |
| 69 | self.__votes |= {poc.name: 0 for poc in parties_or_coallitions} | 77 | self.__votes |= {str(party_or_coallition): 0 for party_or_coallition in parties_or_coalitions} | ||
| 70 | 78 | ||||
| n | 71 | def rig_elections(self, party_or_coallition, amount, currency): | n | 79 | def rig_elections(self, party_or_coalition, amount, currency): |
| 72 | self.__votes[party_or_coallition.name] += ( | ||||
| 73 | party_or_coallition.convert_currency_to_voters(amount, currency) | 80 | self.__votes[str(party_or_coalition)] += party_or_coalition.convert_currency_to_voters(amount, currency) | ||
| 74 | ) | ||||
| 75 | 81 | ||||
| 76 | def get_results(self): | 82 | def get_results(self): | ||
| 77 | return self.__votes | 83 | return self.__votes | ||
| 78 | 84 | ||||
| t | 79 | def vote(self, party_or_coallition): | t | 85 | def vote(self, party_or_coalition): |
| 80 | self.__votes[party_or_coallition.name] += 1 | 86 | self.__votes[str(party_or_coalition)] += 1 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||