Integration Toolkit Solutions Wiki

Incremental readings from totalising meter using asMap() and lag()

Useful for extracting the difference in periodic meter readings.

Sample dataset
"#NAMES"
"t_stamp","reading"
"#TYPES"
"date","I"
"#ROWS","6"
"2025-04-17 00:00:00.000","5"
"2025-04-17 01:00:00.000","7"
"2025-04-17 02:00:00.000","11"
"2025-04-17 03:00:00.000","17"
"2025-04-17 04:00:00.000","25"
"2025-04-17 05:00:00.000","35"

or paste the JSON below onto a component's custom.data.

[
  {"t_stamp": 1744844400000, "reading": 5 },
  {"t_stamp": 1744848000000, "reading": 7},
  {"t_stamp": 1744851600000, "reading": 11},
  {"t_stamp": 1744855200000, "reading": 17},
  {"t_stamp": 1744858800000, "reading": 25},
  {"t_stamp": 1744862400000, "reading": 35}
]
Output
[
  {"t_stamp":1744844400000,"reading": null},
  {"t_stamp":1744848000000,"reading": 2},
  {"t_stamp":1744851600000,"reading": 4},
  {"t_stamp":1744855200000,"reading": 6},
  {"t_stamp":1744858800000,"reading": 8},
  {"t_stamp":1744862400000,"reading": 10}
]
Expression binding

e.g., on Perspective custom property:

forEach(
	{this.custom.data},
	asMap(
		't_stamp', it()['t_stamp'], 
		'Increment', it()['reading'] - lag()['reading']
	)
)
Functions employed
  • forEach() loops through the items in the source.
  • asMap() produce a Java Map with string keys.
  • it() retrieves the loop value for the iterator.
  • lag() retrieves the previous loop value for the iterator. It returns null for the first pass and so the incremental reading will be null for the first interval. (The null in calculation seems to be neatly handled by the asMap() function which returns a null.)
2 Likes