Implement --numbers in web client
This commit is contained in:
parent
b7f18a74ac
commit
441e266b17
@ -143,16 +143,18 @@
|
||||
Numeric representation:
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<!--<label>
|
||||
<label>
|
||||
Numbers:
|
||||
<select id="selNumbers">
|
||||
<option value="native">Native</option>
|
||||
<!--<option value="native">Native</option>
|
||||
<option value="rational">Rational</option>
|
||||
<option value="fixed" selected>Fixed</option>
|
||||
<option value="gfixed">Fixed (guarded)</option>
|
||||
<option value="gfixed">Fixed (guarded)</option>-->
|
||||
<option value="rational">Rational</option>
|
||||
<option value="float64">Float (64-bit)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<!--<label>
|
||||
Decimal places (if Numbers = Fixed):
|
||||
<input type="number" id="txtDP" value="5" min="0" style="width: 3em;">
|
||||
</label>-->
|
||||
|
@ -61,6 +61,10 @@ worker.onmessage = function(evt) {
|
||||
}
|
||||
}
|
||||
|
||||
worker.onerror = function(evt) {
|
||||
alert('An unknown error occurred while counting the votes. More details may be available in the browser\'s developer console.');
|
||||
}
|
||||
|
||||
async function clickCount() {
|
||||
if (document.getElementById('bltFile').files.length === 0) {
|
||||
return;
|
||||
@ -93,6 +97,7 @@ async function clickCount() {
|
||||
'type': 'countElection',
|
||||
'electionData': electionData,
|
||||
'optsStr': optsStr,
|
||||
'filePath': filePath
|
||||
'filePath': filePath,
|
||||
'numbers': document.getElementById('selNumbers').value,
|
||||
});
|
||||
}
|
||||
|
@ -10,36 +10,43 @@ initWasm();
|
||||
|
||||
onmessage = function(evt) {
|
||||
if (evt.data.type === 'countElection') {
|
||||
let numbers;
|
||||
if (evt.data.numbers === 'rational') {
|
||||
numbers = 'Rational';
|
||||
} else if (evt.data.numbers === 'float64') {
|
||||
numbers = 'NativeFloat64';
|
||||
}
|
||||
|
||||
// Init election
|
||||
let election = wasm.election_from_blt_Rational(evt.data.electionData);
|
||||
let election = wasm['election_from_blt_' + numbers](evt.data.electionData);
|
||||
|
||||
// Init results table
|
||||
postMessage({'type': 'initResultsTable', 'content': wasm.init_results_table_Rational(election)});
|
||||
postMessage({'type': 'initResultsTable', 'content': wasm['init_results_table_' + numbers](election)});
|
||||
|
||||
// Init STV options
|
||||
let opts = wasm.STVOptions.new.apply(null, evt.data.optsStr);
|
||||
|
||||
// Describe count
|
||||
postMessage({'type': 'describeCount', 'content': wasm.describe_count_Rational(evt.data.filePath, election, opts)});
|
||||
postMessage({'type': 'describeCount', 'content': wasm['describe_count_' + numbers](evt.data.filePath, election, opts)});
|
||||
|
||||
// Step election
|
||||
let state = wasm.CountStateRational.new(election);
|
||||
wasm.count_init_Rational(state, opts);
|
||||
let state = wasm['CountState' + numbers].new(election);
|
||||
wasm['count_init_' + numbers](state, opts);
|
||||
|
||||
postMessage({'type': 'updateResultsTable', 'result': wasm.update_results_table_Rational(1, state, opts)});
|
||||
postMessage({'type': 'updateStageComments', 'comment': wasm.update_stage_comments_Rational(state)});
|
||||
postMessage({'type': 'updateResultsTable', 'result': wasm['update_results_table_' + numbers](1, state, opts)});
|
||||
postMessage({'type': 'updateStageComments', 'comment': wasm['update_stage_comments_' + numbers](state)});
|
||||
|
||||
for (let stageNum = 2;; stageNum++) {
|
||||
let isDone = wasm.count_one_stage_Rational(state, opts);
|
||||
let isDone = wasm['count_one_stage_' + numbers](state, opts);
|
||||
if (isDone) {
|
||||
break;
|
||||
}
|
||||
|
||||
postMessage({'type': 'updateResultsTable', 'result': wasm.update_results_table_Rational(stageNum, state, opts)});
|
||||
postMessage({'type': 'updateStageComments', 'comment': wasm.update_stage_comments_Rational(state)});
|
||||
postMessage({'type': 'updateResultsTable', 'result': wasm['update_results_table_' + numbers](stageNum, state, opts)});
|
||||
postMessage({'type': 'updateStageComments', 'comment': wasm['update_stage_comments_' + numbers](state)});
|
||||
}
|
||||
|
||||
postMessage({'type': 'updateResultsTable', 'result': wasm.finalise_results_table_Rational(state)});
|
||||
postMessage({'type': 'finalResultSummary', 'summary': wasm.final_result_summary_Rational(state)});
|
||||
postMessage({'type': 'updateResultsTable', 'result': wasm['finalise_results_table_' + numbers](state)});
|
||||
postMessage({'type': 'finalResultSummary', 'summary': wasm['final_result_summary_' + numbers](state)});
|
||||
}
|
||||
}
|
||||
|
@ -208,9 +208,7 @@ impl ops::SubAssign<&NativeFloat64> for NativeFloat64 {
|
||||
}
|
||||
|
||||
impl ops::MulAssign<&NativeFloat64> for NativeFloat64 {
|
||||
fn mul_assign(&mut self, _rhs: &NativeFloat64) {
|
||||
todo!()
|
||||
}
|
||||
fn mul_assign(&mut self, rhs: &NativeFloat64) { self.0 *= &rhs.0 }
|
||||
}
|
||||
|
||||
impl ops::DivAssign<&NativeFloat64> for NativeFloat64 {
|
||||
|
Loading…
Reference in New Issue
Block a user