示例#1
0
 def get_question():
     return SingleSelectQuestion(
         id="ejemplo_Q{}".format(n),
         question=question,
         all_answers=answers,
         correct_answer=correct,
     )
    def add_a_single_select_question(self, question, description, practice_id):
        all_answers = []
        for choice in question["options"]:
            if choice.get("text"):
                all_answers.append(choice["text"].replace("<p>", "").replace(
                    "</p>", ""))
            else:
                all_answers.append("{value} {unit}".format(
                    value=choice["value"], unit=question["unit"]))

        question_node = SingleSelectQuestion(
            id="{}-question".format(practice_id),
            question=description,
            correct_answer=all_answers[int(question["correctOption"])],
            all_answers=all_answers)

        return question_node
    def add_multiple_single_select_questions(self, questions, description,
                                             practice_id):
        result = []
        for question in questions:
            source_id = "{practice}-question-{q_index}".format(
                practice=practice_id, q_index=question["id"])
            all_answers = [
                (choice.get("answer")
                 or choice.get("text")).replace("<p>", "").replace("</p>", "")
                for choice in question["options"]
            ]
            question_text = description + "\n" + question["text"]
            question_node = SingleSelectQuestion(
                id=source_id,
                question=question_text,
                correct_answer=all_answers[int(question["correctOption"])],
                all_answers=all_answers)
            result.append(question_node)

        return result
示例#4
0
def create_question(raw_question):

    if raw_question["type"] == exercises.MULTIPLE_SELECTION:
        return MultipleSelectQuestion(
            id=raw_question["id"],
            question=raw_question["question"],
            correct_answers=raw_question["correct_answers"],
            all_answers=raw_question["all_answers"],
            hints=raw_question.get("hints"),
        )
    if raw_question["type"] == exercises.SINGLE_SELECTION:
        return SingleSelectQuestion(
            id=raw_question["id"],
            question=raw_question["question"],
            correct_answer=raw_question["correct_answer"],
            all_answers=raw_question["all_answers"],
            hints=raw_question.get("hints"),
        )
    if raw_question["type"] == exercises.INPUT_QUESTION:
        return InputQuestion(
            id=raw_question["id"],
            question=raw_question["question"],
            answers=raw_question["answers"],
            hints=raw_question.get("hints"),
        )
    if raw_question["type"] == exercises.FREE_RESPONSE:
        return FreeResponseQuestion(
            id=raw_question["id"],
            question=raw_question["question"],
            hints=raw_question.get("hints"),
        )
    if raw_question["type"] == exercises.PERSEUS_QUESTION:
        return PerseusQuestion(
            id=raw_question["id"],
            raw_data=raw_question["item_data"],
        )
    else:
        raise UnknownQuestionTypeError(
            "Unrecognized question type '{0}': accepted types are {1}".format(
                raw_question["type"],
                [key for key, value in exercises.question_choices]))
示例#5
0
    def create_question(self, question_data):
        question_arr = []

        for id, question_metadata in question_data:
            if question_metadata["question"] is None:
                question_text = question_metadata["question_image"]
            else:
                question_text = question_metadata[
                    "question"] if question_metadata[
                        "question_image"] == None else question_metadata[
                            "question"] + " " + question_metadata[
                                "question_image"]

            question = SingleSelectQuestion(
                id=id,
                question=question_text,
                correct_answer=question_metadata["correct_answer"],
                all_answers=question_metadata["all_answers"],
                hints=[])
            question_arr.append(question)

        return question_arr
示例#6
0
def exercise_question():
    return SingleSelectQuestion("question_1", "Question", "Answer", ["Answer"])
