Update WebAssembly build for recent changes
This commit is contained in:
parent
a4a28f3345
commit
f1a730e885
2
build_wasm.sh
Executable file
2
build_wasm.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
cargo build --lib --target wasm32-unknown-unknown && /home/runassudo/.cargo/bin/wasm-bindgen --target no-modules target/wasm32-unknown-unknown/debug/opentally.wasm --out-dir pkg --no-typescript
|
@ -27,7 +27,7 @@
|
|||||||
async function run() {
|
async function run() {
|
||||||
await wasm_bindgen("opentally_bg.wasm");
|
await wasm_bindgen("opentally_bg.wasm");
|
||||||
|
|
||||||
let stv_opts = wasm.STVOptions.new(2, "one_round");
|
let stv_opts = wasm.STVOptions.new(null, "wig", "by_size", false, "single_stage", 2);
|
||||||
|
|
||||||
let election = wasm.election_from_blt_Rational(election_data);
|
let election = wasm.election_from_blt_Rational(election_data);
|
||||||
let state = wasm.CountStateRational.new(election);
|
let state = wasm.CountStateRational.new(election);
|
||||||
|
31
src/main.rs
31
src/main.rs
@ -125,29 +125,14 @@ where
|
|||||||
for<'r> &'r N: ops::Neg<Output=N>
|
for<'r> &'r N: ops::Neg<Output=N>
|
||||||
{
|
{
|
||||||
// Copy applicable options
|
// Copy applicable options
|
||||||
let stv_opts = stv::STVOptions {
|
let stv_opts = stv::STVOptions::new(
|
||||||
round_votes: cmd_opts.round_votes,
|
cmd_opts.round_votes,
|
||||||
surplus: match cmd_opts.surplus.as_str() {
|
&cmd_opts.surplus,
|
||||||
"wig" => stv::SurplusMethod::WIG,
|
&cmd_opts.surplus_order,
|
||||||
"uig" => stv::SurplusMethod::UIG,
|
cmd_opts.transferable_only,
|
||||||
"eg" => stv::SurplusMethod::EG,
|
&cmd_opts.exclusion,
|
||||||
"meek" => stv::SurplusMethod::Meek,
|
cmd_opts.pp_decimals,
|
||||||
_ => panic!("Invalid --surplus"),
|
);
|
||||||
},
|
|
||||||
surplus_order: match cmd_opts.surplus_order.as_str() {
|
|
||||||
"by_size" => stv::SurplusOrder::BySize,
|
|
||||||
"by_order" => stv::SurplusOrder::ByOrder,
|
|
||||||
_ => panic!("Invalid --surplus-order"),
|
|
||||||
},
|
|
||||||
transferable_only: cmd_opts.transferable_only,
|
|
||||||
exclusion: match cmd_opts.exclusion.as_str() {
|
|
||||||
"single_stage" => stv::ExclusionMethod::SingleStage,
|
|
||||||
"by_value" => stv::ExclusionMethod::ByValue,
|
|
||||||
"parcels_by_order" => stv::ExclusionMethod::ParcelsByOrder,
|
|
||||||
_ => panic!("Invalid --exclusion"),
|
|
||||||
},
|
|
||||||
pp_decimals: cmd_opts.pp_decimals,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialise count state
|
// Initialise count state
|
||||||
let mut state = CountState::new(&election);
|
let mut state = CountState::new(&election);
|
||||||
|
@ -38,6 +38,42 @@ pub struct STVOptions {
|
|||||||
pub pp_decimals: usize,
|
pub pp_decimals: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl STVOptions {
|
||||||
|
pub fn new(
|
||||||
|
round_votes: Option<usize>,
|
||||||
|
surplus: &str,
|
||||||
|
surplus_order: &str,
|
||||||
|
transferable_only: bool,
|
||||||
|
exclusion: &str,
|
||||||
|
pp_decimals: usize,
|
||||||
|
) -> Self {
|
||||||
|
return STVOptions {
|
||||||
|
round_votes: round_votes,
|
||||||
|
surplus: match surplus {
|
||||||
|
"wig" => SurplusMethod::WIG,
|
||||||
|
"uig" => SurplusMethod::UIG,
|
||||||
|
"eg" => SurplusMethod::EG,
|
||||||
|
"meek" => SurplusMethod::Meek,
|
||||||
|
_ => panic!("Invalid --surplus"),
|
||||||
|
},
|
||||||
|
surplus_order: match surplus_order {
|
||||||
|
"by_size" => SurplusOrder::BySize,
|
||||||
|
"by_order" => SurplusOrder::ByOrder,
|
||||||
|
_ => panic!("Invalid --surplus-order"),
|
||||||
|
},
|
||||||
|
transferable_only: transferable_only,
|
||||||
|
exclusion: match exclusion {
|
||||||
|
"single_stage" => ExclusionMethod::SingleStage,
|
||||||
|
"by_value" => ExclusionMethod::ByValue,
|
||||||
|
"parcels_by_order" => ExclusionMethod::ParcelsByOrder,
|
||||||
|
_ => panic!("Invalid --exclusion"),
|
||||||
|
},
|
||||||
|
pp_decimals: pp_decimals,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum SurplusMethod {
|
pub enum SurplusMethod {
|
||||||
|
Loading…
Reference in New Issue
Block a user