Update WebAssembly build for recent changes
This commit is contained in:
parent
a4a28f3345
commit
f1a730e885
|
@ -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() {
|
||||
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 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>
|
||||
{
|
||||
// Copy applicable options
|
||||
let stv_opts = stv::STVOptions {
|
||||
round_votes: cmd_opts.round_votes,
|
||||
surplus: match cmd_opts.surplus.as_str() {
|
||||
"wig" => stv::SurplusMethod::WIG,
|
||||
"uig" => stv::SurplusMethod::UIG,
|
||||
"eg" => stv::SurplusMethod::EG,
|
||||
"meek" => stv::SurplusMethod::Meek,
|
||||
_ => 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,
|
||||
};
|
||||
let stv_opts = stv::STVOptions::new(
|
||||
cmd_opts.round_votes,
|
||||
&cmd_opts.surplus,
|
||||
&cmd_opts.surplus_order,
|
||||
cmd_opts.transferable_only,
|
||||
&cmd_opts.exclusion,
|
||||
cmd_opts.pp_decimals,
|
||||
);
|
||||
|
||||
// Initialise count state
|
||||
let mut state = CountState::new(&election);
|
||||
|
|
|
@ -38,6 +38,42 @@ pub struct STVOptions {
|
|||
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]
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum SurplusMethod {
|
||||
|
|
Loading…
Reference in New Issue