JSON Formulas
Smart Knowledge Hub provides an interpreter for the calculation of status that will be automatically triggered when the user closes a learning content.
Standard formulas
Normally, you don't have to take care of all the features this interpreter provides; you can just use (via copy and paste if you like) the standard formula for the calculation of the completion status:
[
{
"op": "contains",
"value": "cmi.completion_status",
"value2": "completed"
}
]
This formula just looks at the cmi.completion_status
SCORM field and determines if it is set to completed
. If so, the course is assumed to be completed, else it is assumed to be incomplete.
Using cmi.score.raw
For all other SCORM 2004-based courses, you may use the cmi.score.raw
field.
Please note that SCORM does not make any requirement for the SCORM package to set this field correctly. This must be handled by the creator of the SCORM package or the manufactorer of the respective software the creator is using.
[
{
"op": "value",
"value": "0"
},
{
"op": "set"
},
{
"op": "scorm",
"value": "cmi.score.raw"
},
{
"op": "add"
}
]
This formula sets an internal register to zero and adds the value of the cmi.score.raw
field to it.
Advanced usage
The interpreter is very versatile and provides a huge number of operations you can use to calculate the completion status as needed.
Note: This is an advanced topic. Don't hesitate to contact us if you need any assistance here.
How the formula works
The formula is represented as an array of operations that are represented as JSON objects.
All operations are beeing executed from top to bottom.
There are two kinds of operations:
- Unary operation just have an
op
property. They execute the provided operation and provide it as the result, which will then be returned by the interpreter. - Binary operations have two properties:
op
andvalue
. They set the internal register to a specific value. - Ternary operations have three properties:
op
,value
andvalue2
. They provide a result after executing the operation.
List of unary operations
Value of op | Description |
---|---|
add | adds the value of the internal register to the result |
sub | subtracts the internal register from the result |
mul | multiplies the internal register to the result |
div | divides the result by the internal register |
set | copies the internal register to the result |
round | rounds the result half away from zero |
floor | rounds the result down |
ceil | rounds the result up |
Please note: A division by zero leads to a
NULL
value!
List of binary operations
Value of op | Description |
---|---|
value | writes the value property into the internal register |
scorm | reads the SCORM field whose name corresponds to value , converts the value of the SCORM field into a decimal number and puts this number into the internal register |
Note: If the
scorm
operation is not able to convert the value of the corresponding SCORM field into a decimal number, it puts0
(zero) into the internal register.
List of ternary operations
Value of op | Description |
---|---|
contains | checks if the SCORM field whose name corresponds to value contains value2 . If so, it provides 1 as a result, otherwise it provides 0 as a result. |