Skip to content

Commit ccca2e3

Browse files
authored
Merge pull request #160 from MaryamZi/res-type-fixes
Change vote and summary percentages to xx.dd% format
2 parents e240fe8 + 4d86778 commit ccca2e3

File tree

11 files changed

+56
-60
lines changed

11 files changed

+56
-60
lines changed

distributor/src/distributor/genhtml.bal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ function generateParliamentaryResultHtml(string electionCode, map<json> result,
191191
body += "<div class='container-fluid'>";
192192
body += " <div class='col-md-4 col-md-offset-2'>Total Valid Votes</div>" +
193193
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.valid) +
194-
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "%</div><div class='col-md-2'></div>";
194+
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "</div><div class='col-md-2'></div>";
195195
body += " <div class='col-md-4 col-md-offset-2'>Rejected Votes</div>" +
196196
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.rejected) +
197-
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "%</div><div class='col-md-2'></div>";
197+
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "</div><div class='col-md-2'></div>";
198198
body += " <div class='col-md-4 col-md-offset-2'>Total Polled</div>" +
199199
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.polled) +
200-
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "%</div><div class='col-md-2'></div>";
200+
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "</div><div class='col-md-2'></div>";
201201
body += " <div class='col-md-4 col-md-offset-2'>Registered No. of Electors</div>" +
202202
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.electors) +
203203
" </div><div class='col-md-2'></div>";

distributor/src/distributor/save.bal

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,6 @@ function addToPresidentialCumulative(map<json> jm) returns PresidentialCumulativ
300300
accum.summary.valid += <int>jm.summary.valid;
301301
accum.summary.rejected += <int>jm.summary.rejected;
302302
accum.summary.polled += <int>jm.summary.polled;
303-
// don't add up electors from postal PDs as those are already in the district elsewhere
304-
string pdCode = <string>jm.pd_code; // check
305303
accum.summary.electors += <int>jm.summary.electors;
306304
accum.summary.percent_valid = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.valid*100.0/accum.summary.polled);
307305
accum.summary.percent_rejected = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.rejected*100.0/accum.summary.polled);
@@ -365,12 +363,10 @@ function addToParliamentaryCumulativeVotes(map<json> jm) returns ParliamentaryCu
365363
summary.valid += <int>jm.summary.valid;
366364
summary.rejected += <int>jm.summary.rejected;
367365
summary.polled += <int>jm.summary.polled;
368-
// // don't add up electors from postal PDs as those are already in the district elsewhere
369-
// string pdCode = <string>jm.pd_code; // check
370366
summary.electors += <int>jm.summary.electors;
371-
summary.percent_valid = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.valid*100.0/accum.summary.polled);
372-
summary.percent_rejected = (accum.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.rejected*100.0/accum.summary.polled);
373-
summary.percent_polled = (accum.summary.electors == 0) ? "0.00" : io:sprintf("%.2f", accum.summary.polled*100.0/accum.summary.electors);
367+
summary.percent_valid = (accum.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.valid*100.0/accum.summary.polled)}%`;
368+
summary.percent_rejected = (accum.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.rejected*100.0/accum.summary.polled)}%`;
369+
summary.percent_polled = (accum.summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", accum.summary.polled*100.0/accum.summary.electors)}%`;
374370

375371
if accum.nadded == 0 {
376372
pr.forEach(x => accum.by_party.push(checkpanic ParliamentaryPartyResult.constructFrom(x)));
@@ -384,7 +380,7 @@ function addToParliamentaryCumulativeVotes(map<json> jm) returns ParliamentaryCu
384380
} else {
385381
int accumVoteCount = <int> accum.by_party[i]?.vote_count + <int>pr[i].vote_count;
386382
accum.by_party[i].vote_count = accumVoteCount;
387-
accum.by_party[i].vote_percentage = (accum.summary.valid == 0) ? "0.00" : io:sprintf ("%.2f", ((accumVoteCount*1.0)/accum.summary.valid));
383+
accum.by_party[i].vote_percentage = (accum.summary.valid == 0) ? "0.00%" : string `${io:sprintf ("%.2f", ((accumVoteCount*100.0)/accum.summary.valid))}%`;
388384
}
389385
}
390386
}

distributor/web/info.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
****** IMPORTANT *******
44
**
5-
** The latest version of the subscriber JAR is subscriber-20200726.jar
5+
** The latest version of the subscriber JAR is subscriber-20200728-I.jar
66
**
7-
** Available at https://github.com/ECLK/Results-Dist/releases/tag/v2020-07-26
7+
** Available at https://github.com/ECLK/Results-Dist/releases/tag/v2020-07-28-I
88
**
99
****** IMPORTANT *******
1010

