From 2d194f151b90b25c0a51480949acfe435070be1f Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Tue, 28 Jul 2020 02:42:34 +0530 Subject: [PATCH 1/3] Change vote and summary percentages to xx.dd% format --- distributor/src/distributor/genhtml.bal | 16 +++--- distributor/src/distributor/save.bal | 20 +++----- subscriber/src/subscriber/genhtml.bal | 14 +++--- subscriber/src/subscriber/tests/main_test.bal | 6 +-- .../src/testdriver/gen_fake_parliamentary.bal | 50 +++++++++---------- .../testdriver/sendparliamentaryresults.bal | 8 +-- testdriver/src/testdriver/sendresults.bal | 24 ++++----- 7 files changed, 67 insertions(+), 71 deletions(-) diff --git a/distributor/src/distributor/genhtml.bal b/distributor/src/distributor/genhtml.bal index 6e81c6f..9f022f6 100644 --- a/distributor/src/distributor/genhtml.bal +++ b/distributor/src/distributor/genhtml.bal @@ -57,14 +57,14 @@ function generatePresidentialResultHtml(string electionCode, map result, b foreach json j in partyResults { map pr = > j; // value is a json object if firstRound { - body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + "%"; + body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + ""; } else { body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.votes1st) + "" + commaFormatInt(pr.votes2nd) + "" + commaFormatInt(pr.votes3rd) + "" + commaFormatInt(pr.vote_count) - + "" + pr.vote_percentage + "%"; + + "" + pr.vote_percentage + ""; } } body += ""; @@ -73,13 +73,13 @@ function generatePresidentialResultHtml(string electionCode, map result, b body += "
"; body += "
Total Valid Votes
" + "
" + commaFormatInt(result.summary.valid) + - "
" + result.summary.percent_valid + "%
"; + "
" + result.summary.percent_valid + "
"; body += "
Rejected Votes
" + "
" + commaFormatInt(result.summary.rejected) + - "
" + result.summary.percent_rejected + "%
"; + "
" + result.summary.percent_rejected + "
"; body += "
Total Polled
" + "
" + commaFormatInt(result.summary.polled) + - "
" + result.summary.percent_polled + "%
"; + "
" + result.summary.percent_polled + "
"; body += "
Registered No. of Electors
" + "
" + commaFormatInt(result.summary.electors) + "
"; @@ -191,13 +191,13 @@ function generateParliamentaryResultHtml(string electionCode, map result, body += "
"; body += "
Total Valid Votes
" + "
" + commaFormatInt(result.summary.valid) + - "
" + result.summary.percent_valid + "%
"; + "
" + result.summary.percent_valid + "
"; body += "
Rejected Votes
" + "
" + commaFormatInt(result.summary.rejected) + - "
" + result.summary.percent_rejected + "%
"; + "
" + result.summary.percent_rejected + "
"; body += "
Total Polled
" + "
" + commaFormatInt(result.summary.polled) + - "
" + result.summary.percent_polled + "%
"; + "
" + result.summary.percent_polled + "
"; body += "
Registered No. of Electors
" + "
" + commaFormatInt(result.summary.electors) + "
"; diff --git a/distributor/src/distributor/save.bal b/distributor/src/distributor/save.bal index 8dd105b..a17286f 100644 --- a/distributor/src/distributor/save.bal +++ b/distributor/src/distributor/save.bal @@ -300,12 +300,10 @@ function addToPresidentialCumulative(map jm) returns PresidentialCumulativ accum.summary.valid += jm.summary.valid; accum.summary.rejected += jm.summary.rejected; accum.summary.polled += jm.summary.polled; - // don't add up electors from postal PDs as those are already in the district elsewhere - string pdCode = jm.pd_code; // check accum.summary.electors += jm.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); + 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)}%`; } // if first PD being added to cumulative then just copy the party results over @@ -323,7 +321,7 @@ function addToPresidentialCumulative(map jm) returns PresidentialCumulativ accum.by_party[i]["votes2nd"] = (accum.by_party[i]["votes2nd"] ?: 0) + pr[i].votes2nd; accum.by_party[i]["votes3rd"] = (accum.by_party[i]["votes3rd"] ?: 0) + pr[i].votes3rd; } - 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.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.nadded += 1; @@ -365,12 +363,10 @@ function addToParliamentaryCumulativeVotes(map jm) returns ParliamentaryCu summary.valid += jm.summary.valid; summary.rejected += jm.summary.rejected; summary.polled += jm.summary.polled; - // // don't add up electors from postal PDs as those are already in the district elsewhere - // string pdCode = jm.pd_code; // check summary.electors += jm.summary.electors; - summary.percent_valid = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.valid*100.0/accum.summary.polled); - summary.percent_rejected = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.rejected*100.0/accum.summary.polled); - summary.percent_polled = (accum.summary.electors == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.polled*100.0/accum.summary.electors); + summary.percent_valid = (accum.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.valid*100.0/accum.summary.polled)}%`; + summary.percent_rejected = (accum.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.rejected*100.0/accum.summary.polled)}%`; + summary.percent_polled = (accum.summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.polled*100.0/accum.summary.electors)}%`; if accum.nadded == 0 { pr.forEach(x => accum.by_party.push(checkpanic ParliamentaryPartyResult.constructFrom(x))); @@ -384,7 +380,7 @@ function addToParliamentaryCumulativeVotes(map jm) returns ParliamentaryCu } else { int accumVoteCount = accum.by_party[i]?.vote_count + pr[i].vote_count; accum.by_party[i].vote_count = accumVoteCount; - accum.by_party[i].vote_percentage = (accum.summary.valid == 0) ? "0.00" : io:sprintf ("%.2f", ((accumVoteCount*1.0)/accum.summary.valid)); + accum.by_party[i].vote_percentage = (accum.summary.valid == 0) ? "0.00%" : string `${io:sprintf ("%.2f", ((accumVoteCount*100.0)/accum.summary.valid))}%`; } } } diff --git a/subscriber/src/subscriber/genhtml.bal b/subscriber/src/subscriber/genhtml.bal index 406e724..2f9f58c 100644 --- a/subscriber/src/subscriber/genhtml.bal +++ b/subscriber/src/subscriber/genhtml.bal @@ -48,7 +48,7 @@ function generatePresidentialResultHtml(string electionCode, map result, b json[] partyResults = sorted ? sortByPartyResultsByVoteCount(result.by_party) : result.by_party; foreach json j in partyResults { map pr = > j; // value is a json object - body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + "%"; + body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + ""; } body += ""; body += ""; @@ -56,13 +56,13 @@ function generatePresidentialResultHtml(string electionCode, map result, b body += "
"; body += "
Total Valid Votes
" + "
" + commaFormatInt(result.summary.valid) + - "
" + result.summary.percent_valid + "%
"; + "
" + result.summary.percent_valid + "
"; body += "
Rejected Votes
" + "
" + commaFormatInt(result.summary.rejected) + - "
" + result.summary.percent_rejected + "%
"; + "
" + result.summary.percent_rejected + "
"; body += "
Total Polled
" + "
" + commaFormatInt(result.summary.polled) + - "
" + result.summary.percent_polled + "%
"; + "
" + result.summary.percent_polled + "
"; body += "
Registered No. of Electors
" + "
" + commaFormatInt(result.summary.electors) + "
"; @@ -175,13 +175,13 @@ function generateParliamentaryResultHtml(string electionCode, map result, body += "
"; body += "
Total Valid Votes
" + "
" + commaFormatInt(result.summary.valid) + - "
" + result.summary.percent_valid + "%
"; + "
" + result.summary.percent_valid + "
"; body += "
Rejected Votes
" + "
" + commaFormatInt(result.summary.rejected) + - "
" + result.summary.percent_rejected + "%
"; + "
" + result.summary.percent_rejected + "
"; body += "
Total Polled
" + "
" + commaFormatInt(result.summary.polled) + - "
" + result.summary.percent_polled + "%
"; + "
" + result.summary.percent_polled + "
"; body += "
Registered No. of Electors
" + "
" + commaFormatInt(result.summary.electors) + "
"; diff --git a/subscriber/src/subscriber/tests/main_test.bal b/subscriber/src/subscriber/tests/main_test.bal index 7bfff75..6ccab8f 100644 --- a/subscriber/src/subscriber/tests/main_test.bal +++ b/subscriber/src/subscriber/tests/main_test.bal @@ -49,17 +49,17 @@ function testRE_VI(string filePath, int fooCount, int barCount, int bazCount, in map party = >parties[0]; test:assertEquals(party["party_name"], "Foo foo"); test:assertEquals(party["vote_count"], fooCount); - test:assertEquals(party["vote_percentage"], io:sprintf("%.2f", ((fooCount*1.0)/valid))); + test:assertEquals(party["vote_percentage"], string `${io:sprintf("%.2f", ((fooCount*100.0)/valid))}%`); party = >parties[1]; test:assertEquals(party["party_name"], "Bar bar"); test:assertEquals(party["vote_count"], barCount); - test:assertEquals(party["vote_percentage"], io:sprintf("%.2f", ((barCount*1.0)/valid))); + test:assertEquals(party["vote_percentage"], string `${io:sprintf("%.2f", ((barCount*100.0)/valid))}%`); party = >parties[2]; test:assertEquals(party["party_name"], "Baz baz"); test:assertEquals(party["vote_count"], bazCount); - test:assertEquals(party["vote_percentage"], io:sprintf("%.2f", ((bazCount*1.0)/valid))); + test:assertEquals(party["vote_percentage"], string `${io:sprintf("%.2f", ((bazCount*100.0)/valid))}%`); map edSummary = >value.summary; test:assertEquals(edSummary["valid"], valid); diff --git a/testdriver/src/testdriver/gen_fake_parliamentary.bal b/testdriver/src/testdriver/gen_fake_parliamentary.bal index fa7b1c3..7a55820 100644 --- a/testdriver/src/testdriver/gen_fake_parliamentary.bal +++ b/testdriver/src/testdriver/gen_fake_parliamentary.bal @@ -14,7 +14,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 15, - "vote_percentage": 0.17, + "vote_percentage": "16.67%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -22,7 +22,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 65, - "vote_percentage": 0.72, + "vote_percentage": "72.22%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -30,7 +30,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 10, - "vote_percentage": 0.11, + "vote_percentage": "11.11%", "seat_count": 0, "national_list_seat_count": 0 } @@ -56,7 +56,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 90, - "vote_percentage": 0.6, + "vote_percentage": "60.00%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -64,7 +64,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 35, - "vote_percentage": 0.23, + "vote_percentage": "23.33%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -72,7 +72,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 25, - "vote_percentage": 0.17, + "vote_percentage": "16.67%", "seat_count": 0, "national_list_seat_count": 0 } @@ -98,7 +98,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 10, - "vote_percentage": 0.46, + "vote_percentage": "45.45%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -106,7 +106,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 0, - "vote_percentage": 0.00, + "vote_percentage": "0.00%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -114,7 +114,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 12, - "vote_percentage": 0.54, + "vote_percentage": "54.55%", "seat_count": 0, "national_list_seat_count": 0 } @@ -140,7 +140,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 10, - "vote_percentage": 0.13, + "vote_percentage": "12.50%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -148,7 +148,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 50, - "vote_percentage": 0.63, + "vote_percentage": "62.50%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -156,7 +156,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 20, - "vote_percentage": 0.25, + "vote_percentage": "25.00%", "seat_count": 0, "national_list_seat_count": 0 } @@ -182,7 +182,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 50, - "vote_percentage": 0.55, + "vote_percentage": "55.56%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -190,7 +190,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 20, - "vote_percentage": 0.22, + "vote_percentage": "22.22%", "seat_count": 0, "national_list_seat_count": 0 }, @@ -198,7 +198,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 20, - "vote_percentage": 0.22, + "vote_percentage": "22.22%", "seat_count": 0, "national_list_seat_count": 0 } @@ -222,7 +222,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 0, - "vote_percentage": 0.00, + "vote_percentage": "0.00%", "seat_count": 3, "national_list_seat_count": 0 }, @@ -230,7 +230,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 0, - "vote_percentage": 0.00, + "vote_percentage": "0.00%", "seat_count": 10, "national_list_seat_count": 0 }, @@ -254,7 +254,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 0, - "vote_percentage": 0.00, + "vote_percentage": "0.00%", "seat_count": 8, "national_list_seat_count": 0 }, @@ -262,7 +262,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 0, - "vote_percentage": 0.00, + "vote_percentage": "0.00%", "seat_count": 20, "national_list_seat_count": 0 }, @@ -284,7 +284,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 12540, - "vote_percentage": 0.33, + "vote_percentage": "32.79%", "seat_count": 75, "national_list_seat_count": 0 }, @@ -292,7 +292,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 7500, - "vote_percentage": 0.20, + "vote_percentage": "19.61%", "seat_count": 25, "national_list_seat_count": 0 }, @@ -300,7 +300,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 18200, - "vote_percentage": 0.48, + "vote_percentage": "47.59%", "seat_count": 100, "national_list_seat_count": 0 } @@ -322,7 +322,7 @@ function genFakeParliamentary() { "party_code": "Baz", "party_name": "Baz baz", "vote_count": 7500, - "vote_percentage": 0.20, + "vote_percentage": "19.61%", "seat_count": 25, "national_list_seat_count": 4 }, @@ -330,7 +330,7 @@ function genFakeParliamentary() { "party_code": "Foo", "party_name": "Foo foo", "vote_count": 18200, - "vote_percentage": 0.48, + "vote_percentage": "47.59%", "seat_count": 100, "national_list_seat_count": 12 }, @@ -338,7 +338,7 @@ function genFakeParliamentary() { "party_code": "Bar", "party_name": "Bar bar", "vote_count": 12540, - "vote_percentage": 0.33, + "vote_percentage": "32.79%", "seat_count": 75, "national_list_seat_count": 9 } diff --git a/testdriver/src/testdriver/sendparliamentaryresults.bal b/testdriver/src/testdriver/sendparliamentaryresults.bal index 46a1c50..c44d1bc 100644 --- a/testdriver/src/testdriver/sendparliamentaryresults.bal +++ b/testdriver/src/testdriver/sendparliamentaryresults.bal @@ -62,7 +62,7 @@ function updateByParty(json[] byPartyJson) returns error? { json val = party["vote_percentage"]; if val is float { - party["vote_percentage"] = io:sprintf ("%.2f", val); + party["vote_percentage"] = string `${io:sprintf ("%.2f", val * 100.0)}%`; } else { // already a string so let it go } @@ -72,9 +72,9 @@ function updateByParty(json[] byPartyJson) returns error? { function updateSummary(map result) returns error? { // set the percentages in the summary map summary = >result.summary; - summary["percent_valid"] = (result.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", result.summary.valid*100.0/result.summary.polled); - summary["percent_rejected"] = (result.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", result.summary.rejected*100.0/result.summary.polled); - summary["percent_polled"] = (result.summary.electors == 0) ? "0.00" : io:sprintf("%.2f", result.summary.polled*100.0/result.summary.electors); + summary["percent_valid"] = (result.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", result.summary.valid*100.0/result.summary.polled)}%`; + summary["percent_rejected"] = (result.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", result.summary.rejected*100.0/result.summary.polled)}%`; + summary["percent_polled"] = (result.summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", result.summary.polled*100.0/result.summary.electors)}%`; } diff --git a/testdriver/src/testdriver/sendresults.bal b/testdriver/src/testdriver/sendresults.bal index f6cae25..c8dc829 100644 --- a/testdriver/src/testdriver/sendresults.bal +++ b/testdriver/src/testdriver/sendresults.bal @@ -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"] = io:sprintf ("%.2f", val); + onePr["vote_percentage"] = string `${io:sprintf ("%.2f", val * 100.0)}%`; } // 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 :( @@ -86,9 +86,9 @@ function sendResults(string resultType, string electionCode, http:Client rc, map // set the percentages in the summary map summary = >resultsByPD[pdCode].summary; - summary["percent_valid"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00" : io:sprintf("%.2f", resultsByPD[pdCode].summary.valid*100.0/resultsByPD[pdCode].summary.polled); - summary["percent_rejected"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00" : io:sprintf("%.2f", resultsByPD[pdCode].summary.rejected*100.0/resultsByPD[pdCode].summary.polled); - summary["percent_polled"] = (resultsByPD[pdCode].summary.electors == 0) ? "0.00" : io:sprintf("%.2f", resultsByPD[pdCode].summary.polled*100.0/resultsByPD[pdCode].summary.electors); + summary["percent_valid"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", resultsByPD[pdCode].summary.valid*100.0/resultsByPD[pdCode].summary.polled)}%`; + summary["percent_rejected"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", resultsByPD[pdCode].summary.rejected*100.0/resultsByPD[pdCode].summary.polled)}%`; + summary["percent_polled"] = (resultsByPD[pdCode].summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", resultsByPD[pdCode].summary.polled*100.0/resultsByPD[pdCode].summary.electors)}%`; string resCode = resultsByPD[pdCode]?.pd_code.toString(); string edCodeFromPD = resultsByPD[pdCode]?.ed_code.toString(); @@ -196,13 +196,13 @@ function createEDResult (string resultType, map>[] results, map[ distByParty[i]["votes2nd"] = votes2nd_by_party[i]; distByParty[i]["votes3rd"] = votes3rd_by_party[i]; } - distByParty[i]["vote_percentage"] = (distSummary.valid == 0) ? "0.00" : io:sprintf ("%.2f", votes_by_party[i]*100.0/distSummary.valid); + distByParty[i]["vote_percentage"] = (distSummary.valid == 0) ? "0.00%" : string `${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" : 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); + 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)}%`; return { 'type: resultType, @@ -279,13 +279,13 @@ function createNationalResult (string resultType, map>[] 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" : io:sprintf ("%.2f", votes_by_party[i]*100.0/natSummary.valid); + natByParty[i]["vote_percentage"] = (natSummary.valid == 0) ? "0.00%" : string `${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" : 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); + 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)}%`; return { 'type: resultType, From c01abd1d9a6403ff7749f25d245f458701ffadad Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Tue, 28 Jul 2020 02:47:09 +0530 Subject: [PATCH 2/3] Temporarily remove retry and bump client version --- .../web/{active-2020-07-26 => active-2020-07-28-I} | 0 distributor/web/info.txt | 6 +++--- subscriber/src/subscriber/constants.bal | 2 +- subscriber/src/subscriber/subscriber.bal | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) rename distributor/web/{active-2020-07-26 => active-2020-07-28-I} (100%) diff --git a/distributor/web/active-2020-07-26 b/distributor/web/active-2020-07-28-I similarity index 100% rename from distributor/web/active-2020-07-26 rename to distributor/web/active-2020-07-28-I diff --git a/distributor/web/info.txt b/distributor/web/info.txt index be5e764..b36d46c 100644 --- a/distributor/web/info.txt +++ b/distributor/web/info.txt @@ -2,15 +2,15 @@ ****** IMPORTANT ******* ** -** The latest version of the subscriber JAR is subscriber-20200726.jar +** The latest version of the subscriber JAR is subscriber-20200728-I.jar ** -** Available at https://github.com/ECLK/Results-Dist/releases/tag/v2020-07-26 +** Available at https://github.com/ECLK/Results-Dist/releases/tag/v2020-07-28-I ** ****** IMPORTANT ******* Run it as follows: -java -jar subscriber-20200726.jar [options] +java -jar subscriber-20200728-I.jar [options] where options are: -username=name my username for authentication diff --git a/subscriber/src/subscriber/constants.bal b/subscriber/src/subscriber/constants.bal index 1653061..859f514 100644 --- a/subscriber/src/subscriber/constants.bal +++ b/subscriber/src/subscriber/constants.bal @@ -9,7 +9,7 @@ const LEVEL_NF = "NATIONAL-FINAL"; const WANT_IMAGE = "image=true"; const WANT_AWAIT_RESULTS = "await=true"; -const MY_VERSION = "2020-07-26"; +const MY_VERSION = "2020-07-28-I"; const UNDERSOCRE = "_"; const COLON = ":"; diff --git a/subscriber/src/subscriber/subscriber.bal b/subscriber/src/subscriber/subscriber.bal index 82a89f7..33debb4 100644 --- a/subscriber/src/subscriber/subscriber.bal +++ b/subscriber/src/subscriber/subscriber.bal @@ -131,13 +131,13 @@ public function main (string? username = (), // my username http:WebSocketClient wsClientEp = new (wsUrl, config = { callbackService: callbackService, - customHeaders: headers, - retryConfig: { - intervalInMillis: 3000, - maxCount: 10, - backOffFactor: 1.5, - maxWaitIntervalInMillis: 20000 - } + customHeaders: headers + // retryConfig: { + // intervalInMillis: 3000, + // maxCount: 10, + // backOffFactor: 1.5, + // maxWaitIntervalInMillis: 20000 + // } }); if wsClientEp.isOpen() { From 4d86778884f54e0168eac2d3c0b5167e8db3be5c Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Tue, 28 Jul 2020 09:12:45 +0530 Subject: [PATCH 3/3] Undo changes to PRE percentages --- distributor/src/distributor/genhtml.bal | 10 +++++----- distributor/src/distributor/save.bal | 8 ++++---- subscriber/src/subscriber/genhtml.bal | 8 ++++---- testdriver/src/testdriver/sendresults.bal | 24 +++++++++++------------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/distributor/src/distributor/genhtml.bal b/distributor/src/distributor/genhtml.bal index 9f022f6..bd29f9a 100644 --- a/distributor/src/distributor/genhtml.bal +++ b/distributor/src/distributor/genhtml.bal @@ -57,14 +57,14 @@ function generatePresidentialResultHtml(string electionCode, map result, b foreach json j in partyResults { map pr = > j; // value is a json object if firstRound { - body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + ""; + body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + "%"; } else { body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.votes1st) + "" + commaFormatInt(pr.votes2nd) + "" + commaFormatInt(pr.votes3rd) + "" + commaFormatInt(pr.vote_count) - + "" + pr.vote_percentage + ""; + + "" + pr.vote_percentage + "%"; } } body += ""; @@ -73,13 +73,13 @@ function generatePresidentialResultHtml(string electionCode, map result, b body += "
"; body += "
Total Valid Votes
" + "
" + commaFormatInt(result.summary.valid) + - "
" + result.summary.percent_valid + "
"; + "
" + result.summary.percent_valid + "%
"; body += "
Rejected Votes
" + "
" + commaFormatInt(result.summary.rejected) + - "
" + result.summary.percent_rejected + "
"; + "
" + result.summary.percent_rejected + "%
"; body += "
Total Polled
" + "
" + commaFormatInt(result.summary.polled) + - "
" + result.summary.percent_polled + "
"; + "
" + result.summary.percent_polled + "%
"; body += "
Registered No. of Electors
" + "
" + commaFormatInt(result.summary.electors) + "
"; diff --git a/distributor/src/distributor/save.bal b/distributor/src/distributor/save.bal index a17286f..18f1bb8 100644 --- a/distributor/src/distributor/save.bal +++ b/distributor/src/distributor/save.bal @@ -301,9 +301,9 @@ function addToPresidentialCumulative(map jm) returns PresidentialCumulativ accum.summary.rejected += jm.summary.rejected; accum.summary.polled += jm.summary.polled; accum.summary.electors += 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 @@ -321,7 +321,7 @@ function addToPresidentialCumulative(map jm) returns PresidentialCumulativ accum.by_party[i]["votes2nd"] = (accum.by_party[i]["votes2nd"] ?: 0) + pr[i].votes2nd; accum.by_party[i]["votes3rd"] = (accum.by_party[i]["votes3rd"] ?: 0) + 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; diff --git a/subscriber/src/subscriber/genhtml.bal b/subscriber/src/subscriber/genhtml.bal index 2f9f58c..a5ccde0 100644 --- a/subscriber/src/subscriber/genhtml.bal +++ b/subscriber/src/subscriber/genhtml.bal @@ -48,7 +48,7 @@ function generatePresidentialResultHtml(string electionCode, map result, b json[] partyResults = sorted ? sortByPartyResultsByVoteCount(result.by_party) : result.by_party; foreach json j in partyResults { map pr = > j; // value is a json object - body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + ""; + body += "" + pr.candidate + "" + pr.party_code + "" + commaFormatInt(pr.vote_count) + "" + pr.vote_percentage + "%"; } body += ""; body += ""; @@ -56,13 +56,13 @@ function generatePresidentialResultHtml(string electionCode, map result, b body += "
"; body += "
Total Valid Votes
" + "
" + commaFormatInt(result.summary.valid) + - "
" + result.summary.percent_valid + "
"; + "
" + result.summary.percent_valid + "%
"; body += "
Rejected Votes
" + "
" + commaFormatInt(result.summary.rejected) + - "
" + result.summary.percent_rejected + "
"; + "
" + result.summary.percent_rejected + "%
"; body += "
Total Polled
" + "
" + commaFormatInt(result.summary.polled) + - "
" + result.summary.percent_polled + "
"; + "
" + result.summary.percent_polled + "%
"; body += "
Registered No. of Electors
" + "
" + commaFormatInt(result.summary.electors) + "
"; diff --git a/testdriver/src/testdriver/sendresults.bal b/testdriver/src/testdriver/sendresults.bal index c8dc829..e1869d1 100644 --- a/testdriver/src/testdriver/sendresults.bal +++ b/testdriver/src/testdriver/sendresults.bal @@ -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 :( @@ -86,9 +86,9 @@ function sendResults(string resultType, string electionCode, http:Client rc, map // set the percentages in the summary map summary = >resultsByPD[pdCode].summary; - summary["percent_valid"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", resultsByPD[pdCode].summary.valid*100.0/resultsByPD[pdCode].summary.polled)}%`; - summary["percent_rejected"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", resultsByPD[pdCode].summary.rejected*100.0/resultsByPD[pdCode].summary.polled)}%`; - summary["percent_polled"] = (resultsByPD[pdCode].summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", resultsByPD[pdCode].summary.polled*100.0/resultsByPD[pdCode].summary.electors)}%`; + summary["percent_valid"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00" : io:sprintf("%.2f", resultsByPD[pdCode].summary.valid*100.0/resultsByPD[pdCode].summary.polled); + summary["percent_rejected"] = (resultsByPD[pdCode].summary.polled == 0) ? "0.00" : io:sprintf("%.2f", resultsByPD[pdCode].summary.rejected*100.0/resultsByPD[pdCode].summary.polled); + summary["percent_polled"] = (resultsByPD[pdCode].summary.electors == 0) ? "0.00" : io:sprintf("%.2f", resultsByPD[pdCode].summary.polled*100.0/resultsByPD[pdCode].summary.electors); string resCode = resultsByPD[pdCode]?.pd_code.toString(); string edCodeFromPD = resultsByPD[pdCode]?.ed_code.toString(); @@ -196,13 +196,13 @@ function createEDResult (string resultType, map>[] results, map[ 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, @@ -279,13 +279,13 @@ function createNationalResult (string resultType, map>[] 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,