Skip to content

Commit

Permalink
Merge pull request #205 from dinukadesilva/gh-204
Browse files Browse the repository at this point in the history
gh-204: Fix the candidate wise total calculation in PRE-30-ED
  • Loading branch information
dinukadesilva authored Oct 19, 2019
2 parents 5e389de + e01d561 commit 19cf4fa
Showing 1 changed file with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,30 +279,54 @@ def non_postal_area_wise_vote_count_query(self):
non_postal_area_wise_valid_vote_count_subquery.c.areaId
)

def candidate_wise_vote_count(self):
def non_postal_candidate_wise_vote_count(self):
non_postal_candidate_and_area_wise_valid_vote_count_subquery = self.non_postal_candidate_and_area_wise_valid_vote_count_query().subquery()
postal_candidate_and_area_wise_valid_vote_count_subquery = self.postal_candidate_and_area_wise_valid_vote_count_query().subquery()

return db.session.query(
non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId,
non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateName,
func.sum(
sqlalchemy_num_or_zero(non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.validVoteCount)
).label("nonPostalValidVoteCount"),
).label("validVoteCount")
).group_by(
non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId
)

def postal_candidate_wise_vote_count(self):
postal_candidate_and_area_wise_valid_vote_count_subquery = self.postal_candidate_and_area_wise_valid_vote_count_query().subquery()

return db.session.query(
postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId,
postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateName,
func.sum(
sqlalchemy_num_or_zero(postal_candidate_and_area_wise_valid_vote_count_subquery.c.validVoteCount)
).label("validVoteCount")
).group_by(
postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId
)

def candidate_wise_vote_count(self):
non_postal_candidate_wise_vote_count_subquery = self.non_postal_candidate_wise_vote_count().subquery()
postal_candidate_wise_vote_count_subquery = self.postal_candidate_wise_vote_count().subquery()

return db.session.query(
non_postal_candidate_wise_vote_count_subquery.c.candidateId,
non_postal_candidate_wise_vote_count_subquery.c.candidateName,
func.sum(
sqlalchemy_num_or_zero(non_postal_candidate_wise_vote_count_subquery.c.validVoteCount)
).label("nonPostalValidVoteCount"),
func.sum(
sqlalchemy_num_or_zero(postal_candidate_wise_vote_count_subquery.c.validVoteCount)
).label("postalValidVoteCount"),
func.sum(
sqlalchemy_num_or_zero(non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.validVoteCount) +
sqlalchemy_num_or_zero(postal_candidate_and_area_wise_valid_vote_count_subquery.c.validVoteCount)
sqlalchemy_num_or_zero(non_postal_candidate_wise_vote_count_subquery.c.validVoteCount) +
sqlalchemy_num_or_zero(postal_candidate_wise_vote_count_subquery.c.validVoteCount)
).label("validVoteCount")
).join(
postal_candidate_and_area_wise_valid_vote_count_subquery,
postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId == non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId
postal_candidate_wise_vote_count_subquery,
postal_candidate_wise_vote_count_subquery.c.candidateId == non_postal_candidate_wise_vote_count_subquery.c.candidateId
).group_by(
non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId
).group_by(
non_postal_candidate_and_area_wise_valid_vote_count_subquery.c.candidateId
non_postal_candidate_wise_vote_count_subquery.c.candidateId
)

def vote_count_query(self):
Expand Down

0 comments on commit 19cf4fa

Please sign in to comment.