From 1c14a2853f8b65c581e71a16c31ad8e42a26e2d1 Mon Sep 17 00:00:00 2001 From: sm1990 Date: Mon, 5 Apr 2021 19:15:58 +0530 Subject: [PATCH 1/7] gh-879: PCE-CE-RO-PR-1 - Report template update --- .../PCE-CE-RO-PR-1.html | 106 ++++++++++-------- 1 file changed, 61 insertions(+), 45 deletions(-) diff --git a/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-PR-1.html b/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-PR-1.html index 1900d24b..c30e73ee 100644 --- a/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-PR-1.html +++ b/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-PR-1.html @@ -17,40 +17,24 @@ }
-
- Report: CE-RO-PR/1 -
- - - - - - - - - + -
-

{{content.election.electionName}}

+
+
{{content.election.electionName}}
CENTER FOR DECLARATION OF RESULTS
TOTAL OF PREFERENCES COUNTED IN ALL THE COUNTING CENTERS
- (Inclusive of those counted at the Postal Votes Counting Centers) -
-

RO

-
- *Polling Division/Postal Voting/Votes of displaced Voters : - {{content.pollingDivision}} - - Name of Political Party/ Independent Group No : - {{content.partyName}} - + {{content.partyName}}
Administrative District : - {{content.administrativeDistrict}} + {{content.administrativeDistrict}} +
+

CE-RO-PR/1

+


+
Polling Division : {{content.pollingDivision}}
@@ -60,9 +44,6 @@

{{content.election.electionName}}

Serial No. of the Candidate Counting Centre No. Total - - Order of Candidates according to the No. of Preferences - {% for countingCentre in content.countingCentres %} @@ -77,37 +58,72 @@

{{content.election.electionName}}

{{cell}} {% endfor %} - {% endfor %} - - - - - + Total {% for totalVoteCount in content.totalVoteCounts %} {{totalVoteCount}} {% endfor %} + + - + Ensure that the results are entered under the correct Center No. - - - - - + + + + + + + - - - - - + + + + +
Date: ............................................Prepared by (Name): ....................................... Signature: .......................................
Date: ............................................ +
+ Time: ............................................ +
+ ....................................... +
+ Returning Officer
+ {{content.administrativeDistrict}} Administrative District +
1 +
+ Prepared by:

+ Signature .......................

+ Name ..........................

+ Designation ........................ +
+
+
+ Checked by:

+ Signature .......................

+ Name ..........................

+ Designation ........................ +
+
Checked by (Name): ....................................... Signature: ..............................................................................
Returning Officer
2 +
+ Prepared by:

+ Signature .......................

+ Name ..........................

+ Designation ........................ +
+
+
+ Checked by:

+ Signature .......................

+ Name ..........................

+ Designation ........................ +
+
From 0dfc9b568ca368bd7910c13b289eb94496b8ea9a Mon Sep 17 00:00:00 2001 From: umayanga Date: Mon, 19 Apr 2021 17:23:28 +0530 Subject: [PATCH 2/7] post election tallysheet code added --- .../TALLY_SHEET_CODE.js | 1 + .../ProvincialCouncilElection2021/index.js | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/TALLY_SHEET_CODE.js b/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/TALLY_SHEET_CODE.js index 06a081c6..0a9d9dab 100644 --- a/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/TALLY_SHEET_CODE.js +++ b/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/TALLY_SHEET_CODE.js @@ -23,3 +23,4 @@ export const TALLY_SHEET_CODE_PCE_PC_BS_1 = "PCE-PC-BS-1"; export const TALLY_SHEET_CODE_PCE_PC_BS_2 = "PCE-PC-BS-2"; export const TALLY_SHEET_CODE_PCE_PC_SA_1 = "PCE-PC-SA-1"; export const TALLY_SHEET_CODE_PCE_PC_SA_2 = "PCE-PC-SA-2"; +export const TALLY_SHEET_CODE_PCE_POST_PC = "PCE-POST-PC"; diff --git a/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/index.js b/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/index.js index 2bda42b1..ea0553a0 100644 --- a/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/index.js +++ b/results-tabulation-ui/src/components/election/extended-election/ProvincialCouncilElection2021/index.js @@ -28,7 +28,8 @@ import { TALLY_SHEET_CODE_PCE_PC_BS_1, TALLY_SHEET_CODE_PCE_PC_BS_2, TALLY_SHEET_CODE_PCE_PC_SA_1, - TALLY_SHEET_CODE_PCE_PC_SA_2 + TALLY_SHEET_CODE_PCE_PC_SA_2, + TALLY_SHEET_CODE_PCE_POST_PC } from "./TALLY_SHEET_CODE"; import {Link, useHistory} from "react-router-dom"; import Divider from "@material-ui/core/Divider"; @@ -164,6 +165,36 @@ export default class ExtendedElectionProvincialCouncilElection2021 extends Exten + +

Post Election Reports

+ + + +
    + {(() => { + let tallySheetCodes = [TALLY_SHEET_CODE_PCE_POST_PC + + ]; + let tallySheetCodeLabels = [ + "Provincial Results Summary" + ]; + + return tallySheetCodes.map((tallySheetCode, tallySheetCodeIndex) => { + return
  • + {tallySheetCodeLabels[tallySheetCodeIndex]} + + List + +
  • + }); + })()} + +
+
+ From f1b5b2a60c7bcd661d525bb2c047fb621024d8ab Mon Sep 17 00:00:00 2001 From: umayanga Date: Wed, 28 Apr 2021 16:14:05 +0530 Subject: [PATCH 3/7] fix typo --- .../templates/ProvincialCouncilElection2021/PCE-CE-RO-V2.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-V2.html b/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-V2.html index e98f2d5e..8e9747c5 100644 --- a/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-V2.html +++ b/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-CE-RO-V2.html @@ -30,7 +30,7 @@

{{content.election.electionName}}

