Skip to content

Commit

Permalink
Add relative_start_position to hanging protocol schema (#3287)
Browse files Browse the repository at this point in the history
  • Loading branch information
amickan authored Mar 25, 2024
1 parent 09d6e1e commit 9c7930c
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# Generated by Django 4.2.11 on 2024-03-25 10:55

from django.db import migrations, models

import grandchallenge.core.validators


class Migration(migrations.Migration):

dependencies = [
("hanging_protocols", "0011_alter_hangingprotocol_json"),
]

operations = [
migrations.AlterField(
model_name="hangingprotocol",
name="json",
field=models.JSONField(
validators=[
grandchallenge.core.validators.JSONValidator(
schema={
"$schema": "http://json-schema.org/draft-07/schema#",
"contains": {
"properties": {
"viewport_name": {
"pattern": "^main$",
"type": "string",
}
},
"type": "object",
},
"definitions": {},
"items": {
"additionalProperties": False,
"allOf": [
{
"else": {
"properties": {
"viewport_name": {
"enum": [
"main",
"secondary",
"tertiary",
"quaternary",
"quinary",
"senary",
"septenary",
"octonary",
"nonary",
"denary",
"undenary",
"duodenary",
"tredenary",
"quattuordenary",
"quindenary",
"sexdenary",
"septendenary",
"octodenary",
"novemdenary",
"vigintenary",
],
"type": "string",
}
}
},
"if": {
"properties": {
"specialized_view": {
"enum": [
"minimap",
"3D-sideview",
]
}
},
"required": ["specialized_view"],
},
"then": {
"properties": {
"viewport_name": {
"pattern": "^[a-zA-Z0-9_]+$",
"type": "string",
}
},
"required": ["parent_id"],
},
},
{
"if": {
"properties": {
"specialized_view": {
"const": "3D-sideview"
}
},
"required": ["specialized_view"],
},
"then": {"required": ["orientation"]},
},
{
"if": {
"properties": {
"specialized_view": {
"const": "intensity-over-time-chart"
}
},
"required": ["specialized_view"],
},
"then": {"required": ["parent_id"]},
},
],
"properties": {
"draggable": {"type": "boolean"},
"fullsizable": {"type": "boolean"},
"h": {"type": "integer"},
"label": {"type": "string"},
"linkable": {"type": "boolean"},
"opacity": {
"maximum": 1,
"minimum": 0,
"type": "number",
},
"order": {"type": "integer"},
"orientation": {
"enum": [
"axial",
"coronal",
"sagittal",
],
"type": "string",
},
"parent_id": {
"enum": [
"main",
"secondary",
"tertiary",
"quaternary",
"quinary",
"senary",
"septenary",
"octonary",
"nonary",
"denary",
"undenary",
"duodenary",
"tredenary",
"quattuordenary",
"quindenary",
"sexdenary",
"septendenary",
"octodenary",
"novemdenary",
"vigintenary",
],
"type": "string",
},
"relative_start_position": {
"maximum": 1,
"minimum": 0,
"type": "number",
},
"selectable": {"type": "boolean"},
"show_current_slice": {"type": "boolean"},
"show_mouse_coordinate": {
"type": "boolean"
},
"show_mouse_voxel_value": {
"type": "boolean"
},
"slice_plane_indicator": {
"enum": [
"main",
"secondary",
"tertiary",
"quaternary",
"quinary",
"senary",
"septenary",
"octonary",
"nonary",
"denary",
"undenary",
"duodenary",
"tredenary",
"quattuordenary",
"quindenary",
"sexdenary",
"septendenary",
"octodenary",
"novemdenary",
"vigintenary",
],
"type": "string",
},
"slice_plane_indicator_fade_ms": {
"minimum": 0,
"type": "number",
},
"specialized_view": {
"enum": [
"minimap",
"3D-sideview",
"clientside",
"intensity-over-time-chart",
],
"type": "string",
},
"viewport_name": {"type": "string"},
"w": {"type": "integer"},
"x": {"type": "integer"},
"y": {"type": "integer"},
},
"required": ["viewport_name"],
"title": "The Layout Object Schema",
"type": "object",
},
"minItems": 1,
"title": "The Hanging Protocol Schema",
"type": "array",
"uniqueItems": True,
}
)
]
),
),
]
5 changes: 5 additions & 0 deletions app/grandchallenge/hanging_protocols/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class Orientation(models.TextChoices):
"type": "number",
"minimum": 0,
},
"relative_start_position": {
"type": "number",
"minimum": 0,
"maximum": 1,
},
},
"additionalProperties": False,
"allOf": [
Expand Down
31 changes: 31 additions & 0 deletions app/tests/hanging_protocols_tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"show_current_slice": True,
"show_mouse_coordinate": True,
"show_mouse_voxel_value": True,
"relative_start_position": 0.5,
"label": "Test label",
"opacity": 0.5,
}
Expand Down Expand Up @@ -425,6 +426,36 @@
],
pytest.raises(ValidationError),
),
# valid json containing relative_start_position
(
[
{
"viewport_name": "main",
"relative_start_position": 0.5,
}
],
nullcontext(),
),
# invalid json containing relative_start_position > 1
(
[
{
"viewport_name": "main",
"relative_start_position": 1.5,
}
],
pytest.raises(ValidationError),
),
# invalid json containing relative_start_position < 0
(
[
{
"viewport_name": "main",
"relative_start_position": -1.5,
}
],
pytest.raises(ValidationError),
),
],
)
def test_hanging_protocol_schema_validation(client, json, expectation):
Expand Down

0 comments on commit 9c7930c

Please sign in to comment.