forked from ECLK/results-tabulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ECLK#886 from umayangag/main2
post election summary report ECLK#885
- Loading branch information
Showing
11 changed files
with
393 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...lectionProvincialCouncilElection2021/ExtendedTallySheet/ExtendedTallySheet_PCE_POST_PC.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" |
68 changes: 68 additions & 0 deletions
68
...Election/ExtendedElectionProvincialCouncilElection2021/TallysheetTemplates/pce_post_pc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} | ||
] | ||
} | ||
} | ||
) |
Oops, something went wrong.