Beispiel #1
0
        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
Beispiel #4
0
        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
Beispiel #5
0
        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 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 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 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, 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 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
Beispiel #16
0
    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
Beispiel #17
0
    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
Beispiel #20
0
    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
Beispiel #21
0
    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
Beispiel #22
0
    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
        def html_letter(self, title="", total_registered_voters=None):
            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
            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":
                "PE/R1",
                "electoralDistrict":
                Area.get_associated_areas(
                    tallySheetVersion.submission.area,
                    AreaTypeEnum.ElectoralDistrict)[0].areaName,
                "pollingDivision":
                pollingDivision,
                "data": [],
                "validVoteCount":
                '',
                "rejectedVoteCount":
                '',
                "totalVoteCount":
                ''
            }
            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(
            ):
                total_valid_vote_count += area_wise_valid_vote_count_result_item.incompleteNumValue
            content["validVoteCount"] = to_comma_seperated_num(
                total_valid_vote_count)
            for area_wise_rejected_vote_count_result_item in area_wise_rejected_vote_count_result.itertuples(
            ):
                total_rejected_vote_count += area_wise_rejected_vote_count_result_item.numValue
            content["rejectedVoteCount"] = to_comma_seperated_num(
                total_rejected_vote_count)
            for area_wise_vote_count_result_item in area_wise_vote_count_result.itertuples(
            ):
                total_vote_count += area_wise_vote_count_result_item.incompleteNumValue
            content["totalVoteCount"] = to_comma_seperated_num(
                total_vote_count)

            # sort by vote count descending
            party_wise_valid_vote_count_result = party_wise_valid_vote_count_result.sort_values(
                by=['numValue'], ascending=False).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_index + 1,
                    party_wise_valid_vote_count_result_item.partyName,
                    to_comma_seperated_num(
                        party_wise_valid_vote_count_result_item["numValue"])
                ]
                content["data"].append(data_row)

            html = render_template('PE-R1.html', content=content)

            return html
