Skip to content

Commit

Permalink
Merge pull request ECLK#886 from umayangag/main2
Browse files Browse the repository at this point in the history
post election summary report ECLK#885
  • Loading branch information
kosalag authored Apr 30, 2021
2 parents e32cab2 + c154774 commit 6bf42a8
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
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
from orm.entities import Area
from orm.enums import AreaTypeEnum


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 = "NATIONAL"

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

print("hello")
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(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_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

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"],
}

get_province_from_administrative_district_map = {}

# 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] = {}

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 = []

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
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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]
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from orm.entities import Template
from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TALLY_SHEET_CODES import PCE_POST_PC, \
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 \
TEMPLATE_ROW_TYPE_BONUS_SEATS_ALLOCATED, TEMPLATE_ROW_TYPE_SEATS_ALLOCATED


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,
"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"}
]
}
}
)
Loading

0 comments on commit 6bf42a8

Please sign in to comment.