Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ECLK/results-tabulation i…
Browse files Browse the repository at this point in the history
…nto gh-858
  • Loading branch information
sm1990 committed Feb 13, 2021
2 parents 113a874 + fa34edc commit 9de9ac5
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 249 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Platformer Generated ui-master-push Build
name: Platformer Generated ui-dev-master-push Build
on:
push:
branches:
Expand All @@ -24,16 +24,16 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build the Docker image
run: docker build --tag
${SERVICE_NAME}:${{steps.event-version.outputs.SOURCE_TAG }} --file
${SERVICE_NAME}:ui-${{steps.event-version.outputs.SOURCE_TAG }} --file
./results-tabulation-ui/Dockerfile ./results-tabulation-ui/
- name: GitHub Image Push
run: docker push $SERVICE_NAME:${{steps.event-version.outputs.SOURCE_TAG }}
run: docker push $SERVICE_NAME:ui-${{steps.event-version.outputs.SOURCE_TAG }}
- name: Platformer Deploy
uses: platformer-com/build-deploy-action@v1
with:
org-id: ${{secrets.ORG_ID_FCB1AEBE_71DB_4911_9067_F5FA9BA73D4D}}
project-id: ${{secrets.PROJECT_ID_FCB1AEBE_71DB_4911_9067_F5FA9BA73D4D}}
token: ${{secrets.AUTOGENERATED_CICD_FCB1AEBE_71DB_4911_9067_F5FA9BA73D4D}}
image-name: ${{env.SERVICE_NAME}}
tag: ${{steps.event-version.outputs.SOURCE_TAG }}
tag: ui-${{steps.event-version.outputs.SOURCE_TAG }}
container-id: 42534598-30c1-475f-bd37-6853261010d1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Platformer Generated ui-stag-tag-push Build
on:
push:
tags:
- 'stag-**'
jobs:
build:
runs-on:
- ubuntu-latest
env:
SERVICE_NAME: ghcr.io/eclk/results-tabulation
CONTAINER_REGISTRY: ghcr.io
steps:
- uses: actions/checkout@v2
- name: Set Version
id: event-version
run: echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build the Docker image
run: docker build --tag
${SERVICE_NAME}:ui-${{steps.event-version.outputs.SOURCE_TAG }} --file
./results-tabulation-ui/Staging.Dockerfile ./results-tabulation-ui/
- name: GitHub Image Push
run: docker push $SERVICE_NAME:ui-${{steps.event-version.outputs.SOURCE_TAG }}
- name: Platformer Deploy
uses: platformer-com/build-deploy-action@v1
with:
org-id: ${{secrets.ORG_ID_FCB1AEBE_71DB_4911_9067_F5FA9BA73D4D}}
project-id: ${{secrets.PROJECT_ID_FCB1AEBE_71DB_4911_9067_F5FA9BA73D4D}}
token: ${{secrets.AUTOGENERATED_CICD_FCB1AEBE_71DB_4911_9067_F5FA9BA73D4D}}
image-name: ${{env.SERVICE_NAME}}
tag: ui-${{steps.event-version.outputs.SOURCE_TAG }}
container-id: d5978be8-fb29-4f53-b951-acf8995587f3
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Platformer Generated stag-api-tag-push Build
on:
push:
tags:
- 'stag-**'
jobs:
build:
runs-on:
- ubuntu-latest
env:
SERVICE_NAME: ghcr.io/eclk/results-tabulation
CONTAINER_REGISTRY: ghcr.io
steps:
- uses: actions/checkout@v2
- name: Set Version
id: event-version
run: echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build the Docker image
run: docker build --tag
${SERVICE_NAME}:api-${{steps.event-version.outputs.SOURCE_TAG }} --file
./results-tabulation-api/Dockerfile ./results-tabulation-api/
- name: GitHub Image Push
run: docker push $SERVICE_NAME:api-${{steps.event-version.outputs.SOURCE_TAG }}
- name: Platformer Deploy
uses: platformer-com/build-deploy-action@v1
with:
org-id: ${{secrets.ORG_ID_BCBDC02D_6FBA_4B10_9603_D19453632123}}
project-id: ${{secrets.PROJECT_ID_BCBDC02D_6FBA_4B10_9603_D19453632123}}
token: ${{secrets.AUTOGENERATED_CICD_BCBDC02D_6FBA_4B10_9603_D19453632123}}
image-name: ${{env.SERVICE_NAME}}
tag: api-${{steps.event-version.outputs.SOURCE_TAG }}
container-id: 017c3bee-7f08-49fd-b82a-f4b6f3504eee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Platformer Generated master-push Build
name: Platformer Generated dev-master-push Build
on:
push:
branches:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from exception.messages import MESSAGE_CODE_PCE_PC_BS_1_CANNOT_BE_PROCESSED_WITHOUT_PCE_PC_V
from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TEMPLATE_ROW_TYPE import \
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_1, TEMPLATE_ROW_TYPE_VALID_VOTES_REMAIN_FROM_ROUND_1, \
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_2, TEMPLATE_ROW_TYPE_VALID_VOTE_COUNT_CEIL_PER_SEAT, \
TEMPLATE_ROW_TYPE_DRAFT_SEATS_ALLOCATED_FROM_ROUND_2, TEMPLATE_ROW_TYPE_SEATS_ALLOCATED
TEMPLATE_ROW_TYPE_VALID_VOTE_COUNT_CEIL_PER_SEAT, \
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED
from ext.ExtendedTallySheet import ExtendedEditableTallySheetReport
from orm.entities import TallySheet
from orm.entities.Template import TemplateRowModel, TemplateModel
Expand All @@ -15,10 +15,6 @@
import numpy as np

