-
Notifications
You must be signed in to change notification settings - Fork 6
Data loading
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.
- Initialize AlosiClient
- Define data sources
- Create data structures (e.g. dataframe, dictionary) for:
- collection
- activity
- kc
- activity_kc
- kc_kc
- Instantiate client objects with AlosiClient for items in data structures
- Update remote object state with
client.push()
The following assumes you have installed the alosi python package, with the optional data package.
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 administratorThen 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,
)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:
collection = client.Collection(slug='my-slug',name='my-name')activity = client.Activity(
collection=...,
url=...,
name=...,
activity_type=...,
difficulty=...,
knowledge_components=...,
prerequisite_activities=...,
)knowledge_component = client.KnowledgeComponent(...)Note: relationship between activity and the collection it belongs to is already performed during intitial activity instantiation.
# 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)# 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)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
)