Skip to content
Snippets Groups Projects
Commit 086c9373 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

SensorLineChartTile: added tests for prepare_ghost_trace()

parent acdc4024
No related branches found
No related tags found
No related merge requests found
......@@ -84,12 +84,7 @@ class SensorLineChartTile(Tile):
# Check if all values are above zero and the min value for the sensor group is below zero.
# Therefore a ghost trace must be generated that fills the area underneath the x-axis.
ghostTraceX = []
ghostTraceY = []
if all(float(i) >= 0 for i in y):
if minValue < 0:
ghostTraceX = [x[0], x[-1]]
ghostTraceY = [minValue, minValue]
ghostTraceX, ghostTraceY = self._prepare_ghost_trace(minValue, x, y)
return {
'latest': latestValue,
......@@ -149,6 +144,17 @@ class SensorLineChartTile(Tile):
y.reverse()
return x, y
def _prepare_ghost_trace(self, minValue, x, y):
ghostTraceX = []
ghostTraceY = []
if all(float(i) >= 0 for i in y):
if minValue < 0:
ghostTraceX = [x[0], x[-1]]
ghostTraceY = [minValue, minValue]
return ghostTraceX, ghostTraceY
def render(self, data: Dict) -> str:
sensorType = data['sensorInfo']['type']
unit = self.UNIT_BY_SENSOR_TYPE.get(sensorType, '')
......
......@@ -142,3 +142,23 @@ class TestPrepareMeasurementData:
]
assert tile._prepare_measurement_data(measurements) == ([timestamp2, timestamp1], ['-6.2', '-5.4'])
class TestPrepareGhostTrace:
def test_all_values_below_zero_returns_empty_lists(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
x = ['2021-02-09 17:47:55']
y = [-12]
assert tile._prepare_ghost_trace(-10, x, y) == ([], [])
def test_all_values_above_zero_and_min_from_api_above_zero_returns_empty_lists(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
x = ['2021-02-09 17:47:55', '2021-02-09 17:48:55']
y = [6, 8]
assert tile._prepare_ghost_trace(10, x, y) == ([], [])
def test_all_values_above_zero_and_min_from_api_below_zero_returns_ghost_trace(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
x = ['2021-02-09 17:47:55', '2021-02-09 17:48:55']
y = [6, 8]
assert tile._prepare_ghost_trace(-10, x, y) == (x, [-10, -10])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment