Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ entities:
- 0.0 -> 0.0
- 40.0 -> 45.0
- 100.0 -> 102.5
- delata # computes the delta between each two consecutive numeric y values.
- derivate: h # computes rate of change per unit of time: h # ms (milisecond), s (second), m (minute), h (hour), d (day), w (week), M (month), y (year)
- integrate: h # computes area under the curve per unit of time using Right hand riemann integration. Same units as the derivative
- map_y_numbers: Math.sqrt(y + 10*100) # map the y coordinate of each datapoint.
Expand Down
22 changes: 20 additions & 2 deletions src/filters/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ const filters = {
meta: { ...meta, regression },
};
},
delta:
() =>
({ ys, meta }) => {
const last = {
y: NaN,
};
return {
meta: {
...meta,
unit_of_measurement: `Δ${meta.unit_of_measurement}`,
},
ys: mapNumbers(ys, (y) => {
const yDelta = y - last.y;
last.y = y;
return yDelta;
}),
};
},
derivate:
(unit: keyof typeof timeUnits = "h") =>
({ xs, ys, meta }) => {
Expand All @@ -91,10 +109,10 @@ const filters = {
ys: mapNumbers(ys, (y, i) => {
const x = +xs[i];
const dateDelta = (x - last.x) / timeUnits[unit];
const yDelta = (y - last.y) / dateDelta;
const yDeriv = (y - last.y) / dateDelta;
last.y = y;
last.x = x;
return yDelta;
return yDeriv;
}),
};
},
Expand Down