Skip to content

Commit

Permalink
Merge pull request #843 from BIDMCDigitalPsychiatry/portal-update
Browse files Browse the repository at this point in the history
 D-cog, funny memory, trails B and speech recording
  • Loading branch information
sarithapillai8 authored Nov 29, 2024
2 parents 615fe9f + 14bb0b0 commit c228275
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 48 deletions.
1 change: 0 additions & 1 deletion src/components/ActivityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default function ActivityCard({
const [helpAnchor, setHelpAnchor] = useState<Element>()
const [showGrid, setShowGrid] = useState<boolean>(forceDefaultGrid || Boolean(freeText.length))
const { t } = useTranslation()

const selectedActivity = activity
events.sort((a, b) => a.timestamp - b.timestamp)
let each = Object.values(
Expand Down
4 changes: 3 additions & 1 deletion src/components/EmbeddedActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const demoActivities = {
"lamp.symbol_digit_substitution": "symbol_digit_substitution",
"lamp.gyroscope": "gyroscope",
"lamp.dcog": "d-cog",
"lamp.simple_memory": "funnymemory",
"lamp.funny_memory": "funnymemory",
"lamp.trails_b": "dottouch",
"lamp.voice_survey": "speech",
}

export default function EmbeddedActivity({ participant, activity, name, onComplete, noBack, tab, ...props }) {
Expand Down
24 changes: 11 additions & 13 deletions src/components/Participant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,17 @@ export default function Participant({

useEffect(() => {
setLoading(true)
LAMP.Activity.allByParticipant(participant.id, null, !(LAMP.Auth._auth.serverAddress === "demo.lamp.digital")).then(
(activities) => {
setActivities(activities)
props.activeTab(tab, participant.id)
let language = !!localStorage.getItem("LAMP_user_" + participant.id)
? JSON.parse(localStorage.getItem("LAMP_user_" + participant.id)).language
: getSelectedLanguage()
? getSelectedLanguage()
: "en-US"
i18n.changeLanguage(language)
// getShowWelcome(participant).then(setOpen)
}
)
LAMP.Activity.allByParticipant(participant.id, null).then((activities) => {
setActivities(activities)
props.activeTab(tab, participant.id)
let language = !!localStorage.getItem("LAMP_user_" + participant.id)
? JSON.parse(localStorage.getItem("LAMP_user_" + participant.id)).language
: getSelectedLanguage()
? getSelectedLanguage()
: "en-US"
i18n.changeLanguage(language)
// getShowWelcome(participant).then(setOpen)
})
getHiddenEvents(participant).then(setHiddenEvents)
tempHideCareTeam(participant).then(setHideCareTeam)
}, [])
Expand Down
58 changes: 31 additions & 27 deletions src/components/PreventSelectedActivities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,33 +186,31 @@ const useStyles = makeStyles((theme: Theme) =>

export const strategies = {
"lamp.survey": (slices, activity, scopedItem) =>
(slices || []).map((x) => x.duration).reduce((prev, cur) => prev + cur, 0) / slices.length / 1000,
// (slices || []).map((x) => x.duration).reduce((prev, cur) => prev + cur, 0) / slices.length / 1000,

// (slices ?? [])
// .filter((x, idx) => (scopedItem !== undefined ? idx === scopedItem : true))
// .map((x, idx) => {
// console.log(slices)

// let question = (Array.isArray(activity.settings) ? activity.settings : []).filter((y) => y.text === x.item)[0]
// if (!!question && typeof x?.value !== "undefined")
// return ["Yes", "True"].includes(x.value) ? 1 : ["No", "False"].includes(x.value) ? 0 : Number(x.value) || 0
// else if (!!question && !!!question.options) return Math.max((question.options || []).indexOf(x.value), 0)
// else if (typeof x?.value !== "number" && typeof x?.value !== "string") {
// let sum = 0
// Object.keys(x.value || []).map((val) => {
// if (!!x.value[val]?.value && x.value[val]?.value.length > 0) {
// sum += (x.value[val]?.value || [])
// .map((elt) => {
// // assure the value can be converted into an integer
// return !isNaN(Number(elt)) ? Number(elt) : 0
// })
// .reduce((sum, current) => sum + current)
// }
// })
// return sum
// } else return Number(x?.value) || 0
// })
// .reduce((prev, curr) => prev + curr, 0),
(slices ?? [])
.filter((x, idx) => (scopedItem !== undefined ? idx === scopedItem : true))
.map((x, idx) => {
let question = (Array.isArray(activity.settings) ? activity.settings : []).filter((y) => y.text === x.item)[0]
if (!!question && typeof x?.value !== "undefined")
return ["Yes", "True"].includes(x.value) ? 1 : ["No", "False"].includes(x.value) ? 0 : Number(x.value) || 0
else if (!!question && !!!question.options) return Math.max((question.options || []).indexOf(x.value), 0)
else if (typeof x?.value !== "number" && typeof x?.value !== "string") {
let sum = 0
Object.keys(x.value || []).map((val) => {
if (!!x.value[val]?.value && x.value[val]?.value.length > 0) {
sum += (x.value[val]?.value || [])
.map((elt) => {
// assure the value can be converted into an integer
return !isNaN(Number(elt)) ? Number(elt) : 0
})
.reduce((sum, current) => sum + current)
}
})
return sum
} else return Number(x?.value) || 0
})
.reduce((prev, curr) => prev + curr, 0),

"lamp.spin_wheel": (slices, activity, scopedItem) => slices[slices.length - 1]?.type ?? 0,
"lamp.jewels_a": (slices, activity, scopedItem) =>
Expand All @@ -221,6 +219,12 @@ export const strategies = {
: (parseInt(slices.score ?? 0).toFixed(1) || 0) > 100
? 100
: parseInt(slices.score ?? 0).toFixed(1) || 0,
"lamp.trails_b": (slices, activity, scopedItem) =>
slices.score == "NaN"
? 0
: (parseInt(slices.score ?? 0).toFixed(1) || 0) > 100
? 100
: parseInt(slices.score ?? 0).toFixed(1) || 0,
"lamp.jewels_b": (slices, activity, scopedItem) =>
slices.score == "NaN"
? 0
Expand Down Expand Up @@ -254,7 +258,7 @@ export const strategies = {
},
"lamp.cats_and_dogs": (slices, activity, scopedItem) => (slices.correct_answers / slices.total_questions) * 100,
"lamp.memory_game": (slices, activity, scopedItem) => (slices.correct_answers / slices.total_questions) * 100,
"lamp.simple_memory": (slices, activity, scopedItem) =>
"lamp.funny_memory": (slices, activity, scopedItem) =>
(slices.number_of_correct_pairs_recalled / slices.number_of_total_pairs) * 100,
"lamp.scratch_image": (slices, activity, scopedItem) =>
((parseInt(slices?.duration ?? 0) / 1000).toFixed(1) || 0) > 100
Expand Down
4 changes: 3 additions & 1 deletion src/components/Researcher/ActivityList/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const games = [
"lamp.symbol_digit_substitution",
"lamp.gyroscope",
"lamp.dcog",
"lamp.simple_memory",
"lamp.funny_memory",
"lamp.trails_b",
"lamp.voice_survey",
]

const useStyles = makeStyles((theme: Theme) =>
Expand Down
74 changes: 73 additions & 1 deletion src/components/Researcher/ActivityList/ActivityMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const SchemaList = () => {
},
},
},
"lamp.simple_memory": {
"lamp.funny_memory": {
type: "object",
properties: {
settings: {
Expand Down Expand Up @@ -276,6 +276,58 @@ export const SchemaList = () => {
},
},
},
"lamp.trails_b": {
type: "object",
properties: {
settings: {
title: i18n.t("Activity Settings"),
type: "object",
required: ["level1dot_count", "level2_dot_count", "level1_timeout", "level2_timeout"],
properties: {
level1dot_count: {
title: i18n.t("Number of dots for Level"),
type: "number",
enum: [10, 12],
enumNames: [i18n.t("10"), i18n.t("12")],
"ui:grid": {
xs: 4,
},
},
level2_dot_count: {
title: i18n.t("Number of Learning trials"),
type: "number",
enum: [20, 24],
enumNames: [i18n.t("20"), i18n.t("24")],
"ui:grid": {
xs: 4,
},
},
level1_timeout: {
title: i18n.t("Timeout period for Level 1"),
description: i18n.t("Seconds"),
type: "number",
enum: [60, 90, 120],
enumNames: [i18n.t("60"), i18n.t("90"), i18n.t("120")],
default: 2,
"ui:grid": {
xs: 4,
},
},
level2_timeout: {
title: i18n.t("Timeout period for Level 2"),
description: i18n.t("Seconds"),
type: "number",
enum: [90, 120, 180],
enumNames: [i18n.t("90"), i18n.t("120"), i18n.t("180")],
default: 2,
"ui:grid": {
xs: 4,
},
},
},
},
},
},
"lamp.pop_the_bubbles": {
type: "object",
properties: {
Expand Down Expand Up @@ -1051,6 +1103,26 @@ export const SchemaList = () => {
},
},
},
"lamp.voice_survey": {
type: "object",
properties: {
settings: {
title: i18n.t("Activity settings"),
type: "array",
items: {
required: ["question"],
type: "object",
properties: {
question: {
title: i18n.t("Question"),
type: "string",
default: "",
},
},
},
},
},
},
"lamp.dbt_diary_card": {
type: "object",
properties: {
Expand Down
4 changes: 3 additions & 1 deletion src/components/Researcher/ActivityList/AddActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export default function AddActivity({
"lamp.cats_and_dogs": `${t("Cats and Dogs")}`,
"lamp.jewels_a": `${t("Jewels A")}`,
"lamp.jewels_b": `${t("Jewels B")}`,
"lamp.trails_b": `${t("Trails B")}`,
"lamp.spatial_span": `${t("Spatial Span")}`,
"lamp.pop_the_bubbles": `${t("Pop the bubbles")}`,
"lamp.balloon_risk": `${t("Balloon Risk")}`,
Expand All @@ -158,7 +159,8 @@ export default function AddActivity({
"lamp.emotion_recognition": `${t("Emotion Recognition")}`,
"lamp.symbol_digit_substitution": `${t("Symbol-digit Substitution")}`,
"lamp.dcog": `${t("D-Cog")}`,
"lamp.simple_memory": `${t("Funny Memory Game")}`,
"lamp.funny_memory": `${t("Funny Memory Game")}`,
"lamp.voice_survey": `${t("Speech Recording")}`,
}

const getActivitySpec = async (id) => {
Expand Down
6 changes: 4 additions & 2 deletions src/components/Researcher/ActivityList/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const availableActivitySpecs = [
"lamp.maze_game",
"lamp.emotion_recognition",
"lamp.symbol_digit_substitution",
"lamp.simple_memory",
"lamp.funny_memory",
]
export const games = [
"lamp.jewels_a",
Expand All @@ -75,7 +75,9 @@ export const games = [
"lamp.symbol_digit_substitution",
"lamp.gyroscope",
"lamp.dcog",
"lamp.simple_memory",
"lamp.funny_memory",
"lamp.trails_b",
"lamp.voice_survey",
]
export default function ActivityList({
researcherId,
Expand Down
4 changes: 3 additions & 1 deletion src/components/Survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const games = [
"lamp.symbol_digit_substitution",
"lamp.gyroscope",
"lamp.dcog",
"lamp.simple_memory",
"lamp.funny_memory",
"lamp.trails_b",
"lamp.voice_survey",
]

export default function Survey({ participant, activities, showStreak, ...props }) {
Expand Down

0 comments on commit c228275

Please sign in to comment.