- RETURNING OFFICER'S STATEMENTOF THE TOTAL NUMBER OF VOTES POLLED BY + RETURNING OFFICER'S STATEMENT OF THE TOTAL NUMBER OF VOTES POLLED BY
EACH PARTY/ INDEPENDENT GROUP FOR THE ELECTOTRAL DISTRICT
From 3d290c5b3e245136a21e35d2cbe4792845a59e2b Mon Sep 17 00:00:00 2001 From: umayanga Date: Wed, 28 Apr 2021 16:14:59 +0530 Subject: [PATCH 4/7] initialize post election report --- .../get_extended_tally_sheet_class.py | 5 +- .../ExtendedTallySheet_PCE_POST_PC.py | 257 ++++++++++++++++++ .../RoleBasedAccess.py | 8 +- .../TALLY_SHEET_CODES.py | 2 + .../TallysheetTemplates/pce_post_pc.py | 55 ++++ .../__init__.py | 27 +- 6 files changed, 347 insertions(+), 7 deletions(-) create mode 100644 results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py create mode 100644 results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedFunctions/get_extended_tally_sheet_class.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedFunctions/get_extended_tally_sheet_class.py index a7311f78..1c016eda 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedFunctions/get_extended_tally_sheet_class.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedFunctions/get_extended_tally_sheet_class.py @@ -38,10 +38,12 @@ ExtendedTallySheet_PCE_PC_V from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.ExtendedTallySheet.ExtendedTallySheet_PCE_PD_V import \ ExtendedTallySheet_PCE_PD_V +from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.ExtendedTallySheet.ExtendedTallySheet_PCE_POST_PC import \ + ExtendedTallySheet_PCE_POST_PC from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TALLY_SHEET_CODES import CE_201, CE_201_PV, \ PCE_31, PCE_34, PCE_35, PCE_42, PCE_CE_CO_PR_1, PCE_CE_CO_PR_2, PCE_CE_CO_PR_3, PCE_CE_CO_PR_4, PCE_CE_RO_PR_1, \ PCE_CE_RO_PR_2, PCE_CE_RO_PR_3, PCE_CE_RO_V1, PCE_CE_RO_V2, PCE_R1, PCE_R1_PV, PCE_R2, PCE_PD_V, PCE_PC_V, \ - PCE_PC_CD, PCE_PC_BS_1, PCE_PC_BS_2, PCE_PC_SA_1, PCE_PC_SA_2 + PCE_PC_CD, PCE_PC_BS_1, PCE_PC_BS_2, PCE_PC_SA_1, PCE_PC_SA_2, PCE_POST_PC def get_extended_tally_sheet_class(election, templateName, electionClass): @@ -66,6 +68,7 @@ def get_extended_tally_sheet_class(election, templateName, electionClass): PCE_PC_V: ExtendedTallySheet_PCE_PC_V, PCE_PD_V: ExtendedTallySheet_PCE_PD_V, PCE_R2: ExtendedTallySheet_PCE_R2, + PCE_POST_PC: ExtendedTallySheet_PCE_POST_PC } if templateName in EXTENDED_TEMPLATE_MAP: diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py new file mode 100644 index 00000000..6133e081 --- /dev/null +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py @@ -0,0 +1,257 @@ +from flask import render_template +import re + +from ext.ExtendedTallySheet import ExtendedTallySheetReport +from constants.VOTE_TYPES import NonPostal +from util import to_comma_seperated_num, to_percentage, convert_image_to_data_uri + + +class ExtendedTallySheet_PCE_POST_PC(ExtendedTallySheetReport): + def on_get_release_result_params(self): + pd_code = None + pd_name = None + ed_code = None + ed_name = None + + result_type = "RE_V" + result_code = ed_code + result_level = "PROVINCIAL" + + return result_type, result_code, result_level, ed_code, ed_name, pd_code, pd_name + + class ExtendedTallySheetVersion(ExtendedTallySheetReport.ExtendedTallySheetVersion): + def json(self): + extended_tally_sheet = self.tallySheet.get_extended_tally_sheet() + result_type, result_code, result_level, ed_code, ed_name, pd_code, pd_name = extended_tally_sheet.on_get_release_result_params() + + party_wise_results = self.get_party_wise_valid_vote_count_result().sort_values( + by=['numValue', "electionPartyId"], ascending=[False, True] + ).reset_index() + + registered_voters_count = self.tallySheetVersion.tallySheet.area.get_registered_voters_count( + vote_type=self.tallySheetVersion.tallySheet.election.voteType) + total_valid_vote_count = 0 + total_rejected_vote_count = self.get_rejected_vote_count_result()["numValue"].values[0] + for party_wise_result in party_wise_results.itertuples(): + total_valid_vote_count += float(party_wise_result.numValue) + total_vote_count = total_valid_vote_count + total_rejected_vote_count + + return { + "type": result_type, + "level": result_level, + "ed_code": ed_code, + "ed_name": ed_name, + "by_party": [ + { + "party_code": party_wise_result.partyAbbreviation, + "party_name": party_wise_result.partyName, + "vote_count": int(party_wise_result.numValue), + "vote_percentage": to_percentage((party_wise_result.numValue / total_valid_vote_count) * 100), + "seat_count": 0, + "bonus_seat_count": 0 + } for party_wise_result in party_wise_results.itertuples() + ], + "summary": { + "valid": int(total_valid_vote_count), + "rejected": int(total_rejected_vote_count), + "polled": int(total_vote_count), + "electors": int(registered_voters_count), + "percent_valid": to_percentage((total_valid_vote_count / total_vote_count) * 100), + "percent_rejected": to_percentage((total_rejected_vote_count / total_vote_count) * 100), + "percent_polled": to_percentage((total_vote_count / registered_voters_count) * 100) + } + } + + # def html_letter(self, title="", total_registered_voters=None, signatures=[]): + # tallySheetVersion = self.tallySheetVersion + # party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result() + # area_wise_valid_vote_count_result = self.get_area_wise_valid_vote_count_result() + # area_wise_rejected_vote_count_result = self.get_area_wise_rejected_vote_count_result() + # area_wise_vote_count_result = self.get_area_wise_vote_count_result() + # stamp = tallySheetVersion.stamp + # + # registered_voters_count = tallySheetVersion.tallySheet.area.get_registered_voters_count( + # vote_type=tallySheetVersion.tallySheet.election.voteType) + # + # content = { + # "election": { + # "electionName": tallySheetVersion.tallySheet.election.get_official_name() + # }, + # "stamp": { + # "createdAt": stamp.createdAt, + # "createdBy": stamp.createdBy, + # "barcodeString": stamp.barcodeString + # }, + # "signatures": signatures, + # "administrativeDistrict": tallySheetVersion.tallySheet.area.areaName, + # "data": [], + # "validVoteCounts": [0, "0%"], + # "rejectedVoteCounts": [0, "0%"], + # "totalVoteCounts": [0, "0%"], + # "registeredVoters": [ + # to_comma_seperated_num(registered_voters_count), + # 100 + # ], + # "logo": convert_image_to_data_uri("static/Emblem_of_Sri_Lanka.png"), + # "date": stamp.createdAt.strftime("%d/%m/%Y"), + # "time": stamp.createdAt.strftime("%H:%M:%S %p") + # } + # + # total_vote_count = 0 + # for area_wise_vote_count_result_item in area_wise_vote_count_result.itertuples(): + # total_vote_count += float(area_wise_vote_count_result_item.incompleteNumValue) + # content["totalVoteCounts"][0] = to_comma_seperated_num(total_vote_count) + # content["totalVoteCounts"][1] = to_percentage((total_vote_count / registered_voters_count) * 100) + # + # total_valid_vote_count = 0 + # for area_wise_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples(): + # total_valid_vote_count += float(area_wise_valid_vote_count_result_item.incompleteNumValue) + # content["validVoteCounts"][0] = to_comma_seperated_num(total_valid_vote_count) + # content["validVoteCounts"][1] = to_percentage((total_valid_vote_count / total_vote_count) * 100) + # + # total_rejected_vote_count = 0 + # for area_wise_rejected_vote_count_result_item in area_wise_rejected_vote_count_result.itertuples(): + # total_rejected_vote_count += float(area_wise_rejected_vote_count_result_item.numValue) + # content["rejectedVoteCounts"][0] = to_comma_seperated_num(total_rejected_vote_count) + # content["rejectedVoteCounts"][1] = to_percentage((total_rejected_vote_count / total_vote_count) * 100) + # + # # sort by vote count descending + # party_wise_valid_vote_count_result = party_wise_valid_vote_count_result.sort_values( + # by=['numValue', "electionPartyId"], ascending=[False, True] + # ).reset_index() + # + # for party_wise_valid_vote_count_result_item_index, party_wise_valid_vote_count_result_item in party_wise_valid_vote_count_result.iterrows(): + # data_row = [ + # party_wise_valid_vote_count_result_item.partyName, + # party_wise_valid_vote_count_result_item.partyAbbreviation, + # to_comma_seperated_num(party_wise_valid_vote_count_result_item.numValue) + # ] + # + # if total_valid_vote_count > 0: + # data_row.append(to_percentage( + # party_wise_valid_vote_count_result_item.numValue * 100 / total_valid_vote_count)) + # else: + # data_row.append('') + # + # content["data"].append(data_row) + # + # html = render_template( + # 'ProvincialCouncilElection2021/PCE-CE-RO-V2-LETTER.html', + # content=content + # ) + # + # return html + + # def html(self, title="", total_registered_voters=None): + # tallySheetVersion = self.tallySheetVersion + # + # party_and_area_wise_valid_non_postal_vote_count_result = self.get_party_and_area_wise_valid_non_postal_vote_count_result() + # area_wise_valid_non_postal_vote_count_result = self.get_area_wise_valid_non_postal_vote_count_result() + # area_wise_rejected_non_postal_vote_count_result = self.get_area_wise_rejected_non_postal_vote_count_result() + # area_wise_non_postal_vote_count_result = self.get_area_wise_non_postal_vote_count_result() + # party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result() + # + # vote_count_result = self.get_vote_count_result() + # valid_vote_count_result = self.get_valid_vote_count_result() + # rejected_vote_count_result = self.get_rejected_vote_count_result() + # + # stamp = tallySheetVersion.stamp + # election = tallySheetVersion.tallySheet.election + # non_postal_vote_types = [] + # for sub_election in election.subElections: + # if sub_election.voteType != NonPostal: + # non_postal_vote_types.append(sub_election.voteType) + # + # content = { + # "election": { + # "electionName": election.get_official_name() + # }, + # "stamp": { + # "createdAt": stamp.createdAt, + # "createdBy": stamp.createdBy, + # "barcodeString": stamp.barcodeString + # }, + # "tallySheetCode": "CE/RO/V/2", + # "administrativeDistrict": tallySheetVersion.tallySheet.area.areaName, + # "nonPostalVoteTypes": non_postal_vote_types, + # "data": [], + # "pollingDivisions": [], + # "validVoteCounts": [], + # "rejectedVoteCounts": [], + # "totalVoteCounts": [] + # } + # + # total_valid_vote_count = 0 + # total_rejected_vote_count = 0 + # total_vote_count = 0 + # + # # Append the area wise column totals + # for area_wise_non_postal_vote_count_result_item_index, area_wise_non_postal_vote_count_result_item in area_wise_non_postal_vote_count_result.iterrows(): + # content["totalVoteCounts"].append( + # to_comma_seperated_num(area_wise_non_postal_vote_count_result_item.incompleteNumValue)) + # total_vote_count += area_wise_non_postal_vote_count_result_item.incompleteNumValue + # for area_wise_valid_non_postal_vote_count_result_item in area_wise_valid_non_postal_vote_count_result.itertuples(): + # content["pollingDivisions"].append(area_wise_valid_non_postal_vote_count_result_item.areaName) + # content["validVoteCounts"].append( + # to_comma_seperated_num(area_wise_valid_non_postal_vote_count_result_item.incompleteNumValue)) + # total_valid_vote_count += area_wise_valid_non_postal_vote_count_result_item.incompleteNumValue + # + # for area_wise_rejected_non_postal_vote_count_result_item_index, area_wise_rejected_non_postal_vote_count_result_item in area_wise_rejected_non_postal_vote_count_result.iterrows(): + # content["rejectedVoteCounts"].append( + # to_comma_seperated_num(area_wise_rejected_non_postal_vote_count_result_item.numValue)) + # total_rejected_vote_count += area_wise_rejected_non_postal_vote_count_result_item.numValue + # + # for vote_type in non_postal_vote_types: + # postal_vote_count_result = self.get_vote_count_result(vote_type=vote_type) + # postal_valid_vote_count_result = self.get_valid_vote_count_result(vote_type=vote_type) + # postal_rejected_vote_count_result = self.get_rejected_vote_count_result(vote_type=vote_type) + # + # # Append the postal vote count totals + # content["pollingDivisions"].append("%s Votes" % vote_type) + # content["validVoteCounts"].append( + # to_comma_seperated_num(postal_valid_vote_count_result["incompleteNumValue"].values[0])) + # content["rejectedVoteCounts"].append( + # to_comma_seperated_num(postal_rejected_vote_count_result["numValue"].values[0])) + # content["totalVoteCounts"].append( + # to_comma_seperated_num(postal_vote_count_result["incompleteNumValue"].values[0])) + # + # # Append the grand totals + # content["validVoteCounts"].append( + # to_comma_seperated_num(valid_vote_count_result["incompleteNumValue"].values[0])) + # content["rejectedVoteCounts"].append( + # to_comma_seperated_num(rejected_vote_count_result["incompleteNumValue"].values[0])) + # content["totalVoteCounts"].append(to_comma_seperated_num(vote_count_result["incompleteNumValue"].values[0])) + # + # number_of_counting_centres = len(area_wise_non_postal_vote_count_result) + # + # for party_wise_valid_vote_count_result_item_index, party_wise_valid_vote_count_result_item in party_wise_valid_vote_count_result.iterrows(): + # data_row = [] + # + # data_row.append(party_wise_valid_vote_count_result_item.partyName) + # + # for counting_centre_index in range(number_of_counting_centres): + # party_and_area_wise_valid_non_postal_vote_count_result_item_index = \ + # ( + # number_of_counting_centres * party_wise_valid_vote_count_result_item_index) + counting_centre_index + # + # data_row.append( + # to_comma_seperated_num( + # party_and_area_wise_valid_non_postal_vote_count_result["numValue"].values[ + # party_and_area_wise_valid_non_postal_vote_count_result_item_index])) + # + # for vote_type in non_postal_vote_types: + # party_wise_valid_postal_vote_count_result = self.get_party_wise_valid_vote_count_result( + # vote_type=vote_type) + # data_row.append(to_comma_seperated_num(party_wise_valid_postal_vote_count_result["numValue"].values[ + # party_wise_valid_vote_count_result_item_index])) + # + # data_row.append(to_comma_seperated_num(party_wise_valid_vote_count_result_item.incompleteNumValue)) + # + # content["data"].append(data_row) + # + # html = render_template( + # 'ProvincialCouncilElection2021/PCE-CE-RO-V2.html', + # content=content + # ) + # + # return html diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/RoleBasedAccess.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/RoleBasedAccess.py index 79910093..a56bea01 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/RoleBasedAccess.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/RoleBasedAccess.py @@ -5,7 +5,7 @@ from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TALLY_SHEET_CODES import CE_201, CE_201_PV, \ PCE_31, PCE_34, PCE_35, PCE_CE_CO_PR_1, PCE_CE_CO_PR_2, PCE_CE_CO_PR_3, PCE_CE_CO_PR_4, PCE_CE_RO_V1, PCE_R1, \ PCE_R1_PV, PCE_CE_RO_V2, PCE_R2, PCE_CE_RO_PR_1, PCE_CE_RO_PR_2, PCE_CE_RO_PR_3, PCE_42, PCE_PD_V, PCE_PC_V, \ - PCE_PC_CD, PCE_PC_BS_1, PCE_PC_BS_2, PCE_PC_SA_1, PCE_PC_SA_2 + PCE_PC_CD, PCE_PC_BS_1, PCE_PC_BS_2, PCE_PC_SA_1, PCE_PC_SA_2, PCE_POST_PC from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.WORKFLOW_ACTION_TYPE import \ WORKFLOW_ACTION_TYPE_SAVE, WORKFLOW_ACTION_TYPE_VIEW, WORKFLOW_ACTION_TYPE_SUBMIT, WORKFLOW_ACTION_TYPE_VERIFY, \ @@ -371,6 +371,10 @@ PCE_PC_SA_2: { PostalAndNonPostal: [READ, WRITE, UNLOCK, PRINT, PRINT_LETTER, UPLOAD_PROOF_DOCUMENT, MOVE_TO_CERTIFY, CERTIFY, NOTIFY, RELEASE, BACK_TO_VERIFIED] - } + }, + PCE_POST_PC: { + PostalAndNonPostal: [READ, WRITE, PRINT, PRINT_LETTER, UPLOAD_PROOF_DOCUMENT, MOVE_TO_CERTIFY, + CERTIFY, NOTIFY, RELEASE, BACK_TO_VERIFIED] + }, } } diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TALLY_SHEET_CODES.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TALLY_SHEET_CODES.py index 8708599f..b46faa88 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TALLY_SHEET_CODES.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TALLY_SHEET_CODES.py @@ -32,3 +32,5 @@ PCE_PC_BS_2 = "PCE-PC-BS-2" PCE_PC_SA_1 = "PCE-PC-SA-1" PCE_PC_SA_2 = "PCE-PC-SA-2" + +PCE_POST_PC = "PCE-POST-PC" diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py new file mode 100644 index 00000000..724bb50a --- /dev/null +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py @@ -0,0 +1,55 @@ +from orm.entities import Template +from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TALLY_SHEET_CODES import PCE_POST_PC, \ + PCE_CE_RO_V2, PCE_R2, PCE_PC_BS_1 +from constants.TALLY_SHEET_COLUMN_SOURCE import TALLY_SHEET_COLUMN_SOURCE_QUERY as SOURCE_QUERY, \ + TALLY_SHEET_COLUMN_SOURCE_META as SOURCE_META, TALLY_SHEET_COLUMN_SOURCE_CONTENT as SOURCE_CONTENT +from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TEMPLATE_ROW_TYPE import \ + TEMPLATE_ROW_TYPE_BONUS_SEATS_ALLOCATED, TEMPLATE_ROW_TYPE_SEATS_ALLOCATED + + +def create_template(): + return Template.create( + templateName=PCE_POST_PC, + templateRowTypesMap={ + "PARTY_WISE_VOTE": { + "hasMany": True, + "isDerived": True, + "columns": [ + {"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_QUERY}, + {"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_QUERY}, + {"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_QUERY}, + {"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_QUERY} + ], + "derivativeRows": [ + {"templateName": PCE_CE_RO_V2, "templateRowType": "PARTY_WISE_VOTE"} + ] + }, + TEMPLATE_ROW_TYPE_SEATS_ALLOCATED: { + "hasMany": True, + "isDerived": False, + "columns": [ + {"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_META}, + {"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_META}, + {"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_CONTENT}, + {"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_CONTENT} + ] + , + "derivativeRows": [ + {"templateName": PCE_R2, "templateRowType": "TEMPLATE_ROW_TYPE_SEATS_ALLOCATED"} + ] + }, + TEMPLATE_ROW_TYPE_BONUS_SEATS_ALLOCATED: { + "hasMany": True, + "isDerived": False, + "columns": [ + {"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_META}, + {"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_META}, + {"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_CONTENT}, + {"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_CONTENT} + ], + "derivativeRows": [ + {"templateName": PCE_PC_BS_1, "templateRowType": "TEMPLATE_ROW_TYPE_SEATS_ALLOCATED"} + ] + } + } + ) diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py index e55f23ea..5959327e 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py @@ -58,7 +58,7 @@ pce_31, pce_34, pce_35, pce_ce_ro_v1, pce_ce_ro_v2, pce_r2, pce_ce_co_pr_4, pce_ce_ro_pr_1, pce_ce_ro_pr_2, \ pce_ce_ro_pr_3, pce_42, pce_pc_v, pce_pc_bs_1, pce_pc_bs_2, pce_pc_cd, \ pce_pd_v, pce_pc_sa_2, \ - pce_pc_sa_1 + pce_pc_sa_1, pce_post_pc role_based_access_config = RoleBasedAccess.role_based_access_config @@ -74,7 +74,8 @@ def get_area_map_query(self): return get_area_map_query.get_area_map_query(self) def get_extended_tally_sheet_class(self, templateName): - return get_extended_tally_sheet_class.get_extended_tally_sheet_class(self, templateName, ExtendedElectionProvincialCouncilElection2021) + return get_extended_tally_sheet_class.get_extended_tally_sheet_class(self, templateName, + ExtendedElectionProvincialCouncilElection2021) def build_election(self, party_candidate_dataset_file=None, polling_station_dataset_file=None, postal_counting_centers_dataset_file=None, @@ -127,6 +128,8 @@ def build_election(self, party_candidate_dataset_file=None, tally_sheet_template_pce_pc_bs_1 = pce_pc_bs_1.create_template() tally_sheet_template_pce_pc_bs_2 = pce_pc_bs_2.create_template() + tally_sheet_template_pce_post_pc = pce_post_pc.create_template() + data_entry_store = { AreaTypeEnum.Country: {}, AreaTypeEnum.Province: {}, @@ -222,8 +225,24 @@ def _get_country_entry(row): area_name = row["Country"] area_key = area_name + def _create_country_tally_sheets(area): + pce_post_pc_tally_sheet_list = [TallySheet.create( + template=tally_sheet_template_pce_post_pc, + electionId=root_election.electionId, + areaId=area.areaId, + metaId=Meta.create({ + "areaId": area.areaId, + "electionId": root_election.electionId + }).metaId, + workflowInstanceId=workflow_report.get_new_instance().workflowInstanceId + )] + + return { + "pce_post_pc_tally_sheet_list": pce_post_pc_tally_sheet_list, + } + data_entry_obj = _get_area_entry(root_election, area_class, area_name, area_key, - None) + _create_country_tally_sheets) return data_entry_obj @@ -479,7 +498,7 @@ def _create_administrative_district_tally_sheets(area): "areaId": area.areaId, "electionId": administrative_district_election.electionId }).metaId, - parentTallySheets=[*pce_pc_sa_1_tally_sheet_list,*pce_pc_sa_2_tally_sheet_list, + parentTallySheets=[*pce_pc_sa_1_tally_sheet_list, *pce_pc_sa_2_tally_sheet_list, *pce_42_tally_sheet_list], workflowInstanceId=workflow_edit_allowed_released_report.get_new_instance().workflowInstanceId )] From 5d3db3b1127a6542ac395c5e44a01cc66be0d8b5 Mon Sep 17 00:00:00 2001 From: umayanga Date: Wed, 28 Apr 2021 17:02:14 +0530 Subject: [PATCH 5/7] tallysheet config --- .../__init__.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py index 5959327e..8ae0ae67 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py @@ -263,8 +263,11 @@ def _get_province_entry(row): area_key = area_name province_election = _get_province_election(row) + country = _get_country_entry(row) def _create_province_tally_sheets(area): + pce_post_pc_tally_sheet_list = country.pce_post_pc_tally_sheet_list + pce_pc_cd_tally_sheet_list = [TallySheet.create( template=tally_sheet_template_pce_pc_cd, electionId=province_election.electionId, @@ -308,7 +311,7 @@ def _create_province_tally_sheets(area): "electionId": province_election.electionId }).metaId, parentTallySheets=[*pce_pc_bs_2_tally_sheet_list, *pce_pc_cd_tally_sheet_list, - *pce_pc_sa_2_tally_sheet_list], + *pce_pc_sa_2_tally_sheet_list, *pce_post_pc_tally_sheet_list], workflowInstanceId=workflow_edit_allowed_released_report.get_new_instance().workflowInstanceId )] @@ -410,6 +413,8 @@ def _get_administrative_district_election(row): return election def _get_sub_administrative_district_entry(row, vote_type=None): + country = _get_country_entry(row) + pce_post_pc_tally_sheet_list = country.pce_post_pc_tally_sheet_list administrative_district = _get_administrative_district_entry(row) administrative_district_sub_election = _get_administrative_district_sub_election(row, vote_type=vote_type) @@ -433,7 +438,8 @@ def _get_sub_administrative_district_entry(row, vote_type=None): "electionId": administrative_district_sub_election.electionId }).metaId, parentTallySheets=[pce_pd_v_tally_sheet, - *administrative_district.pce_ce_ro_v2_tally_sheet_list], + *administrative_district.pce_ce_ro_v2_tally_sheet_list, + *pce_post_pc_tally_sheet_list], workflowInstanceId=workflow_released_report.get_new_instance().workflowInstanceId ) administrative_district.pce_ce_ro_v1_tally_sheet_list.append(pce_ce_ro_v1_tally_sheet) @@ -467,6 +473,7 @@ def _get_sub_administrative_district_entry(row, vote_type=None): def _get_administrative_district_entry(row): administrative_district_election = _get_administrative_district_election(row) province = _get_province_entry(row) + country = _get_country_entry(row) area_class = AdministrativeDistrict area_name = row["Administrative District"] @@ -479,6 +486,7 @@ def _create_administrative_district_tally_sheets(area): pce_pc_bs_2_tally_sheet_list = province.pce_pc_bs_2_tally_sheet_list pce_pc_cd_tally_sheet_list = province.pce_pc_cd_tally_sheet_list pce_pc_v_tally_sheet_list = province.pce_pc_v_tally_sheet_list + pce_post_pc_tally_sheet_list = country.pce_post_pc_tally_sheet_list pce_42_tally_sheet_list = [TallySheet.create( template=tally_sheet_template_pce_42, electionId=administrative_district_election.electionId, @@ -499,7 +507,7 @@ def _create_administrative_district_tally_sheets(area): "electionId": administrative_district_election.electionId }).metaId, parentTallySheets=[*pce_pc_sa_1_tally_sheet_list, *pce_pc_sa_2_tally_sheet_list, - *pce_42_tally_sheet_list], + *pce_42_tally_sheet_list, *pce_post_pc_tally_sheet_list], workflowInstanceId=workflow_edit_allowed_released_report.get_new_instance().workflowInstanceId )] @@ -511,7 +519,7 @@ def _create_administrative_district_tally_sheets(area): "electionId": administrative_district_election.electionId }).metaId, parentTallySheets=[*pce_r2_tally_sheet_list, - *pce_pc_v_tally_sheet_list], + *pce_pc_v_tally_sheet_list, *pce_post_pc_tally_sheet_list], workflowInstanceId=workflow_report.get_new_instance().workflowInstanceId )] @@ -703,12 +711,14 @@ def _get_polling_division_entry(row): vote_type=NonPostal) administrative_district = _get_administrative_district_entry(row) + country = _get_country_entry(row) area_class = PollingDivision area_name = row["Polling Division"] area_key = area_name def _create_polling_division_tally_sheets(area): + pce_post_pc_tally_sheet_list = country.pce_post_pc_tally_sheet_list pce_ce_ro_pr_2_tally_sheet_list_party_id_wise_map = administrative_district.pce_ce_ro_pr_2_tally_sheet_list_party_id_wise_map pce_ce_ro_v2_tally_sheet_list = administrative_district.pce_ce_ro_v2_tally_sheet_list @@ -731,7 +741,8 @@ def _create_polling_division_tally_sheets(area): "areaId": area.areaId, "electionId": administrative_district_ordinary_election.electionId }).metaId, - parentTallySheets=[*pce_pd_v_tally_sheet_list, *pce_ce_ro_v2_tally_sheet_list], + parentTallySheets=[*pce_pd_v_tally_sheet_list, *pce_ce_ro_v2_tally_sheet_list, + *pce_post_pc_tally_sheet_list], workflowInstanceId=workflow_released_report.get_new_instance().workflowInstanceId )] From af3d4987fb3e8d5373bde1b2cf97b05a048c9c3c Mon Sep 17 00:00:00 2001 From: umayanga Date: Thu, 29 Apr 2021 23:03:37 +0530 Subject: [PATCH 6/7] post election summary tallysheet --- .../ExtendedTallySheet_PCE_POST_PC.py | 256 +++++------------- .../TallysheetTemplates/pce_post_pc.py | 15 +- .../__init__.py | 7 +- .../PCE-POST-PC.html | 94 +++++++ 4 files changed, 174 insertions(+), 198 deletions(-) create mode 100644 results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-POST-PC.html diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py index 6133e081..0617940b 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py @@ -4,6 +4,8 @@ from ext.ExtendedTallySheet import ExtendedTallySheetReport from constants.VOTE_TYPES import NonPostal from util import to_comma_seperated_num, to_percentage, convert_image_to_data_uri +from orm.entities import Area +from orm.enums import AreaTypeEnum class ExtendedTallySheet_PCE_POST_PC(ExtendedTallySheetReport): @@ -15,7 +17,7 @@ def on_get_release_result_params(self): result_type = "RE_V" result_code = ed_code - result_level = "PROVINCIAL" + result_level = "NATIONAL" return result_type, result_code, result_level, ed_code, ed_name, pd_code, pd_name @@ -36,6 +38,7 @@ def json(self): total_valid_vote_count += float(party_wise_result.numValue) total_vote_count = total_valid_vote_count + total_rejected_vote_count + print("hello") return { "type": result_type, "level": result_level, @@ -62,196 +65,63 @@ def json(self): } } - # def html_letter(self, title="", total_registered_voters=None, signatures=[]): - # tallySheetVersion = self.tallySheetVersion - # party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result() - # area_wise_valid_vote_count_result = self.get_area_wise_valid_vote_count_result() - # area_wise_rejected_vote_count_result = self.get_area_wise_rejected_vote_count_result() - # area_wise_vote_count_result = self.get_area_wise_vote_count_result() - # stamp = tallySheetVersion.stamp - # - # registered_voters_count = tallySheetVersion.tallySheet.area.get_registered_voters_count( - # vote_type=tallySheetVersion.tallySheet.election.voteType) - # - # content = { - # "election": { - # "electionName": tallySheetVersion.tallySheet.election.get_official_name() - # }, - # "stamp": { - # "createdAt": stamp.createdAt, - # "createdBy": stamp.createdBy, - # "barcodeString": stamp.barcodeString - # }, - # "signatures": signatures, - # "administrativeDistrict": tallySheetVersion.tallySheet.area.areaName, - # "data": [], - # "validVoteCounts": [0, "0%"], - # "rejectedVoteCounts": [0, "0%"], - # "totalVoteCounts": [0, "0%"], - # "registeredVoters": [ - # to_comma_seperated_num(registered_voters_count), - # 100 - # ], - # "logo": convert_image_to_data_uri("static/Emblem_of_Sri_Lanka.png"), - # "date": stamp.createdAt.strftime("%d/%m/%Y"), - # "time": stamp.createdAt.strftime("%H:%M:%S %p") - # } - # - # total_vote_count = 0 - # for area_wise_vote_count_result_item in area_wise_vote_count_result.itertuples(): - # total_vote_count += float(area_wise_vote_count_result_item.incompleteNumValue) - # content["totalVoteCounts"][0] = to_comma_seperated_num(total_vote_count) - # content["totalVoteCounts"][1] = to_percentage((total_vote_count / registered_voters_count) * 100) - # - # total_valid_vote_count = 0 - # for area_wise_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples(): - # total_valid_vote_count += float(area_wise_valid_vote_count_result_item.incompleteNumValue) - # content["validVoteCounts"][0] = to_comma_seperated_num(total_valid_vote_count) - # content["validVoteCounts"][1] = to_percentage((total_valid_vote_count / total_vote_count) * 100) - # - # total_rejected_vote_count = 0 - # for area_wise_rejected_vote_count_result_item in area_wise_rejected_vote_count_result.itertuples(): - # total_rejected_vote_count += float(area_wise_rejected_vote_count_result_item.numValue) - # content["rejectedVoteCounts"][0] = to_comma_seperated_num(total_rejected_vote_count) - # content["rejectedVoteCounts"][1] = to_percentage((total_rejected_vote_count / total_vote_count) * 100) - # - # # sort by vote count descending - # party_wise_valid_vote_count_result = party_wise_valid_vote_count_result.sort_values( - # by=['numValue', "electionPartyId"], ascending=[False, True] - # ).reset_index() - # - # for party_wise_valid_vote_count_result_item_index, party_wise_valid_vote_count_result_item in party_wise_valid_vote_count_result.iterrows(): - # data_row = [ - # party_wise_valid_vote_count_result_item.partyName, - # party_wise_valid_vote_count_result_item.partyAbbreviation, - # to_comma_seperated_num(party_wise_valid_vote_count_result_item.numValue) - # ] - # - # if total_valid_vote_count > 0: - # data_row.append(to_percentage( - # party_wise_valid_vote_count_result_item.numValue * 100 / total_valid_vote_count)) - # else: - # data_row.append('') - # - # content["data"].append(data_row) - # - # html = render_template( - # 'ProvincialCouncilElection2021/PCE-CE-RO-V2-LETTER.html', - # content=content - # ) - # - # return html + def html(self, title="", total_registered_voters=None): + tallySheetVersion = self.tallySheetVersion - # def html(self, title="", total_registered_voters=None): - # tallySheetVersion = self.tallySheetVersion - # - # party_and_area_wise_valid_non_postal_vote_count_result = self.get_party_and_area_wise_valid_non_postal_vote_count_result() - # area_wise_valid_non_postal_vote_count_result = self.get_area_wise_valid_non_postal_vote_count_result() - # area_wise_rejected_non_postal_vote_count_result = self.get_area_wise_rejected_non_postal_vote_count_result() - # area_wise_non_postal_vote_count_result = self.get_area_wise_non_postal_vote_count_result() - # party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result() - # - # vote_count_result = self.get_vote_count_result() - # valid_vote_count_result = self.get_valid_vote_count_result() - # rejected_vote_count_result = self.get_rejected_vote_count_result() - # - # stamp = tallySheetVersion.stamp - # election = tallySheetVersion.tallySheet.election - # non_postal_vote_types = [] - # for sub_election in election.subElections: - # if sub_election.voteType != NonPostal: - # non_postal_vote_types.append(sub_election.voteType) - # - # content = { - # "election": { - # "electionName": election.get_official_name() - # }, - # "stamp": { - # "createdAt": stamp.createdAt, - # "createdBy": stamp.createdBy, - # "barcodeString": stamp.barcodeString - # }, - # "tallySheetCode": "CE/RO/V/2", - # "administrativeDistrict": tallySheetVersion.tallySheet.area.areaName, - # "nonPostalVoteTypes": non_postal_vote_types, - # "data": [], - # "pollingDivisions": [], - # "validVoteCounts": [], - # "rejectedVoteCounts": [], - # "totalVoteCounts": [] - # } - # - # total_valid_vote_count = 0 - # total_rejected_vote_count = 0 - # total_vote_count = 0 - # - # # Append the area wise column totals - # for area_wise_non_postal_vote_count_result_item_index, area_wise_non_postal_vote_count_result_item in area_wise_non_postal_vote_count_result.iterrows(): - # content["totalVoteCounts"].append( - # to_comma_seperated_num(area_wise_non_postal_vote_count_result_item.incompleteNumValue)) - # total_vote_count += area_wise_non_postal_vote_count_result_item.incompleteNumValue - # for area_wise_valid_non_postal_vote_count_result_item in area_wise_valid_non_postal_vote_count_result.itertuples(): - # content["pollingDivisions"].append(area_wise_valid_non_postal_vote_count_result_item.areaName) - # content["validVoteCounts"].append( - # to_comma_seperated_num(area_wise_valid_non_postal_vote_count_result_item.incompleteNumValue)) - # total_valid_vote_count += area_wise_valid_non_postal_vote_count_result_item.incompleteNumValue - # - # for area_wise_rejected_non_postal_vote_count_result_item_index, area_wise_rejected_non_postal_vote_count_result_item in area_wise_rejected_non_postal_vote_count_result.iterrows(): - # content["rejectedVoteCounts"].append( - # to_comma_seperated_num(area_wise_rejected_non_postal_vote_count_result_item.numValue)) - # total_rejected_vote_count += area_wise_rejected_non_postal_vote_count_result_item.numValue - # - # for vote_type in non_postal_vote_types: - # postal_vote_count_result = self.get_vote_count_result(vote_type=vote_type) - # postal_valid_vote_count_result = self.get_valid_vote_count_result(vote_type=vote_type) - # postal_rejected_vote_count_result = self.get_rejected_vote_count_result(vote_type=vote_type) - # - # # Append the postal vote count totals - # content["pollingDivisions"].append("%s Votes" % vote_type) - # content["validVoteCounts"].append( - # to_comma_seperated_num(postal_valid_vote_count_result["incompleteNumValue"].values[0])) - # content["rejectedVoteCounts"].append( - # to_comma_seperated_num(postal_rejected_vote_count_result["numValue"].values[0])) - # content["totalVoteCounts"].append( - # to_comma_seperated_num(postal_vote_count_result["incompleteNumValue"].values[0])) - # - # # Append the grand totals - # content["validVoteCounts"].append( - # to_comma_seperated_num(valid_vote_count_result["incompleteNumValue"].values[0])) - # content["rejectedVoteCounts"].append( - # to_comma_seperated_num(rejected_vote_count_result["incompleteNumValue"].values[0])) - # content["totalVoteCounts"].append(to_comma_seperated_num(vote_count_result["incompleteNumValue"].values[0])) - # - # number_of_counting_centres = len(area_wise_non_postal_vote_count_result) - # - # for party_wise_valid_vote_count_result_item_index, party_wise_valid_vote_count_result_item in party_wise_valid_vote_count_result.iterrows(): - # data_row = [] - # - # data_row.append(party_wise_valid_vote_count_result_item.partyName) - # - # for counting_centre_index in range(number_of_counting_centres): - # party_and_area_wise_valid_non_postal_vote_count_result_item_index = \ - # ( - # number_of_counting_centres * party_wise_valid_vote_count_result_item_index) + counting_centre_index - # - # data_row.append( - # to_comma_seperated_num( - # party_and_area_wise_valid_non_postal_vote_count_result["numValue"].values[ - # party_and_area_wise_valid_non_postal_vote_count_result_item_index])) - # - # for vote_type in non_postal_vote_types: - # party_wise_valid_postal_vote_count_result = self.get_party_wise_valid_vote_count_result( - # vote_type=vote_type) - # data_row.append(to_comma_seperated_num(party_wise_valid_postal_vote_count_result["numValue"].values[ - # party_wise_valid_vote_count_result_item_index])) - # - # data_row.append(to_comma_seperated_num(party_wise_valid_vote_count_result_item.incompleteNumValue)) - # - # content["data"].append(data_row) - # - # html = render_template( - # 'ProvincialCouncilElection2021/PCE-CE-RO-V2.html', - # content=content - # ) - # - # return html + area_wise_valid_vote_count_result = self.get_area_wise_valid_vote_count_result() + party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result() + # party_wise_valid_postal_vote_count_result = self.get_party_wise_valid_postal_vote_count_result() + + stamp = tallySheetVersion.stamp + election = tallySheetVersion.tallySheet.election + + content = { + "election": { + "electionName": election.get_official_name() + }, + "stamp": { + "createdAt": stamp.createdAt, + "createdBy": stamp.createdBy, + "barcodeString": stamp.barcodeString + }, + "tallySheetCode": "PCE/POST/PC", + "data": [], + "provinces": {}, + "attributes": ["No. of Votes", "No. of Postal Votes", "Total Votes", "Percentage", "No. of Seats", + "No. of Bonus Seats", "Total seats"], + } + + # Append the grand totals + number_of_administrative_districts = len(area_wise_valid_vote_count_result) + + for area_wise_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples(): + province_name = Area.get_associated_areas(tallySheetVersion.tallySheet.area, + AreaTypeEnum.Province)[0].areaName + if province_name not in content['provinces']: + content['provinces'][province_name] = [] + content['provinces'][province_name].append(area_wise_valid_vote_count_result_item.areaName) + print(content['provinces']) + for party_wise_valid_vote_count_result_item_index, party_wise_valid_vote_count_result_item in party_wise_valid_vote_count_result.iterrows(): + data_row = [] + + data_row.append(party_wise_valid_vote_count_result_item.partyName) + + for administrative_district_index in range(number_of_administrative_districts): + party_and_area_wise_valid_vote_count_result_item_index = \ + ( + number_of_administrative_districts * party_wise_valid_vote_count_result_item_index) + administrative_district_index + + # data_row.append( + # to_comma_seperated_num( + # party_wise_valid_vote_count_result["numValue"].values[ + # party_and_area_wise_valid_vote_count_result_item_index])) + data_row.append( + to_comma_seperated_num(0)) + content["data"].append(data_row) + + html = render_template( + 'ProvincialCouncilElection2021/PCE-POST-PC.html', + content=content + ) + + return html diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py index 724bb50a..6386afca 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py @@ -1,6 +1,6 @@ from orm.entities import Template from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TALLY_SHEET_CODES import PCE_POST_PC, \ - PCE_CE_RO_V2, PCE_R2, PCE_PC_BS_1 + PCE_CE_RO_V1, PCE_CE_RO_V2, PCE_R2, PCE_PC_BS_1 from constants.TALLY_SHEET_COLUMN_SOURCE import TALLY_SHEET_COLUMN_SOURCE_QUERY as SOURCE_QUERY, \ TALLY_SHEET_COLUMN_SOURCE_META as SOURCE_META, TALLY_SHEET_COLUMN_SOURCE_CONTENT as SOURCE_CONTENT from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TEMPLATE_ROW_TYPE import \ @@ -11,6 +11,19 @@ def create_template(): return Template.create( templateName=PCE_POST_PC, templateRowTypesMap={ + "PARTY_WISE_POSTAL_VOTE": { + "hasMany": True, + "isDerived": True, + "columns": [ + {"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_QUERY}, + {"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_QUERY}, + {"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_QUERY}, + {"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_QUERY} + ], + "derivativeRows": [ + {"templateName": PCE_CE_RO_V1, "templateRowType": "PARTY_WISE_POSTAL_VOTE"} + ] + }, "PARTY_WISE_VOTE": { "hasMany": True, "isDerived": True, diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py index 8ae0ae67..963b4f97 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/__init__.py @@ -518,8 +518,8 @@ def _create_administrative_district_tally_sheets(area): "areaId": area.areaId, "electionId": administrative_district_election.electionId }).metaId, - parentTallySheets=[*pce_r2_tally_sheet_list, - *pce_pc_v_tally_sheet_list, *pce_post_pc_tally_sheet_list], + parentTallySheets=[*pce_r2_tally_sheet_list, *pce_post_pc_tally_sheet_list, + *pce_pc_v_tally_sheet_list], workflowInstanceId=workflow_report.get_new_instance().workflowInstanceId )] @@ -741,8 +741,7 @@ def _create_polling_division_tally_sheets(area): "areaId": area.areaId, "electionId": administrative_district_ordinary_election.electionId }).metaId, - parentTallySheets=[*pce_pd_v_tally_sheet_list, *pce_ce_ro_v2_tally_sheet_list, - *pce_post_pc_tally_sheet_list], + parentTallySheets=[*pce_pd_v_tally_sheet_list, *pce_ce_ro_v2_tally_sheet_list], workflowInstanceId=workflow_released_report.get_new_instance().workflowInstanceId )] diff --git a/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-POST-PC.html b/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-POST-PC.html new file mode 100644 index 00000000..a73f63a7 --- /dev/null +++ b/results-tabulation-api/templates/ProvincialCouncilElection2021/PCE-POST-PC.html @@ -0,0 +1,94 @@ +{% extends 'base.html' %} + +{% block container %} + +
+ + + + + + +
+

