Skip to content

Commit

Permalink
Adding registered voters and style changes in all island ed report
Browse files Browse the repository at this point in the history
* Added a row to the bottom with the registered voters counts of each electoral district
* Increased the font size of the title.
* Made the candidates column aligned center.
* Removed the total in words column.
* Changed the percentages to same as all island report.
  • Loading branch information
dinukadesilva committed Nov 20, 2019
1 parent 5d9f425 commit ba28c65
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from flask import render_template
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy import func
from sqlalchemy.orm import aliased

from app import db
from orm.entities import Candidate, Party, Area, Election
from orm.entities.Area import AreaMap
from orm.entities.Election import ElectionCandidate
from orm.entities.SubmissionVersion import TallySheetVersion
from orm.entities.TallySheetVersionRow import TallySheetVersionRow_PRE_ALL_ISLAND_RESULTS_BY_ELECTORAL_DISTRICTS, \
Expand Down Expand Up @@ -125,9 +128,32 @@ def area_wise_valid_vote_count_query(self):
candidate_and_area_wise_valid_vote_count_subquery.c.areaName
)

def area_wise_registered_vote_count_query(self):
electoralDistrict = aliased(Area.Model)
pollingStation = aliased(Area.Model)

return db.session.query(
electoralDistrict.areaId,
electoralDistrict.areaName,
func.sum(pollingStation._registeredVotersCount).label("registeredVotersCount")
).join(
AreaMap.Model,
AreaMap.Model.electoralDistrictId == electoralDistrict.areaId
).join(
pollingStation,
pollingStation.areaId == AreaMap.Model.pollingStationId
).filter(
AreaMap.Model.electionId == self.submission.electionId
).group_by(
electoralDistrict.areaId
).order_by(
electoralDistrict.areaName
)

def area_wise_vote_count_query(self):
area_wise_valid_vote_count_subquery = self.area_wise_valid_vote_count_query().subquery()
area_wise_rejected_vote_count_subquery = self.area_wise_rejected_vote_count_query().subquery()
area_wise_registered_vote_count_subquery = self.area_wise_registered_vote_count_query().subquery()

return db.session.query(
area_wise_valid_vote_count_subquery.c.areaId,
Expand All @@ -142,10 +168,16 @@ def area_wise_vote_count_query(self):
func.sum(
sqlalchemy_num_or_zero(area_wise_valid_vote_count_subquery.c.validVoteCount) +
sqlalchemy_num_or_zero(area_wise_rejected_vote_count_subquery.c.rejectedVoteCount)
).label("totalVoteCount")
).label("totalVoteCount"),
func.sum(
area_wise_registered_vote_count_subquery.c.registeredVotersCount
).label("registeredVotersCount"),
).join(
area_wise_rejected_vote_count_subquery,
area_wise_rejected_vote_count_subquery.c.areaId == area_wise_valid_vote_count_subquery.c.areaId
).join(
area_wise_registered_vote_count_subquery,
area_wise_registered_vote_count_subquery.c.areaId == area_wise_valid_vote_count_subquery.c.areaId
).group_by(
area_wise_valid_vote_count_subquery.c.areaId
).order_by(
Expand Down Expand Up @@ -181,7 +213,10 @@ def vote_count_query(self):
).label("rejectedVoteCount"),
func.sum(
sqlalchemy_num_or_zero(area_wise_vote_count_subquery.c.totalVoteCount)
).label("totalVoteCount")
).label("totalVoteCount"),
func.sum(
sqlalchemy_num_or_zero(area_wise_vote_count_subquery.c.registeredVotersCount)
).label("registeredVotersCount")
)

@hybrid_property
Expand Down Expand Up @@ -251,7 +286,8 @@ def get_html_content_dict(self):
"data": [],
"validVoteCounts": [],
"rejectedVoteCounts": [],
"totalVoteCounts": []
"totalVoteCounts": [],
"registeredVoterCounts": []
}

