Result utils
result.utils#
apply_scoring_rule(result, data)
#
Given a Result
object and the data
, apply the scoring_rule
registered on the result
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result |
Result
|
the |
required |
data |
Union[ScoringData, LikertData, ChoiceData]
|
a dictionary with |
required |
Returns:
Type | Description |
---|---|
Optional[float]
|
the value of the score (integer or float), |
Source code in result/utils.py
get_result(session, data)
#
Retrieve and return a Result
object for the given session
Fall back to retrieve a profile result tied to session.participant
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
Session
|
the |
required |
data |
Union[ScoringData, LikertData, ChoiceData]
|
a dictionary with |
required |
Returns:
Type | Description |
---|---|
Result
|
a |
Raises:
Type | Description |
---|---|
DoesNotExist
|
if there is no |
Source code in result/utils.py
handle_results(data, session)
#
Given the data from the frontend, go through the form
array and retrieve and score results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
dict
|
the data passed from the frontend |
required |
session |
Session
|
the session for which results should be defined |
required |
Raises:
Type | Description |
---|---|
KeyError
|
if the request data does not contain a |
Source code in result/utils.py
prepare_profile_result(question_key, participant, **kwargs)
#
Get or create a profile Result
object (i.e., tied to a Participant
instead of a Session
)
As profile Results are usually demographic questions, they are not tied to a section
or an expected_response
Parameters:
Name | Type | Description | Default |
---|---|---|---|
question_key |
str
|
the key of the question in the questionnaire dictionaries |
required |
participant |
Participant
|
the participant on which the Result is going to be registered |
required |
**kwargs |
Any
|
can be any other field(s) defined on the |
{}
|
Returns:
Type | Description |
---|---|
Result
|
|
Source code in result/utils.py
prepare_result(question_key, session, **kwargs)
#
Create a Result
object, and provide its id to be serialized
Parameters:
Name | Type | Description | Default |
---|---|---|---|
question_key |
str
|
the key of the question in the questionnaire dictionaries |
required |
session |
Session
|
the session on which the Result is going to be registered |
required |
**kwargs |
Any
|
can be any other field(s) defined on the |
{}
|
Returns:
Type | Description |
---|---|
int
|
the id of the created |
Raises:
Type | Description |
---|---|
ValueError
|
in case an undefined |
Source code in result/utils.py
score_result(data, session)
#
Retrieve the result for the given session, based on the frontend’s form
data,
and populate the json_data
, given_response
, and score
fields
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
Session
|
a Session object |
required |
data |
Union[ScoringData, LikertData, ChoiceData]
|
a dictionary with |
required |
Returns:
Type | Description |
---|---|
Result
|
the retrieved and modified |