Skip to content

Commit

Permalink
Merge pull request #665 from dinukadesilva/gh-664-enabling-displaced-…
Browse files Browse the repository at this point in the history
…and-quarantine-votes

Gh 664 enabling displaced and quarantine votes
  • Loading branch information
dinukadesilva authored Jul 16, 2020
2 parents 450961e + c20c0fb commit 5aff1fe
Show file tree
Hide file tree
Showing 40 changed files with 1,029 additions and 799 deletions.
9 changes: 7 additions & 2 deletions results-tabulation-api/api/ElectionApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@


@authorize(required_roles=ALL_ROLES)
def get_all(parentElectionId=None, rootElectionId=None):
result = Election.get_all(parentElectionId=parentElectionId, rootElectionId=rootElectionId)
def get_all(parentElectionId=None, rootElectionId=None, isListed=None):
if isListed == "false":
isListed = False
elif isListed == "true":
isListed = True

result = Election.get_all(parentElectionId=parentElectionId, rootElectionId=rootElectionId, isListed=isListed)

result = get_paginated_query(result).all()

Expand Down
4 changes: 2 additions & 2 deletions results-tabulation-api/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def authorize(func, required_roles=None, *args, **kwargs):
area.areaId for area in _get_role_area_ids(
parentAreaIds=claim_area_ids,
areaType=AreaTypeEnum.CountingCentre,
voteTypes=[VOTE_TYPES.Postal, VOTE_TYPES.NonPostal]
voteTypes=[VOTE_TYPES.Postal, VOTE_TYPES.NonPostal, VOTE_TYPES.Quarantine, VOTE_TYPES.Displaced]
)
])

Expand Down Expand Up @@ -299,7 +299,7 @@ def authorize(func, required_roles=None, *args, **kwargs):
area.areaId for area in _get_role_area_ids(
parentAreaIds=claim_area_ids,
areaType=AreaTypeEnum.CountingCentre,
voteTypes=[VOTE_TYPES.Postal]
voteTypes=[VOTE_TYPES.Postal, VOTE_TYPES.Quarantine, VOTE_TYPES.Displaced]
)
])

Expand Down
2 changes: 2 additions & 0 deletions results-tabulation-api/constants/VOTE_TYPES.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Postal = "Postal"
NonPostal = "NonPostal"
Quarantine = "Quarantine"
Displaced = "Displaced"
PostalAndNonPostal = "PostalAndNonPostal"
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def html_letter(self, title="", total_registered_voters=None):
area_wise_vote_count_result = self.get_area_wise_vote_count_result()
stamp = tallySheetVersion.stamp

