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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
94e8ca30
Commit
94e8ca30
authored
4 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: new function that recursively retrieves connected entities
parent
ea5763be
No related branches found
No related tags found
2 merge requests
!33
MAINT: change arguments of create_user
,
!16
F retrieve substructure
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/utils/plantuml.py
+57
-0
57 additions, 0 deletions
src/caosdb/utils/plantuml.py
with
57 additions
and
0 deletions
src/caosdb/utils/plantuml.py
+
57
−
0
View file @
94e8ca30
...
...
@@ -222,6 +222,63 @@ def to_graphics(recordtypes, filename):
data_structure.svg will be created.
"""
pu
=
recordtypes_to_plantuml_string
(
recordtypes
)
def
retrieve_substructure
(
start_record_types
,
depth
,
result_id_set
=
None
,
result_container
=
None
,
cleanup
=
True
):
"""
Recursively retrieves CaosDB record types and properties, starting
from given initial types up to a specific depth.
Parameters
----------
start_record_types : Iterable[db.Entity]
Iterable with the entities to be displayed. Starting from these
entities more entities will be retrieved.
depth : int
The maximum depth up to which to retriev sub entities.
result_id_set : set[int]
Used by recursion. Filled with already visited ids.
result_container : db.Container
Used by recursion. Filled with already visited entities.
cleanup : bool
Used by recursion. If True return the resulting result_container.
Don
'
t return anything otherwise.
Returns
-------
db.Container
A container containing all the retrieved entites or None if cleanup is False.
"""
# Initialize the id set and result container for level zero recursion depth:
if
result_id_set
is
None
:
result_id_set
=
set
()
if
result_container
is
None
:
result_container
=
db
.
Container
()
for
entity
in
start_record_types
:
entity
.
retrieve
()
if
entity
.
id
not
in
result_id_set
:
result_container
.
append
(
entity
)
result_id_set
.
add
(
entity
.
id
)
for
prop
in
entity
.
properties
:
if
is_reference
(
prop
.
datatype
)
and
prop
.
datatype
!=
db
.
FILE
and
depth
>
0
:
rt
=
db
.
RecordType
(
name
=
get_referenced_recordtype
(
prop
.
datatype
)).
retrieve
()
retrieve_substructure
([
rt
],
depth
-
1
,
result_id_set
,
result_container
,
False
)
else
:
if
prop
.
id
not
in
result_id_set
:
result_container
.
append
(
prop
)
result_id_set
.
add
(
prop
.
id
)
for
parent
in
entity
.
parents
:
rt
=
db
.
RecordType
(
id
=
parent
.
id
).
retrieve
()
if
parent
.
id
not
in
result_id_set
:
result_container
.
append
(
rt
)
result_id_set
.
add
(
parent
.
id
)
if
depth
>
0
:
retrieve_substructure
([
rt
],
depth
-
1
,
result_id_set
,
result_container
,
False
)
if
cleanup
:
return
result_container
return
None
pu_filename
=
filename
+
"
.pu
"
with
open
(
pu_filename
,
"
w
"
)
as
pu_file
:
...
...
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