Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Udayraj123
GitHub Repository: Udayraj123/OMRChecker
Path: blob/master/src/schemas/evaluation_schema.py
214 views
1
from src.schemas.constants import (
2
ARRAY_OF_STRINGS,
3
DEFAULT_SECTION_KEY,
4
FIELD_STRING_TYPE,
5
)
6
7
marking_score_regex = "-?(\\d+)(/(\\d+))?"
8
9
marking_score = {
10
"oneOf": [
11
{"type": "string", "pattern": marking_score_regex},
12
{"type": "number"},
13
]
14
}
15
16
marking_object_properties = {
17
"additionalProperties": False,
18
"required": ["correct", "incorrect", "unmarked"],
19
"type": "object",
20
"properties": {
21
# TODO: can support streak marking if we allow array of marking_scores here
22
"correct": marking_score,
23
"incorrect": marking_score,
24
"unmarked": marking_score,
25
},
26
}
27
28
EVALUATION_SCHEMA = {
29
"$schema": "https://json-schema.org/draft/2020-12/schema",
30
"$id": "https://github.com/Udayraj123/OMRChecker/tree/master/src/schemas/evaluation-schema.json",
31
"title": "Evaluation Schema",
32
"description": "OMRChecker evaluation schema i.e. the marking scheme",
33
"type": "object",
34
"additionalProperties": True,
35
"required": ["source_type", "options", "marking_schemes"],
36
"properties": {
37
"additionalProperties": False,
38
"source_type": {"type": "string", "enum": ["csv", "custom"]},
39
"options": {"type": "object"},
40
"marking_schemes": {
41
"type": "object",
42
"required": [DEFAULT_SECTION_KEY],
43
"patternProperties": {
44
f"^{DEFAULT_SECTION_KEY}$": marking_object_properties,
45
f"^(?!{DEFAULT_SECTION_KEY}$).*": {
46
"additionalProperties": False,
47
"required": ["marking", "questions"],
48
"type": "object",
49
"properties": {
50
"questions": {
51
"oneOf": [
52
FIELD_STRING_TYPE,
53
{
54
"type": "array",
55
"items": FIELD_STRING_TYPE,
56
},
57
]
58
},
59
"marking": marking_object_properties,
60
},
61
},
62
},
63
},
64
},
65
"allOf": [
66
{
67
"if": {"properties": {"source_type": {"const": "csv"}}},
68
"then": {
69
"properties": {
70
"options": {
71
"additionalProperties": False,
72
"required": ["answer_key_csv_path"],
73
"dependentRequired": {
74
"answer_key_image_path": [
75
"answer_key_csv_path",
76
"questions_in_order",
77
]
78
},
79
"type": "object",
80
"properties": {
81
"should_explain_scoring": {"type": "boolean"},
82
"answer_key_csv_path": {"type": "string"},
83
"answer_key_image_path": {"type": "string"},
84
"questions_in_order": ARRAY_OF_STRINGS,
85
},
86
}
87
}
88
},
89
},
90
{
91
"if": {"properties": {"source_type": {"const": "custom"}}},
92
"then": {
93
"properties": {
94
"options": {
95
"additionalProperties": False,
96
"required": ["answers_in_order", "questions_in_order"],
97
"type": "object",
98
"properties": {
99
"should_explain_scoring": {"type": "boolean"},
100
"answers_in_order": {
101
"oneOf": [
102
{
103
"type": "array",
104
"items": {
105
"oneOf": [
106
# "standard": single correct, multi-marked single-correct
107
# Example: "q1" --> '67'
108
{"type": "string"},
109
# "multiple-correct": multiple-correct (for ambiguous/bonus questions)
110
# Example: "q1" --> [ 'A', 'B' ]
111
{
112
"type": "array",
113
"items": {"type": "string"},
114
"minItems": 2,
115
},
116
# "multiple-correct-weighted": array of answer-wise weights (marking scheme not applicable)
117
# Example 1: "q1" --> [['A', 1], ['B', 2], ['C', 3]] or
118
# Example 2: "q2" --> [['A', 1], ['B', 1], ['AB', 2]]
119
{
120
"type": "array",
121
"items": {
122
"type": "array",
123
"items": False,
124
"minItems": 2,
125
"maxItems": 2,
126
"prefixItems": [
127
{"type": "string"},
128
marking_score,
129
],
130
},
131
},
132
# Multiple-correct with custom marking scheme
133
# ["A", ["1", "2", "3"]],
134
# [["A", "B", "AB"], ["1", "2", "3"]]
135
],
136
},
137
},
138
]
139
},
140
"questions_in_order": ARRAY_OF_STRINGS,
141
"enable_evaluation_table_to_csv": {
142
"type": "boolean",
143
"default": False,
144
},
145
},
146
}
147
}
148
},
149
},
150
],
151
}
152
153