From 3ff8960038701ac2941cb9597556e1dc1c448b94 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 3 Dec 2022 09:36:01 -0500 Subject: [PATCH] contiguous --- src/store.js | 80 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/src/store.js b/src/store.js index 172a45d..2f2ae58 100644 --- a/src/store.js +++ b/src/store.js @@ -1,6 +1,6 @@ //@ts-check -const size = 100/6; +const size = 1/6; /** @typedef {[frequency:number, position:number, normal:boolean]} ColumnMapping */ /** @type {Array} */ export const ColumnMapping = [ @@ -25,7 +25,10 @@ export const ColumnLookup =(inFrequency)=> return false; }; + + /** @typedef {{Min:number, Max:number}} Limit */ +/** @typedef {(inValue:number, inLimit:Limit)=>number} LimitUse */ /** @type {Record} */ export const ToneLimit = { @@ -33,21 +36,26 @@ export const ToneLimit = Stim: { Min: -10, Max: 120 }, Chan: { Min: 0, Max: 1}, }; -/** @type {(inValue:number, inLimit:Limit)=>number} */ -export const ApplyLimit =(inValue, inLimit)=> +/** @type {LimitUse} */ +export const LimitCut =(inValue, inLimit)=> { if(inValue < inLimit.Min){ return inLimit.Min; } else if(inValue > inLimit.Max) { return inLimit.Max; } else{ return inValue; } -} - -/** @typedef {(freq:TestFrequency, chan:number)=>TestFrequencySample|undefined} MarkLookup */ -/** @type {Record} */ -export const ChanMark = -{ - User: (freq, chan)=> chan == 0 ? freq.UserL : freq.UserR, - Test: (freq, chan)=> chan == 0 ? freq.TestL : freq.TestR }; +/** @type {LimitUse} */ +export const LimitMap =(inValue, inLimit)=>(inValue-inLimit.Min)/(inLimit.Max-inLimit.Min); + + + + +/** @type {(freq:TestFrequency, chan:number, user:boolean)=>TestFrequencySample|undefined} */ +export const MarkGet =(freq, chan, user)=> freq[/** @type {"UserL"|"UserR"|"TestL"|"TestR"} */ (`${user ? "User" : "Test"}${chan ? "R" : "L"}`)]; + +/** @type {(freq:TestFrequency, chan:number, mark:TestFrequencySample|undefined)=>TestFrequencySample|undefined} */ +export const MarkSet =(freq, chan, mark)=> freq[ chan ? "UserR" : "UserL" ] = mark; + + /** @typedef {{Stim:number, Resp:boolean}} TestFrequencySample */ @@ -114,12 +122,54 @@ const Update = const freq = inState.Live.Freq; if(freq) { - inState.Live.Mark = inState.Chan == 0 ? freq.UserL : freq.UserR; + inState.Live.Mark = MarkGet(freq, inState.Chan, true); return true; } return false; } }; + + +/** @type {(inTest:Test, inChannel:number, inIsUser:boolean)=>Array>} */ +function Congtiguous(inTest, inChannel, inIsUser) +{ + const segments = []; + let plot; + /** @type {Array<{x:number, y:number}>} */ + let segment = []; + let valid = false; + for(let i=0; i