template_row_to_df_num_value_column_map = {
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_1: "seatsAllocatedFromRound1",
TEMPLATE_ROW_TYPE_VALID_VOTES_REMAIN_FROM_ROUND_1: "validVotesRemainFromRound1",
TEMPLATE_ROW_TYPE_DRAFT_SEATS_ALLOCATED_FROM_ROUND_2: "draftSeatsAllocatedFromRound2",
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_2: "seatsAllocatedFromRound2",
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED: "seatsAllocated",
TEMPLATE_ROW_TYPE_VALID_VOTE_COUNT_CEIL_PER_SEAT: "voteCountCeilPerSeat"
}
Expand All @@ -29,15 +25,11 @@ class ExtendedTallySheetVersion(ExtendedEditableTallySheetReport.ExtendedTallySh

def get_post_save_request_content(self):
tally_sheet_id = self.tallySheetVersion.tallySheetId
number_of_members_to_be_elected = 29
number_of_members_to_be_elected = 2

df = self.populate_seats_per_party(number_of_members_to_be_elected=number_of_members_to_be_elected)

template_row_map = {
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_1: [],
TEMPLATE_ROW_TYPE_VALID_VOTES_REMAIN_FROM_ROUND_1: [],
TEMPLATE_ROW_TYPE_DRAFT_SEATS_ALLOCATED_FROM_ROUND_2: [],
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_2: [],
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED: [],
TEMPLATE_ROW_TYPE_VALID_VOTE_COUNT_CEIL_PER_SEAT: []
}
Expand Down Expand Up @@ -82,27 +74,18 @@ def populate_seats_per_party(self, number_of_members_to_be_elected=0):
valid_vote_count_required_per_seat = total_valid_vote_count / number_of_members_to_be_elected
valid_vote_count_required_per_seat_ceil = math.ceil(valid_vote_count_required_per_seat)

for index in df.index:
num_value = df.at[index, 'numValue']
number_of_seats_qualified = math.floor(num_value / valid_vote_count_required_per_seat_ceil)
df.at[index, 'seatsAllocatedFromRound1'] = number_of_seats_qualified
number_of_members_to_be_elected -= number_of_seats_qualified
df.at[index, 'validVotesRemainFromRound1'] = num_value % valid_vote_count_required_per_seat_ceil
df = df.sort_values(by=['numValue'], ascending=True)
max_num_value_index = 0
max_num_value = 0

df = df.sort_values(by=['validVotesRemainFromRound1'], ascending=False)
for index in df.index:
if number_of_members_to_be_elected > 0:
number_of_seats_qualified = 1
df.at[index, 'seatsAllocatedFromRound2'] = number_of_seats_qualified
number_of_members_to_be_elected -= number_of_seats_qualified
else:
df.at[index, 'seatsAllocatedFromRound2'] = 0

df['seatsAllocated'] = df.seatsAllocatedFromRound1 + df.seatsAllocatedFromRound2

df['draftSeatsAllocatedFromRound2'] = df.seatsAllocatedFromRound2
num_value = df.at[index, 'numValue']
if num_value > max_num_value:
max_num_value=num_value
max_num_value_index=index
df.at[index, 'seatsAllocated'] = 0

df = df.sort_values(by=['numValue'], ascending=False)
df.at[max_num_value_index, 'seatsAllocated'] = 2

df["voteCountCeilPerSeat"] = pd.Series(
np.full(len(df.index), valid_vote_count_required_per_seat_ceil),
Expand Down Expand Up @@ -250,7 +233,7 @@ def html_letter(self, title="", total_registered_voters=None, signatures=[]):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import render_template

import pandas as pd
from ext.ExtendedElection.ExtendedElectionProvincialCouncilElection2021.TEMPLATE_ROW_TYPE import \
TEMPLATE_ROW_TYPE_ELECTED_CANDIDATE
TEMPLATE_ROW_TYPE_ELECTED_CANDIDATE, TEMPLATE_ROW_TYPE_ELECTED_BONUS_CANDIDATE
from ext.ExtendedTallySheet import ExtendedTallySheetReport
from util import convert_image_to_data_uri

Expand Down Expand Up @@ -45,12 +45,16 @@ def json(self):
def get_candidate_wise_results(self):
elected_candidates = self.df.loc[
(self.df['templateRowType'] == TEMPLATE_ROW_TYPE_ELECTED_CANDIDATE) & (self.df['numValue'] == 0)]
bonus_candidates = self.df.loc[
(self.df['templateRowType'] == TEMPLATE_ROW_TYPE_ELECTED_BONUS_CANDIDATE) & (self.df['numValue'] == 0)]
final_elected_candidates = pd.concat([elected_candidates, bonus_candidates]).drop_duplicates(
subset=['partyId', 'candidateId'])

elected_candidates = elected_candidates.sort_values(
final_elected_candidates = final_elected_candidates.sort_values(
by=['partyId', 'candidateId'], ascending=True
).reset_index()

return elected_candidates
return final_elected_candidates

def html(self, title="", total_registered_voters=None):
tallySheetVersion = self.tallySheetVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_1: "seatsAllocatedFromRound1",
TEMPLATE_ROW_TYPE_VALID_VOTES_REMAIN_FROM_ROUND_1: "validVotesRemainFromRound1",
TEMPLATE_ROW_TYPE_DRAFT_SEATS_ALLOCATED_FROM_ROUND_2: "draftSeatsAllocatedFromRound2",
TEMPLATE_ROW_TYPE_DRAFT_BONUS_SEATS_ALLOCATED: "draftBonusSeatsAllocated",
# TEMPLATE_ROW_TYPE_DRAFT_BONUS_SEATS_ALLOCATED: "draftBonusSeatsAllocated",
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_2: "seatsAllocatedFromRound2",
TEMPLATE_ROW_TYPE_BONUS_SEATS_ALLOCATED: "bonusSeatsAllocated",
# TEMPLATE_ROW_TYPE_BONUS_SEATS_ALLOCATED: "bonusSeatsAllocated",
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED: "seatsAllocated",
TEMPLATE_ROW_TYPE_VALID_VOTE_COUNT_CEIL_PER_SEAT: "voteCountCeilPerSeat",
TEMPLATE_ROW_TYPE_MINIMUM_VALID_VOTE_COUNT_REQUIRED_FOR_SEAT_ALLOCATION: "minimumVoteCountRequiredForSeatAllocation"
Expand Down Expand Up @@ -72,7 +72,7 @@ def json(self):
"vote_count": 0,
"vote_percentage": "",
"seat_count": int(party_wise_result.seatsAllocated),
"bonus_seat_count": 0
# "bonus_seat_count": 0
} for party_wise_result in party_wise_results.itertuples()
]
}
Expand Down Expand Up @@ -100,9 +100,9 @@ def get_post_save_request_content(self):
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_1: [],
TEMPLATE_ROW_TYPE_VALID_VOTES_REMAIN_FROM_ROUND_1: [],
TEMPLATE_ROW_TYPE_DRAFT_SEATS_ALLOCATED_FROM_ROUND_2: [],
TEMPLATE_ROW_TYPE_DRAFT_BONUS_SEATS_ALLOCATED: [],
# TEMPLATE_ROW_TYPE_DRAFT_BONUS_SEATS_ALLOCATED: [],
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_2: [],
TEMPLATE_ROW_TYPE_BONUS_SEATS_ALLOCATED: [],
# TEMPLATE_ROW_TYPE_BONUS_SEATS_ALLOCATED: [],
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED: [],
TEMPLATE_ROW_TYPE_VALID_VOTE_COUNT_CEIL_PER_SEAT: [],
TEMPLATE_ROW_TYPE_MINIMUM_VALID_VOTE_COUNT_REQUIRED_FOR_SEAT_ALLOCATION: []
Expand Down Expand Up @@ -158,12 +158,12 @@ def populate_seats_per_party(self, minimum_vote_count_percentage_required, numbe

max_valid_vote_count_per_party = df['numValue'].max()

for index in df.index:
if df.at[index, 'numValue'] == max_valid_vote_count_per_party:
df.at[index, 'bonusSeatsAllocated'] = 1
number_of_members_to_be_elected -= 1
else:
df.at[index, 'bonusSeatsAllocated'] = 0
# for index in df.index:
# if df.at[index, 'numValue'] == max_valid_vote_count_per_party:
# df.at[index, 'bonusSeatsAllocated'] = 1
# number_of_members_to_be_elected -= 1
# else:
# df.at[index, 'bonusSeatsAllocated'] = 0

valid_vote_count_required_per_seat = total_valid_vote_count_of_qualified_parties / number_of_members_to_be_elected
valid_vote_count_required_per_seat_ceil = math.ceil(valid_vote_count_required_per_seat)
Expand All @@ -188,10 +188,11 @@ def populate_seats_per_party(self, minimum_vote_count_percentage_required, numbe
else:
df.at[index, 'seatsAllocatedFromRound2'] = 0

df['seatsAllocated'] = df.seatsAllocatedFromRound1 + df.seatsAllocatedFromRound2 + df.bonusSeatsAllocated
# df['seatsAllocated'] = df.seatsAllocatedFromRound1 + df.seatsAllocatedFromRound2 + df.bonusSeatsAllocated
df['seatsAllocated'] = df.seatsAllocatedFromRound1 + df.seatsAllocatedFromRound2

df['draftSeatsAllocatedFromRound2'] = df.seatsAllocatedFromRound2
df['draftBonusSeatsAllocated'] = df.bonusSeatsAllocated
# df['draftBonusSeatsAllocated'] = df.bonusSeatsAllocated

df = df.sort_values(by=['numValue'], ascending=False)

Expand Down Expand Up @@ -297,7 +298,7 @@ def html(self, title="", total_registered_voters=None):

total_seatsAllocatedFromRound1 = 0
total_seatsAllocatedFromRound2 = 0
total_bonusSeatsAllocated = 0
# total_bonusSeatsAllocated = 0

party_wise_seat_calculations = party_wise_seat_calculations[
(party_wise_seat_calculations[
Expand All @@ -313,20 +314,20 @@ def html(self, title="", total_registered_voters=None):
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.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)
# 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(total_bonusSeatsAllocated))
content["total"].append(to_comma_seperated_num(party_wise_seat_calculations['seatsAllocated'].sum()))

html = render_template(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,6 @@ def create_template():
{"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_CONTENT}
]
},
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_1: {
"hasMany": True,
"isDerived": False,
"columns": [
{"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_CONTENT},
{"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_CONTENT}
]
},
TEMPLATE_ROW_TYPE_VALID_VOTES_REMAIN_FROM_ROUND_1: {
"hasMany": True,
"isDerived": False,
"columns": [
{"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_CONTENT},
{"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_CONTENT}
]
},
TEMPLATE_ROW_TYPE_DRAFT_SEATS_ALLOCATED_FROM_ROUND_2: {
"hasMany": True,
"isDerived": False,
"columns": [
{"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_CONTENT},
{"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_CONTENT}
]
},
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED_FROM_ROUND_2: {
"hasMany": True,
"isDerived": False,
"columns": [
{"columnName": "electionId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "areaId", "grouped": True, "func": None, "source": SOURCE_META},
{"columnName": "partyId", "grouped": True, "func": None, "source": SOURCE_CONTENT},
{"columnName": "numValue", "grouped": False, "func": "sum", "source": SOURCE_CONTENT}
]
},
TEMPLATE_ROW_TYPE_SEATS_ALLOCATED: {
"hasMany": True,
"isDerived": False,
Expand Down
Loading

0 comments on commit 9de9ac5

Please sign in to comment.