Skip to content
Snippets Groups Projects
Commit 67371bad authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-extern2' into 'dev'

MAINT: further tests and docs

See merge request !19
parents 98da8ac3 921dc85e
No related branches found
No related tags found
2 merge requests!22Release 0.3,!19MAINT: further tests and docs
Pipeline #15569 passed
...@@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
h5py is now an optional dependency h5py is now an optional dependency
- table importer implementations for csv and tsv - table importer implementations for csv and tsv
- string-in-list check for table imports - string-in-list check for table imports
* AbtractCFood has new property, `update_flags`. - AbtractCFood has new property, `update_flags`.
### Changed ### ### Changed ###
......
...@@ -5,18 +5,29 @@ from caosadvancedtools.cfoods.h5 import H5CFood ...@@ -5,18 +5,29 @@ from caosadvancedtools.cfoods.h5 import H5CFood
from caosadvancedtools.models.data_model import DataModel from caosadvancedtools.models.data_model import DataModel
from caosadvancedtools.models.parser import parse_model_from_yaml from caosadvancedtools.models.parser import parse_model_from_yaml
model = parse_model_from_yaml("model.yml")
model.sync_data_model(noquestion=True) def main():
if len(db.execute_query("FIND Property alias")) == 0: # for testing existing data model parts with the YAML Interface
al = db.Property(name="alias") db.RecordType(name="TestRT1", datatype=db.TEXT).insert()
al.add_parent(name="name") db.Property(name="TestP1", datatype=db.TEXT).insert()
al.insert()
model = parse_model_from_yaml("model.yml")
h5model = db.Container() model.sync_data_model(noquestion=True)
h5file = h5py.File('extroot/ExperimentalData/2010_TestProject/2019-02-03/hdf5_dummy_file.hdf5', 'r')
H5CFood.create_structure(h5file, create_recordTypes=True, collection=h5model, if len(db.execute_query("FIND Property alias")) == 0:
root_name="ExampleH5") al = db.Property(name="alias")
print(h5model) al.add_parent(name="name")
h5model = DataModel(h5model) al.insert()
h5model.sync_data_model(noquestion=True)
h5model = db.Container()
h5file = h5py.File(
'extroot/ExperimentalData/2010_TestProject/2019-02-03/hdf5_dummy_file.hdf5', 'r')
H5CFood.create_structure(h5file, create_recordTypes=True, collection=h5model,
root_name="ExampleH5")
h5model = DataModel(h5model)
h5model.sync_data_model(noquestion=True)
if __name__ == "__main__":
main()
...@@ -69,3 +69,6 @@ Report: ...@@ -69,3 +69,6 @@ Report:
- Publication - Publication
hdf5File: hdf5File:
datatype: REFERENCE datatype: REFERENCE
extern:
- TestRT1
- TestP1
...@@ -34,6 +34,8 @@ from caosadvancedtools.models.parser import parse_model_from_yaml ...@@ -34,6 +34,8 @@ from caosadvancedtools.models.parser import parse_model_from_yaml
from caosadvancedtools.scifolder import (AnalysisCFood, ExperimentCFood, from caosadvancedtools.scifolder import (AnalysisCFood, ExperimentCFood,
PublicationCFood, SimulationCFood) PublicationCFood, SimulationCFood)
from insert_model import main as insert_model
def setup_module(): def setup_module():
"""Clear problems and remove all entities except for built-in ones.""" """Clear problems and remove all entities except for built-in ones."""
...@@ -67,8 +69,7 @@ def test_crawler_with_data_model_problems(): ...@@ -67,8 +69,7 @@ def test_crawler_with_data_model_problems():
prefix="", dryrun=False, forceAllowSymlinks=False) prefix="", dryrun=False, forceAllowSymlinks=False)
# load and damage the model # load and damage the model
model = parse_model_from_yaml("model.yml") insert_model()
model.sync_data_model(noquestion=True)
deleted_entities = {"Experiment", "Poster", "results"} deleted_entities = {"Experiment", "Poster", "results"}
for ent in deleted_entities: for ent in deleted_entities:
......
...@@ -39,6 +39,9 @@ Let's start with an example taken from https://gitlab.indiscale.com/caosdb/src/c ...@@ -39,6 +39,9 @@ Let's start with an example taken from https://gitlab.indiscale.com/caosdb/src/c
table: table:
datatype: FILE datatype: FILE
description: 'A table document associated with this recording' description: 'A table document associated with this recording'
extern:
- Textfile
This example defines 3 ``RecordType``s: This example defines 3 ``RecordType``s:
...@@ -46,6 +49,9 @@ This example defines 3 ``RecordType``s: ...@@ -46,6 +49,9 @@ This example defines 3 ``RecordType``s:
- A ``Project`` with one obligatory property ``datatype`` - A ``Project`` with one obligatory property ``datatype``
- A Person with a ``firstName`` and a ``lastName`` (as recommended properties) - A Person with a ``firstName`` and a ``lastName`` (as recommended properties)
- A ``LabbookEntry`` with multiple recommended properties of different data types - A ``LabbookEntry`` with multiple recommended properties of different data types
- It is assumed that the server knows a RecordType or Property with the name
"Textfile".
One major advantage of using this interface (in contrast to the standard python interface) is that properties can be defined and added to record types "on-the-fly". E.g. the three lines for ``firstName`` as sub entries of ``Person`` have two effects on CaosDB: One major advantage of using this interface (in contrast to the standard python interface) is that properties can be defined and added to record types "on-the-fly". E.g. the three lines for ``firstName`` as sub entries of ``Person`` have two effects on CaosDB:
...@@ -60,6 +66,8 @@ Note the difference between the three property declarations of ``LabbookEntry``: ...@@ -60,6 +66,8 @@ Note the difference between the three property declarations of ``LabbookEntry``:
- ``responsible``: This defines and adds a property with name "responsible" to ``LabbookEntry`, which has a datatype ``Person``. ``Person`` is defined above. - ``responsible``: This defines and adds a property with name "responsible" to ``LabbookEntry`, which has a datatype ``Person``. ``Person`` is defined above.
- ``firstName``: This defines and adds a property with the standard data type ``TEXT`` to record type ``Person``. - ``firstName``: This defines and adds a property with the standard data type ``TEXT`` to record type ``Person``.
If the data model depends on already existing parts, those can be added using the ``extern`` keyword.
Datatypes Datatypes
--------- ---------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment