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

#45 - SensorLineChartTile: refactored settings for warning for outdated values

parent dd3a0d92
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,12 @@ ...@@ -18,7 +18,12 @@
"numberOfHoursToShow": 4, "numberOfHoursToShow": 4,
"decimals": 1, "decimals": 1,
"lineColor": "rgba(254, 151, 0, 1)", "lineColor": "rgba(254, 151, 0, 1)",
"fillColor": "rgba(254, 151, 0, 0.2)" "fillColor": "rgba(254, 151, 0, 0.2)",
"showAxes": false,
"outdatedValueWarning": {
"enable": false,
"limitInSeconds": -1
}
}, },
"x": 0, "x": 0,
"y": 0, "y": 0,
......
...@@ -95,10 +95,10 @@ ...@@ -95,10 +95,10 @@
<div class="value">{{ latest }}{{ unit }}</div> <div class="value">{{ latest }}{{ unit }}</div>
{% endif %} {% endif %}
</div> </div>
{% if timeAgo %} {% if timeSinceLastValue %}
<div class="warning"> <div class="warning">
<i class="material-icons icon-warning">warning</i> <i class="material-icons icon-warning">warning</i>
<div class="warning-text">{{ timeAgo }}</div> <div class="warning-text">{{ timeSinceLastValue }}</div>
</div> </div>
{% endif %} {% endif %}
<div class="header-right"> <div class="header-right">
......
...@@ -32,7 +32,10 @@ class SensorLineChartTile(Tile): ...@@ -32,7 +32,10 @@ class SensorLineChartTile(Tile):
"lineColor": "rgba(254, 151, 0, 1)", "lineColor": "rgba(254, 151, 0, 1)",
"fillColor": "rgba(254, 151, 0, 0.2)", "fillColor": "rgba(254, 151, 0, 0.2)",
"showAxes": True, "showAxes": True,
"outdatedValueWarningLimitInSeconds": 300 # use -1 to disable warning "outdatedValueWarning": {
"enable": False,
"limitInSeconds": 300
}
} }
UNIT_BY_SENSOR_TYPE = { UNIT_BY_SENSOR_TYPE = {
...@@ -176,13 +179,8 @@ class SensorLineChartTile(Tile): ...@@ -176,13 +179,8 @@ class SensorLineChartTile(Tile):
days = int(self._settings['numberOfHoursToShow'] / 24) days = int(self._settings['numberOfHoursToShow'] / 24)
title = f'{title} - {days} days' title = f'{title} - {days} days'
now = datetime.now() warningSettings = self._settings['outdatedValueWarning']
timeAgo = '' timeSinceLastValue = self.__get_time_since_last_value(warningSettings, data)
outdatedValueWarningLimitInSeconds = self._settings['outdatedValueWarningLimitInSeconds']
if outdatedValueWarningLimitInSeconds > 0:
timeDifference = now - data['latestTime']
if timeDifference.total_seconds() > outdatedValueWarningLimitInSeconds:
timeAgo = format(timeDifference)
return Tile.render_template(os.path.dirname(__file__), __class__.__name__, return Tile.render_template(os.path.dirname(__file__), __class__.__name__,
x=data['x'], x=data['x'],
...@@ -200,7 +198,24 @@ class SensorLineChartTile(Tile): ...@@ -200,7 +198,24 @@ class SensorLineChartTile(Tile):
ghostTraceX=data['ghostTraceX'], ghostTraceX=data['ghostTraceX'],
ghostTraceY=data['ghostTraceY'], ghostTraceY=data['ghostTraceY'],
showAxes=self._settings['showAxes'], showAxes=self._settings['showAxes'],
timeAgo=timeAgo) timeSinceLastValue=timeSinceLastValue)
def __get_time_since_last_value(self, warningSettings: Dict, data):
timeAgo = ''
if not warningSettings['enable']:
return timeAgo
now = datetime.now()
limitInSeconds = warningSettings['limitInSeconds']
if limitInSeconds > 0:
timeDifference = now - data['latestTime']
if timeDifference.total_seconds() > limitInSeconds:
timeAgo = format(timeDifference)
return timeAgo
def __format_date(self, dateTime: str): def __format_date(self, dateTime: str):
parsedDateTime = datetime.strptime(dateTime, self.DATE_FORMAT) parsedDateTime = datetime.strptime(dateTime, self.DATE_FORMAT)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment