Skip to content

Commit

Permalink
Add sample()
Browse files Browse the repository at this point in the history
  • Loading branch information
C451 committed Jan 26, 2021
1 parent 6587aa2 commit 2cb0331
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/helpers/script_std.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ export default class ScriptStd {
return ts
}

/**
* Creates a new custom sampler.
* Return the an array. Id is auto-genrated
* @param {*} x - A variable to sample from
* @param {string} type - Sampler type
* @param {(number|string)} tf - Timeframe in ms or as a string
* @return {TS} - New time-series
*/
sample(x, type, tf, _id) {
let ts = this.env.tss[_id]
if (!ts) {
ts = this.env.tss[_id] = [x]
ts.__id__ = _id
ts.__tf__ = u.tf_from_str(tf)
ts.__fn__ = Sampler(type).bind(ts)
} else {
ts.__fn__(x)
}
return ts
}

/**
* Replaces the variable if it's NaN
* @param {*} x - The variable
Expand Down

0 comments on commit 2cb0331

Please sign in to comment.