Skip to content

Commit

Permalink
Merge pull request #160 from MaryamZi/res-type-fixes
Browse files Browse the repository at this point in the history
Change vote and summary percentages to xx.dd% format
  • Loading branch information
MaryamZi committed Jul 28, 2020
2 parents e240fe8 + 4d86778 commit ccca2e3
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 60 deletions.
6 changes: 3 additions & 3 deletions distributor/src/distributor/genhtml.bal
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ function generateParliamentaryResultHtml(string electionCode, map<json> result,
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
12 changes: 4 additions & 8 deletions distributor/src/distributor/save.bal
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ function addToPresidentialCumulative(map<json> jm) returns PresidentialCumulativ
accum.summary.valid += <int>jm.summary.valid;
accum.summary.rejected += <int>jm.summary.rejected;
accum.summary.polled += <int>jm.summary.polled;
// don't add up electors from postal PDs as those are already in the district elsewhere
string pdCode = <string>jm.pd_code; // check
accum.summary.electors += <int>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);
Expand Down Expand Up @@ -365,12 +363,10 @@ function addToParliamentaryCumulativeVotes(map<json> jm) returns ParliamentaryCu
summary.valid += <int>jm.summary.valid;
summary.rejected += <int>jm.summary.rejected;
summary.polled += <int>jm.summary.polled;
// // don't add up electors from postal PDs as those are already in the district elsewhere
// string pdCode = <string>jm.pd_code; // check
summary.electors += <int>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)));
Expand All @@ -384,7 +380,7 @@ function addToParliamentaryCumulativeVotes(map<json> jm) returns ParliamentaryCu
} else {
int accumVoteCount = <int> accum.by_party[i]?.vote_count + <int>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))}%`;
}
}
}
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions distributor/web/info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion subscriber/src/subscriber/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ":";
Expand Down
6 changes: 3 additions & 3 deletions subscriber/src/subscriber/genhtml.bal
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ function generateParliamentaryResultHtml(string electionCode, map<json> result,
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
14 changes: 7 additions & 7 deletions subscriber/src/subscriber/subscriber.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions subscriber/src/subscriber/tests/main_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ function testRE_VI(string filePath, int fooCount, int barCount, int bazCount, in
map<json> party = <map<json>>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 = <map<json>>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 = <map<json>>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<json> edSummary = <map<json>>value.summary;
test:assertEquals(edSummary["valid"], valid);
Expand Down
50 changes: 25 additions & 25 deletions testdriver/src/testdriver/gen_fake_parliamentary.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ 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
},
{
"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
},
{
"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
}
Expand All @@ -56,23 +56,23 @@ 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
},
{
"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
},
{
"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
}
Expand All @@ -98,23 +98,23 @@ 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
},
{
"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
},
{
"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
}
Expand All @@ -140,23 +140,23 @@ 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
},
{
"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
},
{
"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
}
Expand All @@ -182,23 +182,23 @@ 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
},
{
"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
},
{
"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
}
Expand All @@ -222,15 +222,15 @@ 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
},
{
"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
},
Expand All @@ -254,15 +254,15 @@ 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
},
{
"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
},
Expand All @@ -284,23 +284,23 @@ 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
},
{
"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
},
{
"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
}
Expand All @@ -322,23 +322,23 @@ 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
},
{
"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
},
{
"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
}
Expand Down
8 changes: 4 additions & 4 deletions testdriver/src/testdriver/sendparliamentaryresults.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -72,9 +72,9 @@ function updateByParty(json[] byPartyJson) returns error? {
function updateSummary(map<json> result) returns error? {
// set the percentages in the summary
map<json> summary = <map<json>>result.summary;
summary["percent_valid"] = (<int>result.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", <int>result.summary.valid*100.0/<int>result.summary.polled);
summary["percent_rejected"] = (<int>result.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", <int>result.summary.rejected*100.0/<int>result.summary.polled);
summary["percent_polled"] = (<int>result.summary.electors == 0) ? "0.00" : io:sprintf("%.2f", <int>result.summary.polled*100.0/<int>result.summary.electors);
summary["percent_valid"] = (<int>result.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>result.summary.valid*100.0/<int>result.summary.polled)}%`;
summary["percent_rejected"] = (<int>result.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>result.summary.rejected*100.0/<int>result.summary.polled)}%`;
summary["percent_polled"] = (<int>result.summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>result.summary.polled*100.0/<int>result.summary.electors)}%`;
}


Expand Down
Loading

0 comments on commit ccca2e3

Please sign in to comment.