From 0a815eafa92ee2b8337b0520240b8e86eadb29b3 Mon Sep 17 00:00:00 2001 From: Evert-R Date: Tue, 5 Nov 2024 08:14:18 +0100 Subject: [PATCH 1/6] Add timestamp for start of turn --- frontend/src/components/MatchingPairs/MatchingPairs.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/components/MatchingPairs/MatchingPairs.tsx b/frontend/src/components/MatchingPairs/MatchingPairs.tsx index 7e37ade79..ad81c8485 100644 --- a/frontend/src/components/MatchingPairs/MatchingPairs.tsx +++ b/frontend/src/components/MatchingPairs/MatchingPairs.tsx @@ -62,6 +62,8 @@ const MatchingPairs = ({ yPosition.current = posY; } + let startOfTurn = performance.now(); + // Show (animated) feedback after second click on second card or finished playing const showFeedback = (score: number) => { @@ -142,6 +144,7 @@ const MatchingPairs = ({ currentCard.noevents = true; currentCard.boardposition = index + 1; currentCard.timestamp = performance.now(); + currentCard.start_of_turn = startOfTurn; // reset response interval in case this card has a value from a previous turn currentCard.response_interval_ms = ''; // clear feedback text @@ -152,6 +155,7 @@ const MatchingPairs = ({ }; const finishTurn = () => { + startOfTurn = performance.now(); finishedPlaying(); // remove matched cards from the board if (score === 10 || score === 20) { From 0074e8ae54904eb51487c5bbb8056d8e4966bb2f Mon Sep 17 00:00:00 2001 From: Evert-R Date: Tue, 5 Nov 2024 12:30:38 +0100 Subject: [PATCH 2/6] use state for start_of_turn --- frontend/src/components/MatchingPairs/MatchingPairs.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/MatchingPairs/MatchingPairs.tsx b/frontend/src/components/MatchingPairs/MatchingPairs.tsx index ad81c8485..6583d2ce9 100644 --- a/frontend/src/components/MatchingPairs/MatchingPairs.tsx +++ b/frontend/src/components/MatchingPairs/MatchingPairs.tsx @@ -50,6 +50,7 @@ const MatchingPairs = ({ const [inBetweenTurns, setInBetweenTurns] = useState(false); const [score, setScore] = useState(null); const [total, setTotal] = useState(bonusPoints); + const [startOfTurn, setStartOfTurn] = useState(performance.now()); const columnCount = sections.length > 6 ? 4 : 3; @@ -62,8 +63,6 @@ const MatchingPairs = ({ yPosition.current = posY; } - let startOfTurn = performance.now(); - // Show (animated) feedback after second click on second card or finished playing const showFeedback = (score: number) => { @@ -126,7 +125,7 @@ const MatchingPairs = ({ const first_card = firstCard; const second_card = currentCard; try { - const scoreResponse = await scoreIntermediateResult({ session, participant, result: { first_card, second_card } }); + const scoreResponse = await scoreIntermediateResult({ session, participant, result: { "start_timestamp": StartOfTurn, first_card, second_card } }); if (!scoreResponse) { throw new Error('We cannot currently proceed with the game. Try again later'); } @@ -143,7 +142,7 @@ const MatchingPairs = ({ currentCard.turned = true; currentCard.noevents = true; currentCard.boardposition = index + 1; - currentCard.timestamp = performance.now(); + setStartOfTurn(performance.now()); currentCard.start_of_turn = startOfTurn; // reset response interval in case this card has a value from a previous turn currentCard.response_interval_ms = ''; From e327325551cc3a4f845749359e6cbfd378eb753d Mon Sep 17 00:00:00 2001 From: Evert-R Date: Tue, 5 Nov 2024 14:18:12 +0100 Subject: [PATCH 3/6] Log start_timestamp in result's json_data --- frontend/src/components/MatchingPairs/MatchingPairs.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/MatchingPairs/MatchingPairs.tsx b/frontend/src/components/MatchingPairs/MatchingPairs.tsx index 6583d2ce9..70f4d3c67 100644 --- a/frontend/src/components/MatchingPairs/MatchingPairs.tsx +++ b/frontend/src/components/MatchingPairs/MatchingPairs.tsx @@ -125,7 +125,7 @@ const MatchingPairs = ({ const first_card = firstCard; const second_card = currentCard; try { - const scoreResponse = await scoreIntermediateResult({ session, participant, result: { "start_timestamp": StartOfTurn, first_card, second_card } }); + const scoreResponse = await scoreIntermediateResult({ session, participant, result: { "start_timestamp": startOfTurn, first_card, second_card } }); if (!scoreResponse) { throw new Error('We cannot currently proceed with the game. Try again later'); } @@ -154,7 +154,7 @@ const MatchingPairs = ({ }; const finishTurn = () => { - startOfTurn = performance.now(); + setStartOfTurn(performance.now()); finishedPlaying(); // remove matched cards from the board if (score === 10 || score === 20) { From bd48456cad39c9f99a85e339472636fdd66daf82 Mon Sep 17 00:00:00 2001 From: Evert-R Date: Thu, 7 Nov 2024 08:35:09 +0100 Subject: [PATCH 4/6] remove response_interval, rename start_of_turn --- frontend/src/components/MatchingPairs/MatchingPairs.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/frontend/src/components/MatchingPairs/MatchingPairs.tsx b/frontend/src/components/MatchingPairs/MatchingPairs.tsx index 70f4d3c67..4a24a0fa1 100644 --- a/frontend/src/components/MatchingPairs/MatchingPairs.tsx +++ b/frontend/src/components/MatchingPairs/MatchingPairs.tsx @@ -118,14 +118,11 @@ const MatchingPairs = ({ currentCard.boardposition = index + 1; currentCard.timestamp = performance.now(); - const firstCardTimestamp = firstCard?.timestamp ?? 0; - currentCard.response_interval_ms = Math.round(currentCard.timestamp - firstCardTimestamp); - // check for match const first_card = firstCard; const second_card = currentCard; try { - const scoreResponse = await scoreIntermediateResult({ session, participant, result: { "start_timestamp": startOfTurn, first_card, second_card } }); + const scoreResponse = await scoreIntermediateResult({ session, participant, result: { "start_of_turn": startOfTurn, first_card, second_card } }); if (!scoreResponse) { throw new Error('We cannot currently proceed with the game. Try again later'); } @@ -142,10 +139,7 @@ const MatchingPairs = ({ currentCard.turned = true; currentCard.noevents = true; currentCard.boardposition = index + 1; - setStartOfTurn(performance.now()); currentCard.start_of_turn = startOfTurn; - // reset response interval in case this card has a value from a previous turn - currentCard.response_interval_ms = ''; // clear feedback text setFeedbackText(''); } From 89f038431148c90c4dd78e58f4d6e37a5687da7b Mon Sep 17 00:00:00 2001 From: Evert-R Date: Thu, 7 Nov 2024 08:38:23 +0100 Subject: [PATCH 5/6] remove start_of_turn from card result --- frontend/src/components/MatchingPairs/MatchingPairs.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/MatchingPairs/MatchingPairs.tsx b/frontend/src/components/MatchingPairs/MatchingPairs.tsx index 4a24a0fa1..44c4048ec 100644 --- a/frontend/src/components/MatchingPairs/MatchingPairs.tsx +++ b/frontend/src/components/MatchingPairs/MatchingPairs.tsx @@ -139,7 +139,6 @@ const MatchingPairs = ({ currentCard.turned = true; currentCard.noevents = true; currentCard.boardposition = index + 1; - currentCard.start_of_turn = startOfTurn; // clear feedback text setFeedbackText(''); } From c62edc5669b035b7987ebc2819a178c5c2c79ab0 Mon Sep 17 00:00:00 2001 From: Evert-R Date: Thu, 7 Nov 2024 08:44:16 +0100 Subject: [PATCH 6/6] bring back timestamp on first card --- frontend/src/components/MatchingPairs/MatchingPairs.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/components/MatchingPairs/MatchingPairs.tsx b/frontend/src/components/MatchingPairs/MatchingPairs.tsx index 44c4048ec..53e99e8a9 100644 --- a/frontend/src/components/MatchingPairs/MatchingPairs.tsx +++ b/frontend/src/components/MatchingPairs/MatchingPairs.tsx @@ -139,6 +139,7 @@ const MatchingPairs = ({ currentCard.turned = true; currentCard.noevents = true; currentCard.boardposition = index + 1; + currentCard.timestamp = performance.now(); // clear feedback text setFeedbackText(''); }