1111
Run it as follows:
1212

13-
java -jar subscriber-20200726.jar [options]
13+
java -jar subscriber-20200728-I.jar [options]
1414

1515
where options are:
1616
-username=name my username for authentication

subscriber/src/subscriber/constants.bal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const LEVEL_NF = "NATIONAL-FINAL";
99
const WANT_IMAGE = "image=true";
1010
const WANT_AWAIT_RESULTS = "await=true";
1111

12-
const MY_VERSION = "2020-07-26";
12+
const MY_VERSION = "2020-07-28-I";
1313

1414
const UNDERSOCRE = "_";
1515
const COLON = ":";

subscriber/src/subscriber/genhtml.bal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ function generateParliamentaryResultHtml(string electionCode, map<json> result,
175175
body += "<div class='container-fluid'>";
176176
body += " <div class='col-md-4 col-md-offset-2'>Total Valid Votes</div>" +
177177
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.valid) +
178-
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "%</div><div class='col-md-2'></div>";
178+
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_valid + "</div><div class='col-md-2'></div>";
179179
body += " <div class='col-md-4 col-md-offset-2'>Rejected Votes</div>" +
180180
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.rejected) +
181-
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "%</div><div class='col-md-2'></div>";
181+
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_rejected + "</div><div class='col-md-2'></div>";
182182
body += " <div class='col-md-4 col-md-offset-2'>Total Polled</div>" +
183183
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.polled) +
184-
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "%</div><div class='col-md-2'></div>";
184+
" </div><div class='col-md-2 text-right'>" + <string>result.summary.percent_polled + "</div><div class='col-md-2'></div>";
185185
body += " <div class='col-md-4 col-md-offset-2'>Registered No. of Electors</div>" +
186186
" <div class='col-md-2 text-right'>" + commaFormatInt(<int>result.summary.electors) +
187187
" </div><div class='col-md-2'></div>";