+ {{ content.election.electionName }} +

+ Post Election Summary Report - Internal Use Only +
+ + + + + + {% for province_name in content.provinces %} + + {% endfor %} + + + {% for province in content.provinces %} + {% for administrative_district in content.provinces[province] %} + + {% endfor %} + {% endfor %} + + {% for row in content.data %} + {% for attribute in content.attributes %} + {% set attribute_loop = loop %} + + {% if loop.index0==0 %} + + {% endif %} + + {% for cell in row %} + {% if loop.index0 > 0 %} + + {% endif %} + {% endfor %} + + {% endfor %} + {% endfor %} + + +
+ Political Party/ Independent Group + + + + {{ province_name }} Province +
+
{{ administrative_district }}
+
{{ row[0] }}{{ attribute }} + 4 %}colspan="1" {% endif %}class="left right top bottom text-right {% if cell=="" %}missing-value{% endif %}" + style="vertical-align: middle; padding-left:initial;">{{ cell }}
+ +
+{% endblock %} From c154774e8be8f5a516a877cd3e25757e0f8ff362 Mon Sep 17 00:00:00 2001 From: umayanga Date: Fri, 30 Apr 2021 13:41:50 +0530 Subject: [PATCH 7/7] post election postal vote func --- .../ExtendedTallySheet_PCE_POST_PC.py | 19 ++++++++++++++----- .../ext/ExtendedTallySheet/__init__.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py index 0617940b..448f07b9 100644 --- a/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py +++ b/results-tabulation-api/ext/ExtendedElection/ExtendedElectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py @@ -68,10 +68,13 @@ def json(self): def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion + party_and_area_wise_valid_vote_count_result = self.get_party_and_area_wise_valid_vote_count_result() area_wise_valid_vote_count_result = self.get_area_wise_valid_vote_count_result() party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result() - # party_wise_valid_postal_vote_count_result = self.get_party_wise_valid_postal_vote_count_result() - + party_and_area_wise_valid_postal_vote_count_result = self.get_party_and_area_wise_valid_postal_vote_count_result() + print("hello") + print(party_and_area_wise_valid_vote_count_result) + print(party_and_area_wise_valid_postal_vote_count_result) stamp = tallySheetVersion.stamp election = tallySheetVersion.tallySheet.election @@ -91,6 +94,8 @@ def html(self, title="", total_registered_voters=None): "No. of Bonus Seats", "Total seats"], } + get_province_from_administrative_district_map = {} + # Append the grand totals number_of_administrative_districts = len(area_wise_valid_vote_count_result) @@ -98,9 +103,13 @@ def html(self, title="", total_registered_voters=None): province_name = Area.get_associated_areas(tallySheetVersion.tallySheet.area, AreaTypeEnum.Province)[0].areaName if province_name not in content['provinces']: - content['provinces'][province_name] = [] - content['provinces'][province_name].append(area_wise_valid_vote_count_result_item.areaName) - print(content['provinces']) + content['provinces'][province_name] = {} + + administrative_district_name = area_wise_valid_vote_count_result_item.areaName + if administrative_district_name not in content['provinces'][province_name]: + get_province_from_administrative_district_map[administrative_district_name] = province_name + content['provinces'][province_name][administrative_district_name] = {} + for party_wise_valid_vote_count_result_item_index, party_wise_valid_vote_count_result_item in party_wise_valid_vote_count_result.iterrows(): data_row = [] diff --git a/results-tabulation-api/ext/ExtendedTallySheet/__init__.py b/results-tabulation-api/ext/ExtendedTallySheet/__init__.py index 7d6f4976..a95485b0 100644 --- a/results-tabulation-api/ext/ExtendedTallySheet/__init__.py +++ b/results-tabulation-api/ext/ExtendedTallySheet/__init__.py @@ -841,6 +841,18 @@ def get_party_and_area_wise_valid_vote_count_result(self): ).reset_index() return df + def get_party_and_area_wise_valid_postal_vote_count_result(self): + df = self.df.copy() + + df = df.loc[df['templateRowType'] == "PARTY_WISE_POSTAL_VOTE"] + df = df.loc[df['voteType'] == Postal] + + df = df.sort_values( + by=['electionPartyId', 'partyId', 'partyName', 'partyAbbreviation', 'partySymbol', 'areaId', + 'areaName'], ascending=True + ).reset_index() + return df + def get_area_wise_valid_vote_count_result(self): df = self.df.copy() df['numValue'] = df['numValue'].astype(float)