Skip to content

Commit

Permalink
Merge pull request #970 from Amsterdam-Music-Lab/feature-er/matching-…
Browse files Browse the repository at this point in the history
…pairs-dry-run-issues

Feature er/matching pairs dry run issues
  • Loading branch information
Evert-R authored Apr 30, 2024
2 parents c5422eb + 3c6f415 commit 2290159
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions backend/experiment/rules/matching_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def calculate_score(self, result, data):
def calculate_intermediate_score(self, session, result):
''' will be called every time two cards have been turned '''
result_data = json.loads(result)
first_card = result_data['lastCard']
first_card = result_data['first_card']
first_section = Section.objects.get(pk=first_card['id'])
first_card['filename'] = str(first_section.filename)
second_card = result_data['currentCard']
second_card = result_data['second_card']
second_section = Section.objects.get(pk=second_card['id'])
second_card['filename'] = str(second_section.filename)
if first_section.group == second_section.group:
Expand Down
12 changes: 6 additions & 6 deletions backend/experiment/rules/tests/test_matching_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ def test_intermediate_score(self):
self.session.save()
self.session_data = {'session_id': self.session.id}
sections = self.playlist.section_set.all()
data = {'lastCard': {'id': sections[0].id},
'currentCard': {'id': sections[1].id}}
data = {'first_card': {'id': sections[0].id},
'second_card': {'id': sections[1].id}}
result = self.intermediate_score_request(data)
assert result.score == 10
assert result.given_response == 'lucky match'
data['currentCard'].update({'seen': True})
data['second_card'].update({'seen': True})
result = self.intermediate_score_request(data)
assert result.score == 20
assert result.given_response == 'match'
data['currentCard'] = {'id': sections[3].id, 'seen': True}
data['second_card'] = {'id': sections[3].id, 'seen': True}
result = self.intermediate_score_request(data)
assert result.score == -10
assert result.given_response == 'misremembered'
data['lastCard'].update({'seen': True})
data['currentCard'].pop('seen')
data['first_card'].update({'seen': True})
data['second_card'].pop('seen')
result = self.intermediate_score_request(data)
assert result.score == 0
assert result.given_response == 'no match'
14 changes: 10 additions & 4 deletions frontend/src/components/MatchingPairs/MatchingPairs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const MatchingPairs = ({

const xPosition = useRef(-1);
const yPosition = useRef(-1);
const [firstCard, setFirstCard] = useState(null);
const [secondCard, setSecondCard] = useState(null);
const [firstCard, setFirstCard] = useState({});
const [secondCard, setSecondCard] = useState({});
const [feedbackText, setFeedbackText] = useState('Pick a card');
const [feedbackClass, setFeedbackClass] = useState('');
const [inBetweenTurns, setInBetweenTurns] = useState(false);
Expand Down Expand Up @@ -94,10 +94,14 @@ const MatchingPairs = ({
// set no mouse events for all but current
sections.forEach(section => section.noevents = true);
currentCard.noevents = true;
currentCard.boardposition = parseInt(index) + 1;
currentCard.timestamp = performance.now();
currentCard.response_interval_ms = Math.round(currentCard.timestamp - firstCard.timestamp);
// check for match
const lastCard = firstCard;
const first_card = firstCard;
const second_card = currentCard;
try {
const scoreResponse = await scoreIntermediateResult({ session, participant, result: { currentCard, lastCard } });
const scoreResponse = await scoreIntermediateResult({ session, participant, result: { first_card, second_card } });
setScore(scoreResponse.score);
showFeedback(scoreResponse.score);
} catch {
Expand All @@ -111,6 +115,8 @@ const MatchingPairs = ({
currentCard.turned = true;
currentCard.noevents = true;
currentCard.seen = true;
currentCard.boardposition = parseInt(index) + 1;
currentCard.timestamp = performance.now();
// clear feedback text
setFeedbackText('');
}
Expand Down

0 comments on commit 2290159

Please sign in to comment.