diff --git a/js/store.js b/js/store.js index 1d4fa3b..23ec9cc 100644 --- a/js/store.js +++ b/js/store.js @@ -77,12 +77,29 @@ 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)=> { /** @type {Store.Context} */ - const output = { Test:inTest??inState.Live.Test }; + const output = { Test:inTest??inState.Live.Test, Mark:{User:undefined} }; const column = ColumnMapping[inState.Freq.Value]; if(column && output.Test) { @@ -93,7 +110,8 @@ const Reselect =(inState, inTest)=> if(plot.Hz == hz) { output.Freq = plot; - output.Mark = inState.Chan.Value ? plot.UserR : plot.UserL; + output.Mark.User = inState.Chan.Value ? plot.UserR : plot.UserL; + output.Mark.Test = inState.Chan.Value ? plot.TestR : plot.TestL; break; } } @@ -179,8 +197,8 @@ export function Reducer(inState, inAction) if(clone.Live.Test && clone.Live.Freq) { const key = clone.Chan.Value == 0 ? "UserL" : "UserR"; - clone.Live.Mark = Data !== null ? {Stim:clone.Stim.Value, Resp:Data} : undefined; - clone.Live.Freq[key] = clone.Live.Mark; + clone.Live.Mark.User = Data !== null ? {Stim:clone.Stim.Value, Resp:Data} : undefined; + clone.Live.Freq[key] = clone.Live.Mark.User; clone.Draw[key] = Redraw(clone.Live.Test, clone.Chan.Value, clone.Stim, true); clone.Live.Test.Done = Grade(clone.Live.Test); SaveTests(clone); @@ -227,6 +245,7 @@ export function Reducer(inState, inAction) clone.Show.Answer = Data; } + ErrorProbability(clone); SaveSettings(clone); return clone; @@ -328,7 +347,7 @@ export const Initial = Reducer( { Test: undefined, Freq: undefined, - Mark: undefined + Mark: {User: undefined} }, Draw: { diff --git a/js/ui.js b/js/ui.js index 19b36c1..525024b 100644 --- a/js/ui.js +++ b/js/ui.js @@ -5,8 +5,8 @@ import * as Tone from "./tone.js"; /** @typedef {({children, classes}:{children?:preact.ComponentChildren, classes?:string})=>preact.VNode} BasicElement */ -/** @type {({children, icon, light, disabled, inactive, onClick, classes}:{children:preact.VNode, icon?:preact.VNode, light:boolean, disabled:boolean, inactive:boolean, onClick:()=>void, classes?:string})=>preact.VNode} */ -export function Button({children, icon, light, disabled, inactive, onClick, classes}) +/** @type {({children, icon, light, disabled, inactive, onClick, classes, classesActive}:{children:preact.VNode, icon?:preact.VNode, light:boolean, disabled:boolean, inactive:boolean, onClick:()=>void, classes?:string, classesActive?:string})=>preact.VNode} */ +export function Button({children, icon, light, disabled, inactive, onClick, classes, classesActive}) { const [FlashGet, FlashSet] = React.useState(0); const handleClick =()=> @@ -19,7 +19,7 @@ export function Button({children, icon, light, disabled, inactive, onClick, clas return html`