def get_html_content_dict(self):
        tallySheetContent = self.content
        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
            ]
        }

        candidate_wise_valid_vote_count_result = self.candidate_wise_valid_vote_count_query().all()
        vote_count_result = self.vote_count_result()

        for candidate_wise_valid_vote_count_result_item in candidate_wise_valid_vote_count_result:
            content["data"].append([
                candidate_wise_valid_vote_count_result_item.candidateName,
                candidate_wise_valid_vote_count_result_item.partyAbbreviation,
                to_comma_seperated_num(candidate_wise_valid_vote_count_result_item.validVoteCount),
                to_percentage(candidate_wise_valid_vote_count_result_item.validVotePercentage),
                candidate_wise_valid_vote_count_result_item.validVoteCount
            ])

        content['data'] = sorted(content['data'], key=operator.itemgetter(4), reverse=True)
        content["validVoteCounts"] = [
            to_comma_seperated_num(vote_count_result["validVoteCount"]),
            to_percentage(vote_count_result["validVoteCountPercentage"])
        ]

        content["rejectedVoteCounts"] = [
            to_comma_seperated_num(vote_count_result["rejectedVoteCount"]),
            to_percentage(vote_count_result["rejectedVoteCountPercentage"])
        ]

        content["totalVoteCounts"] = [
            to_comma_seperated_num(vote_count_result["totalVoteCount"]),
            to_percentage(vote_count_result["totalVoteCountPercentage"])
        ]

        content["logo"] = convert_image_to_data_uri("static/Emblem_of_Sri_Lanka.png")

        return content
Exemplo n.º 2
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": 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
            ]
        }

        candidate_wise_valid_vote_count_result = self.candidate_wise_valid_vote_count_query().all()
        vote_count_result = self.vote_count_result()

        for candidate_wise_valid_vote_count_result_item in candidate_wise_valid_vote_count_result:
            content["data"].append([
                candidate_wise_valid_vote_count_result_item.candidateName,
                candidate_wise_valid_vote_count_result_item.partyAbbreviation,
                to_comma_seperated_num(candidate_wise_valid_vote_count_result_item.validVoteCount),
                to_percentage(candidate_wise_valid_vote_count_result_item.validVotePercentage)
            ])

        content["validVoteCounts"] = [
            to_comma_seperated_num(vote_count_result["validVoteCount"]),
            to_percentage(vote_count_result["validVoteCountPercentage"])
        ]

        content["rejectedVoteCounts"] = [
            to_comma_seperated_num(vote_count_result["rejectedVoteCount"]),
            to_percentage(vote_count_result["rejectedVoteCountPercentage"])
        ]

        content["totalVoteCounts"] = [
            to_comma_seperated_num(vote_count_result["totalVoteCount"]),
            to_percentage(vote_count_result["totalVoteCountPercentage"])
        ]

        html = render_template(
            'PRE_ALL_ISLAND_RESULTS.html',
            content=content
        )

        return html
Exemplo n.º 3
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
Exemplo n.º 4
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, 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_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
Exemplo n.º 7
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
    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
