Exemplo n.º 1
0
def do_submission_hooks(the_item: SurveyBase,
                        submission_data: dict,
                        actor: Party = None):
    assert not isinstance(the_item,
                          Question)  # no submission hooks for single questions

    hook_configuration = get_hook_configuration(the_item)
    if hook_configuration is None:
        return

    score = hook_configuration['scoring_strategy'].score_item(submission_data)

    actor = get_current_user_as_actor(
    ) if actor is None else get_party_as_actor(actor)
    verb = XApiVerb(XApiVerbs.Answered)
    activity = get_xapi_object(the_item)
    result = XApiScoredResult(score, hook_configuration['score_min'],
                              hook_configuration['score_max'], 1)
    context = XApiSurveyContext(the_item)

    statement = XApiStatement(actor, verb, activity, result, context)

    questionnaire = get_questionnaire(the_item)
    XApiPublisher().enqueue_deferred([statement], get_xapi_target(the_item),
                                     questionnaire.id)
Exemplo n.º 2
0
def enqueue_answered_xapi_statements(sender: QuestionResponse):
    question = sender.question
    subject = next(filter(lambda s: isinstance(s, DataSubject), sender.owners))
    receiver = get_xapi_target(sender.question)
    statement = XApiAnswerSubmittedStatement(subject, question, sender.value)

    XApiPublisher().enqueue_deferred([statement], receiver, sender.id)
Exemplo n.º 3
0
def publish_questionnaire_retracted_xapi_statement(sender: Questionnaire):
    actor = get_current_user_as_actor()
    verb = XApiVerb(XApiVerbs.RetractedSurvey)
    activity = get_xapi_object(sender)
    context = XApiSt3k101Context()

    receiver = get_xapi_target(sender)
    statement = XApiStatement(actor, verb, activity, xapi_context=context)
    XApiPublisher().enqueue([statement], receiver)
Exemplo n.º 4
0
def publish_reference_id_updated_xapi_statement(sender: SurveyBase,
                                                previous_value: str = "Missing"
                                                ):
    actor = get_current_user_as_actor()
    verb = XApiVerb(XApiVerbs.ChangedReferenceId)
    activity = None
    if isinstance(sender, Question):
        activity = XApiActivities.Question
    elif isinstance(sender, Dimension):
        activity = XApiActivities.Dimension
    elif isinstance(sender, Questionnaire):
        activity = XApiActivities.Questionnaire
    assert activity is not None
    previous_value = "<{}>:{}".format(sender.owning_dataclient.email,
                                      previous_value)
    activity = XApiActivityObject(activity, previous_value,
                                  sender.name_translations)
    result = XApiResponseResult("<{}>:{}".format(
        sender.owning_dataclient.email, sender.reference_id))
    context = XApiSt3k101Context()

    receiver = get_xapi_target(sender)
    statement = XApiStatement(actor, verb, activity, result, context)
    XApiPublisher().enqueue([statement], receiver)