From 2858977e9dc05993596690213d0c0b55826687db Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Wed, 14 Jun 2023 22:53:59 -0400 Subject: [PATCH] move error calc into store --- js/store.js | 18 ++++++++++++++++++ js/ui.js | 17 +++-------------- ts/store.d.ts | 1 + 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/js/store.js b/js/store.js index 0f3269a..23ec9cc 100644 --- a/js/store.js +++ b/js/store.js @@ -77,6 +77,23 @@ export const Grade =(inTest)=> } + +const ErrorCol = + [30, 25, 20, 15, 10, 5, 0, -5, -10, -15 ] +const ErrorLUT = [ + [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00], + [0.00, 0.00, 0.00, 0.00, 0.10, 0.15, 0.10, 0.10, 0.00, 0.00], + [0.00, 0.00, 0.02, 0.05, 0.15, 0.20, 0.30, 0.15, 0.05, 0.00], + [0.00, 0.02, 0.05, 0.10, 0.20, 0.40, 0.60, 0.30, 0.05, 0.00] +]; +/** @type {(inState:Store.State)=>void} */ +const ErrorProbability =(inState)=> +{ + const miss = inState.Stim.Value - (inState.Live.Mark.Test?.Stim ?? inState.Stim.Value); + inState.Live.Mark.Errs = ErrorLUT[inState.Errs]?.[ErrorCol.indexOf(miss)] ?? 0; +} + + /** Creates a new Store.Context object that contain the current selections * @type {(inState:Store.State, inTest?:Store.Test)=>Store.Context} */ const Reselect =(inState, inTest)=> @@ -228,6 +245,7 @@ export function Reducer(inState, inAction) clone.Show.Answer = Data; } + ErrorProbability(clone); SaveSettings(clone); return clone; diff --git a/js/ui.js b/js/ui.js index 8ed01a0..525024b 100644 --- a/js/ui.js +++ b/js/ui.js @@ -96,17 +96,6 @@ export const Display =()=> }; -const ErrorCol = - [30, 25, 20, 15, 10, 5, 0, -5, -10, -15 ] -const ErrorLUT = [ - [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00], - [0.00, 0.00, 0.00, 0.00, 0.10, 0.15, 0.10, 0.10, 0.00, 0.00], - [0.00, 0.00, 0.02, 0.05, 0.15, 0.20, 0.30, 0.15, 0.05, 0.00], - [0.00, 0.02, 0.05, 0.10, 0.20, 0.40, 0.60, 0.30, 0.05, 0.00] -]; -/** @type {(inDelta:number, inPatentError:number)=>number} */ -const ErrorProbability =(inDelta, inPatentError)=> ErrorLUT[inPatentError]?.[ErrorCol.indexOf(inDelta)] ?? 0; - /** @type {BasicElement} */ export const Controls =()=> { @@ -125,10 +114,9 @@ export const Controls =()=> if(State.Live.Freq) { - const testMark = State.Live.Freq[/** @type {"TestL"|"TestR"}*/(`Test${State.Chan.Value ? "R":"L"}`)]; - const audible = State.Stim.Value >= testMark.Stim; + const audible = State.Stim.Value >= (State.Live.Mark.Test?.Stim??0); - const errorScaled = ErrorProbability(State.Stim.Value - testMark.Stim, State.Errs); + const errorScaled = State.Live.Mark.Errs; const errorSampled = Math.random() < errorScaled; const percieved = errorSampled ? !audible : audible; @@ -205,6 +193,7 @@ export const Controls =()=> +

Response${State.Live.Mark.Errs > 0 && ` (${State.Live.Mark.Errs*100}% Error Chance)` }:

diff --git a/ts/store.d.ts b/ts/store.d.ts index dda77a1..0d3f924 100644 --- a/ts/store.d.ts +++ b/ts/store.d.ts @@ -25,6 +25,7 @@ declare namespace Store { { User?: TestFrequencySample, Test?: TestFrequencySample, + Errs : number } };