# Append the area wise column totals
Expand All @@ -261,17 +297,23 @@ def get_html_content_dict(self):
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(100))

content["validVoteCounts"].append(
to_percentage(vote_count_result.validVoteCount * 100 / vote_count_result.registeredVotersCount))
content["rejectedVoteCounts"].append(
to_percentage(vote_count_result.rejectedVoteCount * 100 / vote_count_result.registeredVotersCount))
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)

Expand Down Expand Up @@ -301,7 +343,8 @@ def get_html_content_dict(self):

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
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)
Expand Down
21 changes: 14 additions & 7 deletions templates/PRE_ALL_ISLAND_RESULTS_BY_ELECTORAL_DISTRICTS.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</style>
<div class="pre-all-ed">
<div style="text-align: center; margin-bottom: 10px;">
<b>{{content.election.electionName}}</b>
<b style="font-size: 45px;">{{content.election.electionName}}</b>
<br/><br/>
Detailed statement on the number of votes cast in favour of each candidate according to each Electoral
District
Expand All @@ -57,7 +57,6 @@
<th class="left right top bottom percentage-th" rowspan="2" style="width:100px">
<div>Percentage</div>
</th>
<th class="left right top bottom" rowspan="2" style="width:170px">TOTAL NUMBER OF VOTES IN WORDS</th>
</tr>
<tr class="ed">
{% for electoralDistrict in content.electoralDistricts %}
Expand All @@ -69,39 +68,47 @@
<tr>
<td class="left right top bottom">{{loop.index}}</td>
{% for cell in row %}
{% if loop.index == 1 %}
<td class="left right top bottom {%if cell=="" %}missing-value{% endif %}" style="text-align:center">{{cell}}</td>
{% else %}
<td class="left right top bottom {%if cell=="" %}missing-value{% endif %}" style="text-align:right">{{cell}}</td>
{% endif %}
{% endfor %}
<td class="left right top bottom" style="vertical-align: middle;"></td>
</tr>
{% endfor %}

<tr>
<th colspan="{{content.electoralDistricts|length + 5}}"></th>
<th colspan="{{content.electoralDistricts|length + 4}}"></th>
</tr>

<tr>
<th class="left right top bottom" colspan="2">NO OF VALID VOTES</th>
{% for validVoteCount in content.validVoteCounts %}
<td class="left right top bottom {%if validVoteCount=="" %}missing-value{% endif %}" style="text-align:right">{{validVoteCount}}</td>
{% endfor %}
<td class="left right top bottom" style="vertical-align: middle;"></td>
</tr>

<tr>
<th colspan="2" class="left right top bottom">NO OF REJECTED VOTES</th>
{% for rejectedVoteCount in content.rejectedVoteCounts %}
<td class="left right top bottom {%if rejectedVoteCount=="" %}missing-value{% endif %}" style="text-align:right">{{rejectedVoteCount}}</td>
{% endfor %}
<td class="left right top bottom" style="vertical-align: middle;"></td>
</tr>

<tr>
<th colspan="2" class="left right top bottom">TOTAL NO OF VOTES POLLED (INCLUDING REJECTED VOTES)</th>
{% for totalVoteCount in content.totalVoteCounts %}
<td class="left right top bottom {%if totalVoteCount=="" %}missing-value{% endif %}" style="text-align:right">{{totalVoteCount}}</td>
{% endfor %}
<td class="left right top bottom" style="vertical-align: middle;"></td>
</tr>
<tr>
<th colspan="2" class="left right top bottom">REGISTERED NO. OF ELECTORS</th>
{% for registeredVoterCount in content.registeredVoterCounts %}
<td class="left right top bottom {%if totalVoteCount=="" %}missing-value{% endif %}" style="text-align:right">{{registeredVoterCount}}</td>
{% endfor %}
</tr>



</tbody>
</table>
Expand Down

0 comments on commit ba28c65

Please sign in to comment.