Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DashboardLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
ProjectLeaf
DashboardLeaf
Commits
acdc4024
Commit
acdc4024
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
SensorLineChartTile: added tests for prepare_measurement_data()
parent
56861662
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/logic/tile/tiles/SensorLineChartTile.py
+2
-2
2 additions, 2 deletions
src/logic/tile/tiles/SensorLineChartTile.py
src/logic/tile/tiles/TestSensorLineChartTile.py
+30
-0
30 additions, 0 deletions
src/logic/tile/tiles/TestSensorLineChartTile.py
with
32 additions
and
2 deletions
src/logic/tile/tiles/SensorLineChartTile.py
+
2
−
2
View file @
acdc4024
...
@@ -71,7 +71,7 @@ class SensorLineChartTile(Tile):
...
@@ -71,7 +71,7 @@ class SensorLineChartTile(Tile):
cacheKey
=
f
'
{
pageName
}
_
{
self
.
_uniqueName
}
_all
'
cacheKey
=
f
'
{
pageName
}
_
{
self
.
_uniqueName
}
_all
'
sensorData
=
storageLeafService
.
get_data
(
cacheKey
,
self
.
_intervalInSeconds
,
serviceSettings
)
sensorData
=
storageLeafService
.
get_data
(
cacheKey
,
self
.
_intervalInSeconds
,
serviceSettings
)
x
,
y
=
self
.
_
_
prepare_measurement_data
(
sensorData
[
'
sensorValue
'
])
x
,
y
=
self
.
_prepare_measurement_data
(
sensorData
[
'
sensorValue
'
])
latestTime
=
datetime
.
strptime
(
x
[
-
1
],
self
.
DATE_FORMAT
)
if
x
else
self
.
DATETIME_UNIX_TIMESTAMP_START
latestTime
=
datetime
.
strptime
(
x
[
-
1
],
self
.
DATE_FORMAT
)
if
x
else
self
.
DATETIME_UNIX_TIMESTAMP_START
latestValue
=
y
[
-
1
]
if
y
else
''
latestValue
=
y
[
-
1
]
if
y
else
''
...
@@ -134,7 +134,7 @@ class SensorLineChartTile(Tile):
...
@@ -134,7 +134,7 @@ class SensorLineChartTile(Tile):
LOGGER
.
debug
(
f
'
Received min/max:
{
minMaxData
}
for sensorIDs:
{
self
.
_settings
[
"
sensorIDsForMinMax
"
]
}
'
)
LOGGER
.
debug
(
f
'
Received min/max:
{
minMaxData
}
for sensorIDs:
{
self
.
_settings
[
"
sensorIDsForMinMax
"
]
}
'
)
return
minMaxData
.
get
(
'
min
'
,
0
)
or
0
,
minMaxData
.
get
(
'
max
'
,
0
)
or
0
return
minMaxData
.
get
(
'
min
'
,
0
)
or
0
,
minMaxData
.
get
(
'
max
'
,
0
)
or
0
def
_
_prepare_measurement_data
(
self
,
measurements
:
List
[
Dict
])
->
Tuple
[
List
[
str
],
List
[
str
]]:
def
_prepare_measurement_data
(
self
,
measurements
:
List
[
Dict
])
->
Tuple
[
List
[
str
],
List
[
str
]]:
x
=
[]
x
=
[]
y
=
[]
y
=
[]
...
...
This diff is collapsed.
Click to expand it.
src/logic/tile/tiles/TestSensorLineChartTile.py
+
30
−
0
View file @
acdc4024
import
datetime
import
datetime
from
unittest.mock
import
MagicMock
from
unittest.mock
import
MagicMock
import
pytest
from
logic.tile.tiles.SensorLineChartTile
import
SensorLineChartTile
,
SensorType
from
logic.tile.tiles.SensorLineChartTile
import
SensorLineChartTile
,
SensorType
...
@@ -112,3 +114,31 @@ class TestGetMinMax:
...
@@ -112,3 +114,31 @@ class TestGetMinMax:
storage_leaf_service_mock
(
None
,
None
),
storage_leaf_service_mock
(
None
,
None
),
[
-
6.0
,
12
])
[
-
6.0
,
12
])
assert
result
==
(
-
6
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
12
+
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
assert
result
==
(
-
6
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
12
+
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
class
TestPrepareMeasurementData
:
def
test_no_measurements
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
measurements
=
[]
assert
tile
.
_prepare_measurement_data
(
measurements
)
==
([],
[])
def
test_should_return_rounded_values
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
measurements
=
[
{
'
id
'
:
409281
,
'
value
'
:
'
-5.37
'
,
'
timestamp
'
:
'
2021-02-09 17:47:55
'
,
'
sensor_id
'
:
5
}
]
assert
tile
.
_prepare_measurement_data
(
measurements
)
==
([
'
2021-02-09 17:47:55
'
],
[
'
-5.4
'
])
def
test_multiple_measurements_should_return_timestamps_from_latest_to_oldest
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
timestamp1
=
'
2021-02-09 17:47:55
'
timestamp2
=
'
2021-02-09 17:48:55
'
measurements
=
[
{
'
id
'
:
409281
,
'
value
'
:
'
-5.37
'
,
'
timestamp
'
:
timestamp1
,
'
sensor_id
'
:
5
},
{
'
id
'
:
409282
,
'
value
'
:
'
-6.2
'
,
'
timestamp
'
:
timestamp2
,
'
sensor_id
'
:
5
}
]
assert
tile
.
_prepare_measurement_data
(
measurements
)
==
([
timestamp2
,
timestamp1
],
[
'
-6.2
'
,
'
-5.4
'
])
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