♻️ Refactor output text to de_DE

This commit is contained in:
Brian Wiborg 2023-04-03 13:37:17 +02:00
parent e209036d1f
commit 4eeff41537
No known key found for this signature in database
GPG Key ID: BE53FA9286B719D6

View File

@ -16,9 +16,9 @@ import json.tool
class Vote(Enum): class Vote(Enum):
"""Vote represents a vote by a voter.""" """Vote represents a vote by a voter."""
YES = 0 JA = 0
NO = 1 NEIN = 1
ABSTENTION = 2 ENTHALTUNG = 2
class Voting(object): class Voting(object):
@ -51,6 +51,9 @@ class Voting(object):
for voter in votes: for voter in votes:
self.votes[voter] = self.votes[voter] if isinstance(votes[voter], Vote) else Vote[votes[voter]] self.votes[voter] = self.votes[voter] if isinstance(votes[voter], Vote) else Vote[votes[voter]]
def __repr__(self) -> str:
return self.title
def is_over(self) -> bool: def is_over(self) -> bool:
return Arrow.utcnow() >= arrow_get(self.start).shift(days=self.days) return Arrow.utcnow() >= arrow_get(self.start).shift(days=self.days)
@ -78,7 +81,7 @@ class Voting(object):
f.write(self.dumps()) f.write(self.dumps())
@classmethod @classmethod
def loads(cls, data: Dict) -> None: def loads(cls, data: str) -> None:
return cls(**json.loads(data)) return cls(**json.loads(data))
@classmethod @classmethod
@ -90,6 +93,15 @@ class Voting(object):
class Result: class Result:
voting: Voting voting: Voting
def __repr__(self):
votes = self.votes()
out = []
if self.voting.quorum.kind != QuorumKind.NONE:
out.append(f"QUORUM: {self.voting.quorum.value}{'%' if self.voting.quorum.kind == QuorumKind.PERCENT else ''}")
out.append(f"GESAMT: {len(self.voting.votes)} => DAFUER: {votes[Vote.JA.name]} DAGEGEN: {votes[Vote.NEIN.name]} ENTHALTUNGEN: {votes[Vote.ENTHALTUNG.name]}")
out.append(f"ERGEBNIS: {self.outcome()}")
return '\n'.join(out)
@abc.abstractmethod @abc.abstractmethod
def result(self) -> Dict: def result(self) -> Dict:
return { return {
@ -104,7 +116,7 @@ class Result:
if not self.has_ended(): if not self.has_ended():
return "LAUFEND" return "LAUFEND"
else: else:
return "ANGENOMMEN" if self.votes()[Vote.YES.name] > self.votes()[Vote.NO.name] and self.quorum_reached() else "ABGELEHNT" return "ANGENOMMEN" if self.votes()[Vote.JA.name] > self.votes()[Vote.NEIN.name] and self.quorum_reached() else "ABGELEHNT"
def has_ended(self) -> bool: def has_ended(self) -> bool:
end_at = arrow_get(self.voting.start).shift(days=self.voting.days) end_at = arrow_get(self.voting.start).shift(days=self.voting.days)
@ -112,9 +124,9 @@ class Result:
def votes(self) -> Dict: def votes(self) -> Dict:
return { return {
Vote.YES.name: len([vote for vote in self.voting.votes if self.voting.votes[vote] == Vote.YES]), Vote.JA.name: len([vote for vote in self.voting.votes if self.voting.votes[vote] == Vote.JA]),
Vote.NO.name: len([vote for vote in self.voting.votes if self.voting.votes[vote] == Vote.NO]), Vote.NEIN.name: len([vote for vote in self.voting.votes if self.voting.votes[vote] == Vote.NEIN]),
Vote.ABSTENTION.name: len([vote for vote in self.voting.votes if self.voting.votes[vote] == Vote.ABSTENTION]), Vote.ENTHALTUNG.name: len([vote for vote in self.voting.votes if self.voting.votes[vote] == Vote.ENTHALTUNG]),
} }
def quorum_reached(self) -> bool: def quorum_reached(self) -> bool: