Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Udayraj123
GitHub Repository: Udayraj123/OMRChecker
Path: blob/master/src/schemas/template_schema.py
214 views
1
from src.constants import FIELD_TYPES
2
from src.schemas.constants import ARRAY_OF_STRINGS, FIELD_STRING_TYPE
3
4
positive_number = {"type": "number", "minimum": 0}
5
positive_integer = {"type": "integer", "minimum": 0}
6
two_positive_integers = {
7
"type": "array",
8
"prefixItems": [
9
positive_integer,
10
positive_integer,
11
],
12
"maxItems": 2,
13
"minItems": 2,
14
}
15
two_positive_numbers = {
16
"type": "array",
17
"prefixItems": [
18
positive_number,
19
positive_number,
20
],
21
"maxItems": 2,
22
"minItems": 2,
23
}
24
zero_to_one_number = {
25
"type": "number",
26
"minimum": 0,
27
"maximum": 1,
28
}
29
30
TEMPLATE_SCHEMA = {
31
"$schema": "https://json-schema.org/draft/2020-12/schema",
32
"$id": "https://github.com/Udayraj123/OMRChecker/tree/master/src/schemas/template-schema.json",
33
"title": "Template Validation Schema",
34
"description": "OMRChecker input template schema",
35
"type": "object",
36
"required": [
37
"bubbleDimensions",
38
"pageDimensions",
39
"preProcessors",
40
"fieldBlocks",
41
],
42
"additionalProperties": False,
43
"properties": {
44
"bubbleDimensions": {
45
**two_positive_integers,
46
"description": "The dimensions of the overlay bubble area: [width, height]",
47
},
48
"customLabels": {
49
"description": "The customLabels contain fields that need to be joined together before generating the results sheet",
50
"type": "object",
51
"patternProperties": {
52
"^.*$": {"type": "array", "items": FIELD_STRING_TYPE}
53
},
54
},
55
"outputColumns": {
56
"type": "array",
57
"items": FIELD_STRING_TYPE,
58
"description": "The ordered list of columns to be contained in the output csv(default order: alphabetical)",
59
},
60
"pageDimensions": {
61
**two_positive_integers,
62
"description": "The dimensions(width, height) to which the page will be resized to before applying template",
63
},
64
"preProcessors": {
65
"description": "Custom configuration values to use in the template's directory",
66
"type": "array",
67
"items": {
68
"type": "object",
69
"properties": {
70
"name": {
71
"type": "string",
72
"enum": [
73
"CropOnMarkers",
74
"CropPage",
75
"FeatureBasedAlignment",
76
"GaussianBlur",
77
"Levels",
78
"MedianBlur",
79
],
80
},
81
},
82
"required": ["name", "options"],
83
"allOf": [
84
{
85
"if": {"properties": {"name": {"const": "CropOnMarkers"}}},
86
"then": {
87
"properties": {
88
"options": {
89
"type": "object",
90
"additionalProperties": False,
91
"properties": {
92
"apply_erode_subtract": {"type": "boolean"},
93
"marker_rescale_range": two_positive_numbers,
94
"marker_rescale_steps": {"type": "number"},
95
"max_matching_variation": {"type": "number"},
96
"min_matching_threshold": {"type": "number"},
97
"relativePath": {"type": "string"},
98
"sheetToMarkerWidthRatio": {"type": "number"},
99
},
100
"required": ["relativePath"],
101
}
102
}
103
},
104
},
105
{
106
"if": {
107
"properties": {"name": {"const": "FeatureBasedAlignment"}}
108
},
109
"then": {
110
"properties": {
111
"options": {
112
"type": "object",
113
"additionalProperties": False,
114
"properties": {
115
"2d": {"type": "boolean"},
116
"goodMatchPercent": {"type": "number"},
117
"maxFeatures": {"type": "integer"},
118
"reference": {"type": "string"},
119
},
120
"required": ["reference"],
121
}
122
}
123
},
124
},
125
{
126
"if": {"properties": {"name": {"const": "Levels"}}},
127
"then": {
128
"properties": {
129
"options": {
130
"type": "object",
131
"additionalProperties": False,
132
"properties": {
133
"gamma": zero_to_one_number,
134
"high": zero_to_one_number,
135
"low": zero_to_one_number,
136
},
137
}
138
}
139
},
140
},
141
{
142
"if": {"properties": {"name": {"const": "MedianBlur"}}},
143
"then": {
144
"properties": {
145
"options": {
146
"type": "object",
147
"additionalProperties": False,
148
"properties": {"kSize": {"type": "integer"}},
149
}
150
}
151
},
152
},
153
{
154
"if": {"properties": {"name": {"const": "GaussianBlur"}}},
155
"then": {
156
"properties": {
157
"options": {
158
"type": "object",
159
"additionalProperties": False,
160
"properties": {
161
"kSize": two_positive_integers,
162
"sigmaX": {"type": "number"},
163
},
164
}
165
}
166
},
167
},
168
{
169
"if": {"properties": {"name": {"const": "CropPage"}}},
170
"then": {
171
"properties": {
172
"options": {
173
"type": "object",
174
"additionalProperties": False,
175
"properties": {
176
"morphKernel": two_positive_integers
177
},
178
}
179
}
180
},
181
},
182
],
183
},
184
},
185
"fieldBlocks": {
186
"description": "The fieldBlocks denote small groups of adjacent fields",
187
"type": "object",
188
"patternProperties": {
189
"^.*$": {
190
"type": "object",
191
"required": [
192
"origin",
193
"bubblesGap",
194
"labelsGap",
195
"fieldLabels",
196
],
197
"oneOf": [
198
{"required": ["fieldType"]},
199
{"required": ["bubbleValues", "direction"]},
200
],
201
"properties": {
202
"bubbleDimensions": two_positive_numbers,
203
"bubblesGap": positive_number,
204
"bubbleValues": ARRAY_OF_STRINGS,
205
"direction": {
206
"type": "string",
207
"enum": ["horizontal", "vertical"],
208
},
209
"emptyValue": {"type": "string"},
210
"fieldLabels": {"type": "array", "items": FIELD_STRING_TYPE},
211
"labelsGap": positive_number,
212
"origin": two_positive_integers,
213
"fieldType": {
214
"type": "string",
215
"enum": list(FIELD_TYPES.keys()),
216
},
217
},
218
}
219
},
220
},
221
"emptyValue": {
222
"description": "The value to be used in case of empty bubble detected at global level.",
223
"type": "string",
224
},
225
},
226
}
227
228