Learning Records to xAPI – Prometheus-X Components & Services

Learning Records to xAPI

Overview

The aim of this process is to convert Learning Records to xAPI format. This involves two consecutive steps: Input Data Validation and Data Transformation.

Table of Contents

  1. Input Data Validation
  2. Data Transformation

Input Data Validation

Pydantic File

Overview

The Validation Config is a Pydantic (.py) file used to validate the format of an input file. It defines the structure and types of the input data, ensuring that the data conforms to the expected format before transformation.

Data transformation

YAML file

Overview

The Transformation Config is a YAML file that defines mappings and transformations from a source format (e.g., SCORM, IMS Caliper) to a target format (e.g., xAPI).

The Transformation Config file follows this structure:

version: 1.0
input_format: "SOURCE_FORMAT"
output_format: "TARGET_FORMAT"
mappings:
  # Mapping rules (see mappings section)
default_values:
  # Default values (see default values section)
metadata:
  # Metadata information (see metadata section)

Mapping

The mappings section defines how to transform the input trace into the output format. Each mapping rule has this structure:

- description: "Optional description"
  input_fields: ["field.path", "otherfield.path.subpath"]
  output_fields:
    # Output field definition
Output fields

Output fields can be defined in several ways:

  1. Static value:
    output_field: "target.field"
    value: "static_value"
    
  1. Custom transformation:
    output_field: "target.field"
    custom:
      - "lambda x: some_function(x)"
    
  1. Switch cases:
    switch:
      - condition: "lambda a: some_condition(a)"
        output_field: "target.field"
        value: "value_if_true"
    
  1. Multiple outputs:
    multiple:
      - output_field: "target.field1"
        value: "value1"
      - output_field: "target.field2"
        custom:
          - "lambda x: some_function(x)"
    
  1. Profile association:
    profile: "profile.name"
    

Profiles are used to enrich and validate the trace. The LRC supports multiple profiles, including LMS, Forum, and Assessment profiles.

Profiles

In the LRC, profiles and their templates are referenced using the format profile_name.template_name. This convention is crucial for correctly applying profile-specific rules to xAPI statements.

Structure

Example: lms.accessed-page

Implications
  1. Profile Selection:

    • The profile_name determines which JSON-LD profile file is used for enrichment and validation.
    • It corresponds to one of the profiles defined in the PROFILES_NAMES environment variable.
  2. Template Application:

    • The template_name identifies a specific StatementTemplate within the chosen profile.
    • This template contains rules for structuring and validating the xAPI statement.
  3. Enrichment Process:

    • When a profile_name.template_name is specified in the YAML configuration, the LRC will: a. Load the corresponding profile JSON-LD file. b. Find the specified template within that profile. c. Apply the template's rules to enrich the xAPI statement.
  4. Validation:

    • The specified template's rules are used to validate the xAPI statement.
    • This includes checking for required fields, correct verb usage, and proper activity types.
  5. Recommendations:

    • Recommendations for improving the xAPI statement are based on the specified template's rules.

Default

The default_values section specifies default values for certain output fields:

default_values:
  - output_field: "default.field"
    value: "default_value"

Metadata

The metadata section provides information about the configuration:

metadata:
  author: "Author Name"
  date:
    publication: "2023-01-01"
    update: "2023-02-01"

Available Functions in Lambdas

When writing custom transformations in your mapping files, several utility functions are available for use in your lambda expressions:

Date and Time Functions

parse_date(date: str | int, date_format: str | None = None, user_locale: str | None = None) -> str | None

URL and Path Functions

urlparse(url: str) -> ParseResult
path_join(*paths: str) -> str

String Functions

search(pattern, string)

Search for pattern in string

match(pattern, string)

Match pattern at start of string

Data Validation

is_empty(x: Any) -> bool

Checks if a value is empty (None, empty string, empty list/dict, etc.).

How to create my own YAML file?

Please refer to the YAML File section to create your own config file. The example (in the example folder) can also help with understanding and creating a new YAML file. Once this file is created, here are the steps to follow:

As reference, look at app/common/enums/trace_formats.py