OpenTally/pkg/test.html

50 lines
1.1 KiB
HTML

<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;
async function run() {
await wasm_bindgen("opentally_bg.wasm");
let stv_opts = wasm.STVOptions.new(2, "one_round");
let election = wasm.election_from_blt_Rational(election_data);
let state = wasm.CountStateRational.new(election);
wasm.count_init_Rational(state, stv_opts);
wasm.make_and_print_result_Rational(1, state);
for (let stage_num = 2;; stage_num++) {
let is_done = wasm.count_one_stage_Rational(state, stv_opts);
if (is_done) {
break;
}
wasm.make_and_print_result_Rational(stage_num, state);
}
}
run();
</script>
</body>
</html>