diff --git a/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_30_PD.py b/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_30_PD.py index 5d102db1..4f0d8871 100644 --- a/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_30_PD.py +++ b/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_30_PD.py @@ -5,6 +5,8 @@ from orm.entities import Area, Candidate, Party, Election from orm.entities.Election import ElectionCandidate from orm.entities.SubmissionVersion import TallySheetVersion +from orm.entities.SubmissionVersion.TallySheetVersion.fake_polling_division_voters_map import \ + get_polling_division_total_registered_voters from orm.entities.TallySheetVersionRow import TallySheetVersionRow_PRE_30_PD, TallySheetVersionRow_RejectedVoteCount from util import to_comma_seperated_num, sqlalchemy_num_or_zero, to_percentage, convert_image_to_data_uri, \ split_area_name @@ -248,26 +250,10 @@ def content(self): func.cast(Area.Model.areaName, db.Integer) ).all() - def get_total_registered_voters(self): - election = self.submission.election - total_registered_voters = 0 - - if election.voteType == VoteTypeEnum.Postal: - electoral_district = self.submission.area - postal_counting_centres = electoral_district.get_associated_areas( - areaType=AreaTypeEnum.CountingCentre, - electionId=election.electionId - ) - for postal_counting_centre in postal_counting_centres: - total_registered_voters = total_registered_voters + postal_counting_centre._registeredVotersCount - else: - total_registered_voters = self.submission.area.registeredVotersCount - return total_registered_voters - def html_letter(self): stamp = self.stamp - total_registered_voters = self.get_total_registered_voters() + total_registered_voters = get_polling_division_total_registered_voters(tallySheetVersion=self) content = { "election": { @@ -417,7 +403,7 @@ def html(self): def json_data(self): - total_registered_voters = self.get_total_registered_voters() + total_registered_voters = get_polling_division_total_registered_voters(tallySheetVersion=self) electoral_district = Area.get_associated_areas(self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName polling_division = self.submission.area.areaName @@ -429,7 +415,7 @@ def json_data(self): candidates.append({ "party_code": candidate_wise_valid_vote_count_result_item.partyAbbreviation, "votes": str(candidate_wise_valid_vote_count_result_item.validVoteCount), - "percentage": f'{round(candidate_wise_valid_vote_count_result_item.validVotePercentage or 0,2)}', + "percentage": f'{round(candidate_wise_valid_vote_count_result_item.validVotePercentage or 0, 2)}', "party_name": candidate_wise_valid_vote_count_result_item.partyName, "candidate": candidate_wise_valid_vote_count_result_item.candidateName }) diff --git a/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_34_PD.py b/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_34_PD.py index 25b89246..e611f657 100644 --- a/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_34_PD.py +++ b/orm/entities/SubmissionVersion/TallySheetVersion/TallySheetVersion_PRE_34_PD.py @@ -5,6 +5,8 @@ from orm.entities import Area, Candidate, Party, Election from orm.entities.Election import ElectionCandidate from orm.entities.SubmissionVersion import TallySheetVersion +from orm.entities.SubmissionVersion.TallySheetVersion.fake_polling_division_voters_map import \ + get_polling_division_total_registered_voters from orm.entities.TallySheetVersionRow import TallySheetVersionRow_PRE_34_preference from util import to_comma_seperated_num, sqlalchemy_num_or_zero, convert_image_to_data_uri, split_area_name from orm.enums import TallySheetCodeEnum, AreaTypeEnum, VoteTypeEnum @@ -70,6 +72,7 @@ def content(self): def html_letter(self): stamp = self.stamp + total_registered_voters = get_polling_division_total_registered_voters(tallySheetVersion=self) content = { "election": { @@ -89,7 +92,7 @@ def html_letter(self): "rejectedVoteCounts": [0, 0], "totalVoteCounts": [0, 0], "registeredVoters": [ - to_comma_seperated_num(self.submission.area.registeredVotersCount), + to_comma_seperated_num(total_registered_voters), 100 ], "electoralDistrict": Area.get_associated_areas( diff --git a/orm/entities/SubmissionVersion/TallySheetVersion/fake_polling_division_voters_map.py b/orm/entities/SubmissionVersion/TallySheetVersion/fake_polling_division_voters_map.py new file mode 100644 index 00000000..fa4a45ed --- /dev/null +++ b/orm/entities/SubmissionVersion/TallySheetVersion/fake_polling_division_voters_map.py @@ -0,0 +1,189 @@ +# TODO remove this + +from orm.enums import VoteTypeEnum, AreaTypeEnum + +polling_division_postal_voters_count = { + "3": 480, + "140": 981, + "358": 1061, + "454": 1401, + "551": 478, + "614": 761, + "698": 927, + "803": 1800, + "1005": 1015, + "1112": 4495, + "1387": 4347, + "1589": 7254, + "1872": 3255, + "2067": 4147, + "2330": 1518, + "2508": 1307, + "2691": 775, + "2858": 2548, + "3082": 3876, + "3253": 6620, + "3445": 5311, + "3644": 5926, + "3853": 5932, + "4079": 2493, + "4274": 4706, + "4498": 4962, + "4678": 2847, + "4856": 1311, + "5003": 3070, + "5158": 5139, + "5338": 5210, + "5496": 3413, + "5622": 5761, + "5767": 5061, + "5923": 2660, + "6077": 4903, + "6269": 4164, + "6377": 7964, + "6639": 4150, + "6779": 3712, + "6894": 2855, + "6986": 5106, + "7125": 3716, + "7241": 3692, + "7368": 1616, + "7433": 5554, + "7570": 4727, + "7707": 4559, + "7870": 4121, + "8023": 7636, + "8251": 3985, + "8400": 4644, + "8534": 5029, + "8707": 6502, + "9244": 2879, + "9413": 4692, + "9569": 4051, + "9726": 2218, + "9833": 3822, + "9975": 2682, + "10106": 4570, + "10261": 4408, + "10451": 4309, + "10627": 4265, + "10772": 3747, + "10913": 4870, + "11076": 3154, + "11238": 3095, + "11374": 4246, + "11513": 4209, + "11651": 4825, + "11786": 3446, + "11920": 5010, + "12055": 3408, + "12200": 5076, + "12381": 3931, + "12539": 4918, + "12756": 5410, + "13062": 700, + "13160": 2100, + "13278": 1400, + "13398": 2100, + "13527": 2100, + "13656": 2100, + "13766": 1844, + "13862": 2036, + "13969": 2827, + "14078": 1696, + "14168": 2868, + "14378": 4009, + "14540": 4140, + "14837": 2845, + "15118": 2309, + "15366": 6513, + "15766": 2700, + "16006": 14564, + "16379": 2306, + "16572": 2215, + "16727": 5175, + "17096": 6415, + "17292": 3900, + "17508": 3833, + "17736": 8412, + "17905": 6953, + "18055": 9061, + "18224": 6135, + "18385": 5405, + "18503": 3951, + "18627": 3111, + "18772": 3008, + "18931": 5265, + "19095": 5165, + "19247": 4951, + "19367": 5149, + "19499": 5396, + "19649": 3994, + "19762": 2042, + "19939": 5619, + "20134": 2634, + "20312": 1881, + "20452": 1577, + "20612": 8624, + "20798": 7467, + "20973": 7841, + "21159": 7271, + "21365": 7968, + "21615": 4474, + "21755": 5456, + "21935": 4990, + "22100": 4624, + "22254": 7622, + "22541": 5989, + "22702": 3264, + "22805": 2989, + "22935": 4125, + "23024": 3948, + "23146": 3630, + "23254": 4373, + "23383": 4723, + "23520": 3639, + "23645": 7435, + "23851": 7783, + "24091": 7112, + "24384": 3798, + "24534": 4790, + "24723": 2269, + "24860": 4768, + "25056": 3820, + "25221": 2690, + "25380": 2046, + "25487": 5534, + "25702": 4343, + "25867": 3741, + "25994": 4540, + "26127": 4223, + "26239": 4733, + "26393": 3079, + "26504": 2584, + "26647": 2965, + "26788": 2361 +} + + +def get_polling_division_total_registered_voters(tallySheetVersion): + election = tallySheetVersion.submission.election + polling_division_id = tallySheetVersion.submission.areaId + total_registered_voters = 0 + + if election.voteType == VoteTypeEnum.Postal: + electoral_district = tallySheetVersion.submission.area + postal_counting_centres = electoral_district.get_associated_areas( + areaType=AreaTypeEnum.CountingCentre, + electionId=election.electionId + ) + for postal_counting_centre in postal_counting_centres: + total_registered_voters = total_registered_voters + postal_counting_centre._registeredVotersCount + else: + total_registered_voters = tallySheetVersion.submission.area.registeredVotersCount + + if str(polling_division_id) in polling_division_postal_voters_count: + total_registered_postal_voters = polling_division_postal_voters_count[str(polling_division_id)] + total_registered_voters = total_registered_voters - total_registered_postal_voters + + return total_registered_voters