Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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-advanced-user-tools
Commits
51728602
Commit
51728602
authored
1 year ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: comments and sanity checks
parent
b8ab0b16
No related branches found
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!100
WIP: Filling XLSX: Seems to be working.
,
!94
ENH: add framework for converting json schema into table templates
,
!93
Filling XLSX: Everything except multiple choice.
,
!92
ENH: xlsx template generator
Pipeline
#48100
failed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/table_json_conversion/table_generator.py
+33
-21
33 additions, 21 deletions
...aosadvancedtools/table_json_conversion/table_generator.py
with
33 additions
and
21 deletions
src/caosadvancedtools/table_json_conversion/table_generator.py
+
33
−
21
View file @
51728602
...
...
@@ -139,6 +139,9 @@ class TableTemplateGenerator(ABC):
----------
array_paths: list
a list of path along the way to the current object, where the json contains arrays
schema: dict
part of the json schema; it must be the level that contains the type definition
(e.g.
'
type
'
or
'
oneOf
'
key)
Returns
-------
...
...
@@ -161,20 +164,26 @@ class TableTemplateGenerator(ABC):
if
'
type
'
in
schema
and
schema
[
'
type
'
]
==
'
array
'
:
if
(
'
type
'
in
schema
[
'
items
'
]
and
schema
[
'
items
'
][
'
type
'
]
==
'
object
'
and
len
(
path
)
>
1
):
# list of references; special treatment
# we add a new sheet
# we add a new sheet
with columns generated from the subtree of the schema
sheetname
=
"
.
"
.
join
(
path
)
if
sheetname
in
sheets
:
raise
ValueError
(
f
"
The shema would lead to two sheets with the same name which
"
f
"
is forbidden:
{
sheetname
}
"
)
sheets
[
sheetname
]
=
self
.
_treat_schema_element
(
schema
[
'
items
'
],
sheets
,
path
,
foreign_keys
,
len
(
path
),
array_paths
=
array_paths
+
[
path
]
# since this level is an array, we extend the list
)
# and add the foreign keys that are necessary up to this point
for
p
in
array_paths
:
keys
=
self
.
_get_foreign_keys
(
foreign_keys
,
p
)
for
k
in
keys
:
sheets
[
sheetname
].
update
({
k
:
(
ColumnType
.
FOREIGN
,
f
"
see sheet
'
{
path
[
0
]
}
'"
,
p
+
[
k
])})
if
k
in
sheets
[
sheetname
]:
raise
ValueError
(
f
"
The shema would lead to two columns with the same
"
f
"
name which is forbidden:
{
k
}
"
)
sheets
[
sheetname
][
k
]
=
(
ColumnType
.
FOREIGN
,
f
"
see sheet
'
{
path
[
0
]
}
'"
,
p
+
[
k
])
# columns are added to the new sheet, thus we do not return columns
return
{}
else
:
# it is a list of primitive types -> semi colon separated list
else
:
# it is a list of primitive types -> semi colon separated list
schema
=
schema
[
'
items
'
]
ctype
=
ColumnType
.
LIST
...
...
@@ -183,31 +192,34 @@ class TableTemplateGenerator(ABC):
if
'
type
'
in
el
:
schema
=
el
if
"
properties
"
in
schema
:
# recurse for each property
if
"
properties
"
in
schema
:
# recurse for each property
cols
=
{}
for
pname
in
schema
[
"
properties
"
].
keys
():
col
s
.
update
(
self
.
_treat_schema_element
(
col
_defs
=
self
.
_treat_schema_element
(
schema
[
"
properties
"
][
pname
],
sheets
,
path
+
[
pname
],
foreign_keys
,
level_in_sheet_name
,
array_paths
=
array_paths
))
level_in_sheet_name
,
array_paths
=
array_paths
)
for
k
in
col_defs
.
keys
():
if
k
in
cols
:
raise
ValueError
(
f
"
The shema would lead to two columns with the same
"
f
"
name which is forbidden:
{
k
}
"
)
cols
.
update
(
col_defs
)
return
cols
else
:
else
:
# those are the leaves
description
=
schema
[
'
description
'
]
if
'
description
'
in
schema
else
None
# those are the leaves
if
'
type
'
not
in
schema
:
if
'
enum
'
in
schema
:
return
{
"
.
"
.
join
(
path
[
level_in_sheet_name
:]):
(
ctype
,
description
,
path
)}
if
'
anyOf
'
in
schema
:
for
d
in
schema
[
'
anyOf
'
]:
# currently the only case where this occurs is date formats
assert
d
[
'
type
'
]
==
'
string
'
assert
d
[
'
format
'
]
==
'
date
'
or
d
[
'
format
'
]
==
'
date-time
'
return
{
"
.
"
.
join
(
path
[
level_in_sheet_name
:]):
(
ctype
,
description
,
path
)}
# definition of a single column
default_return
=
{
"
.
"
.
join
(
path
[
level_in_sheet_name
:]):
(
ctype
,
description
,
path
)}
if
'
type
'
not
in
schema
and
'
enum
'
in
schema
:
return
default_return
elif
'
type
'
not
in
schema
and
'
anyOf
'
in
schema
:
for
d
in
schema
[
'
anyOf
'
]:
# currently the only case where this occurs is date formats
assert
d
[
'
type
'
]
==
'
string
'
assert
d
[
'
format
'
]
==
'
date
'
or
d
[
'
format
'
]
==
'
date-time
'
return
default_return
elif
schema
[
"
type
"
]
in
[
'
string
'
,
'
number
'
,
'
integer
'
,
'
boolean
'
]:
if
'
format
'
in
schema
and
schema
[
'
format
'
]
==
'
data-url
'
:
return
{}
# file; ignore for now
return
{
"
.
"
.
join
(
path
[
level_in_sheet_name
:]):
(
ctype
,
description
,
path
)}
return
default_return
else
:
raise
ValueError
(
"
Inappropriate JSON schema: The following part should define an
"
f
"
object with properties or a primitive type:
\n
{
schema
}
\n
"
)
...
...
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