OpenTally/pkg/test.html

50 lines
1.1 KiB
HTML
Raw Normal View History

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");
};
var wasm = wasm_bindgen;
2021-05-30 10:28:39 +02:00
async function run() {
await wasm_bindgen("opentally_bg.wasm");
let stv_opts = wasm.STVOptions.new(2, "one_round");
2021-05-30 10:28:39 +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
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++) {
let is_done = wasm.count_one_stage_Rational(state, stv_opts);
2021-05-30 10:28:39 +02:00
if (is_done) {
break;
}
wasm.make_and_print_result_Rational(stage_num, state);
2021-05-30 10:28:39 +02:00
}
}
run();
</script>
</body>
</html>