Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
a56e8186
Commit
a56e8186
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: refactored multiple methods needed for parameter management of simulations
parent
ede2a96f
No related branches found
No related tags found
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Pipeline
#20012
failed
3 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/apiutils.py
+23
-0
23 additions, 0 deletions
src/caosdb/apiutils.py
src/caosdb/high_level_api.py
+43
-9
43 additions, 9 deletions
src/caosdb/high_level_api.py
with
66 additions
and
9 deletions
src/caosdb/apiutils.py
+
23
−
0
View file @
a56e8186
...
@@ -480,3 +480,26 @@ def resolve_reference(prop: Property):
...
@@ -480,3 +480,26 @@ def resolve_reference(prop: Property):
else
:
else
:
if
isinstance
(
prop
.
value
,
int
):
if
isinstance
(
prop
.
value
,
int
):
prop
.
value
=
retrieve_entity_with_id
(
prop
.
value
)
prop
.
value
=
retrieve_entity_with_id
(
prop
.
value
)
def
create_flat_list
(
ent_list
:
list
[
Entity
],
flat
:
list
[
Entity
]):
"""
Recursively adds all properties contained in entities from ent_list to
the output list flat. Each element will only be added once to the list.
TODO: Currently this function is also contained in newcrawler module crawl.
We are planning to permanently move it to here.
"""
for
ent
in
ent_list
:
for
p
in
ent
.
properties
:
# For lists append each element that is of type Entity to flat:
if
isinstance
(
p
.
value
,
list
):
for
el
in
p
.
value
:
if
isinstance
(
el
,
Entity
):
if
el
not
in
flat
:
flat
.
append
(
el
)
create_flat_list
([
el
],
flat
)
# TODO: move inside if block?
elif
isinstance
(
p
.
value
,
Entity
):
if
p
.
value
not
in
flat
:
flat
.
append
(
p
.
value
)
create_flat_list
([
p
.
value
],
flat
)
# TODO: move inside if block?
This diff is collapsed.
Click to expand it.
src/caosdb/high_level_api.py
+
43
−
9
View file @
a56e8186
...
@@ -37,7 +37,7 @@ from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
...
@@ -37,7 +37,7 @@ from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
is_reference
)
is_reference
)
import
caosdb
as
db
import
caosdb
as
db
from
.apiutils
import
get_type_of_entity_with
from
.apiutils
import
get_type_of_entity_with
,
create_flat_list
from
typing
import
Any
,
Optional
,
List
,
Union
,
Dict
from
typing
import
Any
,
Optional
,
List
,
Union
,
Dict
...
@@ -806,11 +806,9 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity],
...
@@ -806,11 +806,9 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity],
high_level_type_for_standard_type
(
entity
)(),
entity
,
references
)
high_level_type_for_standard_type
(
entity
)(),
entity
,
references
)
def
new_high_level_entity_for_record_type
(
entity
:
db
.
RecordType
,
def
new_high_level_entity
(
entity
:
db
.
RecordType
,
importance_level
:
str
,
importance_level
:
str
,
name
:
str
=
None
,
name
:
str
=
None
):
deep
:
bool
=
True
,
references
:
Optional
[
db
.
Container
]
=
None
):
"""
"""
Create an new record in high level format based on a record type in standard format.
Create an new record in high level format based on a record type in standard format.
...
@@ -840,9 +838,45 @@ def new_high_level_entity_for_record_type(entity: db.RecordType,
...
@@ -840,9 +838,45 @@ def new_high_level_entity_for_record_type(entity: db.RecordType,
r
.
add_property
(
prop
)
r
.
add_property
(
prop
)
if
deep
:
raise
NotImplementedError
(
"
Recursive creation is not possible at the moment.
"
)
return
convert_to_python_object
(
r
)
return
convert_to_python_object
(
r
)
def
create_record
(
rtname
:
str
,
name
:
str
=
None
,
**
kwargs
):
"""
Create a new record based on the name of a record type. The new record is returned.
rtname: str
The name of the record type.
name: str
This is optional. A name for the new record.
kwargs:
Additional arguments are used to set attributes of the
new record.
"""
obj
=
new_high_level_entity
(
db
.
RecordType
(
name
=
rtname
).
retrieve
(),
"
SUGGESTED
"
,
name
)
for
key
,
value
in
kwargs
.
items
():
obj
.
__setattr__
(
key
,
value
)
return
obj
def
load_external_record
(
record_name
:
str
):
"""
Retrieve a record by name and convert it to the high level API format.
"""
return
convert_to_python_object
(
db
.
Record
(
name
=
record_name
).
retrieve
())
def
create_entity_container
(
record
:
CaosDBPythonEntity
):
"""
Convert this record into an entity container in standard format that can be used
to insert or update entities in a running CaosDB instance.
"""
ent
=
convert_to_entity
(
record
)
lse
:
List
[
db
.
Entity
]
=
[
ent
]
create_flat_list
([
ent
],
lse
)
return
db
.
Container
().
extend
(
lse
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment