Skip to content

Commit 7e641ba

Browse files
committed
Add sample()
1 parent 5b6ee14 commit 7e641ba

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/helpers/script_std.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ export default class ScriptStd {
131131
return ts
132132
}
133133

134+
/**
135+
* Creates a new custom sampler.
136+
* Return the an array. Id is auto-genrated
137+
* @param {*} x - A variable to sample from
138+
* @param {string} type - Sampler type
139+
* @param {(number|string)} tf - Timeframe in ms or as a string
140+
* @return {TS} - New time-series
141+
*/
142+
sample(x, type, tf, _id) {
143+
let ts = this.env.tss[_id]
144+
if (!ts) {
145+
ts = this.env.tss[_id] = [x]
146+
ts.__id__ = _id
147+
ts.__tf__ = u.tf_from_str(tf)
148+
ts.__fn__ = Sampler(type).bind(ts)
149+
} else {
150+
ts.__fn__(x)
151+
}
152+
return ts
153+
}
154+
134155
/**
135156
* Replaces the variable if it's NaN
136157
* @param {*} x - The variable

0 commit comments

Comments
 (0)