2021-05-30 10:28:39 +02:00
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<div id="output" style="white-space: pre-wrap;"></div>
|
|
|
|
|
|
|
|
<script src="opentally.js"></script>
|
|
|
|
<script>
|
|
|
|
var election_data = '4 2\n\
|
|
|
|
3 1 3 4 0\n\
|
|
|
|
4 1 3 2 0\n\
|
|
|
|
2 4 1 3 0\n\
|
|
|
|
1 2 0\n\
|
|
|
|
2 2 4 3 1 0\n\
|
|
|
|
1 3 4 2 0\n\
|
|
|
|
0\n\
|
|
|
|
"Adam"\n\
|
|
|
|
"Basil"\n\
|
|
|
|
"Charlotte"\n\
|
|
|
|
"Donald"\n\
|
|
|
|
"Title"';
|
|
|
|
|
|
|
|
console.log = function(v) {
|
|
|
|
document.getElementById('output').append(v);
|
|
|
|
document.getElementById('output').append("\n");
|
|
|
|
};
|
|
|
|
|
2021-05-30 15:00:28 +02:00
|
|
|
var wasm = wasm_bindgen;
|
2021-05-30 10:28:39 +02:00
|
|
|
async function run() {
|
|
|
|
await wasm_bindgen("opentally_bg.wasm");
|
|
|
|
|
2021-06-01 11:04:03 +02:00
|
|
|
let stv_opts = wasm.STVOptions.new(null, "wig", "by_size", false, "single_stage", 2);
|
2021-05-30 10:28:39 +02:00
|
|
|
|
2021-05-30 15:00:28 +02:00
|
|
|
let election = wasm.election_from_blt_Rational(election_data);
|
|
|
|
let state = wasm.CountStateRational.new(election);
|
2021-05-30 10:28:39 +02:00
|
|
|
|
2021-05-30 15:00:28 +02:00
|
|
|
wasm.count_init_Rational(state, stv_opts);
|
|
|
|
wasm.make_and_print_result_Rational(1, state);
|
2021-05-30 10:28:39 +02:00
|
|
|
|
|
|
|
for (let stage_num = 2;; stage_num++) {
|
2021-05-30 15:00:28 +02:00
|
|
|
let is_done = wasm.count_one_stage_Rational(state, stv_opts);
|
2021-05-30 10:28:39 +02:00
|
|
|
if (is_done) {
|
|
|
|
break;
|
|
|
|
}
|
2021-05-30 15:00:28 +02:00
|
|
|
wasm.make_and_print_result_Rational(stage_num, state);
|
2021-05-30 10:28:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
run();
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|