Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dccQuantities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
DigitalDynamicMeasurement
dccQuantities
Commits
17e82fc8
Commit
17e82fc8
authored
4 months ago
by
Vanessa Stehr
Browse files
Options
Downloads
Patches
Plain Diff
Implement toJsonDict for list types (siList, siHybrid).
parent
cf9d8c98
No related branches found
No related tags found
No related merge requests found
Pipeline
#51997
passed
4 months ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/AbstractListType.py
+9
-1
9 additions, 1 deletion
src/AbstractListType.py
src/SiHybrid.py
+3
-0
3 additions, 0 deletions
src/SiHybrid.py
src/SiList.py
+18
-0
18 additions, 0 deletions
src/SiList.py
with
30 additions
and
1 deletion
src/AbstractListType.py
+
9
−
1
View file @
17e82fc8
from
__future__
import
annotations
# for type annotation recursion
from
__future__
import
annotations
from
collections
import
defaultdict
# for type annotation recursion
from
AbstractQuantityTypeData
import
AbstractQuantityTypeData
from
AbstractValueType
import
AbstractValueType
...
...
@@ -10,6 +11,13 @@ class AbstractListType(AbstractQuantityTypeData):
super
().
__init__
()
self
.
children
=
children
def
toJsonDict
(
self
):
result
=
defaultdict
(
list
)
for
child
in
self
.
children
:
childJson
=
child
.
toJsonDict
()
for
key
,
value
in
childJson
.
items
():
result
[
key
].
append
(
value
)
return
dict
(
result
)
def
flatten
(
self
):
pass
...
...
This diff is collapsed.
Click to expand it.
src/SiHybrid.py
+
3
−
0
View file @
17e82fc8
...
...
@@ -14,6 +14,9 @@ class SiHybrid(AbstractListType):
def
getUnits
(
self
):
pass
def
toJsonDict
(
self
):
return
{
'
si:hybrid
'
:
super
().
toJsonDict
()}
def
__repr__
(
self
)
->
str
:
params
=
{
key
:
value
for
key
,
value
in
vars
(
self
).
items
()
if
value
is
not
None
}
paramStr
=
"
,
"
.
join
(
f
"
{
key
}
=
{
repr
(
value
)
}
"
for
key
,
value
in
params
.
items
())
...
...
This diff is collapsed.
Click to expand it.
src/SiList.py
+
18
−
0
View file @
17e82fc8
...
...
@@ -16,6 +16,24 @@ class SiList(AbstractListType):
super
().
__init__
(
children
)
self
.
label
=
label
self
.
dateTime
=
dateTime
def
toJsonDict
(
self
):
keyMapping
=
{
'
label
'
:
'
si:label
'
,
'
dateTime
'
:
'
si:dateTime
'
,
}
attributes
=
super
().
toJsonDict
()
# converts all the data in 'children'
for
key
,
value
in
self
.
__dict__
.
items
():
if
value
:
if
key
in
keyMapping
:
attributes
[
keyMapping
[
key
]]
=
value
elif
key
==
'
children
'
:
pass
else
:
attributes
[
key
]
=
value
# TODO: This should not happen, maybe add a warning?
return
{
'
si:list
'
:
attributes
}
def
__repr__
(
self
)
->
str
:
params
=
{
key
:
value
for
key
,
value
in
vars
(
self
).
items
()
if
value
is
not
None
}
...
...
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