ricecooker exercises

This mini-tutorial will walk you through the steps of running a simple chef script ExercisesChef that creates two exercises nodes, and four exercises questions.

Running the notebooks

To follow along and run the code in this notebook, you'll need to clone the ricecooker repository, crate a virtual environement, install ricecooker using pip install ricecooker, install Jypyter notebook using pip install jupyter, then start the jupyter notebook server by running jupyter notebook. You will then be able to run all the code sections in this notebook and poke around.

Creating a Sushi Chef class


In [1]:
from ricecooker.chefs import SushiChef
from ricecooker.classes.nodes import TopicNode, ExerciseNode
from ricecooker.classes.questions import SingleSelectQuestion, MultipleSelectQuestion, InputQuestion, PerseusQuestion
from ricecooker.classes.licenses import get_license
from le_utils.constants import licenses
from le_utils.constants import exercises
from le_utils.constants.languages import getlang


class ExercisesChef(SushiChef):
    channel_info = {
        'CHANNEL_TITLE': 'Sample Exercises',
        'CHANNEL_SOURCE_DOMAIN': '<yourdomain.org>',     # where you got the content
        'CHANNEL_SOURCE_ID': '<unique id for channel>',  # channel's unique id  CHANGE ME
        'CHANNEL_LANGUAGE': 'en',                        # le_utils language code
        'CHANNEL_DESCRIPTION': 'A test channel with different types of exercise questions',      # (optional)
        'CHANNEL_THUMBNAIL': None, # (optional)
    }

    def construct_channel(self, **kwargs):
        channel = self.get_channel(**kwargs)
        topic = TopicNode(title="Math Exercises", source_id="folder-id")
        channel.add_child(topic)

        exercise_node = ExerciseNode(
            source_id='<some unique id>',
            title='Basic questions',
            author='LE content team',
            description='Showcase of the simple question type supported by Ricecooker and Studio',
            language=getlang('en').code,
            license=get_license(licenses.PUBLIC_DOMAIN),
            thumbnail=None,
            exercise_data={
                'mastery_model': exercises.M_OF_N,  # \
                'm': 2,                             #   learners must get 2/3 questions correct to complete exercise
                'n': 3,                             # /
                'randomize': True,                  # show questions in random order
            },
            questions=[
                MultipleSelectQuestion(
                    id='sampleEX_Q1',
                    question = "Which numbers the following numbers are even?",
                    correct_answers = ["2", "4",],
                    all_answers = ["1", "2", "3", "4", "5"],
                    hints=['Even numbers are divisible by 2.'],
                ),
                SingleSelectQuestion(
                    id='sampleEX_Q2',
                    question = "What is 2 times 3?",
                    correct_answer = "6",
                    all_answers = ["2", "3", "5", "6"],
                    hints=['Multiplication of $a$ by $b$ is like computing the area of a rectangle with length $a$ and width $b$.'],
                ),
                InputQuestion(
                    id='sampleEX_Q3',
                    question = "Name one of the *factors* of 10.",
                    answers = ["1", "2", "5", "10"],
                    hints=['The factors of a number are the divisors of the number that leave a whole remainder.'],
                )
            ]
        )
        topic.add_child(exercise_node)

        # LOAD JSON DATA (as string) FOR PERSEUS QUESTIONS    
        RAW_PERSEUS_JSON_STR = open('../../examples/exercises/chefdata/perseus_graph_question.json', 'r').read()
        # or
        # import requests
        # RAW_PERSEUS_JSON_STR = requests.get('https://raw.githubusercontent.com/learningequality/sample-channels/master/contentnodes/exercise/perseus_graph_question.json').text
        exercise_node2 = ExerciseNode(
                source_id='<another unique id>',
                title='An exercise containing a perseus question',
                author='LE content team',
                description='An example exercise with a Persus question',
                language=getlang('en').code,
                license=get_license(licenses.CC_BY, copyright_holder='Copyright holder name'),
                thumbnail=None,
                exercise_data={
                    'mastery_model': exercises.M_OF_N,
                    'm': 1,
                    'n': 1,
                },
                questions=[
                    PerseusQuestion(
                        id='ex2bQ4',
                        raw_data=RAW_PERSEUS_JSON_STR,
                        source_url='https://github.com/learningequality/sample-channels/blob/master/contentnodes/exercise/perseus_graph_question.json'
                    ),
                ]
        )
        topic.add_child(exercise_node2)

        return channel

Running the chef

Run of you chef by creating an instance of the chef class and calling it's run method:


In [2]:
chef = ExercisesChef()
args = {
    'command': 'dryrun',  # use  'uploadchannel'  for real run
    'verbose': True,
    'token': 'YOURTOKENHERE9139139f3a23232'
}
options = {}

chef.run(args, options)


INFO     In SushiChef.run method. args={'command': 'dryrun', 'reset': True, 'verbose': True, 'token': 'YOURTO...'} options={}
INFO     

***** Starting channel build process *****


INFO     Calling construct_channel... 
INFO        Setting up initial channel structure... 
INFO        Validating channel structure...
INFO           Sample Exercises (ChannelNode): 3 descendants
INFO              Math Exercises (TopicNode): 2 descendants
INFO                 Basic questions (ExerciseNode): 3 questions
INFO                 An exercise containing a perseus question (ExerciseNode): 1 question
INFO        Tree is valid

INFO     Downloading files...
INFO     Processing content...
INFO     	*** Processing images for exercise: Basic questions
INFO     	*** Images for Basic questions have been processed
INFO     	*** Processing images for exercise: An exercise containing a perseus question
INFO     	*** Images for An exercise containing a perseus question have been processed
INFO        All files were successfully downloaded
INFO     Command is dryrun so we are not uploading chanel.

Congratulations, you put some math exercises on the internet!

Note: you will need to change the value of CHANNEL_SOURCE_ID if you before you try running this script with {'command': 'uploadchannel', ...}. The combination of source domain and source id are used to compute the channel_id for the Kolibri channel you're creating. If you keep the lines above unchanged, you'll get an error because you don't have edit rights on that channel.


In [ ]: