Skip to content

Commit

Permalink
Undo changes to PRE percentages
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryamZi committed Jul 28, 2020
1 parent c01abd1 commit 4d86778
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions distributor/src/distributor/genhtml.bal
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ function generatePresidentialResultHtml(string electionCode, map<json> result, b
foreach json j in partyResults {
map<json> pr = <map<json>> j; // value is a json object
if firstRound {
body += "<tr><td>" + <string>pr.candidate + "</td><td class='text-center'>" + <string>pr.party_code + "</td><td class='text-right'>" + commaFormatInt(<int>pr.vote_count) + "</td><td class='text-right'>" + <string>pr.vote_percentage + "</td></tr>";
body += "<tr><td>" + <string>pr.candidate + "</td><td class='text-center'>" + <string>pr.party_code + "</td><td class='text-right'>" + commaFormatInt(<int>pr.vote_count) + "</td><td class='text-right'>" + <string>pr.vote_percentage + "%</td></tr>";
} else {
body += "<tr><td>" + <string>pr.candidate + "</td><td class='text-center'>" + <string>pr.party_code
+ "</td><td class='text-right'>" + commaFormatInt(<int>pr.votes1st)
+ "</td><td class='text-right'>" + commaFormatInt(<int>pr.votes2nd)
+ "</td><td class='text-right'>" + commaFormatInt(<int>pr.votes3rd)
+ "</td><td class='text-right'>" + commaFormatInt(<int>pr.vote_count)
+ "</td><td class='text-right'>" + <string>pr.vote_percentage + "</td></tr>";
+ "</td><td class='text-right'>" + <string>pr.vote_percentage + "%</td></tr>";
}
}
body += "</table>";
Expand All @@ -73,13 +73,13 @@ function generatePresidentialResultHtml(string electionCode, map<json> result, b
body += "<div class='container-fluid'>";
body += " <div class='col-md-4 col-md-offset-2'>Total Valid Votes</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.valid) +
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "</div><div class='col-md-2'></div>";
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "%</div><div class='col-md-2'></div>";
body += " <div class='col-md-4 col-md-offset-2'>Rejected Votes</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.rejected) +
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "</div><div class='col-md-2'></div>";
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "%</div><div class='col-md-2'></div>";
body += " <div class='col-md-4 col-md-offset-2'>Total Polled</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.polled) +
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "</div><div class='col-md-2'></div>";
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "%</div><div class='col-md-2'></div>";
body += " <div class='col-md-4 col-md-offset-2'>Registered No. of Electors</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.electors) +
" </div><div class='col-md-2'></div>";
Expand Down
8 changes: 4 additions & 4 deletions distributor/src/distributor/save.bal
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ function addToPresidentialCumulative(map<json> jm) returns PresidentialCumulativ
accum.summary.rejected += <int>jm.summary.rejected;
accum.summary.polled += <int>jm.summary.polled;
accum.summary.electors += <int>jm.summary.electors;
accum.summary.percent_valid = (accum.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.valid*100.0/accum.summary.polled)}%`;
accum.summary.percent_rejected = (accum.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.rejected*100.0/accum.summary.polled)}%`;
accum.summary.percent_polled = (accum.summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.polled*100.0/accum.summary.electors)}%`;
accum.summary.percent_valid = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.valid*100.0/accum.summary.polled);
accum.summary.percent_rejected = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.rejected*100.0/accum.summary.polled);
accum.summary.percent_polled = (accum.summary.electors == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.polled*100.0/accum.summary.electors);
}

// if first PD being added to cumulative then just copy the party results over
Expand All @@ -321,7 +321,7 @@ function addToPresidentialCumulative(map<json> jm) returns PresidentialCumulativ
accum.by_party[i]["votes2nd"] = (accum.by_party[i]["votes2nd"] ?: 0) + <int>pr[i].votes2nd;
accum.by_party[i]["votes3rd"] = (accum.by_party[i]["votes3rd"] ?: 0) + <int>pr[i].votes3rd;
}
accum.by_party[i].vote_percentage = (accum.summary.valid == 0) ? "0.00%" : string `${io:sprintf ("%.2f", ((accum.by_party[i].vote_count*100.0)/accum.summary.valid))}%`;
accum.by_party[i].vote_percentage = (accum.summary.valid == 0) ? "0.00" : io:sprintf ("%.2f", ((accum.by_party[i].vote_count*100.0)/accum.summary.valid));
}
}
accum.nadded += 1;
Expand Down
8 changes: 4 additions & 4 deletions subscriber/src/subscriber/genhtml.bal
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ function generatePresidentialResultHtml(string electionCode, map<json> result, b
json[] partyResults = sorted ? sortByPartyResultsByVoteCount(<json[]>result.by_party) : <json[]>result.by_party;
foreach json j in partyResults {
map<json> pr = <map<json>> j; // value is a json object
body += "<tr><td>" + <string>pr.candidate + "</td><td class='text-center'>" + <string>pr.party_code + "</td><td class='text-right'>" + commaFormatInt(<int>pr.vote_count) + "</td><td class='text-right'>" + <string>pr.vote_percentage + "</td></tr>";
body += "<tr><td>" + <string>pr.candidate + "</td><td class='text-center'>" + <string>pr.party_code + "</td><td class='text-right'>" + commaFormatInt(<int>pr.vote_count) + "</td><td class='text-right'>" + <string>pr.vote_percentage + "%</td></tr>";
}
body += "</table>";
body += "</div>";

body += "<div class='container-fluid'>";
body += " <div class='col-md-4 col-md-offset-2'>Total Valid Votes</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.valid) +
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "</div><div class='col-md-2'></div>";
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "%</div><div class='col-md-2'></div>";
body += " <div class='col-md-4 col-md-offset-2'>Rejected Votes</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.rejected) +
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "</div><div class='col-md-2'></div>";
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "%</div><div class='col-md-2'></div>";
body += " <div class='col-md-4 col-md-offset-2'>Total Polled</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.polled) +
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "</div><div class='col-md-2'></div>";
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "%</div><div class='col-md-2'></div>";
body += " <div class='col-md-4 col-md-offset-2'>Registered No. of Electors</div>" +
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.electors) +
" </div><div class='col-md-2'></div>";
Expand Down
24 changes: 12 additions & 12 deletions testdriver/src/testdriver/sendresults.bal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function sendResults(string resultType, string electionCode, http:Client rc, map
if val is error {
// already a string so let it go
} else {
onePr["vote_percentage"] = string `${io:sprintf ("%.2f", val * 100.0)}%`;
onePr["vote_percentage"] = io:sprintf ("%.2f", val);
}
// this line causes generated code to hang here: the cast is in error but no runtime error but just STOP!
// looks like updating a json property that is already there really upsets the code :(
Expand All @@ -86,9 +86,9 @@ function sendResults(string resultType, string electionCode, http:Client rc, map

// set the percentages in the summary
map<json> summary = <map<json>>resultsByPD[pdCode].summary;
summary["percent_valid"] = (<int>resultsByPD[pdCode].summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>resultsByPD[pdCode].summary.valid*100.0/<int>resultsByPD[pdCode].summary.polled)}%`;
summary["percent_rejected"] = (<int>resultsByPD[pdCode].summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>resultsByPD[pdCode].summary.rejected*100.0/<int>resultsByPD[pdCode].summary.polled)}%`;
summary["percent_polled"] = (<int>resultsByPD[pdCode].summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>resultsByPD[pdCode].summary.polled*100.0/<int>resultsByPD[pdCode].summary.electors)}%`;
summary["percent_valid"] = (<int>resultsByPD[pdCode].summary.polled == 0) ? "0.00" : io:sprintf("%.2f", <int>resultsByPD[pdCode].summary.valid*100.0/<int>resultsByPD[pdCode].summary.polled);
summary["percent_rejected"] = (<int>resultsByPD[pdCode].summary.polled == 0) ? "0.00" : io:sprintf("%.2f", <int>resultsByPD[pdCode].summary.rejected*100.0/<int>resultsByPD[pdCode].summary.polled);
summary["percent_polled"] = (<int>resultsByPD[pdCode].summary.electors == 0) ? "0.00" : io:sprintf("%.2f", <int>resultsByPD[pdCode].summary.polled*100.0/<int>resultsByPD[pdCode].summary.electors);

