Skip to content
Snippets Groups Projects
Verified Commit ccda768b authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP: More extensive testing data.

parent 2686a10c
No related branches found
No related tags found
3 merge requests!100WIP: Filling XLSX: Seems to be working.,!94ENH: add framework for converting json schema into table templates,!93Filling XLSX: Everything except multiple choice.
Pipeline #48167 failed
...@@ -16,50 +16,57 @@ ...@@ -16,50 +16,57 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Create JSON-Schema according to configuration """Create JSON-Schema according to configuration.
""" """
import argparse import argparse
import json import json
import os from typing import List
import sys
import caosadvancedtools.json_schema_exporter as jsex import caosadvancedtools.json_schema_exporter as jsex
import caosadvancedtools.models.parser as parser from caosadvancedtools.models import parser
import tomli # import tomli
# TODO why do I need a running LA instance?
def prepare_datamodel(): def prepare_datamodel(modelfile, recordtypes: List[str], outfile: str,
model = parser.parse_model_from_yaml("./model.yml") do_not_create: List[str] = None):
if do_not_create is None:
do_not_create = []
model = parser.parse_model_from_yaml(modelfile)
exporter = jsex.JsonSchemaExporter(additional_properties=False, exporter = jsex.JsonSchemaExporter(additional_properties=False,
# additional_options_for_text_props=additional_text_options, # additional_options_for_text_props=additional_text_options,
# name_and_description_in_properties=True, # name_and_description_in_properties=True,
name_property_for_new_records=True, name_property_for_new_records=True,
do_not_create=["Organisation"], do_not_create=do_not_create,
# do_not_retrieve=do_not_retrieve, # do_not_retrieve=do_not_retrieve,
no_remote=True,
use_rt_pool=model,
) )
schema_top = exporter.recordtype_to_json_schema(model.get_deep("Training")) schemas = []
schema_pers = exporter.recordtype_to_json_schema(model.get_deep("Person")) for recordtype in recordtypes:
merged_schema = jsex.merge_schemas([schema_top, schema_pers]) schemas.append(exporter.recordtype_to_json_schema(model.get_deep(recordtype)))
merged_schema = jsex.merge_schemas(schemas)
with open("model_schema.json", mode="w", encoding="utf8") as json_file: with open(outfile, mode="w", encoding="utf8") as json_file:
json.dump(merged_schema, json_file, ensure_ascii=False, indent=2) json.dump(merged_schema, json_file, ensure_ascii=False, indent=2)
def _parse_arguments(): def _parse_arguments():
"""Parse the arguments.""" """Parse the arguments."""
parser = argparse.ArgumentParser(description='') arg_parser = argparse.ArgumentParser(description='')
return parser.parse_args() return arg_parser.parse_args()
def main(): def main():
"""The main function of this script.""" """The main function of this script."""
args = _parse_arguments() _ = _parse_arguments()
prepare_datamodel() prepare_datamodel("model_simple.yml", ["Training", "Person"], "model_schema.json",
do_not_create=["Organisation"])
prepare_datamodel("model_multiple_refs.yml", ["Training", "Person"],
"schema_multiple_refs.json")
if __name__ == "__main__": if __name__ == "__main__":
......
{ {
"Training": { "Training": {
"date": "2023-01-01", "date": "2023-01-01",
"url": "www.indiscale.com", "url": "www.indiscale.com",
"coach": [ "coach": [
{ {
"family_name": "Sky", "family_name": "Sky",
"given_name": "Max", "given_name": "Max",
"Organisation": "ECB" "Organisation": "ECB"
},{ },
"family_name": "Sky", {
"given_name": "Min", "family_name": "Sky",
"Organisation": "ECB" "given_name": "Min",
}], "Organisation": "ECB"
"supervisor": { }
"family_name": "Steve", ],
"given_name": "Stevie", "supervisor": {
"family_name": "Steve",
"given_name": "Stevie",
"Organisation": "IMF" "Organisation": "IMF"
},
"duration": 1.0,
"participants": 1,
"subjects": ["Math", "Physics"],
"remote": false
}, },
"Person": { "duration": 1.0,
"family_name": "Steve", "participants": 1,
"given_name": "Stevie", "subjects": ["Math", "Physics"],
"Organisation": "IMF" "remote": false
} },
"Person": {
"family_name": "Steve",
"given_name": "Stevie",
"Organisation": "IMF"
}
} }
Person:
recommended_properties:
full_name:
datatype: TEXT
email:
datatype: TEXT
Organisation:
Training:
recommended_properties:
date:
datatype: DATETIME
description: 'The date of the training.'
url:
datatype: TEXT
description: 'The URL'
trainer:
datatype: LIST<Person>
participant:
datatype: LIST<Person>
supervisor:
datatype: Person
responsible:
datatype: Person
supervisor_inherit:
inherit_from_suggested:
- Person
responsible_inherit:
inherit_from_suggested:
- Person
Organisation:
recommended_properties:
Country:
datatype: TEXT
...@@ -91,6 +91,10 @@ ...@@ -91,6 +91,10 @@
}, },
"remote": { "remote": {
"type": "boolean" "type": "boolean"
},
"slides": {
"type": "string",
"format": "data-url"
} }
}, },
"$schema": "https://json-schema.org/draft/2020-12/schema" "$schema": "https://json-schema.org/draft/2020-12/schema"
......
{
"type": "object",
"properties": {
"Training": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Training",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"date": {
"description": "The date of the training.",
"anyOf": [
{
"type": "string",
"format": "date"
},
{
"type": "string",
"format": "date-time"
}
]
},
"url": {
"type": "string",
"description": "The URL"
},
"trainer": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "trainer",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
},
"Organisation": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
}
}
}
}
}
},
"participant": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "participant",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
},
"Organisation": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
}
}
}
}
}
},
"supervisor": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "supervisor",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
},
"Organisation": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
}
}
}
}
},
"responsible": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "responsible",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
},
"Organisation": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
}
}
}
}
},
"supervisor_inherit": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "supervisor_inherit",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
},
"Organisation": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
}
}
}
}
},
"responsible_inherit": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "responsible_inherit",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
},
"Organisation": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
}
}
}
}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
},
"Person": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Person",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
},
"Organisation": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
}
}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
},
"required": [
"Training",
"Person"
],
"additionalProperties": false,
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
\ No newline at end of file
...@@ -44,6 +44,6 @@ def test_detect(): ...@@ -44,6 +44,6 @@ def test_detect():
def test_fill_xlsx(): def test_fill_xlsx():
path = os.path.join(tempfile.mkdtemp(), 'test.xlsx') path = os.path.join(tempfile.mkdtemp(), 'test.xlsx')
assert not os.path.exists(path) assert not os.path.exists(path)
fill_template(rfp('example_template.xlsx'), rfp('example.json'), path) fill_template(data=rfp('example.json'), template=rfp('example_template.xlsx'), result=path)
assert os.path.exists(path) assert os.path.exists(path)
generated = load_workbook(path) # workbook can be read generated = load_workbook(path) # workbook can be read
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment