Skip to content

Commit

Permalink
Reverted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sarithapillai8 committed Dec 3, 2024
1 parent 6df1bef commit 2107dd7
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 98 deletions.
107 changes: 55 additions & 52 deletions src/components/ActivityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,43 @@ 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(
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")
Expand Down Expand Up @@ -190,27 +191,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 @@ -235,7 +238,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 @@ -245,7 +248,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
11 changes: 3 additions & 8 deletions src/components/EmbeddedActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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 Expand Up @@ -202,13 +204,6 @@ export default function EmbeddedActivity({ participant, activity, name, onComple
const exist = localStorage.getItem("first-time-" + (participant?.id ?? participant) + "-" + currentActivity?.id)
try {
setSaved(false)
console.log({
...settings,
activity: currentActivity,
configuration: { language: i18n.language },
autoCorrect: !(exist === "true"),
noBack: noBack,
})
setSettings({
...settings,
activity: currentActivity,
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
67 changes: 37 additions & 30 deletions src/components/PreventSelectedActivities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,40 @@ 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 ?? [])
// .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.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) {
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.replace(/\"/g, "")) || 0
})
.reduce((prev, curr) => prev + curr, 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.spin_wheel": (slices, activity, scopedItem) => slices[slices.length - 1]?.type ?? 0,
"lamp.jewels_a": (slices, activity, scopedItem) =>
slices.score == "NaN"
Expand Down Expand Up @@ -255,7 +261,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 Expand Up @@ -499,7 +505,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: 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
75 changes: 74 additions & 1 deletion src/components/Researcher/ActivityList/ActivityMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,59 @@ export const SchemaList = () => {
},
},
},
"lamp.simple_memory": {
"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 1"),
type: "number",
enum: [10, 12],
enumNames: [i18n.t("10"), i18n.t("12")],
"ui:grid": {
xs: 4,
},
},
level2_dot_count: {
title: i18n.t("Number of dots for Level 2"),
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.funny_memory": {
type: "object",
properties: {
settings: {
Expand Down Expand Up @@ -1033,6 +1085,7 @@ export const SchemaList = () => {
"ui:widget": "file",
"ui:options": {
accept: ".gif,.jpg,.png,.svg",
maxSize: 4000,
},
},
emotionText: {
Expand All @@ -1050,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 @@ -158,7 +158,9 @@ 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.trails_b": `${t("Trails B")}`,
"lamp.voice_survey": `${t("Speech Recording")}`,
}

const getActivitySpec = async (id) => {
Expand Down
Loading

0 comments on commit 2107dd7

Please sign in to comment.