Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
anselm
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
Container Registry
Model registry
Operate
Environments
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
vaclab
anselm
Commits
7c0a4e16
Commit
7c0a4e16
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
overwrite entry if result.Value length is > 1, +unittests
parent
0e3d67e4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
anselm/db.py
+10
-2
10 additions, 2 deletions
anselm/db.py
anselm/test_db.py
+20
-5
20 additions, 5 deletions
anselm/test_db.py
with
30 additions
and
7 deletions
anselm/db.py
+
10
−
2
View file @
7c0a4e16
...
...
@@ -204,10 +204,18 @@ class DB(System):
found
=
False
for
entr
in
doc
[
last_entr
]:
if
entr
.
get
(
'
Type
'
)
==
result
.
get
(
'
Type
'
):
found
=
True
if
isinstance
(
result
.
get
(
'
Value
'
),
list
)
and
len
(
result
.
get
(
'
Value
'
))
>
1
:
entr
=
result
# override
self
.
log
.
debug
(
"
value is list an length > 1, overwrite
"
)
entr
[
'
Value
'
]
=
result
.
get
(
'
Value
'
)
# override
entr
[
'
Unit
'
]
=
result
.
get
(
'
Unit
'
)
if
result
.
get
(
'
SdValue
'
):
if
entr
.
get
(
'
SdValue
'
):
entr
[
'
SdValue
'
]
=
result
[
'
SdValue
'
]
if
result
.
get
(
'
N
'
):
if
entr
.
get
(
'
N
'
):
entr
[
'
N
'
]
=
result
[
'
N
'
]
else
:
found
=
True
entr
[
'
Value
'
].
append
(
result
[
'
Value
'
]
)
entr
[
'
Unit
'
]
=
result
[
'
Unit
'
]
if
result
.
get
(
'
SdValue
'
):
...
...
This diff is collapsed.
Click to expand it.
anselm/test_db.py
+
20
−
5
View file @
7c0a4e16
...
...
@@ -46,8 +46,23 @@ class TestDB(unittest.TestCase):
self
.
db
.
doc_write_result
(
doc
,
doc_path
=
"
Calibration.Measurement.AuxValues.Pressure
"
,
result
=
{
"
Type
"
:
"
offset_x1
"
,
"
Value
"
:[
1
,
2
,
3
],
"
Unit
"
:
"
Pa
"
})
self
.
db
.
doc_write_result
(
doc
,
doc_path
=
"
Calibration.Measurement.AuxValues.Pressure
"
,
result
=
{
"
Type
"
:
"
offset_x0.1
"
,
"
Value
"
:[
4
,
5
,
6
],
"
Unit
"
:
"
Pa
"
})
self
.
db
.
doc_write_result
(
doc
,
doc_path
=
"
Calibration.Measurement.AuxValues.Pressure
"
,
result
=
{
"
Type
"
:
"
offset_x0.01
"
,
"
Value
"
:[
7
,
8
,
9
],
"
Unit
"
:
"
Pa
"
})
auxvalues
=
doc
.
get
(
'
Calibration
'
).
get
(
'
Measurement
'
,
{}).
get
(
'
AuxValues
'
,
{}).
get
(
'
Pressure
'
,
{})
self
.
assertEqual
(
len
(
auxvalues
),
4
)
self
.
assertEqual
(
auxvalues
[
1
].
get
(
'
Value
'
)[
2
],
3
)
self
.
assertEqual
(
auxvalues
[
2
].
get
(
'
Value
'
)[
2
],
6
)
self
.
assertEqual
(
auxvalues
[
3
].
get
(
'
Value
'
)[
2
],
9
)
pressure
=
doc
.
get
(
'
Calibration
'
).
get
(
'
Measurement
'
,
{}).
get
(
'
AuxValues
'
,
{}).
get
(
'
Pressure
'
,
{})
self
.
assertEqual
(
len
(
pressure
),
4
)
self
.
assertEqual
(
pressure
[
1
].
get
(
'
Value
'
)[
2
],
3
)
self
.
assertEqual
(
pressure
[
2
].
get
(
'
Value
'
)[
2
],
6
)
self
.
assertEqual
(
pressure
[
3
].
get
(
'
Value
'
)[
2
],
9
)
def
test_doc_write_result_5
(
self
):
"""
should override if len(value) > 1
"""
doc
=
{
'
Calibration
'
:
{
'
Measurement
'
:
{
'
AuxValues
'
:
{}}}}
self
.
db
.
doc_write_result
(
doc
,
doc_path
=
"
Calibration.Measurement.AuxValues.Pressure
"
,
result
=
{
"
Type
"
:
"
offset_x0.1
"
,
"
Value
"
:[
1
,
2
,
3
],
"
Unit
"
:
"
Pa
"
})
self
.
db
.
doc_write_result
(
doc
,
doc_path
=
"
Calibration.Measurement.AuxValues.Pressure
"
,
result
=
{
"
Type
"
:
"
offset_x0.1
"
,
"
Value
"
:[
4
,
5
,
6
],
"
Unit
"
:
"
Pa
"
})
pressure
=
doc
.
get
(
'
Calibration
'
).
get
(
'
Measurement
'
,
{}).
get
(
'
AuxValues
'
,
{}).
get
(
'
Pressure
'
,
{})
self
.
assertEqual
(
len
(
pressure
),
1
)
self
.
assertEqual
(
pressure
[
0
].
get
(
'
Value
'
)[
2
],
6
)
self
.
db
.
doc_write_result
(
doc
,
doc_path
=
"
Calibration.Measurement.AuxValues.Pressure
"
,
result
=
{
"
Type
"
:
"
offset_x0.1
"
,
"
Value
"
:[
7
,
8
,
9
],
"
Unit
"
:
"
Pa
"
})
pressure
=
doc
.
get
(
'
Calibration
'
).
get
(
'
Measurement
'
,
{}).
get
(
'
AuxValues
'
,
{}).
get
(
'
Pressure
'
,
{})
self
.
assertEqual
(
len
(
pressure
),
1
)
self
.
assertEqual
(
pressure
[
0
].
get
(
'
Value
'
)[
2
],
9
)
\ No newline at end of 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