string resCode = resultsByPD[pdCode]?.pd_code.toString();
string edCodeFromPD = resultsByPD[pdCode]?.ed_code.toString();
Expand Down Expand Up @@ -196,13 +196,13 @@ function createEDResult (string resultType, map<map<json>>[] results, map<json>[
distByParty[i]["votes2nd"] = votes2nd_by_party[i];
distByParty[i]["votes3rd"] = votes3rd_by_party[i];
}
distByParty[i]["vote_percentage"] = (distSummary.valid == 0) ? "0.00%" : string `${io:sprintf("%.2f", votes_by_party[i]*100.0/distSummary.valid)}%`;
distByParty[i]["vote_percentage"] = (distSummary.valid == 0) ? "0.00" : io:sprintf("%.2f", votes_by_party[i]*100.0/distSummary.valid);
}

// set the percentages in the summary
distSummary.percent_valid = (distSummary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", distSummary.valid*100.0/distSummary.polled)}%`;
distSummary.percent_rejected = (distSummary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", distSummary.rejected*100.0/distSummary.polled)}%`;
distSummary.percent_polled = (distSummary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", distSummary.polled*100.0/distSummary.electors)}%`;
distSummary.percent_valid = (distSummary.polled == 0) ? "0.00" : io:sprintf("%.2f", distSummary.valid*100.0/distSummary.polled);
distSummary.percent_rejected = (distSummary.polled == 0) ? "0.00" : io:sprintf("%.2f", distSummary.rejected*100.0/distSummary.polled);
distSummary.percent_polled = (distSummary.electors == 0) ? "0.00" : io:sprintf("%.2f", distSummary.polled*100.0/distSummary.electors);

return {
'type: resultType,
Expand Down Expand Up @@ -279,13 +279,13 @@ function createNationalResult (string resultType, map<map<json>>[] results, map<
natByParty[i]["votes2nd"] = votes2nd_by_party[i];
natByParty[i]["votes3rd"] = votes3rd_by_party[i];
}
natByParty[i]["vote_percentage"] = (natSummary.valid == 0) ? "0.00%" : string `${io:sprintf("%.2f", votes_by_party[i]*100.0/natSummary.valid)}%`;
natByParty[i]["vote_percentage"] = (natSummary.valid == 0) ? "0.00" : io:sprintf("%.2f", votes_by_party[i]*100.0/natSummary.valid);
}

// set the percentages in the summary
natSummary.percent_valid = (natSummary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", natSummary.valid*100.0/natSummary.polled)}%`;
natSummary.percent_rejected = (natSummary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", natSummary.rejected*100.0/natSummary.polled)}%`;
natSummary.percent_polled = (natSummary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", natSummary.polled*100.0/natSummary.electors)}%`;
natSummary.percent_valid = (natSummary.polled == 0) ? "0.00" : io:sprintf("%.2f", natSummary.valid*100.0/natSummary.polled);
natSummary.percent_rejected = (natSummary.polled == 0) ? "0.00" : io:sprintf("%.2f", natSummary.rejected*100.0/natSummary.polled);
natSummary.percent_polled = (natSummary.electors == 0) ? "0.00" : io:sprintf("%.2f", natSummary.polled*100.0/natSummary.electors);

return {
'type: resultType,
Expand Down

0 comments on commit 4d86778

Please sign in to comment.