Exemplo n.º 9
0
    def html_letter(self, title="", total_registered_voters=None):
        tallySheetVersion = self.tallySheetVersion
        stamp = tallySheetVersion.stamp

        if total_registered_voters is None:
            total_registered_voters = float(
                tallySheetVersion.submission.area.registeredVotersCount)

        content = {
            "resultTitle":
            title,
            "election": {
                "electionName":
                tallySheetVersion.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(total_registered_voters), 100]
        }

        candidate_wise_valid_vote_count_result = self.get_candidate_wise_valid_vote_count_result(
        )
        vote_count_result = self.get_vote_count_result()
        valid_vote_count_result = self.get_valid_vote_count_result()
        rejected_vote_count_result = self.get_rejected_vote_count_result()

        for candidate_wise_valid_non_postal_vote_count_result_item in candidate_wise_valid_vote_count_result.itertuples(
        ):
            content["data"].append([
                candidate_wise_valid_non_postal_vote_count_result_item.
                candidateName,
                candidate_wise_valid_non_postal_vote_count_result_item.
                partyAbbreviation,
                to_comma_seperated_num(
                    candidate_wise_valid_non_postal_vote_count_result_item.
                    numValue),
                to_percentage(
                    candidate_wise_valid_non_postal_vote_count_result_item.
                    numValue * 100 /
                    valid_vote_count_result["numValue"].values[0])
                if valid_vote_count_result["numValue"].values[0] > 0 else ""
            ])

        content["validVoteCounts"] = [
            to_comma_seperated_num(
                valid_vote_count_result["numValue"].values[0]),
            to_percentage(valid_vote_count_result["numValue"].values[0] * 100 /
                          vote_count_result["numValue"].values[0])
            if vote_count_result["numValue"].values[0] > 0 else ""
        ]

        content["rejectedVoteCounts"] = [
            to_comma_seperated_num(
                rejected_vote_count_result["numValue"].values[0]),
            rejected_vote_count_result["numValue"].values[0] * 100 /
            vote_count_result["numValue"].values[0]
            if vote_count_result["numValue"].values[0] > 0 else ""
        ]

        content["totalVoteCounts"] = [
            to_comma_seperated_num(vote_count_result["numValue"].values[0]),
            to_percentage(vote_count_result["numValue"].values[0] * 100 /
                          total_registered_voters)
        ]

        content["logo"] = convert_image_to_data_uri(
            "static/Emblem_of_Sri_Lanka.png")

        html = render_template('PRE_ALL_ISLAND_RESULTS.html', content=content)

        return html
    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)
            ]),
            "totalBallotBoxCount":
            0,
            "data": []
        }

        for row_index in range(len(tallySheetContent)):
            row = tallySheetContent[row_index]

            area = None
            if isinstance(row, TallySheetVersionRow_CE_201.Model):
                area = row.area
                content[
                    "totalBallotBoxCount"] += row.ordinaryBallotCountFromBoxCount
            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(
                        to_comma_seperated_num(
                            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(
                        to_comma_seperated_num(
                            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_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
Exemplo n.º 12
0
        def html_letter(self,
                        title="",
                        total_registered_voters=None,
                        signatures=[]):
            tallySheetVersion = self.tallySheetVersion
            party_wise_valid_vote_count_result = self.get_party_wise_seat_calculations(
            )
            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

            registered_voters_count = tallySheetVersion.tallySheet.area.get_registered_voters_count(
            )
            content = {
                "election": {
                    "electionName":
                    tallySheetVersion.tallySheet.election.get_official_name(),
                    "provinceName":
                    tallySheetVersion.tallySheet.area.areaName
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "signatures":
                signatures,
                "data": [],
                "validVoteCounts": [0, "0%"],
                "rejectedVoteCounts": [0, "0%"],
                "totalVoteCounts": [0, "0%"],
                "registeredVoters":
                [to_comma_seperated_num(registered_voters_count), 100],
                "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")
            }

            total_vote_count = 0
            for area_wise_vote_count_result_item in area_wise_vote_count_result.itertuples(
            ):
                total_vote_count += float(
                    area_wise_vote_count_result_item.incompleteNumValue)
            content["totalVoteCounts"][0] = to_comma_seperated_num(
                total_vote_count)
            content["totalVoteCounts"][1] = to_percentage(
                (total_vote_count / registered_voters_count) * 100)

            total_valid_vote_count = 0
            for area_wise_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples(
            ):
                total_valid_vote_count += float(
                    area_wise_valid_vote_count_result_item.incompleteNumValue)
            content["validVoteCounts"][0] = to_comma_seperated_num(
                total_valid_vote_count)
            content["validVoteCounts"][1] = to_percentage(
                (total_valid_vote_count / total_vote_count) * 100)

            total_rejected_vote_count = 0
            for area_wise_rejected_vote_count_result_item in area_wise_rejected_vote_count_result.itertuples(
            ):
                total_rejected_vote_count += float(
                    area_wise_rejected_vote_count_result_item.numValue)
            content["rejectedVoteCounts"][0] = to_comma_seperated_num(
                total_rejected_vote_count)
            content["rejectedVoteCounts"][1] = to_percentage(
                (total_rejected_vote_count / total_vote_count) * 100)

            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.partyName,
                    party_wise_valid_vote_count_result_item.partyAbbreviation,
                    to_comma_seperated_num(
                        party_wise_valid_vote_count_result_item.numValue)
                ]

                if total_valid_vote_count > 0:
                    data_row.append(
                        to_percentage(
                            party_wise_valid_vote_count_result_item.numValue *
                            100 / total_valid_vote_count))
                else:
                    data_row.append('')

                data_row.append(
                    to_comma_seperated_num(
                        party_wise_valid_vote_count_result_item.seatsAllocated)
                )

                content["data"].append(data_row)

            html = render_template(
                'ProvincialCouncilElection2021/PCE-PC-BS-1-LETTER.html',
                content=content)

            return html
Exemplo n.º 13
0
    def html(self):
        stamp = self.stamp

        content = {
            "election": {
                "electionName": self.submission.election.get_official_name()
            },
            "stamp": {
                "createdAt": stamp.createdAt,
                "createdBy": stamp.createdBy,
                "barcodeString": stamp.barcodeString
            },
            "electoralDistrict": self.submission.area.areaName,
            "pollingDivisions": [],
            "data": [],
            "validVoteCounts": [],
            "rejectedVoteCounts": [],
            "totalVoteCounts": []
        }

        non_postal_candidate_and_area_wise_valid_vote_count_result = self.non_postal_candidate_and_area_wise_valid_vote_count_query(
        ).all()
        postal_candidate_and_area_wise_valid_vote_count_result = self.postal_candidate_and_area_wise_valid_vote_count_query(
        ).all()
        candidate_wise_vote_count_result = self.candidate_wise_vote_count(
        ).all()
        non_postal_area_wise_vote_count_result = self.non_postal_area_wise_vote_count_query(
        ).all()
        postal_area_wise_vote_count_result = self.postal_area_wise_vote_count_query(
        ).all()
        vote_count_result = self.vote_count_query().one_or_none()

        polling_division_count = len(non_postal_area_wise_vote_count_result)
        postal_polling_division_count = len(postal_area_wise_vote_count_result)
        number_of_candidates = len(candidate_wise_vote_count_result)

        for polling_division_index in range(polling_division_count):
            non_postal_area_wise_vote_count_result_item = non_postal_area_wise_vote_count_result[
                polling_division_index]
            content["pollingDivisions"].append(
                non_postal_area_wise_vote_count_result_item.areaName)
            content["rejectedVoteCounts"].append(
                to_comma_seperated_num(
                    non_postal_area_wise_vote_count_result_item.
                    rejectedVoteCount))
            content["validVoteCounts"].append(
                to_comma_seperated_num(
                    non_postal_area_wise_vote_count_result_item.validVoteCount)
            )
            content["totalVoteCounts"].append(
                to_comma_seperated_num(
                    non_postal_area_wise_vote_count_result_item.totalVoteCount)
            )

        for postal_polling_division_index in range(
                postal_polling_division_count):
            postal_area_wise_vote_count_result_item = postal_area_wise_vote_count_result[
                postal_polling_division_index]
            content["rejectedVoteCounts"].append(
                to_comma_seperated_num(
                    postal_area_wise_vote_count_result_item.rejectedVoteCount))
            content["validVoteCounts"].append(
                to_comma_seperated_num(
                    postal_area_wise_vote_count_result_item.validVoteCount))
            content["totalVoteCounts"].append(
                to_comma_seperated_num(
                    postal_area_wise_vote_count_result_item.totalVoteCount))

        content["rejectedVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.rejectedVoteCount))
        content["validVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.validVoteCount))
        content["totalVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.totalVoteCount))

        for candidate_wise_vote_count_result_item_index in range(
                number_of_candidates):
            data_row = []

            data_row_number = candidate_wise_vote_count_result_item_index + 1
            data_row.append(data_row_number)

            candidate_wise_vote_count_result_item = candidate_wise_vote_count_result[
                candidate_wise_vote_count_result_item_index]
            data_row.append(
                candidate_wise_vote_count_result_item.candidateName)

            for polling_division_index in range(polling_division_count):
                non_postal_area_wise_valid_vote_count_result_item_index = (
                    candidate_wise_vote_count_result_item_index *
                    polling_division_count) + polling_division_index
                non_postal_candidate_and_area_wise_valid_vote_count_result_item = \
                    non_postal_candidate_and_area_wise_valid_vote_count_result[
                        non_postal_area_wise_valid_vote_count_result_item_index
                    ]
                data_row.append(
                    to_comma_seperated_num(
                        non_postal_candidate_and_area_wise_valid_vote_count_result_item
                        .validVoteCount))

            postal_candidate_and_area_wise_valid_vote_count_result_item = \
                postal_candidate_and_area_wise_valid_vote_count_result[
                    candidate_wise_vote_count_result_item_index
                ]
            data_row.append(
                to_comma_seperated_num(
                    postal_candidate_and_area_wise_valid_vote_count_result_item
                    .validVoteCount))
            data_row.append(
                to_comma_seperated_num(
                    candidate_wise_vote_count_result_item.validVoteCount))

            content["data"].append(data_row)

        html = render_template('PRE-30-ED.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
Exemplo n.º 15
0
        def html(self, title="", total_registered_voters=None):
            tallySheetVersion = self.tallySheetVersion

            candidate_and_area_wise_valid_non_postal_vote_count_result = self.get_candidate_and_area_wise_valid_non_postal_vote_count_result(
            )
            area_wise_valid_non_postal_vote_count_result = self.get_area_wise_valid_non_postal_vote_count_result(
            )
            area_wise_rejected_non_postal_vote_count_result = self.get_area_wise_rejected_non_postal_vote_count_result(
            )
            area_wise_non_postal_vote_count_result = self.get_area_wise_non_postal_vote_count_result(
            )

            candidate_wise_valid_postal_vote_count_result = self.get_candidate_wise_valid_postal_vote_count_result(
            )
            postal_vote_count_result = self.get_postal_vote_count_result()
            postal_valid_vote_count_result = self.get_postal_valid_vote_count_result(
            )
            postal_rejected_vote_count_result = self.get_postal_rejected_vote_count_result(
            )

            candidate_wise_valid_vote_count_result = self.get_candidate_wise_valid_vote_count_result(
            )
            vote_count_result = self.get_vote_count_result()
            valid_vote_count_result = self.get_valid_vote_count_result()
            rejected_vote_count_result = self.get_rejected_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":
                "PRE/30/PD",
                "electoralDistrict":
                Area.get_associated_areas(
                    tallySheetVersion.submission.area,
                    AreaTypeEnum.ElectoralDistrict)[0].areaName,
                "pollingDivision":
                pollingDivision,
                "data": [],
                "pollingDivisions": [],
                "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_non_postal_vote_count_result_item in area_wise_valid_non_postal_vote_count_result.itertuples(
            ):
                content["pollingDivisions"].append(
                    area_wise_valid_non_postal_vote_count_result_item.areaName)
                content["validVoteCounts"].append(
                    to_comma_seperated_num(
                        area_wise_valid_non_postal_vote_count_result_item.
                        numValue))
                total_valid_vote_count += area_wise_valid_non_postal_vote_count_result_item.numValue

            for area_wise_rejected_non_postal_vote_count_result_item_index, area_wise_rejected_non_postal_vote_count_result_item in area_wise_rejected_non_postal_vote_count_result.iterrows(
            ):
                content["rejectedVoteCounts"].append(
                    to_comma_seperated_num(
                        area_wise_rejected_non_postal_vote_count_result_item.
                        numValue))
                total_rejected_vote_count += area_wise_rejected_non_postal_vote_count_result_item.numValue

            for area_wise_non_postal_vote_count_result_item_index, area_wise_non_postal_vote_count_result_item in area_wise_non_postal_vote_count_result.iterrows(
            ):
                content["totalVoteCounts"].append(
                    to_comma_seperated_num(
                        area_wise_non_postal_vote_count_result_item.numValue))
                total_vote_count += area_wise_non_postal_vote_count_result_item.numValue

            # Append the postal vote count totals
            content["validVoteCounts"].append(
                to_comma_seperated_num(
                    postal_valid_vote_count_result["numValue"].values[0]))
            content["rejectedVoteCounts"].append(
                to_comma_seperated_num(
                    postal_rejected_vote_count_result["numValue"].values[0]))
            content["totalVoteCounts"].append(
                to_comma_seperated_num(
                    postal_vote_count_result["numValue"].values[0]))

            # Append the grand totals
            content["validVoteCounts"].append(
                to_comma_seperated_num(
                    valid_vote_count_result["numValue"].values[0]))
            content["rejectedVoteCounts"].append(
                to_comma_seperated_num(
                    rejected_vote_count_result["numValue"].values[0]))
            content["totalVoteCounts"].append(
                to_comma_seperated_num(
                    vote_count_result["numValue"].values[0]))

            number_of_counting_centres = len(
                area_wise_non_postal_vote_count_result)

            for candidate_wise_valid_vote_count_result_item_index, candidate_wise_valid_vote_count_result_item in candidate_wise_valid_vote_count_result.iterrows(
            ):
                data_row = []

                data_row_number = candidate_wise_valid_vote_count_result_item_index + 1
                data_row.append(data_row_number)

                data_row.append(
                    candidate_wise_valid_vote_count_result_item.candidateName)

                for counting_centre_index in range(number_of_counting_centres):
                    candidate_and_area_wise_valid_non_postal_vote_count_result_item_index = \
                        (
                                number_of_counting_centres * candidate_wise_valid_vote_count_result_item_index) + counting_centre_index

                    data_row.append(
                        to_comma_seperated_num(
                            candidate_and_area_wise_valid_non_postal_vote_count_result[
                                "numValue"].
                            values[
                                candidate_and_area_wise_valid_non_postal_vote_count_result_item_index]
                        ))

                data_row.append(
                    to_comma_seperated_num(
                        candidate_wise_valid_postal_vote_count_result[
                            "numValue"].
                        values[
                            candidate_wise_valid_vote_count_result_item_index])
                )

                data_row.append(
                    to_comma_seperated_num(
                        candidate_wise_valid_vote_count_result_item.numValue))

                content["data"].append(data_row)

            html = render_template('PRE-30-ED.html', content=content)

            return html
Exemplo n.º 16
0
        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

            registered_voters_count = tallySheetVersion.submission.area.get_registered_voters_count(
                vote_type=tallySheetVersion.submission.election.voteType)

            content = {
                "election": {
                    "electionName":
                    tallySheetVersion.submission.election.get_official_name()
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "electoralDistrict":
                tallySheetVersion.submission.area.areaName,
                "data": [],
                "validVoteCounts": [0, "0%"],
                "rejectedVoteCounts": [0, "0%"],
                "totalVoteCounts": [0, "0%"],
                "registeredVoters":
                [to_comma_seperated_num(registered_voters_count), 100],
                "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")
            }

            total_valid_vote_count = 0
            for area_wise_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples(
            ):
                total_valid_vote_count += float(
                    area_wise_valid_vote_count_result_item.incompleteNumValue)
            content["validVoteCounts"][0] = to_comma_seperated_num(
                total_valid_vote_count)
            content["validVoteCounts"][1] = to_percentage(
                (total_valid_vote_count / registered_voters_count) * 100)

            total_rejected_vote_count = 0
            for area_wise_rejected_vote_count_result_item in area_wise_rejected_vote_count_result.itertuples(
            ):
                total_rejected_vote_count += float(
                    area_wise_rejected_vote_count_result_item.numValue)
            content["rejectedVoteCounts"][0] = to_comma_seperated_num(
                total_rejected_vote_count)
            content["rejectedVoteCounts"][1] = to_percentage(
                (total_rejected_vote_count / registered_voters_count) * 100)

            total_vote_count = 0
            for area_wise_vote_count_result_item in area_wise_vote_count_result.itertuples(
            ):
                total_vote_count += float(
                    area_wise_vote_count_result_item.incompleteNumValue)
            content["totalVoteCounts"][0] = to_comma_seperated_num(
                total_vote_count)
            content["totalVoteCounts"][1] = to_percentage(
                (total_vote_count / registered_voters_count) * 100)

            # sort by vote count descending
            party_wise_valid_vote_count_result = party_wise_valid_vote_count_result.sort_values(
                by=['numValue',
                    "electionPartyId"], ascending=[False, True]).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.partyName,
                    party_wise_valid_vote_count_result_item.partyAbbreviation,
                    to_comma_seperated_num(
                        party_wise_valid_vote_count_result_item.numValue)
                ]

                if total_valid_vote_count > 0:
                    data_row.append(
                        to_percentage(
                            party_wise_valid_vote_count_result_item.numValue *
                            100 / total_valid_vote_count))
                else:
                    data_row.append('')

                content["data"].append(data_row)

            html = render_template(
                'ParliamentaryElection2020/PE-CE-RO-V2-LETTER.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
Exemplo n.º 18
0
    def html(self):
        candidate_and_area_wise_valid_vote_count_result = self.candidate_and_area_wise_valid_vote_count_query(
        ).all()
        candidate_wise_vote_count_result = self.candidate_wise_vote_count(
        ).all()
        area_wise_vote_count_result = self.area_wise_vote_count_query().all()
        vote_count_result = self.vote_count_query().one_or_none()

        stamp = self.stamp

        content = {
            "election": {
                "electionName": self.submission.election.get_official_name()
            },
            "stamp": {
                "createdAt": stamp.createdAt,
                "createdBy": stamp.createdBy,
                "barcodeString": stamp.barcodeString
            },
            "electoralDistricts": [],
            "data": [],
            "validVoteCounts": [],
            "rejectedVoteCounts": [],
            "totalVoteCounts": []
        }

        # Append the area wise column totals
        for area_wise_vote_count_result_item in area_wise_vote_count_result:
            content["electoralDistricts"].append(
                area_wise_vote_count_result_item.areaName)
            content["validVoteCounts"].append(
                to_comma_seperated_num(
                    area_wise_vote_count_result_item.validVoteCount))
            content["rejectedVoteCounts"].append(
                to_comma_seperated_num(
                    area_wise_vote_count_result_item.rejectedVoteCount))
            content["totalVoteCounts"].append(
                to_comma_seperated_num(
                    area_wise_vote_count_result_item.totalVoteCount))

        # Append the grand totals
        content["validVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.validVoteCount))
        content["rejectedVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.rejectedVoteCount))
        content["totalVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.totalVoteCount))

        number_of_electoral_districts = len(area_wise_vote_count_result)
        number_of_candidates = len(candidate_wise_vote_count_result)

        for candidate_wise_vote_count_result_item_index in range(
                number_of_candidates):
            candidate_wise_vote_count_result_item = candidate_wise_vote_count_result[
                candidate_wise_vote_count_result_item_index]

            data_row = []

            # data_row_number = candidate_wise_vote_count_result_item_index + 1
            # data_row.append(data_row_number)

            data_row.append(
                candidate_wise_vote_count_result_item.candidateName)

            for electoral_district_index in range(
                    number_of_electoral_districts):
                candidate_and_area_wise_valid_vote_count_result_item_index = \
                    (
                            number_of_electoral_districts * candidate_wise_vote_count_result_item_index) + electoral_district_index

                candidate_and_area_wise_valid_vote_count_result_item = candidate_and_area_wise_valid_vote_count_result[
                    candidate_and_area_wise_valid_vote_count_result_item_index]

                data_row.append(
                    to_comma_seperated_num(
                        candidate_and_area_wise_valid_vote_count_result_item.
                        validVoteCount))

            data_row.append(
                to_comma_seperated_num(
                    candidate_wise_vote_count_result_item.validVoteCount))

            content["data"].append(data_row)

        html = render_template(
            'PRE_ALL_ISLAND_RESULTS_BY_ELECTORAL_DISTRICTS.html',
            content=content)

        return html
Exemplo n.º 19
0
        def html(self, title="", total_registered_voters=None):
            tallySheetVersion = self.tallySheetVersion

            party_and_area_wise_valid_vote_count_result = self.get_party_and_area_wise_valid_vote_count_result(
            )
            area_wise_valid_vote_count_result = self.get_area_wise_valid_vote_count_result(
            )
            party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result(
            )
            party_and_area_wise_valid_postal_vote_count_result = self.get_party_and_area_wise_valid_postal_vote_count_result(
            )
            print("hello")
            print(party_and_area_wise_valid_vote_count_result)
            print(party_and_area_wise_valid_postal_vote_count_result)
            stamp = tallySheetVersion.stamp
            election = tallySheetVersion.tallySheet.election

            content = {
                "election": {
                    "electionName": election.get_official_name()
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "tallySheetCode":
                "PCE/POST/PC",
                "data": [],
                "provinces": {},
                "attributes": [
                    "No. of Votes", "No. of Postal Votes", "Total Votes",
                    "Percentage", "No. of Seats", "No. of Bonus Seats",
                    "Total seats"
                ],
            }

            get_province_from_administrative_district_map = {}

            # Append the grand totals
            number_of_administrative_districts = len(
                area_wise_valid_vote_count_result)

            for area_wise_valid_vote_count_result_item in area_wise_valid_vote_count_result.itertuples(
            ):
                province_name = Area.get_associated_areas(
                    tallySheetVersion.tallySheet.area,
                    AreaTypeEnum.Province)[0].areaName
                if province_name not in content['provinces']:
                    content['provinces'][province_name] = {}

                administrative_district_name = area_wise_valid_vote_count_result_item.areaName
                if administrative_district_name not in content['provinces'][
                        province_name]:
                    get_province_from_administrative_district_map[
                        administrative_district_name] = province_name
                    content['provinces'][province_name][
                        administrative_district_name] = {}

            for party_wise_valid_vote_count_result_item_index, party_wise_valid_vote_count_result_item in party_wise_valid_vote_count_result.iterrows(
            ):
                data_row = []

                data_row.append(
                    party_wise_valid_vote_count_result_item.partyName)

                for administrative_district_index in range(
                        number_of_administrative_districts):
                    party_and_area_wise_valid_vote_count_result_item_index = \
                        (
                                number_of_administrative_districts * party_wise_valid_vote_count_result_item_index) + administrative_district_index

                    # data_row.append(
                    #     to_comma_seperated_num(
                    #         party_wise_valid_vote_count_result["numValue"].values[
                    #             party_and_area_wise_valid_vote_count_result_item_index]))
                    data_row.append(to_comma_seperated_num(0))
                content["data"].append(data_row)

            html = render_template(
                'ProvincialCouncilElection2021/PCE-POST-PC.html',
                content=content)

            return html
        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

            area: AreaModel = tallySheetVersion.submission.area
            pollingDivision = area.areaName
            number_of_electors = float(area.registeredVotersCount)
            if tallySheetVersion.submission.election.voteType == Postal:
                pollingDivision = 'Postal'
                number_of_electors = float(area.registeredPostalVotersCount)

            content = {
                "election": {
                    "electionName":
                    tallySheetVersion.submission.election.get_official_name()
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "tallySheetCode":
                "POLLING DIVISION RESULTS",
                "electoralDistrict":
                Area.get_associated_areas(
                    tallySheetVersion.submission.area,
                    AreaTypeEnum.ElectoralDistrict)[0].areaName,
                "pollingDivision":
                pollingDivision,
                "data": [],
                "totalValidVoteCount":
                '',
                "totalValidVotePercentage":
                '',
                "rejectedVoteCount":
                '',
                "rejectedVotePercentage":
                '',
                "totalVoteCount":
                '',
                "totalVotePercentage":
                '',
                "numberOfElectors":
                to_comma_seperated_num(number_of_electors)
            }

            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 /
                number_of_electors) if number_of_electors > 0 else 0
            content["totalVotePercentage"] = to_percentage(
                total_vote_percentage)

            html = render_template('POLLING-DIVISION-RESULTS.html',
                                   content=content)

            return html
Exemplo n.º 21
0
        def html(self, title="", total_registered_voters=None):
            tallySheetVersion = self.tallySheetVersion

            party_and_area_wise_valid_non_postal_vote_count_result = self.get_party_and_area_wise_valid_non_postal_vote_count_result(
            )
            area_wise_valid_non_postal_vote_count_result = self.get_area_wise_valid_non_postal_vote_count_result(
            )
            area_wise_rejected_non_postal_vote_count_result = self.get_area_wise_rejected_non_postal_vote_count_result(
            )
            area_wise_non_postal_vote_count_result = self.get_area_wise_non_postal_vote_count_result(
            )
            party_wise_valid_vote_count_result = self.get_party_wise_valid_vote_count_result(
            )

            vote_count_result = self.get_vote_count_result()
            valid_vote_count_result = self.get_valid_vote_count_result()
            rejected_vote_count_result = self.get_rejected_vote_count_result()

            stamp = tallySheetVersion.stamp
            election = tallySheetVersion.submission.election
            non_postal_vote_types = []
            for sub_election in election.subElections:
                if sub_election.voteType != NonPostal:
                    non_postal_vote_types.append(sub_election.voteType)

            content = {
                "election": {
                    "electionName": election.get_official_name()
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "tallySheetCode": "CE/RO/V/2",
                "electoralDistrict":
                tallySheetVersion.submission.area.areaName,
                "nonPostalVoteTypes": non_postal_vote_types,
                "data": [],
                "pollingDivisions": [],
                "validVoteCounts": [],
                "rejectedVoteCounts": [],
                "totalVoteCounts": []
            }

            total_valid_vote_count = 0
            total_rejected_vote_count = 0
            total_vote_count = 0

            # Append the area wise column totals
            print(area_wise_valid_non_postal_vote_count_result)
            for area_wise_valid_non_postal_vote_count_result_item in area_wise_valid_non_postal_vote_count_result.itertuples(
            ):
                content["pollingDivisions"].append(
                    area_wise_valid_non_postal_vote_count_result_item.areaName)
                content["validVoteCounts"].append(
                    to_comma_seperated_num(
                        area_wise_valid_non_postal_vote_count_result_item.
                        incompleteNumValue))
                total_valid_vote_count += area_wise_valid_non_postal_vote_count_result_item.incompleteNumValue

            for area_wise_rejected_non_postal_vote_count_result_item_index, area_wise_rejected_non_postal_vote_count_result_item in area_wise_rejected_non_postal_vote_count_result.iterrows(
            ):
                content["rejectedVoteCounts"].append(
                    to_comma_seperated_num(
                        area_wise_rejected_non_postal_vote_count_result_item.
                        numValue))
                total_rejected_vote_count += area_wise_rejected_non_postal_vote_count_result_item.numValue

            for area_wise_non_postal_vote_count_result_item_index, area_wise_non_postal_vote_count_result_item in area_wise_non_postal_vote_count_result.iterrows(
            ):
                content["totalVoteCounts"].append(
                    to_comma_seperated_num(
                        area_wise_non_postal_vote_count_result_item.
                        incompleteNumValue))
                total_vote_count += area_wise_non_postal_vote_count_result_item.incompleteNumValue

            for vote_type in non_postal_vote_types:
                postal_vote_count_result = self.get_vote_count_result(
                    vote_type=vote_type)
                postal_valid_vote_count_result = self.get_valid_vote_count_result(
                    vote_type=vote_type)
                postal_rejected_vote_count_result = self.get_rejected_vote_count_result(
                    vote_type=vote_type)

                # Append the postal vote count totals
                content["pollingDivisions"].append("%s Votes" % vote_type)
                content["validVoteCounts"].append(
                    to_comma_seperated_num(
                        postal_valid_vote_count_result["incompleteNumValue"].
                        values[0]))
                content["rejectedVoteCounts"].append(
                    to_comma_seperated_num(
                        postal_rejected_vote_count_result["numValue"].values[0]
                    ))
                content["totalVoteCounts"].append(
                    to_comma_seperated_num(
                        postal_vote_count_result["incompleteNumValue"].
                        values[0]))

            # Append the grand totals
            content["validVoteCounts"].append(
                to_comma_seperated_num(
                    valid_vote_count_result["incompleteNumValue"].values[0]))
            content["rejectedVoteCounts"].append(
                to_comma_seperated_num(
                    rejected_vote_count_result["incompleteNumValue"].values[0])
            )
            content["totalVoteCounts"].append(
                to_comma_seperated_num(
                    vote_count_result["incompleteNumValue"].values[0]))

            number_of_counting_centres = len(
                area_wise_non_postal_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_non_postal_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_non_postal_vote_count_result[
                                "numValue"].
                            values[
                                party_and_area_wise_valid_non_postal_vote_count_result_item_index]
                        ))

                for vote_type in non_postal_vote_types:
                    party_wise_valid_postal_vote_count_result = self.get_party_wise_valid_vote_count_result(
                        vote_type=vote_type)
                    data_row.append(
                        to_comma_seperated_num(
                            party_wise_valid_postal_vote_count_result[
                                "numValue"].
                            values[
                                party_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-V2.html', content=content)

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

            candidate_and_area_wise_valid_vote_count = self.get_candidate_and_area_wise_valid_vote_count_result(
            )

            noOfCandidates = candidate_and_area_wise_valid_vote_count.shape[0]
            noOfRows = round(noOfCandidates / 2)

            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 != 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":
                "PE-4",
                "electoralDistrict":
                Area.get_associated_areas(
                    tallySheetVersion.submission.area,
                    AreaTypeEnum.ElectoralDistrict)[0].areaName,
                "pollingDivision":
                polling_division_name,
                "countingCentre":
                tallySheetVersion.submission.area.areaName,
                "partyName":
                candidate_and_area_wise_valid_vote_count["partyName"].
                values[0],
                "data1": [],
                "data2": []
            }

            # Appending canditate wise vote count
            i = 0

            for index, row in candidate_and_area_wise_valid_vote_count.iterrows(
            ):

                if i < noOfRows:
                    data_row1 = []
                    data_row1.append(row.candidateName)
                    data_row1.append(row.strValue)
                    data_row1.append(to_comma_seperated_num(row.numValue))
                    content["data1"].append(data_row1)
                    i += 1
                else:
                    data_row2 = []
                    data_row2.append(row.candidateName)
                    print(row.candidateName)
                    data_row2.append(row.strValue)
                    data_row2.append(to_comma_seperated_num(row.numValue))
                    content["data2"].append(data_row2)

            html = render_template('PE-4.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
Exemplo n.º 24
0
    def get_html_content_dict(self):
        candidate_and_area_wise_valid_vote_count_result = self.candidate_and_area_wise_valid_vote_count_query(
        ).all()
        candidate_wise_vote_count_result = self.candidate_wise_vote_count(
        ).all()
        area_wise_vote_count_result = self.area_wise_vote_count_query().all()
        vote_count_result = self.vote_count_query().one_or_none()

        stamp = self.stamp

        content = {
            "election": {
                "electionName": self.submission.election.get_official_name()
            },
            "stamp": {
                "createdAt": stamp.createdAt,
                "createdBy": stamp.createdBy,
                "barcodeString": stamp.barcodeString
            },
            "electoralDistricts": [],
            "data": [],
            "validVoteCounts": [],
            "rejectedVoteCounts": [],
            "totalVoteCounts": [],
            "registeredVoterCounts": []
        }

        # Append the area wise column totals
        for area_wise_vote_count_result_item in area_wise_vote_count_result:
            content["electoralDistricts"].append(
                area_wise_vote_count_result_item.areaName)
            content["validVoteCounts"].append(
                to_comma_seperated_num(
                    area_wise_vote_count_result_item.validVoteCount))
            content["rejectedVoteCounts"].append(
                to_comma_seperated_num(
                    area_wise_vote_count_result_item.rejectedVoteCount))
            content["totalVoteCounts"].append(
                to_comma_seperated_num(
                    area_wise_vote_count_result_item.totalVoteCount))
            content["registeredVoterCounts"].append(
                to_comma_seperated_num(
                    area_wise_vote_count_result_item.registeredVotersCount))

        # Append the grand totals
        content["validVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.validVoteCount))
        content["rejectedVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.rejectedVoteCount))
        content["totalVoteCounts"].append(
            to_comma_seperated_num(vote_count_result.totalVoteCount))
        content["registeredVoterCounts"].append(
            to_comma_seperated_num(vote_count_result.registeredVotersCount))

        # Append the percentages.
        content["validVoteCounts"].append(
            to_percentage(vote_count_result.validVoteCount * 100 /
                          vote_count_result.totalVoteCount))
        content["rejectedVoteCounts"].append(
            to_percentage(vote_count_result.rejectedVoteCount * 100 /
                          vote_count_result.totalVoteCount))
        content["totalVoteCounts"].append(
            to_percentage(vote_count_result.totalVoteCount * 100 /
                          vote_count_result.registeredVotersCount))

        number_of_electoral_districts = len(area_wise_vote_count_result)
        number_of_candidates = len(candidate_wise_vote_count_result)

        for candidate_wise_vote_count_result_item_index in range(
                number_of_candidates):
            candidate_wise_vote_count_result_item = candidate_wise_vote_count_result[
                candidate_wise_vote_count_result_item_index]

            data_row = []

            # data_row_number = candidate_wise_vote_count_result_item_index + 1
            # data_row.append(data_row_number)

            data_row.append(
                candidate_wise_vote_count_result_item.candidateName)

            for electoral_district_index in range(
                    number_of_electoral_districts):
                candidate_and_area_wise_valid_vote_count_result_item_index = \
                    (
                            number_of_electoral_districts * candidate_wise_vote_count_result_item_index) + electoral_district_index

                candidate_and_area_wise_valid_vote_count_result_item = candidate_and_area_wise_valid_vote_count_result[
                    candidate_and_area_wise_valid_vote_count_result_item_index]

                data_row.append(
                    to_comma_seperated_num(
                        candidate_and_area_wise_valid_vote_count_result_item.
                        validVoteCount))

            data_row.append(
                to_comma_seperated_num(
                    candidate_wise_vote_count_result_item.validVoteCount))

            candidate_wise_vote_count_percentage = (
                candidate_wise_vote_count_result_item.validVoteCount /
                vote_count_result.validVoteCount) * 100
            data_row.append(
                to_percentage(candidate_wise_vote_count_percentage))

            content["data"].append(data_row)

        return content
        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
Exemplo n.º 26
0
        def html(self, title="", total_registered_voters=None):
            tallySheetVersion = self.tallySheetVersion

            candidate_and_area_wise_valid_non_postal_vote_count_result = self.get_candidate_and_area_wise_valid_non_postal_vote_count_result()
            candidate_wise_valid_vote_count_result = self.get_candidate_wise_valid_vote_count_result()
            area_wise_non_postal_vote_count_result = self.get_area_wise_non_postal_vote_count_result()

            stamp = tallySheetVersion.stamp
            election = tallySheetVersion.tallySheet.election

            non_postal_vote_types = []
            vote_type_to_candidate_wise_valid_vote_count_result_map = {}

            for sub_election in election.subElections:
                vote_type_to_candidate_wise_valid_vote_count_result_map[
                    sub_election.voteType] = self.get_candidate_wise_valid_vote_count_result(
                    vote_type=sub_election.voteType)

                if sub_election.voteType != NonPostal:
                    non_postal_vote_types.append(sub_election.voteType)

            content = {
                "election": {
                    "electionName": election.get_official_name()
                },
                "stamp": {
                    "createdAt": stamp.createdAt,
                    "createdBy": stamp.createdBy,
                    "barcodeString": stamp.barcodeString
                },
                "tallySheetCode": "CE/RO/PR/2",
                "administrativeDistrict": tallySheetVersion.tallySheet.area.areaName,
                "nonPostalVoteTypes": non_postal_vote_types,
                "partyName": candidate_and_area_wise_valid_non_postal_vote_count_result["partyName"].values[0],
                "data": [],
                "pollingDivisions": [],
                "totalVoteCounts": []
            }

            # Append the area wise column totals
            for area_wise_non_postal_vote_count_result_item in area_wise_non_postal_vote_count_result.itertuples():
                print(area_wise_non_postal_vote_count_result_item.areaName)
                content["pollingDivisions"].append(area_wise_non_postal_vote_count_result_item.areaName)
                content["totalVoteCounts"].append(
                    to_comma_seperated_num(area_wise_non_postal_vote_count_result_item.incompleteNumValue)
                )

            for vote_type in non_postal_vote_types:
                content["pollingDivisions"].append(vote_type)
                content["totalVoteCounts"].append(to_comma_seperated_num(
                    vote_type_to_candidate_wise_valid_vote_count_result_map[vote_type]["numValue"].sum()))

            if tallySheetVersion.tallySheet.election.voteType != NonPostal:
                content["tallySheetCode"] = "CE/RO/PR/2"

            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_non_postal_vote_count_result.index:
                    if candidate_and_area_wise_valid_non_postal_vote_count_result.at[
                        index_2, "candidateId"] == candidate_id:
                        data_row.append(to_comma_seperated_num(
                            candidate_and_area_wise_valid_non_postal_vote_count_result.at[index_2, "numValue"]))

                for vote_type in non_postal_vote_types:
                    data_row.append(to_comma_seperated_num(
                        vote_type_to_candidate_wise_valid_vote_count_result_map[vote_type]["numValue"].values[index_1]))

                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["incompleteNumValue"].sum()))

            html = render_template(
                'ProvincialCouncilElection2021/PCE-CE-RO-PR-2.html',
                content=content
            )

            return html
Exemplo n.º 27
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):
            election = self.tallySheetVersion.tallySheet.election
            party_wise_seat_calculations = self.get_party_wise_seat_calculations(
            )

            number_of_members_to_be_elected = election.meta.get_meta_data(
                metaDataKey=META_DATA_KEY_ELECTION_NUMBER_OF_SEATS_ALLOCATED)
            if number_of_members_to_be_elected is not None:
                number_of_members_to_be_elected = int(
                    number_of_members_to_be_elected)

            total_valid_vote_count = party_wise_seat_calculations[
                'numValue'].sum()

            election = self.tallySheetVersion.tallySheet.election
            tally_sheet_id = self.tallySheetVersion.tallySheetId

            minimum_vote_count_percentage_required = float(
                election.meta.get_meta_data(
                    metaDataKey=
                    META_DATA_KEY_ELECTION_NUMBER_OF_VALID_VOTE_PERCENTAGE_REQUIRED_FOR_SEAT_ALLOCATION
                ))

            minimum_valid_vote_count_required_per_party_to_be_qualified = total_valid_vote_count * minimum_vote_count_percentage_required

            total_disqualified_valid_vote_count = party_wise_seat_calculations[
                party_wise_seat_calculations["numValue"] <
                minimum_valid_vote_count_required_per_party_to_be_qualified][
                    "numValue"].sum()

            total_valid_votes_after_deduction = total_valid_vote_count - total_disqualified_valid_vote_count

            number_of_members_to_be_elected_minus_1 = number_of_members_to_be_elected - 1
            relevant_no_of_votes_div_by_no_of_members = total_valid_votes_after_deduction / number_of_members_to_be_elected_minus_1
            rounded_relevant_no_of_votes_div_by_no_of_members = math.ceil(
                relevant_no_of_votes_div_by_no_of_members)

            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/R2",
                "administrativeDistrict":
                Area.get_associated_areas(
                    tallySheetVersion.tallySheet.area,
                    AreaTypeEnum.AdministrativeDistrict)[0].areaName,
                "administrativeDistrictId":
                Area.get_associated_areas(
                    tallySheetVersion.tallySheet.area,
                    AreaTypeEnum.AdministrativeDistrict)[0].areaId,
                "data": [],
                "rejectedVoteCounts": [],
                "totalVoteCounts":
                to_comma_seperated_num(total_valid_vote_count),
                "twentiethOfTotalVoteCounts":
                to_comma_seperated_num(
                    minimum_valid_vote_count_required_per_party_to_be_qualified,
                    num_type=float),
                "total_less_than_twentiethOfTotalVoteCounts":
                to_comma_seperated_num(total_disqualified_valid_vote_count),
                "total_votes_after_deduction":
                to_comma_seperated_num(total_valid_votes_after_deduction),
                "number_of_members_to_be_elected_minus_1":
                to_comma_seperated_num(
                    number_of_members_to_be_elected_minus_1),
                "relevant_no_of_votes_div_by_no_of_members":
                to_comma_seperated_num(
                    relevant_no_of_votes_div_by_no_of_members,
                    num_type=float,
                    round_to=2),
                "rounded_relevant_no_of_votes_div_by_no_of_members":
                to_comma_seperated_num(
                    rounded_relevant_no_of_votes_div_by_no_of_members),
                "total": []
            }

            total_seatsAllocatedFromRound1 = 0
            total_seatsAllocatedFromRound2 = 0
            total_bonusSeatsAllocated = 0

            party_wise_seat_calculations = party_wise_seat_calculations[
                (party_wise_seat_calculations["numValue"] >=
                 minimum_valid_vote_count_required_per_party_to_be_qualified) |
                (party_wise_seat_calculations["seatsAllocated"] > 0
                 )].sort_values(
                     by=["seatsAllocated", "numValue", "electionPartyId"],
                     ascending=[False, False, True])

            for party_wise_seat_calculation_item in party_wise_seat_calculations.itertuples(
            ):
                data_row = []

                data_row.append(party_wise_seat_calculation_item.partyName)
                data_row.append(
                    to_comma_seperated_num(
                        party_wise_seat_calculation_item.numValue))
                data_row.append(
                    to_comma_seperated_num(party_wise_seat_calculation_item.
                                           seatsAllocatedFromRound1))
                data_row.append(
                    to_comma_seperated_num(party_wise_seat_calculation_item.
                                           validVotesRemainFromRound1))
                data_row.append(
                    to_comma_seperated_num(party_wise_seat_calculation_item.
                                           seatsAllocatedFromRound2))
                data_row.append(
                    to_comma_seperated_num(
                        party_wise_seat_calculation_item.bonusSeatsAllocated))
                data_row.append(
                    to_comma_seperated_num(
                        party_wise_seat_calculation_item.seatsAllocated))

                content["data"].append(data_row)

                total_seatsAllocatedFromRound1 += int(
                    party_wise_seat_calculation_item.seatsAllocatedFromRound1)
                total_seatsAllocatedFromRound2 += int(
                    party_wise_seat_calculation_item.seatsAllocatedFromRound2)
                total_bonusSeatsAllocated += int(
                    party_wise_seat_calculation_item.bonusSeatsAllocated)

            # get the totals
            content["total"].append(
                to_comma_seperated_num(total_valid_votes_after_deduction))
            content["total"].append(
                to_comma_seperated_num(total_seatsAllocatedFromRound1))
            content["total"].append(
                to_comma_seperated_num(total_seatsAllocatedFromRound2))
            content["total"].append(
                to_comma_seperated_num(total_bonusSeatsAllocated))
            content["total"].append(
                to_comma_seperated_num(
                    party_wise_seat_calculations['seatsAllocated'].sum()))

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

            # return super(ExtendedTallySheet_PE_R2.ExtendedTallySheetVersion, self).html(
            #     title="PCE-R2 : %s" % self.tallySheetVersion.tallySheet.area.areaName,
            #     columns=[
            #         "partyId",
            #         "partyName",
            #         "partySymbol",
            #         "partyAbbreviation",
            #         "numValue",
            #         "voteCountCeilPerSeat",
            #         "minimumVoteCountRequiredForSeatAllocation",
            #         "draftBonusSeatsAllocated",
            #         "draftSeatsAllocatedFromRound2",
            #         "bonusSeatsAllocated",
            #         "seatsAllocatedFromRound1",
            #         "validVotesRemainFromRound1",
            #         "seatsAllocatedFromRound2",
            #         "seatsAllocated"
            #     ],
            #     df=party_wise_seat_calculations
            # )

            return html
Exemplo n.º 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