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 json_data(self): 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'] }) response = { "timestamp": str(datetime.now()), "level": "ALL-ISLAND", "by_party": candidates, "summary": { "valid": str(total_valid_votes), "rejected": "", "polled": "", "electors": "", "percent_valid": "", "percent_rejected": "", "percent_polled": "", } } return response, "FINAL"
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 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_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 json_data(self): electoral_district = 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'] }) ed_code, ed_name = split_area_name(electoral_district) response = { "timestamp": str(datetime.now()), "level": "ELECTORAL-DISTRICT", "ed_code": ed_code, "ed_name": ed_name, "by_party": candidates, "summary": { "valid": str(total_valid_votes), "rejected": "", "polled": "", "electors": "", "percent_valid": "", "percent_rejected": "", "percent_polled": "", } } return response, ed_code
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): 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 electoralDistrict = self.submission.area content = { "resultTitle": "Results of Electoral District %s" % electoralDistrict.areaName, "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": 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): stamp = self.stamp content = { "tallySheetCode": "PRE-34-AI", "election": { "electionName": self.submission.election.get_official_name() }, "stamp": { "createdAt": stamp.createdAt, "createdBy": stamp.createdBy, "barcodeString": stamp.barcodeString }, "data": [] } content["data"] = TallySheetVersion.create_candidate_preference_struct( self.content) html = render_template('PRE-34-AI.html', content=content) return html