registered_voters_count = float(tallySheetVersion.submission.area.registeredVotersCount)
registered_voters_count = tallySheetVersion.submission.area.get_registered_voters_count()
content = {
"election": {
"electionName": tallySheetVersion.submission.election.get_official_name()
Expand Down Expand Up @@ -97,7 +97,8 @@ def html(self, title="", total_registered_voters=None):
stamp = tallySheetVersion.stamp

area: AreaModel = tallySheetVersion.submission.area
number_of_electors = float(area.registeredVotersCount) + float(area.registeredPostalVotersCount)

registered_voters_count = tallySheetVersion.submission.area.get_registered_voters_count()

content = {
"election": {
Expand All @@ -116,7 +117,7 @@ def html(self, title="", total_registered_voters=None):
"rejectedVotePercentage": '',
"totalVoteCount": '',
"totalVotePercentage": '',
"numberOfElectors": to_comma_seperated_num(number_of_electors)
"numberOfElectors": to_comma_seperated_num(registered_voters_count)
}

total_valid_vote_count = 0
Expand Down Expand Up @@ -155,7 +156,8 @@ def html(self, title="", total_registered_voters=None):
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
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetDataEntry
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num
from orm.enums import AreaTypeEnum

Expand Down Expand Up @@ -32,8 +33,8 @@ def html(self, title="", total_registered_voters=None):
if len(polling_divisions) > 0:
polling_division_name = polling_divisions[0].areaName

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

content = {
"election": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetDataEntry
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num
from orm.enums import AreaTypeEnum

Expand Down Expand Up @@ -36,8 +37,8 @@ def html(self, title="", total_registered_voters=None):
if len(polling_divisions) > 0:
polling_division_name = polling_divisions[0].areaName

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

content = {
"election": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ def get_post_save_request_content(self):

return content

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetDataEntry
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num
from orm.enums import AreaTypeEnum

Expand All @@ -27,8 +28,8 @@ def html(self, title="", total_registered_voters=None):
if len(polling_divisions) > 0:
polling_division_name = polling_divisions[0].areaName

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

content = {
"election": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetDataEntry
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num
from orm.enums import AreaTypeEnum

Expand All @@ -25,8 +26,8 @@ def html(self, title="", total_registered_voters=None):
if len(polling_divisions) > 0:
polling_division_name = polling_divisions[0].areaName

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

content = {
"election": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetDataEntry
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num
from orm.enums import AreaTypeEnum

Expand All @@ -26,8 +27,8 @@ def html(self, title="", total_registered_voters=None):
if len(polling_divisions) > 0:
polling_division_name = polling_divisions[0].areaName

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

content = {
"election": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetDataEntry
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from orm.enums import AreaTypeEnum


Expand Down Expand Up @@ -29,8 +30,8 @@ def html(self, title="", total_registered_voters=None):
if len(polling_divisions) > 0:
polling_division_name = polling_divisions[0].areaName

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

content = {
"election": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetReport
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num
from orm.enums import AreaTypeEnum

Expand All @@ -23,9 +24,10 @@ def html(self, title="", total_registered_voters=None):

stamp = tallySheetVersion.stamp

pollingDivision = tallySheetVersion.submission.area.areaName
if tallySheetVersion.submission.election.voteType == Postal:
pollingDivision = 'Postal'
polling_division_name = tallySheetVersion.submission.area.areaName

if tallySheetVersion.submission.election.voteType != NonPostal:
polling_division_name = tallySheetVersion.submission.election.voteType

content = {
"election": {
Expand All @@ -39,7 +41,7 @@ def html(self, title="", total_registered_voters=None):
"tallySheetCode": "CE/RO/PR/1",
"electoralDistrict": Area.get_associated_areas(
tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName,
"pollingDivision": pollingDivision,
"pollingDivision": polling_division_name,
"partyName": candidate_and_area_wise_valid_vote_count_result["partyName"].values[0],
"data": [],
"countingCentres": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetReport
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num
from orm.enums import AreaTypeEnum

Expand Down Expand Up @@ -60,7 +61,7 @@ def html(self, title="", total_registered_voters=None):
candidate_wise_valid_postal_vote_count_result["numValue"].sum()
))

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

for index_1 in candidate_wise_valid_vote_count_result.index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from flask import render_template
from ext.ExtendedTallySheet import ExtendedTallySheetReport
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from orm.enums import AreaTypeEnum


Expand All @@ -22,10 +21,6 @@ def html(self, title="", total_registered_voters=None):

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()
Expand All @@ -38,7 +33,6 @@ def html(self, title="", total_registered_voters=None):
"tallySheetCode": "CE/RO/PR/1",
"electoralDistrict": Area.get_associated_areas(
tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName,
"pollingDivision": pollingDivision,
"partyName": candidate_wise_valid_vote_count_result["partyName"].values[0],
"data": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask import render_template

from constants.VOTE_TYPES import NonPostal
from ext.ExtendedTallySheet import ExtendedTallySheetReport
from orm.entities import Area
from constants.VOTE_TYPES import Postal
from util import to_comma_seperated_num, convert_image_to_data_uri, to_percentage
from orm.enums import AreaTypeEnum

Expand All @@ -17,11 +17,13 @@ def html_letter(self, title="", total_registered_voters=None):
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'
polling_division_name = tallySheetVersion.submission.area.areaName
if tallySheetVersion.submission.election.voteType == NonPostal:
polling_division_name = 'Postal'

registered_voters_count = float(tallySheetVersion.submission.area.registeredVotersCount)
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()
Expand All @@ -33,7 +35,7 @@ def html_letter(self, title="", total_registered_voters=None):
},
"electoralDistrict": Area.get_associated_areas(
tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName,
"pollingDivision": pollingDivision,
"pollingDivision": polling_division_name,
"data": [],
"validVoteCounts": [0, "0%"],
"rejectedVoteCounts": [0, "0%"],
Expand Down Expand Up @@ -101,9 +103,11 @@ def html(self, title="", total_registered_voters=None):
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'

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()
Expand All @@ -116,7 +120,7 @@ def html(self, title="", total_registered_voters=None):
"tallySheetCode": "CE/RO/V1",
"electoralDistrict": Area.get_associated_areas(
tallySheetVersion.submission.area, AreaTypeEnum.ElectoralDistrict)[0].areaName,
"pollingDivision": pollingDivision,
"pollingDivision": polling_division_name,
"data": [],
"countingCentres": [],
"validVoteCounts": [],
Expand Down Expand Up @@ -144,8 +148,7 @@ def html(self, title="", total_registered_voters=None):
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 = []
Expand Down
Loading

0 comments on commit 5aff1fe

Please sign in to comment.