Skip to content

Commit

Permalink
fix: switch from fetch_minimum_timestamp to fetch_maximum_timestamp
Browse files Browse the repository at this point in the history
and fix fetch_minimum_timestamp
  • Loading branch information
hbruch committed Aug 26, 2024
1 parent 595e709 commit 4f589b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion templates/weather/weather.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"roadTemperatureC": {{ fetch_timeseries(id, 'act_temp_road_surf') }},
"precipitationType": {{ fetch_timeseries(id, 'precip_type') }},
"roadCondition": {{ fetch_timeseries(id, 'act_road_condition') }},
"updatedAt": "{{ fetch_minimum_timestamp(id) }}"
"updatedAt": "{{ fetch_maximum_timestamp(id) }}"
},
"geometry": {
"type": "Point",
Expand Down
13 changes: 12 additions & 1 deletion thingsboard-json-enhancer
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ def fetch_minimum_timestamp(id, keys = None):
timestamp = ts[key][0]['ts']/1000
if min_timestamp is None or timestamp < min_timestamp:
min_timestamp = timestamp
return time.strftime('%Y-%m-%dT%H:%M:%S%z', time.localtime(timestamp))
return time.strftime('%Y-%m-%dT%H:%M:%S%z', time.localtime(min_timestamp))

def fetch_maximum_timestamp(id, keys = None):
ts = _fetch_timeseries(id)
max_timestamp = None
for key in ts.keys():
if keys is None or key in keys:
timestamp = ts[key][0]['ts']/1000
if max_timestamp is None or timestamp > max_timestamp:
max_timestamp = timestamp
return time.strftime('%Y-%m-%dT%H:%M:%S%z', time.localtime(max_timestamp))

def fetch_attribute(id, key):
return _get_attribute(_fetch_attributes(id), key)
Expand All @@ -96,6 +106,7 @@ def transform_file(input_file, output_file):
template.globals['fetch_timeseries'] = fetch_timeseries_value
template.globals['fetch_timeseries_map'] = fetch_timeseries_map
template.globals['fetch_device_timeseries'] = fetch_device_timeseries_value
template.globals['fetch_maximum_timestamp'] = fetch_maximum_timestamp
template.globals['fetch_minimum_timestamp'] = fetch_minimum_timestamp
template.globals['now'] = now_iso

Expand Down

0 comments on commit 4f589b3

Please sign in to comment.