Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for percentage threshold for pages completion criteria #103

Merged
merged 4 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exclude: (\.git/|\.tox/|\.venv/|le_utils\.egg-info)
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
hooks:
- id: trailing-whitespace
Expand Down
67 changes: 17 additions & 50 deletions js/CompletionCriteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
};

export const SCHEMA = {
"$id": "/schemas/completion_criteria",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for completion criteria of content nodes",
Expand All @@ -27,56 +28,7 @@ export const SCHEMA = {
"reference"
]
},
"mastery_criteria": {
"type": "object",
"$comment": "TODO move to separate schema",
"additionalProperties": false,
"required": ["mastery_model"],
"properties": {
"m": true,
"n": true,
"mastery_model": {
"type": "string",
"enum": [
"do_all",
"m_of_n",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10"
]
}
},
"anyOf": [
{
"properties": {
"mastery_model": {
"const": "m_of_n"
}
},
"required": ["m", "n"]
},
{
"properties": {
"mastery_model": {
"enum": [
"do_all",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10"
]
},
"m": {
"type": "null"
},
"n": {
"type": "null"
}
}
}
]
}
"mastery_criteria": { "$ref": "/schemas/mastery_criteria" }
},
"properties": {
"model": {
Expand Down Expand Up @@ -105,6 +57,21 @@ export const SCHEMA = {
},
"required": ["threshold"]
},
{
"properties": {
"model": {
"const": "pages"
},
"threshold": {
"type": "string",
"pattern": "^(100|[1-9][0-9]?)%$",
"description": "A percentage",
"minLength": 2,
"maxLength": 4
}
},
"required": ["threshold"]
},
{
"properties": {
"model": {
Expand Down
71 changes: 71 additions & 0 deletions js/MasteryCriteria.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// -*- coding: utf-8 -*-
// Generated by scripts/generate_from_specs.py
// MasteryCriteria

export default {
DO_ALL: "do_all",
M_OF_N: "m_of_n",
NUM_CORRECT_IN_A_ROW_10: "num_correct_in_a_row_10",
NUM_CORRECT_IN_A_ROW_2: "num_correct_in_a_row_2",
NUM_CORRECT_IN_A_ROW_3: "num_correct_in_a_row_3",
NUM_CORRECT_IN_A_ROW_5: "num_correct_in_a_row_5",
};

export const SCHEMA = {
"$id": "/schemas/mastery_criteria",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for mastery criteria of exercise content types",
"additionalProperties": false,
"required": ["mastery_model"],
"definitions": {
"mastery_model": {
"type": "string",
"$exportConstants": "mastery_criteria",
"enum": [
"do_all",
"m_of_n",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10"
]
}
},
"properties": {
"m": true,
"n": true,
"mastery_model": {
"$ref": "#/definitions/mastery_model"
}
},
"anyOf": [
{
"properties": {
"mastery_model": {
"const": "m_of_n"
}
},
"required": ["m", "n"]
},
{
"properties": {
"mastery_model": {
"enum": [
"do_all",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10"
]
},
"m": {
"type": "null"
},
"n": {
"type": "null"
}
}
}
]
};
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "0.1.39"
"version": "0.1.40"
}
99 changes: 36 additions & 63 deletions le_utils/constants/completion_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,92 +27,65 @@
]

SCHEMA = {
"$id": "/schemas/completion_criteria",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for completion criteria of content nodes",
"additionalProperties": False,
"definitions": {
"model": {
"type": "string",
"$exportConstants": "completion_criteria",
"enum": ["time", "approx_time", "pages", "mastery", "reference"],
},
"mastery_criteria": {"$ref": "/schemas/mastery_criteria"},
},
"properties": {
"model": {"$ref": "#/definitions/model"},
"learner_managed": {"type": "boolean"},
"threshold": True,
},
"required": ["model"],
"anyOf": [
{
"required": ["threshold"],
"properties": {
"threshold": {"exclusiveMinimum": 0, "type": "number"},
"model": {
"anyOf": [
{"const": "time"},
{"const": "approx_time"},
{"const": "pages"},
]
},
"threshold": {"type": "number", "exclusiveMinimum": 0},
},
"required": ["threshold"],
},
{
"properties": {
"model": {"const": "pages"},
"threshold": {
"type": "string",
"pattern": "^(100|[1-9][0-9]?)%$",
"description": "A percentage",
"minLength": 2,
"maxLength": 4,
},
},
"required": ["threshold"],
},
{
"properties": {
"threshold": {"$ref": "#/definitions/mastery_criteria"},
"model": {"const": "mastery"},
"threshold": {"$ref": "#/definitions/mastery_criteria"},
},
"required": ["threshold"],
},
{
"required": [],
"properties": {
"threshold": {"type": "null"},
"model": {"const": "reference"},
"threshold": {"type": "null"},
},
"required": [],
},
],
"required": ["model"],
"additionalProperties": False,
"definitions": {
"model": {
"$exportConstants": "completion_criteria",
"enum": ["time", "approx_time", "pages", "mastery", "reference"],
"type": "string",
},
"mastery_criteria": {
"type": "object",
"required": ["mastery_model"],
"additionalProperties": False,
"$comment": "TODO move to separate schema",
"anyOf": [
{
"required": ["m", "n"],
"properties": {"mastery_model": {"const": "m_of_n"}},
},
{
"properties": {
"m": {"type": "null"},
"mastery_model": {
"enum": [
"do_all",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10",
]
},
"n": {"type": "null"},
}
},
],
"properties": {
"mastery_model": {
"enum": [
"do_all",
"m_of_n",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10",
],
"type": "string",
},
"m": True,
"n": True,
},
},
},
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"threshold": True,
"model": {"$ref": "#/definitions/model"},
"learner_managed": {"type": "boolean"},
},
}
76 changes: 76 additions & 0 deletions le_utils/constants/mastery_criteria.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
# Generated by scripts/generate_from_specs.py
from __future__ import unicode_literals

# MasteryCriteria

DO_ALL = "do_all"
M_OF_N = "m_of_n"
NUM_CORRECT_IN_A_ROW_10 = "num_correct_in_a_row_10"
NUM_CORRECT_IN_A_ROW_2 = "num_correct_in_a_row_2"
NUM_CORRECT_IN_A_ROW_3 = "num_correct_in_a_row_3"
NUM_CORRECT_IN_A_ROW_5 = "num_correct_in_a_row_5"

choices = (
(DO_ALL, "Do All"),
(M_OF_N, "M Of N"),
(NUM_CORRECT_IN_A_ROW_10, "Num Correct In A Row 10"),
(NUM_CORRECT_IN_A_ROW_2, "Num Correct In A Row 2"),
(NUM_CORRECT_IN_A_ROW_3, "Num Correct In A Row 3"),
(NUM_CORRECT_IN_A_ROW_5, "Num Correct In A Row 5"),
)

MASTERYCRITERIALIST = [
DO_ALL,
M_OF_N,
NUM_CORRECT_IN_A_ROW_10,
NUM_CORRECT_IN_A_ROW_2,
NUM_CORRECT_IN_A_ROW_3,
NUM_CORRECT_IN_A_ROW_5,
]

SCHEMA = {
"$id": "/schemas/mastery_criteria",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for mastery criteria of exercise content types",
"additionalProperties": False,
"required": ["mastery_model"],
"definitions": {
"mastery_model": {
"type": "string",
"$exportConstants": "mastery_criteria",
"enum": [
"do_all",
"m_of_n",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10",
],
}
},
"properties": {
"m": True,
"n": True,
"mastery_model": {"$ref": "#/definitions/mastery_model"},
},
"anyOf": [
{"properties": {"mastery_model": {"const": "m_of_n"}}, "required": ["m", "n"]},
{
"properties": {
"mastery_model": {
"enum": [
"do_all",
"num_correct_in_a_row_2",
"num_correct_in_a_row_3",
"num_correct_in_a_row_5",
"num_correct_in_a_row_10",
]
},
"m": {"type": "null"},
"n": {"type": "null"},
}
},
],
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name="le-utils",
packages=find_packages(),
version="0.1.39",
version="0.1.40",
description="LE-Utils contains shared constants used in Kolibri, Ricecooker, and Kolibri Studio.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
Loading