Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (analysis.xdataset) {
if (
analysis.stream.length === 0 || analysis.stream.split("/").length != 3
) {
yield put({
type: "ANALYSIS_ERROR",
value: "Invalid correlation stream name"
});
return;
}
query.stream = analysis.stream;
query.transform = analysis.transform;
} else {
// Make sure that dt is a number
try {
let dt = math.eval(analysis.dt);
if (isNaN(dt) || dt < 0.001) {
yield put({
type: "ANALYSIS_ERROR",
value: "Invalid time delta (" + analysis.dt + ")"
});
return;
}
query.dt = dt;
} catch (e) {
yield put({
type: "ANALYSIS_ERROR",
value: "Invalid time delta (" + analysis.dt + ")"
});
return;
}
}
const math = require('mathjs');
math.round(math.e, 3) // 2.718
math.atan2(3, -3) / math.pi // 0.75
math.log(10000, 10) // 4
math.sqrt(-4) // 2i
math.derivative('x^2 + x', 'x') // 2*x+1
math.pow([[-1, 2], [3, 1]], 2)
// [[7, 0], [0, 7]]
// expressions
math.eval('1.2 * (2 + 4.5)') // 7.8
math.eval('12.7 cm to inch') // 5 inch
math.eval('sin(45 deg) ^ 2') // 0.5
math.eval('9 / 3 + 2i') // 3 + 2i
math.eval('det([-1, 2; 3, 1])') // -7
// chaining
const res = math.chain(3)
.add(4)
.multiply(2)
.done() // 14
toCrystal({result: res});
const msgReply = s => {
let a1, a2, ans, b1, b2, eqn
try {
ans = '= ' + mathjs['eval'](s).toString()
} catch (e) {
a1 = Math.floor(Math.random() * 10)
b1 = Math.floor(Math.random() * 10)
a2 = Math.floor(Math.random() * 10)
b2 = Math.floor(Math.random() * 10)
eqn = '(' + a1 + ' + ' + b1 + 'i) * (' + a2 + ' + ' + b2 + 'i)'
ans =
"Sorry, I can't do that math. Did you know " + eqn + ' = ' + mathjs['eval'](eqn).toString() + '? True.'
}
return ans
}
private static signalAnimationHelper(channelAnimation: IChannelAnimation, value: number): IChannelInfo {
const scope = {
signal: value
};
return {
downDecrement: channelAnimation.downDecrement === undefined ? undefined : math.eval(channelAnimation.downDecrement, scope),
downDecrementDelay: channelAnimation.downDecrementDelay === undefined ? undefined : math.eval(channelAnimation.downDecrementDelay, scope),
downHoldDelay: channelAnimation.downHoldDelay === undefined ? undefined : math.eval(channelAnimation.downHoldDelay, scope),
downHoldLevel: channelAnimation.downHoldLevel === undefined ? undefined : math.eval(channelAnimation.downHoldLevel, scope),
downMinimumLevel: channelAnimation.downMinimumLevel === undefined ? undefined : math.eval(channelAnimation.downMinimumLevel, scope),
direction: channelAnimation.direction === undefined ? undefined : channelAnimation.direction,
effectId: channelAnimation.effectId === undefined ? undefined : math.eval(channelAnimation.effectId, scope),
upHoldDelay: channelAnimation.upHoldDelay === undefined ? undefined : math.eval(channelAnimation.upHoldDelay, scope),
upHoldLevel: channelAnimation.upHoldLevel === undefined ? undefined : math.eval(channelAnimation.upHoldLevel, scope),
upIncrement: channelAnimation.upIncrement === undefined ? undefined : math.eval(channelAnimation.upIncrement, scope),
upIncrementDelay: channelAnimation.upIncrementDelay === undefined ? undefined : math.eval(channelAnimation.upIncrementDelay, scope),
upMaximumLevel: channelAnimation.upMaximumLevel === undefined ? undefined : math.eval(channelAnimation.upMaximumLevel, scope),
startDelay: channelAnimation.startDelay === undefined ? undefined : math.eval(channelAnimation.startDelay, scope),
transition: channelAnimation.transition === undefined ? undefined : math.eval(channelAnimation.transition, scope),
};
private signalAnimationHelper(channelAnimation: ChannelAnimation, value: number): ChannelInfo {
const scope = {
signal: value
};
return {
upHoldLevel: channelAnimation.upHoldLevel === undefined ? undefined : math.eval(channelAnimation.upHoldLevel, scope),
downHoldLevel: channelAnimation.downHoldLevel === undefined ? undefined : math.eval(channelAnimation.downHoldLevel, scope),
upMaximumLevel: channelAnimation.upMaximumLevel === undefined ? undefined : math.eval(channelAnimation.upMaximumLevel, scope),
downMinimumLevel: channelAnimation.downMinimumLevel === undefined ? undefined : math.eval(channelAnimation.downMinimumLevel, scope),
upHoldDelay: channelAnimation.upHoldDelay === undefined ? undefined : math.eval(channelAnimation.upHoldDelay, scope),
downHoldDelay: channelAnimation.downHoldDelay === undefined ? undefined : math.eval(channelAnimation.downHoldDelay, scope),
upIncrement: channelAnimation.upIncrement === undefined ? undefined : math.eval(channelAnimation.upIncrement, scope),
downDecrement: channelAnimation.downDecrement === undefined ? undefined : math.eval(channelAnimation.downDecrement, scope),
upIncrementDelay: channelAnimation.upIncrementDelay === undefined ? undefined : math.eval(channelAnimation.upIncrementDelay, scope),
downDecrementDelay: channelAnimation.downDecrementDelay === undefined ? undefined : math.eval(channelAnimation.downDecrementDelay, scope),
startDelay: channelAnimation.startDelay === undefined ? undefined : math.eval(channelAnimation.startDelay, scope),
effectId: channelAnimation.effectId === undefined ? undefined : math.eval(channelAnimation.effectId, scope),
direction: channelAnimation.direction === undefined ? undefined : math.eval(channelAnimation.direction, scope),
transition: channelAnimation.transition === undefined ? undefined : math.eval(channelAnimation.transition, scope),
};
}
_calculate(){
let shorten = (str) => { return str.substring(1, str.length); };
let shortened = shorten(this.state);
let replaced = replaceReadableIdsWithMeans(shortened, this._inputs());
let correct = math.eval(replaced);
return {mean: correct, stdev: 0};
}
_inputs(){
export function computeCost(X, y, theta) {
let m = y.length;
let predictions = math.eval('X * theta', {
X,
theta,
});
let sqrErrors = math.eval('(predictions - y).^2', {
predictions,
y,
});
let J = math.eval(`1 / (2 * m) * sum(sqrErrors)`, {
m,
sqrErrors,
});
return J;
}
async function trigger(query) {
if(!isNaN(query)) {
return false;
}
try {
mathjs.eval(query);
return true;
}
catch (error) {
return false;
}
}
private signalAnimationHelper(channelAnimation: ChannelAnimation, value: number): ChannelInfo {
const scope = {
signal: value
};
return {
upHoldLevel: channelAnimation.upHoldLevel === undefined ? undefined : math.eval(channelAnimation.upHoldLevel, scope),
downHoldLevel: channelAnimation.downHoldLevel === undefined ? undefined : math.eval(channelAnimation.downHoldLevel, scope),
upMaximumLevel: channelAnimation.upMaximumLevel === undefined ? undefined : math.eval(channelAnimation.upMaximumLevel, scope),
downMinimumLevel: channelAnimation.downMinimumLevel === undefined ? undefined : math.eval(channelAnimation.downMinimumLevel, scope),
upHoldDelay: channelAnimation.upHoldDelay === undefined ? undefined : math.eval(channelAnimation.upHoldDelay, scope),
downHoldDelay: channelAnimation.downHoldDelay === undefined ? undefined : math.eval(channelAnimation.downHoldDelay, scope),
upIncrement: channelAnimation.upIncrement === undefined ? undefined : math.eval(channelAnimation.upIncrement, scope),
downDecrement: channelAnimation.downDecrement === undefined ? undefined : math.eval(channelAnimation.downDecrement, scope),
upIncrementDelay: channelAnimation.upIncrementDelay === undefined ? undefined : math.eval(channelAnimation.upIncrementDelay, scope),
downDecrementDelay: channelAnimation.downDecrementDelay === undefined ? undefined : math.eval(channelAnimation.downDecrementDelay, scope),
startDelay: channelAnimation.startDelay === undefined ? undefined : math.eval(channelAnimation.startDelay, scope),
effectId: channelAnimation.effectId === undefined ? undefined : math.eval(channelAnimation.effectId, scope),
direction: channelAnimation.direction === undefined ? undefined : math.eval(channelAnimation.direction, scope),
transition: channelAnimation.transition === undefined ? undefined : math.eval(channelAnimation.transition, scope),
};
}
private signalAnimationHelper(channelAnimation: ChannelAnimation, value: number): ChannelInfo {
const scope = {
signal: value
};
return {
upHoldLevel: channelAnimation.upHoldLevel === undefined ? undefined : math.eval(channelAnimation.upHoldLevel, scope),
downHoldLevel: channelAnimation.downHoldLevel === undefined ? undefined : math.eval(channelAnimation.downHoldLevel, scope),
upMaximumLevel: channelAnimation.upMaximumLevel === undefined ? undefined : math.eval(channelAnimation.upMaximumLevel, scope),
downMinimumLevel: channelAnimation.downMinimumLevel === undefined ? undefined : math.eval(channelAnimation.downMinimumLevel, scope),
upHoldDelay: channelAnimation.upHoldDelay === undefined ? undefined : math.eval(channelAnimation.upHoldDelay, scope),
downHoldDelay: channelAnimation.downHoldDelay === undefined ? undefined : math.eval(channelAnimation.downHoldDelay, scope),
upIncrement: channelAnimation.upIncrement === undefined ? undefined : math.eval(channelAnimation.upIncrement, scope),
downDecrement: channelAnimation.downDecrement === undefined ? undefined : math.eval(channelAnimation.downDecrement, scope),
upIncrementDelay: channelAnimation.upIncrementDelay === undefined ? undefined : math.eval(channelAnimation.upIncrementDelay, scope),
downDecrementDelay: channelAnimation.downDecrementDelay === undefined ? undefined : math.eval(channelAnimation.downDecrementDelay, scope),
startDelay: channelAnimation.startDelay === undefined ? undefined : math.eval(channelAnimation.startDelay, scope),
effectId: channelAnimation.effectId === undefined ? undefined : math.eval(channelAnimation.effectId, scope),
direction: channelAnimation.direction === undefined ? undefined : math.eval(channelAnimation.direction, scope),
transition: channelAnimation.transition === undefined ? undefined : math.eval(channelAnimation.transition, scope),
};
}