Beispiel #26
0
    def html(self):
        tallySheetContent = self.content

        stamp = self.stamp

        content = {
            "election": {
                "electionName": self.submission.election.get_official_name()
            },
            "stamp": {
                "createdAt": stamp.createdAt,
                "createdBy": stamp.createdBy,
                "barcodeString": stamp.barcodeString
            },
            "date":
            date.today().strftime("%B %d, %Y"),
            "time":
            datetime.now().strftime("%H:%M:%S"),
            "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]

            area = None
            if isinstance(row, TallySheetVersionRow_CE_201.Model):
                area = row.area
            elif isinstance(row, Area.Model):
                area = row

            data_row = []
            content["data"].append(data_row)

            # polling districts
            data_row.append(", ".join(
                pollingDistrict.areaName
                for pollingDistrict in area.get_associated_areas(
                    AreaTypeEnum.PollingDistrict)))

            # polling station
            data_row.append(row.areaName)

            if isinstance(row, TallySheetVersionRow_CE_201.Model):
                # three ballot boxes
                for ballotBoxIndex in range(3):
                    if ballotBoxIndex < len(row.ballotBoxesReceived):
                        data_row.append(
                            row.ballotBoxesReceived[ballotBoxIndex])
                    else:
                        data_row.append("")

                data_row.append(to_empty_string_or_value(row.ballotsReceived))
                data_row.append(to_empty_string_or_value(row.ballotsSpoilt))
                data_row.append(to_empty_string_or_value(row.ballotsIssued))
                data_row.append(to_empty_string_or_value(row.ballotsUnused))

                data_row.append(
                    to_empty_string_or_value(
                        row.ordinaryBallotCountFromBallotPaperAccount))
                data_row.append(
                    to_empty_string_or_value(
                        row.ordinaryBallotCountFromBoxCount))
                data_row.append(row.ordinaryBallotCountFromBoxCount -
                                row.ordinaryBallotCountFromBallotPaperAccount)

                data_row.append(
                    to_empty_string_or_value(
                        row.tenderedBallotCountFromBallotPaperAccount))
                data_row.append(
                    to_empty_string_or_value(
                        row.tenderedBallotCountFromBoxCount))
                data_row.append(row.tenderedBallotCountFromBoxCount -
                                row.tenderedBallotCountFromBallotPaperAccount)
            elif isinstance(row, Area.Model):
                # three ballot boxes
                for ballotBoxIndex in range(3):
                    data_row.append("")

                data_row.append("")
                data_row.append("")
                data_row.append("")
                data_row.append("")

                data_row.append("")
                data_row.append("")
                data_row.append("")

                data_row.append("")
                data_row.append("")
                data_row.append("")

        html = render_template('CE-201.html', content=content)

        return html
        def html(self, title="", total_registered_voters=None):
            tallySheetVersion = self.tallySheetVersion

            party_wise_invalid_vote_category_counts = self.get_party_wise_invalid_vote_category_count(
            )

            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

            if tallySheetVersion.submission.election.voteType == Postal:
                polling_division_name = 'Postal'

            content = {
                "election": {
                    "electionName":
                    tallySheetVersion.submission.election.get_official_name()
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "tallySheetCode":
                "PE-39",
                "electoralDistrict":
                Area.get_associated_areas(
                    tallySheetVersion.submission.area,
                    AreaTypeEnum.ElectoralDistrict)[0].areaName,
                "pollingDivision":
                polling_division_name,
                "countingCentre":
                tallySheetVersion.submission.area.areaName,
                "partyWiseData": [],
                "reasonWiseTotal": [],
                "totalRejectedVotes":
                0
            }

            invalid_vote_category_ids = []
            party_id_to_name = {}
            party_to_invalid_vote_category_to_count = {}
            total_rejected_count = 0
            for index, party_wise_invalid_vote_category_count in party_wise_invalid_vote_category_counts.iterrows(
            ):
                party_id = party_wise_invalid_vote_category_count.partyId
                invalid_vote_category_id = party_wise_invalid_vote_category_count.invalidVoteCategoryId
                num_value = party_wise_invalid_vote_category_count.numValue

                invalid_vote_category_ids.append(invalid_vote_category_id)
                party_id_to_name[
                    party_id] = party_wise_invalid_vote_category_count.partyName
                if party_id not in party_to_invalid_vote_category_to_count.keys(
                ):
                    party_to_invalid_vote_category_to_count[party_id] = {}

                party_to_invalid_vote_category_to_count[party_id][
                    invalid_vote_category_id] = num_value

            sorted_invalid_vote_category_ids = sorted(
                set(invalid_vote_category_ids))
            for party_id in sorted(
                    party_to_invalid_vote_category_to_count.keys()):
                data_row = []
                data_row.append(party_id_to_name[party_id])
                party_wise_total = 0
                for invalid_vote_category_id in sorted_invalid_vote_category_ids:
                    vote_count = 0
                    if invalid_vote_category_id in party_to_invalid_vote_category_to_count[
                            party_id].keys():
                        vote_count = party_to_invalid_vote_category_to_count[
                            party_id][invalid_vote_category_id]
                    data_row.append(vote_count)
                    party_wise_total += vote_count
                total_rejected_count += party_wise_total
                data_row.append(party_wise_total)
                content["partyWiseData"].append(data_row)
            content["totalRejectedVotes"] = to_comma_seperated_num(
                total_rejected_count)

            html = render_template('PE-22.html', content=content)

            return html
        def html(self, title="", total_registered_voters=None):
            tallySheetVersion = self.tallySheetVersion

            party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result(
            )
            area_wise_rejected_vote_count_result = self.get_area_wise_rejected_vote_count_result(
            )

            stamp = tallySheetVersion.stamp

            registered_voters_count = tallySheetVersion.tallySheet.area.get_registered_voters_count(
                vote_type=tallySheetVersion.tallySheet.election.voteType)
            polling_division_name = tallySheetVersion.tallySheet.area.areaName
            if tallySheetVersion.tallySheet.election.voteType != NonPostal:
                polling_division_name = tallySheetVersion.tallySheet.election.voteType

            content = {
                "election": {
                    "electionName":
                    tallySheetVersion.tallySheet.election.get_official_name(),
                    "provinceName":
                    Area.get_associated_areas(
                        tallySheetVersion.tallySheet.area,
                        AreaTypeEnum.Province)[0].areaName
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "tallySheetCode":
                "PCE-PD-V",
                "administrativeDistrict":
                Area.get_associated_areas(
                    tallySheetVersion.tallySheet.area,
                    AreaTypeEnum.AdministrativeDistrict)[0].areaName,
                "pollingDivision":
                polling_division_name,
                "data": [],
                "totalValidVoteCount":
                '',
                "totalValidVotePercentage":
                '',
                "rejectedVoteCount":
                '',
                "rejectedVotePercentage":
                '',
                "totalVoteCount":
                '',
                "totalVotePercentage":
                '',
                "numberOfElectors":
                to_comma_seperated_num(registered_voters_count),
                "logo":
                convert_image_to_data_uri("static/Emblem_of_Sri_Lanka.png")
            }

            total_valid_vote_count = 0
            total_rejected_vote_count = 0
            total_vote_count = 0
            party_wise_valid_total_votes = []

            for 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]
                vote_count = party_wise_valid_vote_count_result_item.numValue
                party_wise_valid_total_votes.append(
                    vote_count if not math.isnan(vote_count) else 0)
                data_row.append(to_comma_seperated_num(vote_count))
                total_valid_vote_count += vote_count if not math.isnan(
                    vote_count) else 0
                content["data"].append(data_row)

            total_valid_vote_count = total_valid_vote_count if not math.isnan(
                total_valid_vote_count) else 0
            content["totalValidVoteCount"] = to_comma_seperated_num(
                total_valid_vote_count)

            # party wise percentage calculation
            for index, party_vote_count in enumerate(
                    party_wise_valid_total_votes):
                percentage_value = to_percentage(0)
                if total_valid_vote_count > 0:
                    percentage_value = to_percentage(party_vote_count * 100 /
                                                     total_valid_vote_count)
                content["data"][index].append(percentage_value)

            for index, area_wise_rejected_vote_count_result_item in area_wise_rejected_vote_count_result.iterrows(
            ):
                rejected_vote_count = area_wise_rejected_vote_count_result_item.numValue
                total_rejected_vote_count += rejected_vote_count if not math.isnan(
                    rejected_vote_count) else 0
            content["rejectedVoteCount"] = to_comma_seperated_num(
                total_rejected_vote_count)

            total_vote_count = total_valid_vote_count + total_rejected_vote_count
            content["totalVoteCount"] = to_comma_seperated_num(
                total_vote_count)
            total_valid_vote_percentage = (
                total_valid_vote_count * 100 /
                total_vote_count) if total_vote_count > 0 else 0
            content["totalValidVotePercentage"] = to_percentage(
                total_valid_vote_percentage)
            rejected_vote_percentage = (
                total_rejected_vote_count * 100 /
                total_vote_count) if total_vote_count > 0 else 0
            content["rejectedVotePercentage"] = to_percentage(
                rejected_vote_percentage)
            total_vote_percentage = (
                total_vote_count * 100 /
                registered_voters_count) if registered_voters_count > 0 else 0
            content["totalVotePercentage"] = to_percentage(
                total_vote_percentage)

            html = render_template(
                'ProvincialCouncilElection2021/PCE-PD-V.html', content=content)

            return html
Beispiel #29
0
        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):

        tallySheetContent = self.content
        summary = self.summary

        stamp = self.stamp

        polling_divisions = Area.get_associated_areas(
            self.submission.area, AreaTypeEnum.PollingDivision)
        polling_division_name = ""
        if len(polling_divisions) > 0:
            polling_division_name = polling_divisions[0].areaName

        content = {
            "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,
            "pollingDivision":
            polling_division_name,
            "countingCentre":
            self.submission.area.areaName,
            "pollingDistrictNos":
            ", ".join([
                pollingDistrict.areaName
                for pollingDistrict in Area.get_associated_areas(
                    self.submission.area, AreaTypeEnum.PollingDistrict)
            ]),
            "data": [],
            "total":
            to_comma_seperated_num(summary.validVoteCount),
            "rejectedVotes":
            to_comma_seperated_num(summary.rejectedVoteCount),
            "grandTotal":
            to_comma_seperated_num(summary.totalVoteCount)
        }

        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,
                    to_comma_seperated_num(row.count), ""
                ])
            else:
                content["data"].append([
                    row_index + 1, row.candidateName, row.partySymbol, "", "",
                    ""
                ])

        html = render_template('PRE-41.html', content=content)

        return html