Skip to content

Commit

Permalink
feat: Add overlay visibility tracking to MatchingPairs game logic
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Dec 13, 2024
1 parent ada6f1a commit 1f81a70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/experiment/rules/matching_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def calculate_intermediate_score(self, session, result):
second_card = result_data["second_card"]
second_section = Section.objects.get(pk=second_card["id"])
second_card["filename"] = str(second_section.filename)
overlay_was_shown = result_data["overlay_was_shown"]
if first_section.group == second_section.group:
if "seen" in second_card and second_card["seen"]:
score = 20
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/MatchingPairs/MatchingPairs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const MatchingPairs = ({
const [score, setScore] = useState<number | null>(null);
const [total, setTotal] = useState(bonusPoints);
const [startOfTurn, setStartOfTurn] = useState(performance.now());
const [overlayWasShown, setOverlayWasShown] = useState(false);

// New state to track card states
const [sections, setSections] = useState(() => initialSections.map(section => ({
Expand Down Expand Up @@ -191,14 +192,15 @@ const MatchingPairs = ({
const scoreResponse = await scoreIntermediateResult({
session,
participant,
result: { "start_of_turn": startOfTurn, first_card: firstCard, second_card: currentCard }
result: { "start_of_turn": startOfTurn, first_card: firstCard, second_card: currentCard, overlay_was_shown: overlayWasShown, },
});
if (!scoreResponse) {
throw new Error('We cannot currently proceed with the game. Try again later');
}
setScore(scoreResponse.score);
showFeedback(scoreResponse.score);
showOverlay(scoreResponse.score);
const isShowingOverlay = showOverlay(scoreResponse.score);
setOverlayWasShown(isShowingOverlay);
} catch {
setError('We cannot currently proceed with the game. Try again later');
return;
Expand Down

0 comments on commit 1f81a70

Please sign in to comment.