Skip to content

Commit

Permalink
Merge pull request #1350 from Amsterdam-Music-Lab/feature-er/add-time…
Browse files Browse the repository at this point in the history
…stamps-matching-pairs

Add timestamp for start of turn
  • Loading branch information
Evert-R authored Nov 7, 2024
2 parents 5650cf3 + c62edc5 commit 56ac741
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions frontend/src/components/MatchingPairs/MatchingPairs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const MatchingPairs = ({
const [inBetweenTurns, setInBetweenTurns] = useState(false);
const [score, setScore] = useState<number | null>(null);
const [total, setTotal] = useState(bonusPoints);
const [startOfTurn, setStartOfTurn] = useState(performance.now());

const columnCount = sections.length > 6 ? 4 : 3;

Expand Down Expand Up @@ -117,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: { 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');
}
Expand All @@ -142,8 +140,6 @@ const MatchingPairs = ({
currentCard.noevents = true;
currentCard.boardposition = index + 1;
currentCard.timestamp = performance.now();
// reset response interval in case this card has a value from a previous turn
currentCard.response_interval_ms = '';
// clear feedback text
setFeedbackText('');
}
Expand All @@ -152,6 +148,7 @@ const MatchingPairs = ({
};

const finishTurn = () => {
setStartOfTurn(performance.now());
finishedPlaying();
// remove matched cards from the board
if (score === 10 || score === 20) {
Expand Down

0 comments on commit 56ac741

Please sign in to comment.