From 3c1d10eabe7f268a2b9cfd911ef4d25d6fd73af5 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sun, 11 Dec 2022 14:56:43 -0500 Subject: [PATCH] scoring --- src/store.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/ui.js | 15 +++++++++++++++ store.d.ts | 6 ++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/store.js b/src/store.js index ac13cfe..9abf000 100644 --- a/src/store.js +++ b/src/store.js @@ -212,4 +212,55 @@ export const Provider =(props)=> }; /** @type {()=>Store.Binding} */ -export const Consumer =()=> React.useContext(Context); \ No newline at end of file +export const Consumer =()=> React.useContext(Context); + +/** @type {(inTest:Store.Test|undefined)=>Store.Grade} */ +export const Grade =(inTest)=> +{ + /** @type {Store.Grade} */ + const output = { Total:0, Done:0, Score:0 }; + + /** @type {(inGoal:number, inResult:number)=>number} */ + const Mapper =(inGoal, inResult)=> + { + const err = Math.abs(inGoal-inResult); + if(err == 0){ return 1; } + else if(err > 0 && err <= 5){ return 0.9; } + else if(err > 5 && err <= 10){ return 0.7; } + else if(err > 10 && err <= 15){ return 0.2; } + else{ return 0; } + } + + if(inTest) + { + for(let i=0; i 0) + { + output.Score = Math.floor((output.Score/output.Done) * 10000)/100; + } + + return output; +} \ No newline at end of file diff --git a/src/ui.js b/src/ui.js index ac715c2..1d33ac7 100644 --- a/src/ui.js +++ b/src/ui.js @@ -51,6 +51,20 @@ export const Select =()=> `; } +/** @type {BasicElement} */ +export const Grade =()=> +{ + const [State] = Store.Consumer(); + const grade = Store.Grade(State.Live.Test); + return html`
+
Complete: ${grade.Done} of ${grade.Total}
+
Accuracy: ${grade.Score}%
+
+
+
+
` +}; + /** @type {BasicElement} */ export const Controls =()=> { @@ -79,6 +93,7 @@ export const Controls =()=> }, [playGet]); return html` + <${Grade}/>
Channel
${State.Chan.Value}
diff --git a/store.d.ts b/store.d.ts index d433534..757cd6d 100644 --- a/store.d.ts +++ b/store.d.ts @@ -49,4 +49,10 @@ declare namespace Store { type DrawChart = { Cross?:DrawPoint, UserL: DrawGroup, UserR: DrawGroup, TestL: DrawGroup, TestR: DrawGroup }; type Binding = [state:State, dispatch:(inAction:Action)=>void] + + type Grade = { + Total:number, + Done:number, + Score:number + }; } \ No newline at end of file