Skip to content

Result score

backend.result.score#

boolean_score(result, data) #

Binary score: return 1 if participant answered yes, 0 otherwise

Parameters:

Name Type Description Default
result Result

the result to be scored

required
data ScoringData

the participant’s response

required
Source code in backend/result/score.py
def boolean_score(result: Result, data: ScoringData) -> int:
    """Binary score: return 1 if participant answered `yes`, 0 otherwise

    Args:
        result: the result to be scored
        data: the participant's response
    """
    if result.given_response == 'yes':
        return 1
    else:
        return 0

correctness_score(result, data) #

Binary score: return 1 if the participant’s response is equal to the expected response, 0 otherwise

Parameters:

Name Type Description Default
result Result

the result to be scored

required
data ScoringData

the participant’s response

required
Source code in backend/result/score.py
def correctness_score(result: Result, data: ScoringData) -> int:
    """Binary score: return 1 if the participant's response is equal to the expected response, 0 otherwise

    Args:
        result: the result to be scored
        data: the participant's response
    """
    if (
        result.expected_response == result.given_response
    ):  # TODO: raise exception if expected_response or given_response are `None`
        return 1
    else:
        return 0

likert_score(result, data) #

Translate the nth category of a Likert scale into n

Parameters:

Name Type Description Default
result Result

the result to be scored

required
data LikertData

the participant’s response

required
Source code in backend/result/score.py
def likert_score(result: Result, data: LikertData) -> int:
    """Translate the `n`th category of a Likert scale into `n`

    Args:
        result: the result to be scored
        data: the participant's response
    """
    _choices, score = _score_likert(data)
    return score + 1

reaction_time_score(result, data) #

Return the difference between the configured maximal response_time and the participant’s reaction time (decision_time)

If the answer of the participant is incorrect, return the negative reaction time

Parameters:

Name Type Description Default
result Result

the result to be scored

required
data ScoringData

the participant’s response

required
Source code in backend/result/score.py
def reaction_time_score(result: Result, data: ScoringData) -> float:
    """Return the difference between the configured maximal `response_time`
    and the participant's reaction time (`decision_time`)

    If the answer of the participant is incorrect, return the negative reaction time

    Args:
        result: the result to be scored
        data: the participant's response
    """
    expected_response = result.expected_response
    json_data = (
        result.json_data
    )  # TODO: raise exception if either expected_response or json_data is `None`
    if expected_response and json_data:
        time = json_data.get(
            'decision_time'
        )  # TODO: raise exception if json_data does not contain decision_time
        timeout = json_data.get('config').get(
            'response_time'
        )  # TODO: raise exception if json_data does not contain config with response_time
        if expected_response == data['value']:
            return math.ceil(timeout - time)
        else:
            return math.floor(-time)

reverse_likert_score(result, data) #

Translate the nth category of a Likert scale into n_steps - n

Parameters:

Name Type Description Default
result Result

the result to be scored

required
data LikertData

the participant’s response

required
Source code in backend/result/score.py
def reverse_likert_score(result: Result, data: LikertData) -> int:
    """Translate the `n`th category of a Likert scale into `n_steps - n`

    Args:
        result: the result to be scored
        data: the participant's response
    """
    choices, score = _score_likert(data)
    return len(choices) - score

song_sync_recognition_score(result, data) #

First step of SongSync scoring (used in experiment.rules.hooked and derivatives):

If the participant gives no response or negative response to ‘Do you know this song?’, return 0 otherwise, return the decision time

Parameters:

Name Type Description Default
result Result

the result to be scored

required
data ScoringData

the participant’s response

required
Source code in backend/result/score.py
def song_sync_recognition_score(result: Result, data: ScoringData) -> float:
    """First step of SongSync scoring (used in experiment.rules.hooked and derivatives):

    If the participant gives no response or negative response to 'Do you know this song?', return 0
    otherwise, return the decision time

    Args:
        result: the result to be scored
        data: the participant's response
    """
    if result.given_response == 'TIMEOUT' or result.given_response == 'no':
        return 0
    json_data = result.json_data
    if json_data:
        time = json_data.get(
            'decision_time'
        )  # TODO: raise exception if time or timeout are `None`
        timeout = json_data.get('config').get('response_time')
        return math.ceil(timeout - time)

song_sync_verification_score(result, data) #

Second step of the SongSync scoring, only happens if participant stated they know the song, used to verify that the statement was truthful.

After continuation of audio, participants need to decide whether it was continued in the correct place. If answered incorrectly, this function modifies the reaction time score of the previous step.

Parameters:

Name Type Description Default
result Result

the result to be scored

required
data ScoringData

the participant’s response

required
Source code in backend/result/score.py
def song_sync_verification_score(result: Result, data: ScoringData):
    """Second step of the SongSync scoring, only happens if participant stated they know the song,
    used to verify that the statement was truthful.

    After continuation of audio, participants need to decide whether it was continued in the correct place.
    If answered incorrectly, this function modifies the reaction time score of the previous step.

    Args:
        result: the result to be scored
        data: the participant's response
    """
    previous_result = result.session.last_result(["recognize"])
    if result.expected_response != result.given_response:
        previous_result.score *= (
            -1
        )  # will raise exception if `previous_result.score = None`
        previous_result.save()
    return None