Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.

Data loading

Andrew Ang edited this page Aug 27, 2019 · 2 revisions

Table of Contents generated with DocToc

This page outlines the use of the alosi api models to populate course metadata for use in adaptivity modules.

Walkthrough

The following assumes you have installed the alosi python package, with the optional data package.

Initializing the client

Populate variables indicating host URL and credentials specific to your ALOSI system.

BRIDGE_HOST = "https://bridge.example.com"
BRIDGE_TOKEN = ...  # token is provided by ALOSI system administrator

# set up engine api client
ENGINE_HOST = "https://engine.example.com"
ENGINE_TOKEN = ...  # token is provided by ALOSI system administrator

BRIDGE_USER_PK = ...  # integer id of collection owner bridge, provided by ALOSI system administrator
BRIDGE_CONTENT_SOURCE_PK = ...  # integer id of content source, provided by ALOSI system administrator

Then initialize an AlosiClient instance

from alosi import AlosiClient

client = AlosiClient(
    bridge_host=BRIDGE_HOST,
    bridge_token=BRIDGE_TOKEN,
    engine_host=ENGINE_HOST,
    engine_token=ENGINE_TOKEN,
    bridge_owner_pk=BRIDGE_USER_PK,
    content_source_pk=BRIDGE_CONTENT_SOURCE_PK,
)

Instantiate API model instances

Three API models are provided:

  • Collection
  • Activity
  • Knowledge component

They have fields:

  • Collection
    • slug
    • name
  • Activity
    • collection
    • url
    • name
    • activity_type
    • difficulty
    • knowledge_components
    • prerequisite_activities
  • Knowledge Component
    • name
    • slug
    • prerequisite_knowledge_components
    • mastery_prior

Load in your course metadata (typically with Pandas if from a CSV or Google Sheet), then instantiate API model instances. This step varies based on how your metadata is stored and formatted.

Instantiating an API model does not apply changes until the .push() method is called (see later section).

The API models can be instantiated using the client.Collection(), client.KnowledgeComponent() and client.Activity() constructor methods on the client.

Examples for instantiating an API models:

Creating a collection
collection = client.Collection(slug='my-slug',name='my-name')
Creating an activity
activity = client.Activity(
    collection=...,
    url=...,
    name=...,
    activity_type=...,
    difficulty=...,
    knowledge_components=...,
    prerequisite_activities=...,
)
Creating a knowledge component
knowledge_component = client.KnowledgeComponent(...)

Populating relationships

Note: relationship between activity and the collection it belongs to is already performed during intitial activity instantiation.

Adding a knowledge component to an activity
# activity is an instantiated Activity instance
# knowledge_component is an instantiated KnowldgeComponent instance
activity = client.Activity(...)
knowledge_component = client.KnowledgeComponent(...)

# populate the relationship
activity.knowldge_components.append(knowledge_component)
Adding prerequisites between knowledge components
# prerequisite_kc_a and dependent_kc_b are KnowledgeComponent objects
# dependent_kc_b depends on prerequisite_kc_a
knowledge_component_a = client.KnowledgeComponent(...)
knowledge_component_b = client.KnowledgeComponent(...)

# populate the relationship
# dependent_kc_b depends on prerequisite_kc_a
knowledge_component_b.add_prerequisite_knowledge_component(knowledge_component_a)

Applying changes on external system

The client.push() method applies all changes in the external ALOSI system, including creation, modification, and populating relationships between models.

client.push(
    collections=collections,
    activities=activities,
    knowledge_components=knowledge_components
)