Esempio n. 1
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]))
Esempio n. 2
0
def exercise_invalid_question(exercise):
    exercise = copy.deepcopy(exercise)
    exercise.add_question(InputQuestion("question_2", "Question 2",
                                        ["Answer"]))
    return exercise
Esempio n. 3
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)
Esempio n. 4
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)