Code Monkey home page Code Monkey logo

node-moves-cleaner's Introduction

Moves App Segment Cleaner

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.

Installation

npm install --save @claygregory/moves-cleaner

Usage

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: [],},
 
]);

Additional Methods

Normalization steps can also be applied individually. These include:

Close Gaps

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([]);

Filter Off Segments

Removes segments with a type value of off. The gaps in time remain, only the segments are removed.

movesCleaner.filter_off_segments([]);

Flatten Move Segments

Bubbles the individual activities of move segments up as standalone move segments.

movesCleaner.flatten_move_segments([]);

Merge 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([]);

Merge Place Segments

Merges consecutive place segments with same place ID into a single segment. Start/end times are corrected.

movesCleaner.merge_place_segments([]);

Sort

Orders segments according to time. Many of the above methods assume time-ordered segments are provided.

movesCleaner.sort_segments([]);

Options

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
});

License

See the included LICENSE for rights and limitations under the terms of the MIT license.

node-moves-cleaner's People

Contributors

claygregory avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.