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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
99c7bcc8
Commit
99c7bcc8
authored
Feb 26, 2024
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
ceff40d2
No related branches found
No related tags found
No related merge requests found
Pipeline
#47857
failed
Feb 26, 2024
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+16
-8
16 additions, 8 deletions
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
unittests/table_json_conversion/test_fill_xlsx.py
+4
-1
4 additions, 1 deletion
unittests/table_json_conversion/test_fill_xlsx.py
with
20 additions
and
9 deletions
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+
16
−
8
View file @
99c7bcc8
...
@@ -24,14 +24,15 @@ from openpyxl import load_workbook
...
@@ -24,14 +24,15 @@ from openpyxl import load_workbook
from
.table_generator
import
ColumnType
,
RowType
from
.table_generator
import
ColumnType
,
RowType
def
_fill_leaves
(
json_doc
:
dict
,
workbook
):
def
_fill_leaves
(
json_doc
:
dict
,
workbook
,
path
:
list
,
cm
:
dict
):
for
key
,
value
in
json_doc
:
for
key
,
value
in
json_doc
:
if
not
isinstance
(
value
,
list
):
if
not
isinstance
(
value
,
list
):
value
=
[
value
]
value
=
[
value
]
for
el
in
value
:
for
el
in
value
:
if
isinstance
(
el
,
dict
):
if
isinstance
(
el
,
dict
):
_fill_leaves
(
el
,
workbook
)
_fill_leaves
(
el
,
workbook
,
path
+
[
key
])
wb
.
cell
(
1
,
2
,
el
)
sn
,
coli
=
cm
[
"
.
"
.
join
(
path
)]
wb
[
sn
].
columns
[
coli
].
cell
(
1
,
2
,
el
)
#TODO what row ?????
def
_get_row_type_column
(
worksheet
):
def
_get_row_type_column
(
worksheet
):
for
col
in
worksheet
.
columns
:
for
col
in
worksheet
.
columns
:
...
@@ -44,7 +45,6 @@ def _get_path_rows(worksheet):
...
@@ -44,7 +45,6 @@ def _get_path_rows(worksheet):
rows
=
[]
rows
=
[]
rt_col
=
_get_row_type_column
(
worksheet
)
rt_col
=
_get_row_type_column
(
worksheet
)
for
cell
in
list
(
worksheet
.
columns
)[
rt_col
-
1
]:
for
cell
in
list
(
worksheet
.
columns
)[
rt_col
-
1
]:
print
(
cell
.
value
)
if
cell
.
value
==
RowType
.
PATH
.
name
:
if
cell
.
value
==
RowType
.
PATH
.
name
:
rows
.
append
(
cell
.
row
)
rows
.
append
(
cell
.
row
)
return
rows
return
rows
...
@@ -52,11 +52,19 @@ def _get_path_rows(worksheet):
...
@@ -52,11 +52,19 @@ def _get_path_rows(worksheet):
def
_generate_path_col_mapping
(
workbook
):
def
_generate_path_col_mapping
(
workbook
):
rt_col
=
_get_row_type_column
(
workbook
)
col_mapping
=
{}
for
sn
in
workbook
.
sheetnames
:
for
col
in
workbook
.
columns
:
worksheet
=
workbook
[
sn
]
pass
path_rows
=
_get_path_rows
(
worksheet
)
rt_col
=
_get_row_type_column
(
worksheet
)
for
ii
,
col
in
enumerate
(
worksheet
.
columns
):
if
ii
+
1
==
rt_col
:
continue
path
=
[
col
[
el
-
1
].
value
for
el
in
path_rows
if
col
[
el
-
1
].
value
is
not
None
]
col_mapping
[
"
.
"
.
join
(
path
)]
=
(
sn
,
ii
)
print
(
col_mapping
)
return
col_mapping
def
fill_template
(
template_path
:
str
,
json_path
:
str
,
result_path
:
str
)
->
None
:
def
fill_template
(
template_path
:
str
,
json_path
:
str
,
result_path
:
str
)
->
None
:
"""
"""
...
...
This diff is collapsed.
Click to expand it.
unittests/table_json_conversion/test_fill_xlsx.py
+
4
−
1
View file @
99c7bcc8
...
@@ -23,7 +23,8 @@ import os
...
@@ -23,7 +23,8 @@ import os
import
tempfile
import
tempfile
from
caosadvancedtools.table_json_conversion.fill_xlsx
import
(
from
caosadvancedtools.table_json_conversion.fill_xlsx
import
(
_get_path_rows
,
_get_row_type_column
,
fill_template
)
_generate_path_col_mapping
,
_get_path_rows
,
_get_row_type_column
,
fill_template
)
from
openpyxl
import
load_workbook
from
openpyxl
import
load_workbook
...
@@ -39,6 +40,8 @@ def test_detect():
...
@@ -39,6 +40,8 @@ def test_detect():
example
=
load_workbook
(
rfp
(
"
example_template.xlsx
"
))
example
=
load_workbook
(
rfp
(
"
example_template.xlsx
"
))
assert
1
==
_get_row_type_column
(
example
[
'
Person
'
])
assert
1
==
_get_row_type_column
(
example
[
'
Person
'
])
assert
[
2
,
3
,
4
]
==
_get_path_rows
(
example
[
'
Person
'
])
assert
[
2
,
3
,
4
]
==
_get_path_rows
(
example
[
'
Person
'
])
cm
=
_generate_path_col_mapping
(
example
)
assert
cm
[
'
Person.Organisation.Country
'
]
==
(
'
Person
'
,
5
)
def
test_fill_xlsx
():
def
test_fill_xlsx
():
path
=
os
.
path
.
join
(
tempfile
.
mkdtemp
(),
'
test.xlsx
'
)
path
=
os
.
path
.
join
(
tempfile
.
mkdtemp
(),
'
test.xlsx
'
)
...
...
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