subscriber/src/subscriber/subscriber.bal

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ public function main (string? username = (), // my username
131131

132132
http:WebSocketClient wsClientEp = new (wsUrl, config = {
133133
callbackService: callbackService,
134-
customHeaders: headers,
135-
retryConfig: {
136-
intervalInMillis: 3000,
137-
maxCount: 10,
138-
backOffFactor: 1.5,
139-
maxWaitIntervalInMillis: 20000
140-
}
134+
customHeaders: headers
135+
// retryConfig: {
136+
// intervalInMillis: 3000,
137+
// maxCount: 10,
138+
// backOffFactor: 1.5,
139+
// maxWaitIntervalInMillis: 20000
140+
// }
141141
});
142142

143143
if wsClientEp.isOpen() {

subscriber/src/subscriber/tests/main_test.bal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ function testRE_VI(string filePath, int fooCount, int barCount, int bazCount, in
4949
map<json> party = <map<json>>parties[0];
5050
test:assertEquals(party["party_name"], "Foo foo");
5151
test:assertEquals(party["vote_count"], fooCount);
52-
test:assertEquals(party["vote_percentage"], io:sprintf("%.2f", ((fooCount*1.0)/valid)));
52+
test:assertEquals(party["vote_percentage"], string `${io:sprintf("%.2f", ((fooCount*100.0)/valid))}%`);
5353

5454
party = <map<json>>parties[1];
5555
test:assertEquals(party["party_name"], "Bar bar");
5656
test:assertEquals(party["vote_count"], barCount);
57-
test:assertEquals(party["vote_percentage"], io:sprintf("%.2f", ((barCount*1.0)/valid)));
57+
test:assertEquals(party["vote_percentage"], string `${io:sprintf("%.2f", ((barCount*100.0)/valid))}%`);
5858

5959
party = <map<json>>parties[2];
6060
test:assertEquals(party["party_name"], "Baz baz");
6161
test:assertEquals(party["vote_count"], bazCount);
62-
test:assertEquals(party["vote_percentage"], io:sprintf("%.2f", ((bazCount*1.0)/valid)));
62+
test:assertEquals(party["vote_percentage"], string `${io:sprintf("%.2f", ((bazCount*100.0)/valid))}%`);
6363

6464
map<json> edSummary = <map<json>>value.summary;
6565
test:assertEquals(edSummary["valid"], valid);

testdriver/src/testdriver/gen_fake_parliamentary.bal

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ function genFakeParliamentary() {
1414
"party_code": "Foo",
1515
"party_name": "Foo foo",
1616
"vote_count": 15,
17-
"vote_percentage": 0.17,
17+
"vote_percentage": "16.67%",
1818
"seat_count": 0,
1919
"national_list_seat_count": 0
2020
},
2121
{
2222
"party_code": "Bar",
2323
"party_name": "Bar bar",
2424
"vote_count": 65,
25-
"vote_percentage": 0.72,
25+
"vote_percentage": "72.22%",
2626
"seat_count": 0,
2727
"national_list_seat_count": 0
2828
},
2929
{
3030
"party_code": "Baz",
3131
"party_name": "Baz baz",
3232
"vote_count": 10,
33-
"vote_percentage": 0.11,
33+
"vote_percentage": "11.11%",
3434
"seat_count": 0,
3535
"national_list_seat_count": 0
3636
}
@@ -56,23 +56,23 @@ function genFakeParliamentary() {
5656
"party_code": "Foo",
5757
"party_name": "Foo foo",
5858
"vote_count": 90,
59-
"vote_percentage": 0.6,
59+
"vote_percentage": "60.00%",
6060
"seat_count": 0,
6161
"national_list_seat_count": 0
6262
},
6363
{
6464
"party_code": "Bar",
6565
"party_name": "Bar bar",
6666
"vote_count": 35,
67-
"vote_percentage": 0.23,
67+
"vote_percentage": "23.33%",
6868
"seat_count": 0,
6969
"national_list_seat_count": 0
7070
},
7171
{
7272
"party_code": "Baz",
7373
"party_name": "Baz baz",
7474
"vote_count": 25,
75-
"vote_percentage": 0.17,
75+
"vote_percentage": "16.67%",
7676
"seat_count": 0,
7777
"national_list_seat_count": 0
7878
}
@@ -98,23 +98,23 @@ function genFakeParliamentary() {
9898
"party_code": "Foo",
9999
"party_name": "Foo foo",
100100
"vote_count": 10,
101-
"vote_percentage": 0.46,
101+
"vote_percentage": "45.45%",
102102
"seat_count": 0,
103103
"national_list_seat_count": 0
104104
},
105105
{
106106
"party_code": "Bar",
107107
"party_name": "Bar bar",
108108
"vote_count": 0,
109-
"vote_percentage": 0.00,
109+
"vote_percentage": "0.00%",
110110
"seat_count": 0,
111111
"national_list_seat_count": 0
112112
},
113113
{
114114
"party_code": "Baz",
115115
"party_name": "Baz baz",
116116
"vote_count": 12,
117-
"vote_percentage": 0.54,
117+
"vote_percentage": "54.55%",
118118
"seat_count": 0,
119119
"national_list_seat_count": 0
120120
}
@@ -140,23 +140,23 @@ function genFakeParliamentary() {
140140
"party_code": "Foo",
141141
"party_name": "Foo foo",
142142
"vote_count": 10,
143-
"vote_percentage": 0.13,
143+
"vote_percentage": "12.50%",
144144
"seat_count": 0,
145145
"national_list_seat_count": 0
146146
},
147147
{
148148
"party_code": "Bar",
149149
"party_name": "Bar bar",
150150
"vote_count": 50,
151-
"vote_percentage": 0.63,
151+
"vote_percentage": "62.50%",
152152
"seat_count": 0,
153153
"national_list_seat_count": 0
154154
},
155155
{
156156
"party_code": "Baz",
157157
"party_name": "Baz baz",
158158
"vote_count": 20,
159-
"vote_percentage": 0.25,
159+
"vote_percentage": "25.00%",
160160
"seat_count": 0,
161161
"national_list_seat_count": 0
162162
}
@@ -182,23 +182,23 @@ function genFakeParliamentary() {
182182
"party_code": "Foo",
183183
"party_name": "Foo foo",
184184
"vote_count": 50,
185-
"vote_percentage": 0.55,
185+
"vote_percentage": "55.56%",
186186
"seat_count": 0,
187187
"national_list_seat_count": 0
188188
},
189189
{
190190
"party_code": "Bar",
191191
"party_name": "Bar bar",
192192
"vote_count": 20,
193-
"vote_percentage": 0.22,
193+
"vote_percentage": "22.22%",
194194
"seat_count": 0,
195195
"national_list_seat_count": 0
196196
},
197197
{
198198
"party_code": "Baz",
199199
"party_name": "Baz baz",
200200
"vote_count": 20,
201-
"vote_percentage": 0.22,
201+
"vote_percentage": "22.22%",
202202
"seat_count": 0,
203203
"national_list_seat_count": 0
204204
}
@@ -222,15 +222,15 @@ function genFakeParliamentary() {
222222
"party_code": "Baz",
223223
"party_name": "Baz baz",
224224
"vote_count": 0,
225-
"vote_percentage": 0.00,
225+
"vote_percentage": "0.00%",
226226
"seat_count": 3,
227227
"national_list_seat_count": 0
228228
},
229229
{
230230
"party_code": "Foo",
231231
"party_name": "Foo foo",
232232
"vote_count": 0,
233-
"vote_percentage": 0.00,
233+
"vote_percentage": "0.00%",
234234
"seat_count": 10,
235235
"national_list_seat_count": 0
236236
},
@@ -254,15 +254,15 @@ function genFakeParliamentary() {
254254
"party_code": "Foo",
255255
"party_name": "Foo foo",
256256
"vote_count": 0,
257-
"vote_percentage": 0.00,
257+
"vote_percentage": "0.00%",
258258
"seat_count": 8,
259259
"national_list_seat_count": 0
260260
},
261261
{
262262
"party_code": "Bar",
263263
"party_name": "Bar bar",
264264
"vote_count": 0,
265-
"vote_percentage": 0.00,
265+
"vote_percentage": "0.00%",
266266
"seat_count": 20,
267267
"national_list_seat_count": 0
268268
},
@@ -284,23 +284,23 @@ function genFakeParliamentary() {
284284
"party_code": "Bar",
285285
"party_name": "Bar bar",
286286
"vote_count": 12540,
287-
"vote_percentage": 0.33,
287+
"vote_percentage": "32.79%",
288288
"seat_count": 75,
289289
"national_list_seat_count": 0
290290
},
291291
{
292292
"party_code": "Baz",
293293
"party_name": "Baz baz",
294294
"vote_count": 7500,
295-
"vote_percentage": 0.20,
295+
"vote_percentage": "19.61%",
296296
"seat_count": 25,
297297
"national_list_seat_count": 0
298298
},
299299
{
300300
"party_code": "Foo",
301301
"party_name": "Foo foo",
302302
"vote_count": 18200,
303-
"vote_percentage": 0.48,
303+
"vote_percentage": "47.59%",
304304
"seat_count": 100,
305305
"national_list_seat_count": 0
306306
}
@@ -322,23 +322,23 @@ function genFakeParliamentary() {
322322
"party_code": "Baz",
323323
"party_name": "Baz baz",
324324
"vote_count": 7500,
325-
"vote_percentage": 0.20,
325+
"vote_percentage": "19.61%",
326326
"seat_count": 25,
327327
"national_list_seat_count": 4
328328
},
329329
{
330330
"party_code": "Foo",
331331
"party_name": "Foo foo",
332332
"vote_count": 18200,
333-
"vote_percentage": 0.48,
333+
"vote_percentage": "47.59%",
334334
"seat_count": 100,
335335
"national_list_seat_count": 12
336336
},
337337
{
338338
"party_code": "Bar",
339339
"party_name": "Bar bar",
340340
"vote_count": 12540,
341-
"vote_percentage": 0.33,
341+
"vote_percentage": "32.79%",
342342
"seat_count": 75,
343343
"national_list_seat_count": 9
344344
}

testdriver/src/testdriver/sendparliamentaryresults.bal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function updateByParty(json[] byPartyJson) returns error? {
6262
json val = party["vote_percentage"];
6363

6464
if val is float {
65-
party["vote_percentage"] = io:sprintf ("%.2f", val);
65+
party["vote_percentage"] = string `${io:sprintf ("%.2f", val * 100.0)}%`;
6666
} else {
6767
// already a string so let it go
6868
}
@@ -72,9 +72,9 @@ function updateByParty(json[] byPartyJson) returns error? {
7272
function updateSummary(map<json> result) returns error? {
7373
// set the percentages in the summary
7474
map<json> summary = <map<json>>result.summary;
75-
summary["percent_valid"] = (<int>result.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", <int>result.summary.valid*100.0/<int>result.summary.polled);
76-
summary["percent_rejected"] = (<int>result.summary.polled == 0) ? "0.00" : io:sprintf("%.2f", <int>result.summary.rejected*100.0/<int>result.summary.polled);
77-
summary["percent_polled"] = (<int>result.summary.electors == 0) ? "0.00" : io:sprintf("%.2f", <int>result.summary.polled*100.0/<int>result.summary.electors);
75+
summary["percent_valid"] = (<int>result.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>result.summary.valid*100.0/<int>result.summary.polled)}%`;
76+
summary["percent_rejected"] = (<int>result.summary.polled == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>result.summary.rejected*100.0/<int>result.summary.polled)}%`;
77+
summary["percent_polled"] = (<int>result.summary.electors == 0) ? "0.00%" : string `${io:sprintf("%.2f", <int>result.summary.polled*100.0/<int>result.summary.electors)}%`;
7878
}
7979

8080

0 commit comments

Comments
 (0)