1.0.9 • Published 1 year ago

curve-peak v1.0.9

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 year ago

curve-peak

Description

A Javascript library for finding peak and valley points of the given curve.

Installation

Curve matcher can be installed via NPM

npm i curve-peak

Instructions

Curves are defined as arrays of points of y like below:

const curve = [{x: 2, y: 1.5}, {x: 4, y: 3}, ... ];

Finding peak points of a curve is as simple as calling:

import { findPeaks } from 'curve-peak';
const curve1 = [{ x: 0, y: 1 }, { x: 1, y: 3 }, { x: 2, y: 4 }, { x: 3, y: 3 }, { x: 4, y: 5 }, { x: 5, y: 5 }, { x: 6, y: 5 }, { x: 7, y: 1 }, { x: 8, y: 3 }];
console.log(findPV(curve1));  // { peaks: [{ x: 2, y: 4 }, { x: 4, y: 5 }, { x: 8, y: 3 }], valleys: [{ x: 0, y: 1 }, { x: 3, y: 3 }, { x: 7, y: 1 }], min: { x: 0, y: 1 }, max: { x: 4, y: 5 } }

The cover range of peak is set to 1 by default. That means if the y value of a point is bigger than the very left one, and isn't smaller than the very right one, will be recornised as a peak point. You can set the cover range as n like below, meaning that if the y value of a point is bigger than n left points, and isn't smaller than one of the n right points, it matches.

import { findPeaks } from 'curve-peak';
const curve2 = [{ x: 0, y: 2 }, { x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 3 }, { x: 4, y: 4 }, { x: 5, y: 3 }, { x: 6, y: 2 }, { x: 7, y: 1 }, 
        { x: 8, y: 1 }, { x: 9, y: 0 }, { x: 10, y: 0 }, { x: 11, y: 1 }, { x: 12, y: 0 }, { x: 13, y: 1 }, { x: 14, y: 2 }, { x: 15, y: 1 }, 
        { x: 16, y: 3 }, { x: 17, y: 2 }, { x: 18, y: 3 }, { x: 19, y: 4 }, { x: 20, y: 5 }, { x: 21, y: 4 }, { x: 22, y: 3 }, { x: 23, y: 4 }];
console.log(findPV(curve2, { peakCoverRange: 3 }));  // { peaks: [{ x: 4, y: 4 }, { x: 20, y: 5 }], valleys: [{ x: 9, y: 0 }, { x: 12, y: 0 }, { x: 22, y: 3 }], min: { x: 9, y: 0 }, max: { x: 20, y: 5 } }
1.0.9

1 year ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago