Skip to content

Commit

Permalink
Merge pull request #819 from dinukadesilva/gh-fix-pe-21-ordering
Browse files Browse the repository at this point in the history
Fix the ordering in PE-21
  • Loading branch information
dinukadesilva authored Aug 13, 2020
2 parents 1246e90 + b545919 commit d8ec9ad
Showing 1 changed file with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,32 @@ def json(self):
}

def get_candidate_wise_results(self):
elected_candidates_df = self.df.loc[

candidate_wise_results_df = self.df.loc[
(self.df['templateRowType'] == TEMPLATE_ROW_TYPE_ELECTED_CANDIDATE) & (self.df['numValue'] == 0)]
elected_candidates_df = elected_candidates_df.sort_values(
by=['electionPartyId', "candidateId"], ascending=[True, True]).reset_index()

return elected_candidates_df
candidate_wise_results_df["seatsAllocated"] = [0 for i in range(len(candidate_wise_results_df))]
candidate_wise_results_df["preferenceCount"] = [0 for i in range(len(candidate_wise_results_df))]

for index in candidate_wise_results_df.index:
party_id = candidate_wise_results_df.at[index, "partyId"]
candidate_id = candidate_wise_results_df.at[index, "candidateId"]

seats_allocated = self.df.loc[(self.df["partyId"] == party_id) & (
self.df['templateRowType'] == TEMPLATE_ROW_TYPE_SEATS_ALLOCATED)]["numValue"].values[0]

preference_count = self.df.loc[(self.df["candidateId"] == candidate_id) & (
self.df['templateRowType'] == "CANDIDATE_FIRST_PREFERENCE")]["numValue"].values[0]

candidate_wise_results_df.at[index, "seatsAllocated"] = seats_allocated
candidate_wise_results_df.at[index, "preferenceCount"] = preference_count

candidate_wise_results_df = candidate_wise_results_df.sort_values(
by=["seatsAllocated", "electionPartyId", "preferenceCount", "candidateId"],
ascending=[False, True, False, True]
)

return candidate_wise_results_df

def get_post_save_request_content(self):
tally_sheet_id = self.tallySheetVersion.tallySheetId
Expand Down Expand Up @@ -221,7 +241,8 @@ def html(self, title="", total_registered_voters=None):
}

candidate_wise_results = self.get_candidate_wise_results().sort_values(
by=['electionPartyId', "candidateId"], ascending=[True, True]
by=["seatsAllocated", "electionPartyId", "preferenceCount", "candidateId"],
ascending=[False, True, False, True]
).reset_index()

for index in candidate_wise_results.index:
Expand Down Expand Up @@ -262,7 +283,8 @@ def html_letter(self, title="", total_registered_voters=None, signatures=[]):
}

candidate_wise_results = self.get_candidate_wise_results().sort_values(
by=['electionPartyId', "candidateId"], ascending=[True, True]
by=["seatsAllocated", "electionPartyId", "preferenceCount", "candidateId"],
ascending=[False, True, False, True]
).reset_index()

for index in candidate_wise_results.index:
Expand Down

0 comments on commit d8ec9ad

Please sign in to comment.