def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion invalid_vote_category_counts = self.get_invalid_vote_category_count( ) stamp = tallySheetVersion.stamp polling_divisions = Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.PollingDivision) polling_division_name = "" if len(polling_divisions) > 0: polling_division_name = polling_divisions[0].areaName if tallySheetVersion.tallySheet.election.voteType != NonPostal: polling_division_name = tallySheetVersion.tallySheet.election.voteType content = { "election": { "electionName": tallySheetVersion.tallySheet.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "PCE-39", "administrativeDistrict": Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.AdministrativeDistrict)[0].areaName, "pollingDivision": polling_division_name, "countingCentre": tallySheetVersion.tallySheet.area.areaName, "data": [], "rejectedVotes": 0 } total_rejected_count = 0 for index, invalid_vote_category_count in invalid_vote_category_counts.iterrows( ): data_row = [] data_row.append( invalid_vote_category_count.invalidVoteCategoryDescription) data_row.append(invalid_vote_category_count.numValue) content["data"].append(data_row) total_rejected_count += invalid_vote_category_count.numValue content["rejectedVotes"] = to_comma_seperated_num( total_rejected_count) html = render_template('ProvincialCouncilElection2021/PCE-34.html', content=content) return html
def html(self): tallySheetContent = self.content.all() content = { "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": Area.get_associated_areas( self.submission.area, AreaTypeEnum.PollingDivision)[0].areaName, "countingCentre": self.submission.area.areaName, "pollingDistrictNos": ", ".join([ pollingDistrict.areaName for pollingDistrict in Area.get_associated_areas( self.submission.area, AreaTypeEnum.PollingDistrict) ]), "data": [] } for row_index in range(len(tallySheetContent)): row = tallySheetContent[row_index] data_row = [] content["data"].append(data_row) data_row.append(row.categoryDescription) data_row.append(to_empty_string_or_value(row.count)) html = render_template('PRE-21.html', content=content) return html
def html(self): stamp = self.stamp disqualifiedCandidates = db.session.query( ElectionCandidate.Model.candidateId, Candidate.Model.candidateName, ).join( Candidate.Model, Candidate.Model.candidateId == ElectionCandidate.Model.candidateId).filter( ElectionCandidate.Model.qualifiedForPreferences == False, ElectionCandidate.Model.electionId.in_( self.submission.election.mappedElectionIds)).all() content = { "tallySheetCode": "PRE/34/I/RO", "election": { "electionName": self.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "title": "PRESIDENTIAL ELECTION ACT NO. 15 OF 1981", "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivisionOrPostalVoteCountingCentres": "XX", "data": [], "candidates": disqualifiedCandidates, "summary": self.summary } if self.submission.election.voteType == VoteTypeEnum.Postal: content["tallySheetCode"] = "PRE/34/I/RO PV" content["pollingDivisionOrPostalVoteCountingCentres"] = ", ".join([ countingCentre.areaName for countingCentre in Area.get_associated_areas( self.submission.area, AreaTypeEnum.CountingCentre, electionId=self.submission.electionId) ]) elif self.submission.election.voteType == VoteTypeEnum.NonPostal: content[ "pollingDivisionOrPostalVoteCountingCentres"] = Area.get_associated_areas( self.submission.area, AreaTypeEnum.PollingDivision)[0].areaName content["data"] = TallySheetVersion.create_candidate_preference_struct( self.content) html = render_template('PRE-34-I-RO.html', content=content) return html
def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion stamp = tallySheetVersion.stamp content = { "election": { "electionName": tallySheetVersion.tallySheet.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "PCE-42", "provinceNo": Area.get_associated_areas(tallySheetVersion.tallySheet.area, AreaTypeEnum.Province)[0].areaId, "province": Area.get_associated_areas(tallySheetVersion.tallySheet.area, AreaTypeEnum.Province)[0].areaName, "administrativeDistrictNo": Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.AdministrativeDistrict)[0].areaId, "administrativeDistrict": Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.AdministrativeDistrict)[0].areaName, "countingCentre": tallySheetVersion.tallySheet.area.areaName, "data": [] } candidate_wise_results = self.get_candidate_wise_results( ).sort_values(by=[ "seatsAllocated", "electionPartyId", "preferenceCount", "candidateId" ], ascending=[False, True, False, True]).reset_index() for index in candidate_wise_results.index: candidate_name = candidate_wise_results.at[index, "candidateName"] party_name = candidate_wise_results.at[index, "partyName"] content["data"].append({ "candidateName": "" if candidate_name is None else candidate_name, "partyName": party_name }) html = render_template('ProvincialCouncilElection2021/PCE-42.html', content=content) return html
def html_letter(self, title="", total_registered_voters=None, signatures=[]): tallySheetVersion = self.tallySheetVersion stamp = tallySheetVersion.stamp content = { "election": { "electionName": tallySheetVersion.tallySheet.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "signatures": signatures, "province": Area.get_associated_areas(tallySheetVersion.tallySheet.area, AreaTypeEnum.Province)[0].areaName, "administrativeDistrict": Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.AdministrativeDistrict)[0].areaName, "data": [], "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") } candidate_wise_results = self.get_candidate_wise_results( ).sort_values(by=[ "seatsAllocated", "electionPartyId", "preferenceCount", "candidateId" ], ascending=[False, True, False, True]).reset_index() for index in candidate_wise_results.index: data_row = [ candidate_wise_results.at[index, "partyName"], candidate_wise_results.at[index, "partyAbbreviation"], candidate_wise_results.at[index, "candidateNumber"], candidate_wise_results.at[index, "candidateName"] ] content["data"].append(data_row) html = render_template( 'ProvincialCouncilElection2021/PCE-42-LETTER.html', content=content) return html
def html(self): tallySheetContent = self.content print("############# heyyyyy") content = { "title": "PRESIDENTIAL ELECTION ACT NO. 15 OF 1981", "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": Area.get_associated_areas( self.submission.area, AreaTypeEnum.PollingDivision)[0].areaName, "countingCentre": self.submission.area.areaName, "pollingDistrictNos": ", ".join([ pollingDistrict.areaName for pollingDistrict in Area.get_associated_areas( self.submission.area, AreaTypeEnum.PollingDistrict) ]), "data": [], "total": 0, "rejectedVotes": 0, "grandTotal": 0 } for row_index in range(len(tallySheetContent)): row = tallySheetContent[row_index] if row.count is not None: content["data"].append([ row_index + 1, row.candidateName, row.partySymbol, row.countInWords, row.count, "" ]) content["total"] = content["total"] + row.count else: content["data"].append([ row_index + 1, row.candidateName, row.partySymbol, "", "", "" ]) content["rejectedVotes"] = 0 # TODO content["grandTotal"] = content["total"] + content["rejectedVotes"] print("############# Huuui ", content) html = render_template('PRE-41.html', content=content) print("############# html ", html) return html
def html_letter(self): stamp = self.stamp total_registered_voters = get_polling_division_total_registered_voters(tallySheetVersion=self) electoral_district = Area.get_associated_areas(self.submission.area, AreaTypeEnum.ElectoralDistrict)[0] polling_division = self.submission.area content = { "resultTitle": "Results of PD", "election": { "electionName": self.submission.election.get_official_name(), "isPostal": self.submission.election.voteType == VoteTypeEnum.Postal }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "date": stamp.createdAt.strftime("%d/%m/%Y"), "time": stamp.createdAt.strftime("%H:%M:%S %p"), "data": [ ], "validVoteCounts": [0, 0], "rejectedVoteCounts": [0, 0], "totalVoteCounts": [0, 0], "registeredVoters": [ to_comma_seperated_num(total_registered_voters), 100 ], "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": self.submission.area.areaName } if self.submission.election.voteType == VoteTypeEnum.Postal: content["tallySheetCode"] = "PRE/34/PV" content["pollingDivision"] = "Postal" content["resultTitle"] = "Results of Electoral District %s (Postal)" % electoral_district.areaName else: content["pollingDivision"] = self.submission.area.areaName content["resultTitle"] = "Results of Electoral District %s - Polling Division %s" % ( electoral_district.areaName, polling_division.areaName ) content["data"], total_valid_vote_count = TallySheetVersion.create_candidate_preference_struct(self.content) content["logo"] = convert_image_to_data_uri("static/Emblem_of_Sri_Lanka.png") html = render_template( 'PRE_34_ALL_ISLAND_RESULTS.html', content=content ) return html
def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion stamp = tallySheetVersion.stamp content = { "election": { "electionName": tallySheetVersion.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "PE-21", "electoralDistrictNo": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaId, "electoralDistrict": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "countingCentre": tallySheetVersion.submission.area.areaName, "data": [] } elected_candidates_df = self.df.loc[ self.df['templateRowType'] == TEMPLATE_ROW_TYPE_ELECTED_CANDIDATE] for index in elected_candidates_df.index: candidate_name = elected_candidates_df.at[index, "candidateName"] party_name = elected_candidates_df.at[index, "partyName"] content["data"].append({ "candidateName": "" if candidate_name is None else candidate_name, "partyName": party_name }) html = render_template('PE-21.html', content=content) return html
def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion stamp = tallySheetVersion.stamp content = { "election": { "electionName": tallySheetVersion.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "PE-21", "electoralDistrictNo": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaId, "electoralDistrict": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "countingCentre": tallySheetVersion.submission.area.areaName, "data": [] } candidate_wise_results = self.get_candidate_wise_results( ).sort_values(by=['electionPartyId', "candidateId"], ascending=[True, True]).reset_index() for index in candidate_wise_results.index: candidate_name = candidate_wise_results.at[index, "candidateName"] party_name = candidate_wise_results.at[index, "partyName"] content["data"].append({ "candidateName": "" if candidate_name is None else candidate_name, "partyName": party_name }) html = render_template('PE-21.html', content=content) return html
def __init__(self, tallySheetVersion, areaId, ballotBoxesIssued, ballotBoxesReceived, ballotsIssued, ballotsReceived, ballotsSpoilt, ballotsUnused, ordinaryBallotCountFromBoxCount, tenderedBallotCountFromBoxCount, ordinaryBallotCountFromBallotPaperAccount, tenderedBallotCountFromBallotPaperAccount): area = Area.get_by_id(areaId=areaId) if area is None: raise NotFoundException("Area not found. (areaId=%d)" % areaId) if area.electionId != tallySheetVersion.submission.electionId: raise NotFoundException( "Area is not registered for the given election. (areaId=%d)" % areaId) super(TallySheetVersionRow_CE_201_Model, self).__init__( tallySheetVersionId=tallySheetVersion.tallySheetVersionId, areaId=areaId, # ballotBoxesIssued=ballotBoxesIssued, # ballotBoxesReceived=ballotBoxesReceived, ballotsIssued=ballotsIssued, ballotsReceived=ballotsReceived, ballotsSpoilt=ballotsSpoilt, ballotsUnused=ballotsUnused, ordinaryBallotCountFromBoxCount=ordinaryBallotCountFromBoxCount, tenderedBallotCountFromBoxCount=tenderedBallotCountFromBoxCount, ordinaryBallotCountFromBallotPaperAccount= ordinaryBallotCountFromBallotPaperAccount, tenderedBallotCountFromBallotPaperAccount= tenderedBallotCountFromBallotPaperAccount) db.session.add(self) db.session.flush()
def html(self): stamp = self.stamp content = { "tallySheetCode": "PRE-34-ED", "election": { "electionName": self.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "data": [] } content[ "data"], total_valid_vote_count = TallySheetVersion.create_candidate_preference_struct( self.content) html = render_template('PRE-34-ED.html', content=content) return html
def on_get_release_result_params(self): if self.tallySheet.election.voteType == NonPostal: polling_division = self.tallySheet.area electoral_district = Area.get_associated_areas( polling_division, AreaTypeEnum.ElectoralDistrict)[0] pd_name_regex_search = re.match('([0-9a-zA-Z]*) *- *(.*)', polling_division.areaName) pd_code = pd_name_regex_search.group(1) pd_name = pd_name_regex_search.group(2) else: electoral_district = self.tallySheet.area pd_code = "%sV" % self.tallySheet.election.voteType[0] pd_name = self.tallySheet.election.voteType ed_name_regex_search = re.match('([0-9a-zA-Z]*) *- *(.*)', electoral_district.areaName) ed_code = ed_name_regex_search.group(1) ed_name = ed_name_regex_search.group(2) pd_code = "%s%s" % (ed_code, pd_code) result_type = "RP_V" result_code = pd_code result_level = "POLLING-DIVISION" return result_type, result_code, result_level, ed_code, ed_name, pd_code, pd_name
def __init__(self, tallySheetVersion, areaId, ballotsIssued, ballotsReceived, ballotsSpoilt, ballotsUnused, boxCountOrdinary, boxCountTendered, ballotPaperAccountOrdinary, ballotPaperAccountTendered): area = Area.get_by_id(areaId=areaId) if area is None: raise NotFoundException("Area not found. (areaId=%d)" % areaId) if area.electionId != tallySheetVersion.submission.electionId: raise NotFoundException( "Area is not registered for the given election. (areaId=%d)" % areaId) super(TallySheetVersionRow_CE_201_Model, self).__init__( tallySheetVersionId=tallySheetVersion.tallySheetVersionId, areaId=areaId, ballotsIssued=ballotsIssued, ballotsReceived=ballotsReceived, ballotsSpoilt=ballotsSpoilt, ballotsUnused=ballotsUnused, boxCountOrdinary=boxCountOrdinary, boxCountTendered=boxCountTendered, ballotPaperAccountOrdinary=ballotPaperAccountOrdinary, ballotPaperAccountTendered=ballotPaperAccountTendered) db.session.add(self) db.session.commit()
def html(self): stamp = self.stamp content = { "tallySheetCode": "PRE-34-PD", "election": { "electionName": self.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": "XX", "data": [], # "candidates": disqualifiedCandidates } if self.submission.election.voteType == VoteTypeEnum.Postal: content["tallySheetCode"] = "PRE-34-PV" content["pollingDivision"] = "Postal" elif self.submission.election.voteType == VoteTypeEnum.NonPostal: content["pollingDivision"] = self.submission.area.areaName content["data"], total_valid_vote_count = TallySheetVersion.create_candidate_preference_struct(self.content) html = render_template( 'PRE-34-PD.html', content=content ) return html
def _get_role_area_ids(parentAreaIds, areaType, voteTypes=[]): from orm.entities import Area, Election _role_area_ids = [] parentAreas = [] if parentAreaIds is not None and len(parentAreaIds) > 0: parentAreas = db.session.query(Area.Model).filter( Area.Model.areaId.in_(parentAreaIds)).all() if len(parentAreas) > 0: associated_areas_subquery = Area.get_associated_areas_query( areas=parentAreas, areaType=areaType).subquery() query = db.session.query(associated_areas_subquery.c.areaId) if len(voteTypes) > 0: query = query.filter( Election.Model.electionId == associated_areas_subquery.c.electionId, Election.Model.voteType.in_(voteTypes)) _role_area_ids = query.group_by( associated_areas_subquery.c.areaId).all() return _role_area_ids
def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion candidate_wise_valid_vote_count_result = self.get_candidate_wise_valid_vote_count_result( ) stamp = tallySheetVersion.stamp content = { "election": { "electionName": tallySheetVersion.tallySheet.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "CE/RO/PR/1", "electoralDistrict": Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "partyName": candidate_wise_valid_vote_count_result["partyName"].values[0], "data": [] } candidate_wise_valid_vote_count_result = candidate_wise_valid_vote_count_result.sort_values( by=['numValue'], ascending=False) position_of_candidate = 0 for index_1 in candidate_wise_valid_vote_count_result.index: data_row = [] position_of_candidate += 1 candidate_id = candidate_wise_valid_vote_count_result.at[ index_1, "candidateId"] candidate_number = candidate_wise_valid_vote_count_result.at[ index_1, "candidateNumber"] candidate_name = candidate_wise_valid_vote_count_result.at[ index_1, "candidateName"] num_value = to_comma_seperated_num( candidate_wise_valid_vote_count_result.at[index_1, "numValue"]) data_row.append(position_of_candidate) data_row.append("%s - %s" % (candidate_number, candidate_name)) data_row.append(num_value) data_row.append("") data_row.append(position_of_candidate) content["data"].append(data_row) html = render_template('PE-CE-RO-PR-3.html', content=content) return html
def html(self): tallySheetContent = self.content.all() stamp = self.stamp content = { "election": { "electionName": self.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": Area.get_associated_areas( self.submission.area, AreaTypeEnum.PollingDivision)[0].areaName, "countingCentre": self.submission.area.areaName, "pollingDistrictNos": ", ".join([ pollingDistrict.areaName for pollingDistrict in Area.get_associated_areas(self.submission.area, AreaTypeEnum.PollingDistrict) ]), "data": [ ], "totalRejected": 0 } for row_index in range(len(tallySheetContent)): row = tallySheetContent[row_index] data_row = [] content["data"].append(data_row) data_row.append(row.categoryDescription) data_row.append(to_empty_string_or_value(row.count)) if row.count is not None: content["totalRejected"] = content["totalRejected"] + row.count html = render_template( 'PRE-21.html', content=content ) return html
def get_all(electionId=None, areaName=None, associatedAreaId=None, areaType=None): result = Area.get_all(election_id=electionId, area_name=areaName, associated_area_id=associatedAreaId, area_type=get_area_type(area_type=areaType)) return Schema(many=True).dump(result).data
def html(self): tallySheetContent = self.content.all() tallySheetContentSummary = self.summary content = { "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": Area.get_associated_areas( self.submission.area, AreaTypeEnum.PollingDivision)[0].areaName, "countingCentre": self.submission.area.areaName, "pollingDistrictNos": ", ".join([ pollingDistrict.areaName for pollingDistrict in Area.get_associated_areas(self.submission.area, AreaTypeEnum.PollingDistrict) ]), "situation": tallySheetContentSummary.situation, "timeOfCommencementOfCount": tallySheetContentSummary.timeOfCommencementOfCount, "numberOfAPacketsFound": tallySheetContentSummary.numberOfAPacketsFound, "numberOfACoversRejected": tallySheetContentSummary.numberOfACoversRejected, "numberOfBCoversRejected": tallySheetContentSummary.numberOfBCoversRejected, "numberOfValidBallotPapers": tallySheetContentSummary.numberOfValidBallotPapers, "data": [ ], } for row_index in range(len(tallySheetContent)): row = tallySheetContent[row_index] data_row = [] content["data"].append(data_row) data_row.append(row.ballotBox.ballotBoxId) data_row.append(to_empty_string_or_value(row.numberOfPacketsInserted)) data_row.append(to_empty_string_or_value(row.numberOfAPacketsFound)) html = render_template( 'CE-201-PV.html', content=content ) return html
def get_all(electionId=None, areaName=None, associatedAreaId=None, areaType=None): query = Area.get_all(election_id=electionId, area_name=areaName, associated_area_id=associatedAreaId, area_type=get_area_type(area_type=areaType)) query = get_paginated_query(query) result = query.all() return AreaSchema(many=True).dump(result).data
def json_data(self): 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 candidate_wise_vote_count_result = self.candidate_wise_vote_count().all() vote_count_result = self.vote_count_query().one_or_none() candidates = [] for candidate_wise_valid_vote_count_result_item in candidate_wise_vote_count_result: 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)}', "party_name": candidate_wise_valid_vote_count_result_item.partyName, "candidate": candidate_wise_valid_vote_count_result_item.candidateName }) is_postal = self.submission.election.voteType == VoteTypeEnum.Postal ed_code, ed_name = split_area_name(electoral_district) if is_postal: pd_name = "Postal Votes" pd_code = ed_code + 'P' else: pd_code, pd_name = split_area_name(polling_division) pd_code = ed_code + pd_code validVoteCount = vote_count_result.validVoteCount or 0 rejectedVoteCount = vote_count_result.rejectedVoteCount or 0 totalVoteCount = vote_count_result.totalVoteCount or 0 response = { "timestamp": str(datetime.now()), "level": "POLLING-DIVISION", "ed_code": ed_code, "ed_name": ed_name, "pd_code": pd_code, "pd_name": pd_name, "by_party": candidates, "summary": { "valid": str(vote_count_result.validVoteCount), "rejected": str(vote_count_result.rejectedVoteCount), "polled": str(vote_count_result.totalVoteCount), "electors": str(total_registered_voters), "percent_valid": f'{round((validVoteCount * 100 / vote_count_result.totalVoteCount) if vote_count_result.totalVoteCount > 0 else "", 2)}', "percent_rejected": f'{round((rejectedVoteCount * 100 / vote_count_result.totalVoteCount) if vote_count_result.totalVoteCount > 0 else "", 2)}', "percent_polled": f'{round((totalVoteCount * 100 / total_registered_voters), 2)}', } } return response, pd_code
def html(self): tallySheetContent = self.content.all() tallySheetContentSummary = self.summary stamp = self.stamp content = { "election": { "electionName": self.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "countingCentre": self.submission.area.areaName, "situation": tallySheetContentSummary.situation, "timeOfCommencementOfCount": tallySheetContentSummary.timeOfCommencementOfCount, "numberOfAPacketsFound": tallySheetContentSummary.numberOfAPacketsFound, "numberOfACoversRejected": to_comma_seperated_num( tallySheetContentSummary.numberOfACoversRejected), "numberOfBCoversRejected": to_comma_seperated_num( tallySheetContentSummary.numberOfBCoversRejected), "numberOfValidBallotPapers": to_comma_seperated_num( tallySheetContentSummary.numberOfValidBallotPapers), "data": [], } for row_index in range(len(tallySheetContent)): row = tallySheetContent[row_index] data_row = [] content["data"].append(data_row) data_row.append(row.ballotBoxId) data_row.append(to_comma_seperated_num( row.numberOfPacketsInserted)) data_row.append(to_comma_seperated_num(row.numberOfAPacketsFound)) html = render_template('CE-201-PV.html', content=content) return html
def json_data(self): electoral_district = Area.get_associated_areas(self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName polling_division = self.submission.area.areaName candidate_wise_vote_count_result, total_valid_votes = TallySheetVersion.create_candidate_preference_struct( self.content) candidates = [] for candidate_wise_valid_vote_count_result_item in candidate_wise_vote_count_result: total_vote_count = candidate_wise_valid_vote_count_result_item['total'] candidates.append({ "party_code": candidate_wise_valid_vote_count_result_item['partyAbbreviation'], "votes": str(total_vote_count), "votes1st": str(candidate_wise_valid_vote_count_result_item['firstPreferenceCount']), "votes2nd": str(candidate_wise_valid_vote_count_result_item['secondPreferenceCount']), "votes3rd": str(candidate_wise_valid_vote_count_result_item['thirdPreferenceCount']), "percentage": f'{round(total_vote_count * 100 / total_valid_votes, 2)}', "party_name": candidate_wise_valid_vote_count_result_item['partyName'], "candidate": candidate_wise_valid_vote_count_result_item['name'] }) is_postal = self.submission.election.voteType == VoteTypeEnum.Postal ed_code, ed_name = split_area_name(electoral_district) if is_postal: pd_name = "Postal Votes" pd_code = ed_code + 'P' else: pd_code, pd_name = split_area_name(polling_division) pd_code = ed_code + pd_code response = { "timestamp": str(datetime.now()), "level": "POLLING-DIVISION", "ed_code": ed_code, "ed_name": ed_name, "pd_code": pd_code, "pd_name": pd_name, "by_party": candidates, "summary": { "valid": str(total_valid_votes), "rejected": "", "polled": "", "electors": "", "percent_valid": "", "percent_rejected": "", "percent_polled": "", } } return response, pd_code
def html_letter(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion stamp = tallySheetVersion.stamp content = { "election": { "electionName": tallySheetVersion.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "electoralDistrict": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "data": [], "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") } candidate_wise_results = self.get_candidate_wise_results( ).sort_values(by=['electionPartyId', "candidateId"], ascending=[True, True]).reset_index() for index in candidate_wise_results.index: data_row = [ candidate_wise_results.at[index, "partyName"], candidate_wise_results.at[index, "partyAbbreviation"], candidate_wise_results.at[index, "candidateNumber"], candidate_wise_results.at[index, "candidateName"] ] content["data"].append(data_row) html = render_template( 'ParliamentaryElection2020/PE-21-LETTER.html', content=content) return html
def html_letter(self): stamp = self.stamp content = { "election": { "electionName": self.submission.election.get_official_name(), "isPostal": self.submission.election.voteType == VoteTypeEnum.Postal }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "date": stamp.createdAt.strftime("%d/%m/%Y"), "time": stamp.createdAt.strftime("%H:%M:%S %p"), "data": [], "validVoteCounts": [0, 0], "rejectedVoteCounts": [0, 0], "totalVoteCounts": [0, 0], "registeredVoters": [ to_comma_seperated_num( self.submission.area.registeredVotersCount), 100 ], "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": self.submission.area.areaName } content["data"] = TallySheetVersion.create_candidate_preference_struct( self.content) html = render_template('PRE-34-PD-LETTER.html', content=content) return html
def html_letter(self): stamp = self.stamp content = { "resultTitle": "ALL ISLAND RESULT", "election": { "electionName": self.submission.election.get_official_name(), }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "date": stamp.createdAt.strftime("%d/%m/%Y"), "time": stamp.createdAt.strftime("%H:%M:%S %p"), "data": [ ], "validVoteCounts": [0, 0], "rejectedVoteCounts": [0, 0], "totalVoteCounts": [0, 0], "registeredVoters": [ to_comma_seperated_num(self.submission.area.registeredVotersCount), 100 ], "electoralDistrict": Area.get_associated_areas( self.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": self.submission.area.areaName } content["data"], total_valid_vote_count = TallySheetVersion.create_candidate_preference_struct(self.content) content["logo"] = convert_image_to_data_uri("static/Emblem_of_Sri_Lanka.png") html = render_template( 'PRE_34_ALL_ISLAND_RESULTS.html', content=content ) return html
def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion candidate_and_area_wise_valid_vote_count_result = self.get_candidate_and_area_wise_valid_vote_count_result( ) candidate_wise_valid_vote_count_result = self.get_candidate_wise_valid_vote_count_result( ) area_wise_valid_vote_count_result = self.get_area_wise_valid_vote_count_result( ) stamp = tallySheetVersion.stamp polling_division_name = tallySheetVersion.submission.area.areaName if tallySheetVersion.submission.election.voteType != NonPostal: polling_division_name = tallySheetVersion.submission.election.voteType content = { "election": { "electionName": tallySheetVersion.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "CE/RO/PR/1", "electoralDistrict": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": polling_division_name, "partyName": candidate_and_area_wise_valid_vote_count_result["partyName"]. values[0], "data": [], "countingCentres": [], "totalVoteCounts": [] } # Append the area wise column totals for area_wise_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples( ): content["countingCentres"].append( area_wise_valid_vote_count_result_item.areaName) content["totalVoteCounts"].append( to_comma_seperated_num( area_wise_valid_vote_count_result_item. incompleteNumValue)) for index_1 in candidate_wise_valid_vote_count_result.index: data_row = [] candidate_id = candidate_wise_valid_vote_count_result.at[ index_1, "candidateId"] candidate_number = candidate_wise_valid_vote_count_result.at[ index_1, "candidateNumber"] data_row.append(candidate_number) for index_2 in candidate_and_area_wise_valid_vote_count_result.index: if candidate_and_area_wise_valid_vote_count_result.at[ index_2, "candidateId"] == candidate_id: data_row.append( to_comma_seperated_num( candidate_and_area_wise_valid_vote_count_result .at[index_2, "numValue"])) data_row.append( to_comma_seperated_num( candidate_wise_valid_vote_count_result.at[ index_1, "incompleteNumValue"])) content["data"].append(data_row) content["totalVoteCounts"].append( to_comma_seperated_num( candidate_wise_valid_vote_count_result["numValue"].sum())) html = render_template('PE-CE-RO-PR-1.html', content=content) return html
def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion tallySheetContent = tallySheetVersion.content stamp = tallySheetVersion.stamp polling_divisions = Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.PollingDivision) polling_division_name = "" if len(polling_divisions) > 0: polling_division_name = polling_divisions[0].areaName content = { "election": { "electionName": tallySheetVersion.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "title": "PRESIDENTIAL ELECTION ACT NO. 15 OF 1981", "electoralDistrict": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": polling_division_name, "countingCentre": tallySheetVersion.submission.area.areaName, "pollingDistrictNos": ", ".join([ pollingDistrict.areaName for pollingDistrict in Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.PollingDistrict) ]), "data": [], "total": 0, "rejectedVotes": 0, "grandTotal": 0 } for row_index in range(len(tallySheetContent)): row = tallySheetContent[row_index] if row.templateRowType == "CANDIDATE_FIRST_PREFERENCE": content["data"].append([ row_index + 1, row.candidateName, row.partySymbol, "" if row.strValue is None else row.strValue, "" if row.numValue is None else to_comma_seperated_num( row.numValue), "" ]) content["total"] += 0 if row.numValue is None else row.numValue content[ "grandTotal"] += 0 if row.numValue is None else row.numValue elif row.templateRowType == "REJECTED_VOTE": content[ "rejectedVotes"] += 0 if row.numValue is None else row.numValue content[ "grandTotal"] += 0 if row.numValue is None else row.numValue content["total"] = to_comma_seperated_num(content["total"]) content["rejectedVotes"] = to_comma_seperated_num( content["rejectedVotes"]) content["grandTotal"] = to_comma_seperated_num(content["grandTotal"]) html = render_template('PRE-41.html', content=content) return html
def html(self, title="", total_registered_voters=None): tallySheetVersion = self.tallySheetVersion polling_station_wise_number_of_ballots_recieved = self.get_polling_station_wise_number_of_ballots_recieved( ) # polling_station_wise_number_of_spoilt_ballot_papers = self.get_polling_station_wise_number_of_spoilt_ballot_papers() # polling_station_wise_number_of_issued_ballot_papers = self.get_polling_station_wise_number_of_issued_ballot_papers() # polling_station_wise_number_of_unused_ballot_papers = self.get_polling_station_wise_number_of_unused_ballot_papers() # polling_station_wise_number_of_ordinary_ballots_in_ballot_paper_account = self.get_polling_station_wise_number_of_ordinary_ballots_in_ballot_paper_account() polling_station_wise_number_of_ordinary_ballots_in_ballot_box = self.get_polling_station_wise_number_of_ordinary_ballots_in_ballot_box( ) stamp = tallySheetVersion.stamp polling_divisions = Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.PollingDivision) polling_division_name = "" if len(polling_divisions) > 0: polling_division_name = polling_divisions[0].areaName if tallySheetVersion.tallySheet.election.voteType != NonPostal: polling_division_name = tallySheetVersion.tallySheet.election.voteType totalBallotBoxCount = 0 content = { "election": { "electionName": tallySheetVersion.tallySheet.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "CE-201", "electoralDistrict": Area.get_associated_areas( tallySheetVersion.tallySheet.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": polling_division_name, "countingCentre": tallySheetVersion.tallySheet.area.areaName, "parliamentaryElection": 1, "data": [], "totalBallotBoxCount": totalBallotBoxCount } # Appending polling station wise ballot counts for polling_station_wise_number_of_ballots_recieved_item_index, polling_station_wise_number_of_ballots_recieved_item in polling_station_wise_number_of_ballots_recieved.iterrows( ): data_row = [] polling_station = Area.get_by_id( areaId=polling_station_wise_number_of_ballots_recieved_item .areaId) polling_districts = Area.get_associated_areas( polling_station, AreaTypeEnum.PollingDistrict) data_row.append(", ".join([ polling_district.areaName for polling_district in polling_districts ])) data_row.append( polling_station_wise_number_of_ballots_recieved_item. areaName) # data_row.append(to_comma_seperated_num(polling_station_wise_number_of_ballots_recieved_item.numValue)) # data_row.append(to_comma_seperated_num(polling_station_wise_number_of_spoilt_ballot_papers["numValue"].values[ # polling_station_wise_number_of_ballots_recieved_item_index])) # data_row.append(to_comma_seperated_num(polling_station_wise_number_of_issued_ballot_papers["numValue"].values[ # polling_station_wise_number_of_ballots_recieved_item_index])) # data_row.append(to_comma_seperated_num(polling_station_wise_number_of_unused_ballot_papers["numValue"].values[ # polling_station_wise_number_of_ballots_recieved_item_index])) # data_row.append(to_comma_seperated_num(polling_station_wise_number_of_ordinary_ballots_in_ballot_paper_account["numValue"].values[ # polling_station_wise_number_of_ballots_recieved_item_index])) data_row.append( to_comma_seperated_num( polling_station_wise_number_of_ordinary_ballots_in_ballot_box[ "numValue"]. values[ polling_station_wise_number_of_ballots_recieved_item_index] )) totalBallotBoxCount += polling_station_wise_number_of_ordinary_ballots_in_ballot_box[ "numValue"].values[ polling_station_wise_number_of_ballots_recieved_item_index] content["data"].append(data_row) content["totalBallotBoxCount"] = to_comma_seperated_num( totalBallotBoxCount) html = render_template('CE-201.html', content=content) return html
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( ) 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 pollingDivision = tallySheetVersion.submission.area.areaName if tallySheetVersion.submission.election.voteType == Postal: pollingDivision = 'Postal' content = { "election": { "electionName": tallySheetVersion.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "tallySheetCode": "CE/RO/V1", "electoralDistrict": Area.get_associated_areas( tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName, "pollingDivision": pollingDivision, "data": [], "countingCentres": [], "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_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples( ): content["countingCentres"].append( area_wise_valid_vote_count_result_item.areaName) content["validVoteCounts"].append( to_comma_seperated_num( area_wise_valid_vote_count_result_item. incompleteNumValue)) total_valid_vote_count += area_wise_valid_vote_count_result_item.incompleteNumValue for area_wise_rejected_vote_count_result_item_index, area_wise_rejected_vote_count_result_item in area_wise_rejected_vote_count_result.iterrows( ): content["rejectedVoteCounts"].append( to_comma_seperated_num( area_wise_rejected_vote_count_result_item.numValue)) total_rejected_vote_count += area_wise_rejected_vote_count_result_item.numValue for area_wise_vote_count_result_item_index, area_wise_vote_count_result_item in area_wise_vote_count_result.iterrows( ): content["totalVoteCounts"].append( to_comma_seperated_num( area_wise_vote_count_result_item.incompleteNumValue)) total_vote_count += area_wise_vote_count_result_item.incompleteNumValue # Append the grand totals content["validVoteCounts"].append( to_comma_seperated_num(total_valid_vote_count)) content["rejectedVoteCounts"].append( to_comma_seperated_num(total_rejected_vote_count)) content["totalVoteCounts"].append( to_comma_seperated_num(total_vote_count)) if tallySheetVersion.submission.election.voteType == Postal: content["tallySheetCode"] = "CE/RO/V1" number_of_counting_centres = len(area_wise_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_number = party_wise_valid_vote_count_result_item_index + 1 data_row.append(data_row_number) 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_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_vote_count_result[ "numValue"]. values[ party_and_area_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('PE-CE-RO-V1.html', content=content) return html