-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh: incorporate disabling auth into ui
- Loading branch information
1 parent
8415ab0
commit 480fd45
Showing
10 changed files
with
1,287 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,130 @@ | ||
import { IEzbids, IEvents, IBIDSEvent } from './store' | ||
import { IEzbids, IEvents, IBIDSEvent } from './store'; | ||
import axios from './axios.instance'; | ||
//import { parseEvents } from './libUnsafe' | ||
|
||
export function createEventsTSV(ezbids: IEzbids, events: IEvents) { | ||
ezbids.objects.forEach(object => { | ||
object.items.filter(i => !!i.events).forEach(item => { | ||
function fixUnit(v: any, unit: any) { | ||
switch (unit) { | ||
case "ms": return v / 1000; | ||
case "us": return v / 1000000; | ||
default: | ||
return Number(v); | ||
} | ||
} | ||
|
||
item.eventsBIDS = []; | ||
|
||
//emit all values | ||
item.events.forEach((event: any) => { | ||
|
||
//compute onset | ||
let onset = null; | ||
switch (events.columns.onsetLogic) { | ||
case "add": | ||
// @ts-ignore | ||
onset = parseFloat(event[events.columns.onset]) + parseFloat(event[events.columns.onset2]); | ||
break; | ||
case "subtract": | ||
// @ts-ignore | ||
onset = parseFloat(event[events.columns.onset]) - parseFloat(event[events.columns.onset2]); | ||
break; | ||
default: | ||
// @ts-ignore | ||
onset = parseFloat(event[events.columns.onset]); | ||
} | ||
onset = fixUnit(onset, events.columns.onsetUnit); | ||
|
||
//compute duration | ||
let duration = null; | ||
switch (events.columns.durationLogic) { | ||
case "add": | ||
// @ts-ignore | ||
duration = parseFloat(event[events.columns.duration]) + parseFloat(event[events.columns.duration2]); | ||
break; | ||
case "subtract": | ||
// @ts-ignore | ||
duration = parseFloat(event[events.columns.duration]) - parseFloat(event[events.columns.duration2]); | ||
break; | ||
default: | ||
// @ts-ignore | ||
duration = parseFloat(event[events.columns.duration]); | ||
ezbids.objects.forEach((object) => { | ||
object.items | ||
.filter((i) => !!i.events) | ||
.forEach((item) => { | ||
function fixUnit(v: any, unit: any) { | ||
switch (unit) { | ||
case 'ms': | ||
return v / 1000; | ||
case 'us': | ||
return v / 1000000; | ||
default: | ||
return Number(v); | ||
} | ||
} | ||
duration = fixUnit(duration, events.columns.durationUnit); | ||
|
||
const rec: IBIDSEvent = { | ||
onset, | ||
duration, | ||
}; | ||
item.eventsBIDS = []; | ||
|
||
//rest is optional | ||
if (events.columns.sample) { | ||
switch (events.columns.sampleLogic) { | ||
case "add": | ||
//emit all values | ||
item.events.forEach((event: any) => { | ||
//compute onset | ||
let onset = null; | ||
switch (events.columns.onsetLogic) { | ||
case 'add': | ||
// @ts-ignore | ||
rec.sample = parseFloat(event[events.columns.sample]) + parseFloat(event[events.columns.sample2]); | ||
onset = parseFloat(event[events.columns.onset]) + parseFloat(event[events.columns.onset2]); | ||
break; | ||
case "subtract": | ||
case 'subtract': | ||
// @ts-ignore | ||
rec.sample = parseFloat(event[events.columns.sample]) - parseFloat(event[events.columns.sample2]); | ||
onset = parseFloat(event[events.columns.onset]) - parseFloat(event[events.columns.onset2]); | ||
break; | ||
default: | ||
rec.sample = parseFloat(event[events.columns.sample]); | ||
// @ts-ignore | ||
onset = parseFloat(event[events.columns.onset]); | ||
} | ||
} | ||
if (events.columns.responseTime) { | ||
let responseTime = null; | ||
switch (events.columns.responseTimeLogic) { | ||
case "add": | ||
onset = fixUnit(onset, events.columns.onsetUnit); | ||
|
||
//compute duration | ||
let duration = null; | ||
switch (events.columns.durationLogic) { | ||
case 'add': | ||
// @ts-ignore | ||
responseTime = parseFloat(event[events.columns.responseTime]) + parseFloat(event[events.columns.responseTime2]); | ||
duration = | ||
parseFloat(event[events.columns.duration]) + | ||
parseFloat(event[events.columns.duration2]); | ||
break; | ||
case "subtract": | ||
case 'subtract': | ||
// @ts-ignore | ||
responseTime = parseFloat(event[events.columns.responseTime]) - parseFloat(event[events.columns.responseTime2]); | ||
duration = | ||
parseFloat(event[events.columns.duration]) - | ||
parseFloat(event[events.columns.duration2]); | ||
break; | ||
default: | ||
// @ts-ignore | ||
responseTime = parseFloat(event[events.columns.responseTime]); | ||
duration = parseFloat(event[events.columns.duration]); | ||
} | ||
rec.response_time = fixUnit(responseTime, events.columns.responseTimeUnit); | ||
} | ||
duration = fixUnit(duration, events.columns.durationUnit); | ||
|
||
const rec: IBIDSEvent = { | ||
onset, | ||
duration, | ||
}; | ||
|
||
if (events.columns.trialType) rec.trial_type = event[events.columns.trialType]; | ||
if (events.columns.value) rec.value = event[events.columns.value]; | ||
if (events.columns.HED) rec.HED = event[events.columns.HED]; | ||
if (events.columns.stim_file) rec.stim_file = event[events.columns.stim_file]; | ||
//rest is optional | ||
if (events.columns.sample) { | ||
switch (events.columns.sampleLogic) { | ||
case 'add': | ||
// @ts-ignore | ||
rec.sample = | ||
parseFloat(event[events.columns.sample]) + | ||
parseFloat(event[events.columns.sample2]); | ||
break; | ||
case 'subtract': | ||
// @ts-ignore | ||
rec.sample = | ||
parseFloat(event[events.columns.sample]) - | ||
parseFloat(event[events.columns.sample2]); | ||
break; | ||
default: | ||
rec.sample = parseFloat(event[events.columns.sample]); | ||
} | ||
} | ||
if (events.columns.responseTime) { | ||
let responseTime = null; | ||
switch (events.columns.responseTimeLogic) { | ||
case 'add': | ||
// @ts-ignore | ||
responseTime = | ||
parseFloat(event[events.columns.responseTime]) + | ||
parseFloat(event[events.columns.responseTime2]); | ||
break; | ||
case 'subtract': | ||
// @ts-ignore | ||
responseTime = | ||
parseFloat(event[events.columns.responseTime]) - | ||
parseFloat(event[events.columns.responseTime2]); | ||
break; | ||
default: | ||
// @ts-ignore | ||
responseTime = parseFloat(event[events.columns.responseTime]); | ||
} | ||
rec.response_time = fixUnit(responseTime, events.columns.responseTimeUnit); | ||
} | ||
|
||
(item.eventsBIDS as IBIDSEvent[]).push(rec); | ||
if (events.columns.trialType) rec.trial_type = event[events.columns.trialType]; | ||
if (events.columns.value) rec.value = event[events.columns.value]; | ||
if (events.columns.HED) rec.HED = event[events.columns.HED]; | ||
if (events.columns.stim_file) rec.stim_file = event[events.columns.stim_file]; | ||
|
||
(item.eventsBIDS as IBIDSEvent[]).push(rec); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
export function hasAuth() { | ||
return import.meta.env.VITE_BRAINLIFE_AUTHENTICATION === 'true'; | ||
} | ||
|
||
export function hasJWT() { | ||
return !!retrieveJWT(); | ||
} | ||
|
||
export function retrieveJWT() { | ||
return localStorage.getItem('jwt') | ||
} | ||
return localStorage.getItem('jwt'); | ||
} |
Oops, something went wrong.