示例#7
0
    def create_exercise_nodes(self, channel):
        """
        This function adds a few exercise nodes to the channel content tree.
        TODO: handle exercises with embedded image links + base64 encoded data.
        """

        # EXERCISES
        exercices_folder = TopicNode(
            source_id='uniqid011',
            title='Exercise Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        channel.add_child(exercices_folder)

        exercise1 = ExerciseNode(
            source_id='uniqid012',
            title='Basic questions',
            author='LE content team',
            description=
            'Showcase of the simple exercises supported by Ricecooker and Studio',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            exercise_data={
                'mastery_model': exercises.M_OF_N,  # or exercises.DO_ALL
                'randomize': True,
                'm': 2,
                'n': 3,
            },
            questions=[
                MultipleSelectQuestion(
                    id='ex2aQ1',
                    question=
                    "Which numbers are even?\n\nTest local image include: ![](content/ricecooker-channel-files/html5_vuejs.jpg)",
                    correct_answers=[
                        "2",
                        "4",
                    ],
                    all_answers=["1", "2", "3", "4", "5"],
                    hints=[
                        "There are two answers.",
                        "Both answers are multiples of two."
                    ]),
                SingleSelectQuestion(
                    id='ex2aQ2',
                    question="What is 2 times 3?",
                    correct_answer="6",
                    all_answers=["2", "3", "5", "6"],
                ),
                InputQuestion(
                    id='ex2aQ3',
                    question="Name a factor of 10.",
                    answers=["1", "2", "5", "10"],
                )
            ])
        exercices_folder.add_child(exercise1)

        # LOAD JSON DATA (as string) FOR PERSEUS QUESTIONS
        SAMPLE_PERSEUS_4_JSON = open(
            './content/ricecooker-channel-files/perseus_graph_question.json',
            'r').read()
        exercise2 = ExerciseNode(
            source_id='baszzzs1',
            title='Perseus questions',
            author='LE content team',
            description='An example exercise with Persus questions',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            exercise_data={
                'mastery_model': exercises.M_OF_N,  # or exercises.DO_ALL
                'randomize': True,
                'm': 1,
                'n': 1,
            },
            questions=[
                PerseusQuestion(
                    id='ex2bQ4',
                    raw_data=SAMPLE_PERSEUS_4_JSON,
                    source_url=
                    'https://github.com/learningequality/sample-channels/blob/master/contentnodes/exercise/sample_perseus04.json'
                ),
            ])
        exercices_folder.add_child(exercise2)
示例#8
0
    def create_exercise_nodes(self, channel):
        """
        This function adds a few exercise nodes to the channel content tree.
        TODO: handle exercises with embedded image links + base64 encoded data.
        """

        # EXERCISES
        exercices_folder = TopicNode(
            source_id='mdmdmai3i13',
            title='Exercise Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        channel.add_child(exercices_folder)

        exercise2a = ExerciseNode(
            source_id='asisis9',
            title='Basic questions',
            author='LE content team',
            description=
            'Showcase of the simple exercises supported by Ricecooker and Studio',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            exercise_data={
                'mastery_model': exercises.M_OF_N,  # or exercises.DO_ALL
                'randomize': True,
                'm': 2,
                'n': 3,
            },
            questions=[
                MultipleSelectQuestion(
                    id='ex2aQ1',
                    question="Which numbers are even?",
                    correct_answers=[
                        "2",
                        "4",
                    ],
                    all_answers=["1", "2", "3", "4", "5"],
                    # hints?
                ),
                SingleSelectQuestion(
                    id='ex2aQ2',
                    question="What is 2 times 3?",
                    correct_answer="6",
                    all_answers=["2", "3", "5", "6"],
                    # hints?
                ),
                InputQuestion(
                    id='ex2aQ3',
                    question="Name a factor of 10.",
                    answers=["1", "2", "5", "10"],
                    # hints?
                )
            ])
        exercices_folder.add_child(exercise2a)

        # LOAD JSON DATA (as string) FOR PERSEUS QUESTIONS
        SAMPLE_PERSEUS_4_JSON = open(
            './content/ricecooker-channel-files/sample_perseus04.json',
            'r').read()
        exercise2b = ExerciseNode(
            source_id='baszzzs1',
            title='Perseus questions',
            author='LE content team',
            description='An example exercise with Persus questions',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            exercise_data={
                'mastery_model': exercises.M_OF_N,  # or exercises.DO_ALL
                'randomize': True,
                'm': 2,
                'n': 3,
            },
            questions=[
                PerseusQuestion(
                    id='ex2bQ4',
                    raw_data=SAMPLE_PERSEUS_4_JSON,
                    source_url=
                    'https://github.com/learningequality/sample-channels/blob/master/contentnodes/exercise/sample_perseus04.json'
                ),
            ])
        exercices_folder.add_child(exercise2b)

        SAMPLE_PERSEUS_4_dhanam4_JSON = open(
            './content/ricecooker-channel-files/sample_perseus04dhanam4.json',
            'r').read()
        exercise2b_dhanam4 = ExerciseNode(
            source_id='test_dhanam4',
            title='Perseus question by dhanam4',
            author='dhanam4',
            description='dhanam4\'s example exercise with Persus questions',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY, copyright_holder='dhanam4'),
            thumbnail=None,
            exercise_data={
                'mastery_model': exercises.M_OF_N,  # or exercises.DO_ALL
                'randomize': True,
                'm': 2,
                'n': 3,
            },
            questions=[
                PerseusQuestion(
                    id='test_ex2bQ4dhanam4',
                    raw_data=SAMPLE_PERSEUS_4_dhanam4_JSON,
                    source_url=
                    'doesnt matter what goes here.. used for information purposes only'
                ),
            ])
        exercices_folder.add_child(exercise2b_dhanam4)