Having worked with data from the Moves App —both from the API as well as manual JSON exports — I've noticed a few recurring oddities I attempt to correct with this utility. Namely:
- Long stays at a single location (in excess of 24 hours) tend to get truncated, forming a time gap
- Occasionally a single stay or single move will get chopped into multiple segments
- Other time gaps inexplicably appear between segments, absent an 'off' segment
- Not specifically a problem, but multple consecutive movements (e.g. walking → transport → walking) are merged as activities under a single 'move' segment. I prefer these separated into separate segments to simplify analysis.
npm install --save @claygregory/moves-cleaner
For most applications, just call the single apply
method on an array of segments. This will apply all of the normalization
functions in one go.
const MovesCleaner = require('@claygregory/moves-cleaner');
const movesCleaner = new MovesCleaner();
const normalizedSegments = movesCleaner.apply([
{ type: 'move', activities: […], … },
{ type: 'place', activities: […], … },
…
]);
Normalization steps can also be applied individually. These include:
Collapses the gap between two segments so long as no off
segments are logged and the distance between the shoulder segments is within
a given threshold.
movesCleaner.close_gaps([…]);
Removes segments with a type
value of off
. The gaps in time remain, only the segments are removed.
movesCleaner.filter_off_segments([…]);
Bubbles the individual activities of move
segments up as standalone move segments.
movesCleaner.flatten_move_segments([…]);
Merges consecutive move segments of same type into a single segment. Track points are merged and start/end time, duration, and distance are corrected.
movesCleaner.merge_move_segments([…]);
Merges consecutive place segments with same place ID into a single segment. Start/end times are corrected.
movesCleaner.merge_place_segments([…]);
Orders segments according to time. Many of the above methods assume time-ordered segments are provided.
movesCleaner.sort_segments([…]);
Currently only one configuration option is available: near_threshold_m
is used in gap detection to determine when the end of one segment is close enough to the beginning of next. Gaps are only closed between if endpoints are within threshold. The default is 100 meters.
const MovesCleaner = require('@claygregory/moves-cleaner');
const movesCleaner = new MovesCleaner({
near_threshold_m: 250
});
See the included LICENSE for rights and limitations under the terms of the MIT license.