OpenTally/pkg/test.html

50 lines
1.2 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 { CountStateFloat64, STVOptions, count_init_float64, count_one_stage_float64, election_from_blt_float64, make_and_print_result_float64 } = wasm_bindgen;
async function run() {
await wasm_bindgen("opentally_bg.wasm");
let stv_opts = STVOptions.new(2, "one_round");
let election = election_from_blt_float64(election_data);
let state = CountStateFloat64.new(election);
count_init_float64(state, stv_opts);
make_and_print_result_float64(1, state);
for (let stage_num = 2;; stage_num++) {
let is_done = count_one_stage_float64(state, stv_opts);
if (is_done) {
break;
}
make_and_print_result_float64(stage_num, state);
}
}
run();
</script>
</body>
</html>