Skip to content

Commit

Permalink
Merge pull request #420 from BIDMCDigitalPsychiatry/funny-memory
Browse files Browse the repository at this point in the history
Game updates
  • Loading branch information
sarithapillai8 authored Nov 20, 2024
2 parents e5af770 + cadf749 commit 28e4c1f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Emotion_Recognition/src/components/Emotions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Emotions = ({...props} : any) => {
}
else {
setError("")
props.handleLevelCompleted(selected, (new Date().getTime() - duration)/1000, text)
props.handleLevelCompleted(selected, (new Date().getTime() - duration), text)
}
}

Expand Down
75 changes: 29 additions & 46 deletions FunnyMemory/src/components/GameBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const GameBoard = ({ ...props }: any) => {
const [itemsIdentified, setItemsIdentified] = useState(0);
const [itemRecognized, setItemRecognized] = useState(0);
const [correctChoice, setCorrectChoice] = useState(0);

useEffect(() => {
if (trial === 0) {
setShowModalInfo(true);
Expand All @@ -71,11 +72,11 @@ const GameBoard = ({ ...props }: any) => {

const clickBack = () => {
const route = { type: "manual_exit", value: true };
routes.push(route);
routes.push(route);
parent.postMessage(
JSON.stringify({
timestamp: new Date().getTime(),
duration: (new Date().getTime() - startTime) / 1000,
duration: new Date().getTime() - startTime,
static_data: Object.assign(staticdata ?? {}, {
image_exposure_time: imageExposureTime,
learning_trials: numberOfTrials,
Expand All @@ -84,6 +85,7 @@ const GameBoard = ({ ...props }: any) => {
number_of_correct_items_recalled: itemsIdentified,
number_of_correct_recognized: itemRecognized,
number_of_correct_force_choice: correctChoice,
number_of_total_pairs : currentIndex + 1
}),
temporal_slices: JSON.parse(JSON.stringify(routes)),
}),
Expand Down Expand Up @@ -123,23 +125,23 @@ const GameBoard = ({ ...props }: any) => {
}
};

// const saveResult = (recorededText: any[]) => {
// let tempRoute: any = [];
// if (recorededText && recorededText.length > 0) {
// recorededText.map((word) => {
// const route = {
// duration: (new Date().getTime() - timeTaken) / 1000,
// item: currentIndex,
// level: phase,
// type: checkImageIdentified(word),
// value: word,
// };
// tempRoute.push(route);
// });
// }
// setRoutes(routes.concat(tempRoute));
const saveResult = (recorededText: any[]) => {
let tempRoute: any = [];
if (recorededText && recorededText.length > 0) {
recorededText.map((word) => {
const route = {
duration: new Date().getTime() - timeTaken,
item: currentIndex,
level: phase,
type: checkImageIdentified(word),
value: word,
};
tempRoute.push(route);
});
}
setRoutes(routes.concat(tempRoute));

// };
};

const handleRecall = (textArray: string[][]) => {
let tempRoute: any = [];
Expand All @@ -151,7 +153,7 @@ const GameBoard = ({ ...props }: any) => {
if (arr && arr.length > 0) {
replaceDuplicatesWithEmptyString(arr).map((word) => {
const route = {
duration: (new Date().getTime() - timeTaken) / 1000,
duration: new Date().getTime() - timeTaken,
item: null,
level: phase,
type: checkImageIdentified(word),
Expand Down Expand Up @@ -182,7 +184,7 @@ const GameBoard = ({ ...props }: any) => {

const handleRecognition1 = (text: string) => {
const route = {
duration: (new Date().getTime() - timeTaken) / 1000,
duration: new Date().getTime() - timeTaken,
item: randomNumberArray.current[currentIndex],
level: phase,
type:
Expand All @@ -209,16 +211,14 @@ const GameBoard = ({ ...props }: any) => {
};

const handleRecordComplete = (text: any[]) => {
saveResult(text);
setTimeTaken(new Date().getTime());
if (currentIndex < number_of_images_in_trial - 1) {
setCurrentIndex(currentIndex + 1);
setShowImage(true);
setShowAudioRecorder(false);
// if(!phase.includes("Trial")){
// saveResult(text);
// }
setShowAudioRecorder(false);
} else {
setShowAudioRecorder(false);
// saveResult(text);
if (trial === numberOfTrials && phase.includes("Trial")) {
setShowQuestions(true);
setPhase("questions");
Expand Down Expand Up @@ -251,26 +251,8 @@ const GameBoard = ({ ...props }: any) => {
setShowImage(true);
};

console.log("routes", routes);

const sendGameResult = () => {
console.log(
"result",
JSON.stringify({
duration: new Date().getTime() - startTime,
static_data: Object.assign(staticdata ?? {}, {
image_exposure_time: imageExposureTime,
learning_trials: numberOfTrials,
delay_time: delayBeforeRecall,
number_of_correct_pairs_recalled: pairsIdentified,
number_of_correct_items_recalled: itemsIdentified,
number_of_correct_recognized: itemRecognized,
number_of_correct_force_choice: correctChoice,
}),
temporal_slices: JSON.parse(JSON.stringify(routes)),
timestamp: new Date().getTime(),
})
);

const sendGameResult = () => {
parent.postMessage(
JSON.stringify({
duration: new Date().getTime() - startTime,
Expand All @@ -282,6 +264,7 @@ const GameBoard = ({ ...props }: any) => {
number_of_correct_items_recalled: itemsIdentified,
number_of_correct_recognized: itemRecognized,
number_of_correct_force_choice: correctChoice,
number_of_total_pairs : currentIndex + 1
}),
temporal_slices: JSON.parse(JSON.stringify(routes)),
timestamp: new Date().getTime(),
Expand All @@ -293,7 +276,7 @@ const GameBoard = ({ ...props }: any) => {

const handleImageSelection = (img: any) => {
const route = {
duration: (new Date().getTime() - timeTaken) / 1000,
duration: new Date().getTime() - timeTaken,
item: randomNumberArray.current[currentIndex],
level: phase,
type:
Expand Down
2 changes: 1 addition & 1 deletion Gyroscope/src/containers/GameComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export function GameComponent({ ...props }) {
}
setTimeout(() => {
const route = {
duration: Math.floor(new Date().getTime() - time) / 1000,
duration: new Date().getTime() - time ,
item: currentCount,
level: result,
type: angle,
Expand Down
2 changes: 1 addition & 1 deletion Gyroscope/src/containers/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Layout = ({...props} : any) =>{
if(levelCompleted){
setFooterMsg(i18n.t("YOU_WON"))
const route = {
"duration": timeTaken/1000,
"duration": timeTaken,
"item": circles,
"level": gameLevel,
"type": levelCompleted,
Expand Down

0 comments on commit 28e4c1f

Please sign in to comment.