Skip to content

Commit

Permalink
Merge pull request #844 from BIDMCDigitalPsychiatry/portal-update
Browse files Browse the repository at this point in the history
QA fixes and fixes for #857
  • Loading branch information
sarithapillai8 authored Dec 2, 2024
2 parents c228275 + 8a24028 commit 791c195
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 59 deletions.
107 changes: 56 additions & 51 deletions src/components/ActivityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,45 @@ export default function ActivityCard({
let each = Object.values(
events
.map((d) =>
d.temporal_slices.map((t, index) => ({
item:
activity.spec === "lamp.symbol_digit_substitution"
? d.temporal_slices.length > index + 1
? "Digit " + (index + 1) + " : " + t.type
: t.type
: activity.spec === "lamp.maze_game"
? t.level
: t.item,
[new Date(d.timestamp).toLocaleString("en-US", Date.formatStyle("medium"))]:
activity.spec === "lamp.maze_game"
? t.duration
: activity.spec === "lamp.survey" ||
activity.spec === "lamp.pop_the_bubbles" ||
activity.spec === "lamp.symbol_digit_substitution"
? typeof t.value === "string" && t.value !== null
? typeof t.value === "string" && ["Yes", "True"].includes(t.value.replace(/\"/g, ""))
? 1
: typeof t.value === "string" && ["No", "False"].includes(t.value.replace(/\"/g, ""))
? 0
: !isNaN(Number(t.value.replace(/\"/g, "")))
? Number(t.value.replace(/\"/g, ""))
d.temporal_slices
.filter((t) => t.type != "manual_exit")
.map((t, index) => ({
item:
activity.spec === "lamp.symbol_digit_substitution"
? d.temporal_slices.length > index + 1
? "Digit " + (index + 1) + " : " + t.type
: t.type
: activity.spec === "lamp.maze_game"
? t.level
: t.item,
[new Date(d.timestamp).toLocaleString("en-US", Date.formatStyle("medium"))]:
activity.spec === "lamp.maze_game"
? t.duration
: activity.spec === "lamp.survey" ||
activity.spec === "lamp.pop_the_bubbles" ||
activity.spec === "lamp.symbol_digit_substitution"
? typeof t.value === "string" && t.value !== null
? typeof t.value === "string" && ["Yes", "True"].includes(t.value.replace(/\"/g, ""))
? 1
: typeof t.value === "string" && ["No", "False"].includes(t.value.replace(/\"/g, ""))
? 0
: !isNaN(Number(t.value.replace(/\"/g, "")))
? Number(t.value.replace(/\"/g, ""))
: t.value
: t.value
: t.value
: activity.spec === "lamp.spin_wheel" || activity.spec === "lamp.emotion_recognition"
? t.type
: !!t.type
? 1
: 0,
}))
: activity.spec === "lamp.spin_wheel" || activity.spec === "lamp.emotion_recognition"
? t.type
: !!t.type
? 1
: 0,
}))
)
.reduce((x, y) => x.concat(y), [])
.groupBy("item")
)
.map((v: any) => Object.assign({}, ...v))
.reduce((x, y) => x.concat(y), [])
console.log(each)
let eachData = []
each = each.map((d, key) => {
let keys = Object.keys(d)
Expand Down Expand Up @@ -189,27 +192,29 @@ export default function ActivityCard({
value={Object.values(
events
.map((d) =>
d.temporal_slices.map((t, index) => ({
item: activity.spec === "lamp.maze_game" ? t.level : t.item,
[new Date(d.timestamp).toLocaleString("en-US", Date.formatStyle("medium"))]:
activity.spec === "lamp.maze_game"
? t.duration
: activity.spec === "lamp.survey" || activity.spec === "lamp.pop_the_bubbles"
? typeof t.value === "string" && t.value !== null
? typeof t.value === "string" && ["Yes", "True"].includes(t.value.replace(/\"/g, ""))
? 1
: typeof t.value === "string" && ["No", "False"].includes(t.value.replace(/\"/g, ""))
? 0
: !isNaN(Number(t.value.replace(/\"/g, "")))
? Number(t.value.replace(/\"/g, ""))
d.temporal_slices
.filter((t) => t.type != "manual_exit")
.map((t, index) => ({
item: activity.spec === "lamp.maze_game" ? t.level : t.item,
[new Date(d.timestamp).toLocaleString("en-US", Date.formatStyle("medium"))]:
activity.spec === "lamp.maze_game"
? t.duration
: activity.spec === "lamp.survey" || activity.spec === "lamp.pop_the_bubbles"
? typeof t.value === "string" && t.value !== null
? typeof t.value === "string" && ["Yes", "True"].includes(t.value.replace(/\"/g, ""))
? 1
: typeof t.value === "string" && ["No", "False"].includes(t.value.replace(/\"/g, ""))
? 0
: !isNaN(Number(t.value.replace(/\"/g, "")))
? Number(t.value.replace(/\"/g, ""))
: t.value
: t.value
: t.value
: activity.spec === "lamp.spin_wheel" || activity.spec === "lamp.emotion_recognition"
? t.type
: !!t.type
? 1
: 0,
}))
: activity.spec === "lamp.spin_wheel" || activity.spec === "lamp.emotion_recognition"
? t.type
: !!t.type
? 1
: 0,
}))
)
.reduce((x, y) => x.concat(y), [])
.groupBy("item")
Expand All @@ -234,7 +239,7 @@ export default function ActivityCard({
activity.spec === "lamp.spin_wheel" ||
activity.spec === "lamp.pop_the_bubbles" ||
activity.spec === "lamp.maze_game"
? d.temporal_slices
? d.temporal_slices.filter((t) => t.type != "manual_exit")
: activity.spec === "lamp.scratch_image" ||
activity.spec === "lamp.breathe" ||
activity.spec === "lamp.tips"
Expand All @@ -244,7 +249,7 @@ export default function ActivityCard({
undefined
)
: 0,
slice: d.temporal_slices,
slice: d.temporal_slices.filter((t) => t.type != "manual_exit"),
missing:
activity.spec === "lamp.survey" ||
activity.spec === "lamp.pop_the_bubbles" ||
Expand Down
4 changes: 3 additions & 1 deletion src/components/ParticipantData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ export default function ParticipantData({
<Typography variant="subtitle2" color="primary">
{((activityEvents || {})[x.name] || []).slice(-1).length > 0
? strategies["lamp.survey"](
((activityEvents || {})[x.name] || []).slice(-1)?.[0]?.temporal_slices,
((activityEvents || {})[x.name] || [])
.slice(-1)?.[0]
?.temporal_slices.filter((t) => t.type != "manual_exit"),
x,
undefined
)
Expand Down
16 changes: 11 additions & 5 deletions src/components/PreventSelectedActivities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,14 @@ export const strategies = {
.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") {
return ["Yes", "True"].includes(x.value)
? 1
: ["No", "False"].includes(x.value)
? 0
: Number(x.value.replace(/\"/g, "")) || 0
else if (!!question && !!!question.options)
return Math.max((question.options || []).indexOf(x.value.replace(/\"/g, "")), 0)
else if (typeof x?.value.replace(/\"/g, "") !== "number" && typeof x?.value.replace(/\"/g, "") !== "string") {
let sum = 0
Object.keys(x.value || []).map((val) => {
if (!!x.value[val]?.value && x.value[val]?.value.length > 0) {
Expand All @@ -208,7 +213,7 @@ export const strategies = {
}
})
return sum
} else return Number(x?.value) || 0
} else return Number(x?.value.replace(/\"/g, "")) || 0
})
.reduce((prev, curr) => prev + curr, 0),

Expand Down Expand Up @@ -499,7 +504,8 @@ export default function PreventSelectedActivities({
activity.spec === "lamp.pop_the_bubbles" ||
activity.spec === "lamp.maze_game" ||
activity.spec === "lamp.emotion_recognition"
? d?.temporal_slices ?? d["temporal_slices"]
? d?.temporal_slices.filter((t) => t.type != "manual_exit") ??
d["temporal_slices"].filter((t) => t.type != "manual_exit")
: activity.spec === "lamp.scratch_image" ||
activity.spec === "lamp.breathe" ||
activity.spec === "lamp.tips"
Expand Down
4 changes: 2 additions & 2 deletions src/components/Researcher/ActivityList/ActivityMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export const SchemaList = () => {
required: ["level1dot_count", "level2_dot_count", "level1_timeout", "level2_timeout"],
properties: {
level1dot_count: {
title: i18n.t("Number of dots for Level"),
title: i18n.t("Number of dots for Level 1"),
type: "number",
enum: [10, 12],
enumNames: [i18n.t("10"), i18n.t("12")],
Expand All @@ -294,7 +294,7 @@ export const SchemaList = () => {
},
},
level2_dot_count: {
title: i18n.t("Number of Learning trials"),
title: i18n.t("Number of dots for Level 2"),
type: "number",
enum: [20, 24],
enumNames: [i18n.t("20"), i18n.t("24")],
Expand Down

0 comments on commit 791c195

Please sign in to comment.