npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pedometer

v0.0.5

Published

Javascript implementation of a pedometer

Downloads

82

Readme

node-pedometer

Pedometer implementation for node.js

Build status

Build Status Coverage Status

Notes

Uses a windowed average peak counting algorithm to perform low-cost step detection.

Assumes all input data to be 2D arrays

[[x1, y1, z1], [x2, y2, z2],...]
[[pitch1, roll1, yaw1]. [pitch2, roll2, yaw2],... ] (in Radians)

Installation

npm install pedometer --save

Usage

var pedometer = require('pedometer').pedometer;
var steps=pedometer(accelerometerData,attitudeData,samplingrate,options);

accelerometerdata is a time series of 3D acceleration vectors in m/s^2 [[x1, y1, z1], [x2, y2, z2],...]

attitudeData is a time series of 3D attitude vectors in radians [[pitch1, roll1, yaw1]. [pitch2, roll2, yaw2],... ]

samplingrate is the number of samples per second. All tests were done with 100Hz

options provides optional parameters. Default values are:

options={
    windowSize:1, //Length of window in seconds
    minPeak:2, //minimum magnitude of a steps largest positive peak
    maxPeak:8, //maximum magnitude of a steps largest positive peak
    minStepTime: 0.3, //minimum time in seconds between two steps
    peakThreshold: 0.5, //minimum ratio of the current window's maximum to be considered a step
    minConsecutiveSteps: 3, //minimum number of consecutive steps to be counted
    maxStepTime: 0.8, //maximum time between two steps to be considered consecutive
    meanFilterSize: 1, //Amount of smoothing (Values <=1 disable the smoothing)
    debug:false //Enable output of debugging data in matlab/octave format
    }

Returns an array of the indices in the input signal where steps occured

See src/debug.js and test/test.js for more examples

Example

Before you run this, make sure to have installed the modules fs and csv-parse.

var pedometer = require('pedometer').pedometer,
    fs = require('fs'),
    parse = require('csv-parse/lib/sync');

//Function to load Data from csv file
function loadData(filename){
    
    //Load file
    var data=fs.readFileSync(filename,'utf8');
    
    //parse CSV
    data=parse(data, {trim: true, auto_parse: true});
    
    //Store data in arrays
    var acc=[],att=[];
    for (var i=0;i<data.length;i++){
        acc[i]=data[i].slice(0,3);
        att[i]=[data[i][4], -data[i][5],data[i][3]];   //Attitude is adjusted to correctly match [ pitch, roll, yaw ]
    }
    
    //Return arrays
    return {acc:acc,att:att};
}
   
//Load first test case
var data=loadData('node_modules/pedometer/test/DataWalking1.csv');      //You might need to adjust the path here

//Define algorithm options (optional). All recommended default values here.
var options={
                windowSize:1, //Length of window in seconds
                minPeak:2, //minimum magnitude of a steps largest positive peak
                maxPeak:8, //maximum magnitude of a steps largest positive peak
                minStepTime: 0.3, //minimum time in seconds between two steps
                peakThreshold: 0.5, //minimum ratio of the current window's maximum to be considered a step
                minConsecutiveSteps: 3, //minimum number of consecutive steps to be counted
                maxStepTime: 0.8, //maximum time between two steps to be considered consecutive
                meanFilterSize: 1, //Amount of smoothing (Values <=1 disable the smoothing)
                debug:false //Enable output of debugging data in matlab/octave format
};
        
//Perform step detection. Leaving away ,options here (recommended), will use the default settings as specified above.
var steps=pedometer(data.acc,data.att,100,options);

//Print number of detected steps
console.log("The algorithm detected "+steps.length+" steps.");

Output:

The algorithm detected 116 steps.

Test

npm test

Returns:

    Detect steps in acceleration signal
  The algorithm detected 116 steps.
      ✓ Test 1 - Signal of walk 1 (186ms)
  The algorithm detected 292 steps.
      ✓ Test 2 - Signal of walk 2 (442ms)
  The algorithm detected 25 steps.
      ✓ Test 3 - Signal of walk 3 (54ms)
  The algorithm detected 27 steps.
      ✓ Test 4 - Signal of walk 4 (47ms)
  The algorithm detected 483 steps.
      ✓ Test 5 - Signal of walk 5 (732ms)
  The algorithm detected 16 steps.
      ✓ Test 6 - Signal of not walking 1 (558ms)
  The algorithm detected 10 steps.
      ✓ Test 7 - Signal of not walking 2 (130ms)
  The algorithm detected 28 steps.
      ✓ Test 8 - Signal of not walking 3 (787ms)
  The algorithm detected 0 steps.
      ✓ Test 9 - Signal of not walking 4 (891ms)
  The algorithm detected 23 steps.
      ✓ Test 10 - Signal of not walking 5 (235ms)
  The algorithm detected 68 steps.
      ✓ Test 11 - Signal of mixed action 1 (751ms)
  The algorithm detected 46 steps.
      ✓ Test 12 - Signal of mixed action 2 (792ms)
  
  
    12 passing (6s)
    

License

MIT License

Copyright (c) 2016 Maximilian Bügler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.