Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp for start of turn #1350

Merged
merged 7 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set this here and at line 145? Wouldn't it be enough to do it in one of those two places?

finishedPlaying();
// remove matched cards from the board
if (score === 10 || score === 20) {
Expand Down
Loading