pinets 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -3
- package/dist/pinets.dev.browser.js +3019 -391
- package/dist/pinets.dev.cjs +3106 -365
- package/dist/pinets.dev.cjs.map +1 -1
- package/dist/pinets.dev.es.js +3110 -360
- package/dist/pinets.dev.es.js.map +1 -1
- package/dist/pinets.min.browser.js +15 -14
- package/dist/pinets.min.cjs +15 -14
- package/dist/pinets.min.es.js +5 -4
- package/dist/types/Context.class.d.ts +19 -3
- package/dist/types/PineTS.class.d.ts +2 -0
- package/dist/types/marketData/Binance/BinanceProvider.class.d.ts +2 -1
- package/dist/types/marketData/IProvider.d.ts +43 -0
- package/dist/types/marketData/Mock/MockProvider.class.d.ts +13 -1
- package/dist/types/namespaces/Barstate.d.ts +13 -0
- package/dist/types/namespaces/Core.d.ts +15 -0
- package/dist/types/namespaces/Log.d.ts +10 -0
- package/dist/types/namespaces/Str.d.ts +23 -0
- package/dist/types/namespaces/Timeframe.d.ts +17 -0
- package/dist/types/namespaces/Types.d.ts +86 -0
- package/dist/types/namespaces/array/PineArrayObject.d.ts +102 -1
- package/dist/types/namespaces/array/array.index.d.ts +1 -129
- package/dist/types/namespaces/array/methods/avg.d.ts +2 -1
- package/dist/types/namespaces/array/methods/binary_search.d.ts +2 -0
- package/dist/types/namespaces/array/methods/binary_search_leftmost.d.ts +2 -0
- package/dist/types/namespaces/array/methods/binary_search_rightmost.d.ts +2 -0
- package/dist/types/namespaces/array/methods/covariance.d.ts +2 -1
- package/dist/types/namespaces/array/methods/every.d.ts +1 -1
- package/dist/types/namespaces/array/methods/fill.d.ts +2 -1
- package/dist/types/namespaces/array/methods/join.d.ts +5 -0
- package/dist/types/namespaces/array/methods/median.d.ts +2 -0
- package/dist/types/namespaces/array/methods/mode.d.ts +2 -0
- package/dist/types/namespaces/array/methods/new.d.ts +2 -1
- package/dist/types/namespaces/array/methods/new_float.d.ts +2 -1
- package/dist/types/namespaces/array/methods/new_int.d.ts +2 -1
- package/dist/types/namespaces/array/methods/percentile_linear_interpolation.d.ts +3 -0
- package/dist/types/namespaces/array/methods/percentile_nearest_rank.d.ts +2 -0
- package/dist/types/namespaces/array/methods/percentrank.d.ts +2 -0
- package/dist/types/namespaces/array/methods/push.d.ts +2 -1
- package/dist/types/namespaces/array/methods/range.d.ts +2 -1
- package/dist/types/namespaces/array/methods/set.d.ts +2 -1
- package/dist/types/namespaces/array/methods/some.d.ts +1 -1
- package/dist/types/namespaces/array/methods/sort.d.ts +2 -1
- package/dist/types/namespaces/array/methods/sort_indices.d.ts +2 -1
- package/dist/types/namespaces/array/methods/stdev.d.ts +2 -1
- package/dist/types/namespaces/array/methods/sum.d.ts +2 -1
- package/dist/types/namespaces/array/methods/unshift.d.ts +2 -1
- package/dist/types/namespaces/array/methods/variance.d.ts +2 -1
- package/dist/types/namespaces/array/utils.d.ts +5 -0
- package/dist/types/namespaces/input/methods/any.d.ts +1 -2
- package/dist/types/namespaces/input/methods/bool.d.ts +1 -2
- package/dist/types/namespaces/input/methods/color.d.ts +1 -2
- package/dist/types/namespaces/input/methods/enum.d.ts +1 -2
- package/dist/types/namespaces/input/methods/float.d.ts +1 -2
- package/dist/types/namespaces/input/methods/int.d.ts +1 -2
- package/dist/types/namespaces/input/methods/param.d.ts +1 -1
- package/dist/types/namespaces/input/methods/price.d.ts +1 -2
- package/dist/types/namespaces/input/methods/session.d.ts +1 -2
- package/dist/types/namespaces/input/methods/source.d.ts +1 -2
- package/dist/types/namespaces/input/methods/string.d.ts +1 -2
- package/dist/types/namespaces/input/methods/symbol.d.ts +1 -2
- package/dist/types/namespaces/input/methods/text_area.d.ts +1 -2
- package/dist/types/namespaces/input/methods/time.d.ts +1 -2
- package/dist/types/namespaces/input/methods/timeframe.d.ts +1 -2
- package/dist/types/namespaces/input/types.d.ts +12 -1
- package/dist/types/namespaces/input/utils.d.ts +14 -0
- package/dist/types/namespaces/map/PineMapObject.d.ts +26 -0
- package/dist/types/namespaces/map/map.index.d.ts +7 -0
- package/dist/types/namespaces/map/methods/clear.d.ts +3 -0
- package/dist/types/namespaces/map/methods/contains.d.ts +3 -0
- package/dist/types/namespaces/map/methods/copy.d.ts +3 -0
- package/dist/types/namespaces/map/methods/get.d.ts +3 -0
- package/dist/types/namespaces/map/methods/keys.d.ts +4 -0
- package/dist/types/namespaces/map/methods/new.d.ts +3 -0
- package/dist/types/namespaces/map/methods/param.d.ts +1 -0
- package/dist/types/namespaces/map/methods/put.d.ts +3 -0
- package/dist/types/namespaces/map/methods/put_all.d.ts +3 -0
- package/dist/types/namespaces/map/methods/remove.d.ts +3 -0
- package/dist/types/namespaces/map/methods/size.d.ts +3 -0
- package/dist/types/namespaces/map/methods/values.d.ts +4 -0
- package/dist/types/namespaces/math/math.index.d.ts +18 -0
- package/dist/types/namespaces/math/methods/abs.d.ts +2 -1
- package/dist/types/namespaces/math/methods/e.d.ts +5 -0
- package/dist/types/namespaces/math/methods/phi.d.ts +5 -0
- package/dist/types/namespaces/math/methods/pi.d.ts +5 -0
- package/dist/types/namespaces/math/methods/round_to_mintick.d.ts +2 -0
- package/dist/types/namespaces/math/methods/rphi.d.ts +5 -0
- package/dist/types/namespaces/math/methods/sign.d.ts +2 -0
- package/dist/types/namespaces/matrix/PineMatrixObject.d.ts +102 -0
- package/dist/types/namespaces/matrix/matrix.index.d.ts +7 -0
- package/dist/types/namespaces/matrix/methods/add_col.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/add_row.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/avg.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/col.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/columns.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/concat.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/copy.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/det.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/diff.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/eigenvalues.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/eigenvectors.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/elements_count.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/fill.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/get.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/inv.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_antidiagonal.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_antisymmetric.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_binary.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_diagonal.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_identity.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_square.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_stochastic.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_symmetric.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_triangular.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_zero.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/kron.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/max.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/median.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/min.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/mode.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/mult.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/new.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/param.d.ts +1 -0
- package/dist/types/namespaces/matrix/methods/pinv.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/pow.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/rank.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/remove_col.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/remove_row.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/reshape.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/reverse.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/row.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/rows.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/set.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/sort.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/submatrix.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/sum.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/swap_columns.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/swap_rows.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/trace.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/transpose.d.ts +3 -0
- package/dist/types/namespaces/request/methods/security_lower_tf.d.ts +9 -0
- package/dist/types/namespaces/request/request.index.d.ts +3 -0
- package/dist/types/namespaces/ta/methods/atr.d.ts +2 -1
- package/dist/types/namespaces/ta/methods/tr.d.ts +2 -1
- package/dist/types/transpiler/settings.d.ts +4 -0
- package/dist/types/types/PineTypes.d.ts +11 -0
- package/package.json +6 -4
package/dist/pinets.dev.cjs
CHANGED
|
@@ -2363,7 +2363,7 @@ var TokContext = function TokContext(token, isExpr, preserveSpace, override, gen
|
|
|
2363
2363
|
this.generator = !!generator;
|
|
2364
2364
|
};
|
|
2365
2365
|
|
|
2366
|
-
var types = {
|
|
2366
|
+
var types$2 = {
|
|
2367
2367
|
b_stat: new TokContext("{", false),
|
|
2368
2368
|
b_expr: new TokContext("{", true),
|
|
2369
2369
|
b_tmpl: new TokContext("${", false),
|
|
@@ -2379,7 +2379,7 @@ var types = {
|
|
|
2379
2379
|
var pp$6 = Parser.prototype;
|
|
2380
2380
|
|
|
2381
2381
|
pp$6.initialContext = function() {
|
|
2382
|
-
return [types.b_stat]
|
|
2382
|
+
return [types$2.b_stat]
|
|
2383
2383
|
};
|
|
2384
2384
|
|
|
2385
2385
|
pp$6.curContext = function() {
|
|
@@ -2388,9 +2388,9 @@ pp$6.curContext = function() {
|
|
|
2388
2388
|
|
|
2389
2389
|
pp$6.braceIsBlock = function(prevType) {
|
|
2390
2390
|
var parent = this.curContext();
|
|
2391
|
-
if (parent === types.f_expr || parent === types.f_stat)
|
|
2391
|
+
if (parent === types$2.f_expr || parent === types$2.f_stat)
|
|
2392
2392
|
{ return true }
|
|
2393
|
-
if (prevType === types$1.colon && (parent === types.b_stat || parent === types.b_expr))
|
|
2393
|
+
if (prevType === types$1.colon && (parent === types$2.b_stat || parent === types$2.b_expr))
|
|
2394
2394
|
{ return !parent.isExpr }
|
|
2395
2395
|
|
|
2396
2396
|
// The check for `tt.name && exprAllowed` detects whether we are
|
|
@@ -2401,7 +2401,7 @@ pp$6.braceIsBlock = function(prevType) {
|
|
|
2401
2401
|
if (prevType === types$1._else || prevType === types$1.semi || prevType === types$1.eof || prevType === types$1.parenR || prevType === types$1.arrow)
|
|
2402
2402
|
{ return true }
|
|
2403
2403
|
if (prevType === types$1.braceL)
|
|
2404
|
-
{ return parent === types.b_stat }
|
|
2404
|
+
{ return parent === types$2.b_stat }
|
|
2405
2405
|
if (prevType === types$1._var || prevType === types$1._const || prevType === types$1.name)
|
|
2406
2406
|
{ return false }
|
|
2407
2407
|
return !this.exprAllowed
|
|
@@ -2442,25 +2442,25 @@ types$1.parenR.updateContext = types$1.braceR.updateContext = function() {
|
|
|
2442
2442
|
return
|
|
2443
2443
|
}
|
|
2444
2444
|
var out = this.context.pop();
|
|
2445
|
-
if (out === types.b_stat && this.curContext().token === "function") {
|
|
2445
|
+
if (out === types$2.b_stat && this.curContext().token === "function") {
|
|
2446
2446
|
out = this.context.pop();
|
|
2447
2447
|
}
|
|
2448
2448
|
this.exprAllowed = !out.isExpr;
|
|
2449
2449
|
};
|
|
2450
2450
|
|
|
2451
2451
|
types$1.braceL.updateContext = function(prevType) {
|
|
2452
|
-
this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
|
|
2452
|
+
this.context.push(this.braceIsBlock(prevType) ? types$2.b_stat : types$2.b_expr);
|
|
2453
2453
|
this.exprAllowed = true;
|
|
2454
2454
|
};
|
|
2455
2455
|
|
|
2456
2456
|
types$1.dollarBraceL.updateContext = function() {
|
|
2457
|
-
this.context.push(types.b_tmpl);
|
|
2457
|
+
this.context.push(types$2.b_tmpl);
|
|
2458
2458
|
this.exprAllowed = true;
|
|
2459
2459
|
};
|
|
2460
2460
|
|
|
2461
2461
|
types$1.parenL.updateContext = function(prevType) {
|
|
2462
2462
|
var statementParens = prevType === types$1._if || prevType === types$1._for || prevType === types$1._with || prevType === types$1._while;
|
|
2463
|
-
this.context.push(statementParens ? types.p_stat : types.p_expr);
|
|
2463
|
+
this.context.push(statementParens ? types$2.p_stat : types$2.p_expr);
|
|
2464
2464
|
this.exprAllowed = true;
|
|
2465
2465
|
};
|
|
2466
2466
|
|
|
@@ -2470,12 +2470,12 @@ types$1.incDec.updateContext = function() {
|
|
|
2470
2470
|
|
|
2471
2471
|
types$1._function.updateContext = types$1._class.updateContext = function(prevType) {
|
|
2472
2472
|
if (prevType.beforeExpr && prevType !== types$1._else &&
|
|
2473
|
-
!(prevType === types$1.semi && this.curContext() !== types.p_stat) &&
|
|
2473
|
+
!(prevType === types$1.semi && this.curContext() !== types$2.p_stat) &&
|
|
2474
2474
|
!(prevType === types$1._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
|
|
2475
|
-
!((prevType === types$1.colon || prevType === types$1.braceL) && this.curContext() === types.b_stat))
|
|
2476
|
-
{ this.context.push(types.f_expr); }
|
|
2475
|
+
!((prevType === types$1.colon || prevType === types$1.braceL) && this.curContext() === types$2.b_stat))
|
|
2476
|
+
{ this.context.push(types$2.f_expr); }
|
|
2477
2477
|
else
|
|
2478
|
-
{ this.context.push(types.f_stat); }
|
|
2478
|
+
{ this.context.push(types$2.f_stat); }
|
|
2479
2479
|
this.exprAllowed = false;
|
|
2480
2480
|
};
|
|
2481
2481
|
|
|
@@ -2485,20 +2485,20 @@ types$1.colon.updateContext = function() {
|
|
|
2485
2485
|
};
|
|
2486
2486
|
|
|
2487
2487
|
types$1.backQuote.updateContext = function() {
|
|
2488
|
-
if (this.curContext() === types.q_tmpl)
|
|
2488
|
+
if (this.curContext() === types$2.q_tmpl)
|
|
2489
2489
|
{ this.context.pop(); }
|
|
2490
2490
|
else
|
|
2491
|
-
{ this.context.push(types.q_tmpl); }
|
|
2491
|
+
{ this.context.push(types$2.q_tmpl); }
|
|
2492
2492
|
this.exprAllowed = false;
|
|
2493
2493
|
};
|
|
2494
2494
|
|
|
2495
2495
|
types$1.star.updateContext = function(prevType) {
|
|
2496
2496
|
if (prevType === types$1._function) {
|
|
2497
2497
|
var index = this.context.length - 1;
|
|
2498
|
-
if (this.context[index] === types.f_expr)
|
|
2499
|
-
{ this.context[index] = types.f_expr_gen; }
|
|
2498
|
+
if (this.context[index] === types$2.f_expr)
|
|
2499
|
+
{ this.context[index] = types$2.f_expr_gen; }
|
|
2500
2500
|
else
|
|
2501
|
-
{ this.context[index] = types.f_gen; }
|
|
2501
|
+
{ this.context[index] = types$2.f_gen; }
|
|
2502
2502
|
}
|
|
2503
2503
|
this.exprAllowed = true;
|
|
2504
2504
|
};
|
|
@@ -2948,7 +2948,7 @@ pp$5.parseExprAtom = function(refDestructuringErrors, forInit, forNew) {
|
|
|
2948
2948
|
var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
|
|
2949
2949
|
var id = this.parseIdent(false);
|
|
2950
2950
|
if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types$1._function)) {
|
|
2951
|
-
this.overrideContext(types.f_expr);
|
|
2951
|
+
this.overrideContext(types$2.f_expr);
|
|
2952
2952
|
return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit)
|
|
2953
2953
|
}
|
|
2954
2954
|
if (canBeArrow && !this.canInsertSemicolon()) {
|
|
@@ -2997,7 +2997,7 @@ pp$5.parseExprAtom = function(refDestructuringErrors, forInit, forNew) {
|
|
|
2997
2997
|
return this.finishNode(node, "ArrayExpression")
|
|
2998
2998
|
|
|
2999
2999
|
case types$1.braceL:
|
|
3000
|
-
this.overrideContext(types.b_expr);
|
|
3000
|
+
this.overrideContext(types$2.b_expr);
|
|
3001
3001
|
return this.parseObj(false, refDestructuringErrors)
|
|
3002
3002
|
|
|
3003
3003
|
case types$1._function:
|
|
@@ -6153,7 +6153,7 @@ Parser.acorn = {
|
|
|
6153
6153
|
tokTypes: types$1,
|
|
6154
6154
|
keywordTypes: keywords,
|
|
6155
6155
|
TokContext: TokContext,
|
|
6156
|
-
tokContexts: types,
|
|
6156
|
+
tokContexts: types$2,
|
|
6157
6157
|
isIdentifierChar: isIdentifierChar,
|
|
6158
6158
|
isIdentifierStart: isIdentifierStart,
|
|
6159
6159
|
Token: Token,
|
|
@@ -8022,6 +8022,45 @@ const ASTFactory = {
|
|
|
8022
8022
|
}
|
|
8023
8023
|
};
|
|
8024
8024
|
|
|
8025
|
+
const CONTEXT_DATA_VARS = ["open", "high", "low", "close", "volume", "hl2", "hlc3", "ohlc4", "openTime", "closeTime"];
|
|
8026
|
+
const CONTEXT_PINE_VARS = [
|
|
8027
|
+
"input",
|
|
8028
|
+
"ta",
|
|
8029
|
+
"math",
|
|
8030
|
+
"request",
|
|
8031
|
+
"array",
|
|
8032
|
+
"na",
|
|
8033
|
+
"plotchar",
|
|
8034
|
+
"color",
|
|
8035
|
+
"plot",
|
|
8036
|
+
"nz",
|
|
8037
|
+
"strategy",
|
|
8038
|
+
"library",
|
|
8039
|
+
"str",
|
|
8040
|
+
"box",
|
|
8041
|
+
"line",
|
|
8042
|
+
"label",
|
|
8043
|
+
"table",
|
|
8044
|
+
"map",
|
|
8045
|
+
"matrix",
|
|
8046
|
+
"log",
|
|
8047
|
+
"map",
|
|
8048
|
+
//market info
|
|
8049
|
+
"timeframe",
|
|
8050
|
+
"syminfo",
|
|
8051
|
+
"barstate",
|
|
8052
|
+
//builtin variables
|
|
8053
|
+
"bar_index",
|
|
8054
|
+
"last_bar_index",
|
|
8055
|
+
"last_bar_time",
|
|
8056
|
+
// Pine Script enum types
|
|
8057
|
+
"order",
|
|
8058
|
+
"currency",
|
|
8059
|
+
"display",
|
|
8060
|
+
"dayofweek"
|
|
8061
|
+
];
|
|
8062
|
+
const CONTEXT_CORE_VARS = ["na", "nz", "plot", "plotchar", "color"];
|
|
8063
|
+
|
|
8025
8064
|
function injectImplicitImports(ast) {
|
|
8026
8065
|
let mainBody = null;
|
|
8027
8066
|
let contextParamName = CONTEXT_NAME;
|
|
@@ -8087,28 +8126,8 @@ function injectImplicitImports(ast) {
|
|
|
8087
8126
|
addDeclared(stmt.id);
|
|
8088
8127
|
}
|
|
8089
8128
|
});
|
|
8090
|
-
const contextDataVars =
|
|
8091
|
-
const contextPineVars =
|
|
8092
|
-
"input",
|
|
8093
|
-
"ta",
|
|
8094
|
-
"math",
|
|
8095
|
-
"request",
|
|
8096
|
-
"array",
|
|
8097
|
-
"na",
|
|
8098
|
-
"plotchar",
|
|
8099
|
-
"color",
|
|
8100
|
-
"plot",
|
|
8101
|
-
"nz",
|
|
8102
|
-
"strategy",
|
|
8103
|
-
"library",
|
|
8104
|
-
"str",
|
|
8105
|
-
"box",
|
|
8106
|
-
"line",
|
|
8107
|
-
"label",
|
|
8108
|
-
"table",
|
|
8109
|
-
"map",
|
|
8110
|
-
"matrix"
|
|
8111
|
-
];
|
|
8129
|
+
const contextDataVars = CONTEXT_DATA_VARS;
|
|
8130
|
+
const contextPineVars = CONTEXT_PINE_VARS;
|
|
8112
8131
|
const missingDataVars = contextDataVars.filter((v) => !declaredVars.has(v));
|
|
8113
8132
|
const missingPineVars = contextPineVars.filter((v) => !declaredVars.has(v));
|
|
8114
8133
|
const neededDataVars = missingDataVars.filter((v) => usedIdentifiers.has(v));
|
|
@@ -8189,29 +8208,9 @@ function normalizeNativeImports(ast) {
|
|
|
8189
8208
|
}
|
|
8190
8209
|
}
|
|
8191
8210
|
if (!mainBody) return;
|
|
8192
|
-
const contextDataVars =
|
|
8193
|
-
const contextPineVars =
|
|
8194
|
-
|
|
8195
|
-
"ta",
|
|
8196
|
-
"math",
|
|
8197
|
-
"request",
|
|
8198
|
-
"array",
|
|
8199
|
-
"na",
|
|
8200
|
-
"plotchar",
|
|
8201
|
-
"color",
|
|
8202
|
-
"plot",
|
|
8203
|
-
"nz",
|
|
8204
|
-
"strategy",
|
|
8205
|
-
"library",
|
|
8206
|
-
"str",
|
|
8207
|
-
"box",
|
|
8208
|
-
"line",
|
|
8209
|
-
"label",
|
|
8210
|
-
"table",
|
|
8211
|
-
"map",
|
|
8212
|
-
"matrix"
|
|
8213
|
-
]);
|
|
8214
|
-
const contextCoreVars = /* @__PURE__ */ new Set(["na", "nz", "plot", "plotchar", "color"]);
|
|
8211
|
+
const contextDataVars = new Set(CONTEXT_DATA_VARS);
|
|
8212
|
+
const contextPineVars = new Set(CONTEXT_PINE_VARS);
|
|
8213
|
+
const contextCoreVars = new Set(CONTEXT_CORE_VARS);
|
|
8215
8214
|
const renames = /* @__PURE__ */ new Map();
|
|
8216
8215
|
mainBody.forEach((stmt) => {
|
|
8217
8216
|
if (stmt.type === "VariableDeclaration") {
|
|
@@ -8463,6 +8462,7 @@ const UNDEFINED_ARG = {
|
|
|
8463
8462
|
type: "Identifier",
|
|
8464
8463
|
name: "undefined"
|
|
8465
8464
|
};
|
|
8465
|
+
const KNOWN_NAMESPACES = ["ta", "math", "request", "array", "input"];
|
|
8466
8466
|
function transformArrayIndex(node, scopeManager) {
|
|
8467
8467
|
if (node.computed && node.property.type === "Identifier") {
|
|
8468
8468
|
if (scopeManager.isLoopVariable(node.property.name)) {
|
|
@@ -8522,12 +8522,6 @@ function transformIdentifier(node, scopeManager) {
|
|
|
8522
8522
|
if (scopeManager.isLoopVariable(node.name)) {
|
|
8523
8523
|
return;
|
|
8524
8524
|
}
|
|
8525
|
-
if (scopeManager.isContextBound(node.name) && !scopeManager.isRootParam(node.name)) {
|
|
8526
|
-
return;
|
|
8527
|
-
}
|
|
8528
|
-
const isNamespaceMember = node.parent && node.parent.type === "MemberExpression" && node.parent.object === node && scopeManager.isContextBound(node.name);
|
|
8529
|
-
const isParamCall = node.parent && node.parent.type === "CallExpression" && node.parent.callee && node.parent.callee.type === "MemberExpression" && node.parent.callee.property.name === "param";
|
|
8530
|
-
node.parent && node.parent.type === "AssignmentExpression" && node.parent.left === node;
|
|
8531
8525
|
let isSeriesFunctionArg = false;
|
|
8532
8526
|
if (node.parent && node.parent.type === "CallExpression" && node.parent.arguments.includes(node)) {
|
|
8533
8527
|
const callee = node.parent.callee;
|
|
@@ -8538,13 +8532,20 @@ function transformIdentifier(node, scopeManager) {
|
|
|
8538
8532
|
isSeriesFunctionArg = true;
|
|
8539
8533
|
}
|
|
8540
8534
|
} else {
|
|
8541
|
-
|
|
8535
|
+
const isNamespaceCall = callee.type === "MemberExpression" && callee.object && callee.object.type === "Identifier" && KNOWN_NAMESPACES.includes(callee.object.name);
|
|
8536
|
+
if (callee.type === "MemberExpression" && !isNamespaceCall) {
|
|
8537
|
+
isSeriesFunctionArg = false;
|
|
8538
|
+
} else {
|
|
8539
|
+
isSeriesFunctionArg = true;
|
|
8540
|
+
}
|
|
8542
8541
|
}
|
|
8543
8542
|
}
|
|
8544
|
-
const
|
|
8545
|
-
const
|
|
8543
|
+
const isNamespaceMember = node.parent && node.parent.type === "MemberExpression" && node.parent.object === node && scopeManager.isContextBound(node.name);
|
|
8544
|
+
const isParamCall = node.parent && node.parent.type === "CallExpression" && node.parent.callee && node.parent.callee.type === "MemberExpression" && node.parent.callee.property.name === "param";
|
|
8545
|
+
node.parent && node.parent.type === "AssignmentExpression" && node.parent.left === node;
|
|
8546
8546
|
const isFunctionCall = node.parent && node.parent.type === "CallExpression" && node.parent.callee === node;
|
|
8547
8547
|
const hasArrayAccess = node.parent && node.parent.type === "MemberExpression" && node.parent.computed && node.parent.object === node;
|
|
8548
|
+
const isArrayIndexInNamespaceCall = node.parent && node.parent.type === "MemberExpression" && node.parent.computed && node.parent.property === node && node.parent.parent && node.parent.parent.type === "CallExpression" && node.parent.parent.callee && node.parent.parent.callee.type === "MemberExpression" && scopeManager.isContextBound(node.parent.parent.callee.object.name);
|
|
8548
8549
|
if (isNamespaceMember || isParamCall || isSeriesFunctionArg || isArrayIndexInNamespaceCall || isFunctionCall) {
|
|
8549
8550
|
if (isFunctionCall) {
|
|
8550
8551
|
return;
|
|
@@ -8552,13 +8553,23 @@ function transformIdentifier(node, scopeManager) {
|
|
|
8552
8553
|
if (scopeManager.isLocalSeriesVar(node.name)) {
|
|
8553
8554
|
return;
|
|
8554
8555
|
}
|
|
8556
|
+
if (scopeManager.isContextBound(node.name) && !scopeManager.isRootParam(node.name)) {
|
|
8557
|
+
return;
|
|
8558
|
+
}
|
|
8555
8559
|
const [scopedName2, kind2] = scopeManager.getVariable(node.name);
|
|
8556
8560
|
const memberExpr2 = ASTFactory.createContextVariableReference(kind2, scopedName2);
|
|
8557
8561
|
Object.assign(node, memberExpr2);
|
|
8558
8562
|
return;
|
|
8559
8563
|
}
|
|
8564
|
+
const isContextBoundVar = scopeManager.isContextBound(node.name) && !scopeManager.isRootParam(node.name);
|
|
8565
|
+
if (isContextBoundVar) {
|
|
8566
|
+
const isFunctionArg = node.parent && node.parent.type === "CallExpression" && node.parent.arguments.includes(node);
|
|
8567
|
+
if (!isFunctionArg) {
|
|
8568
|
+
return;
|
|
8569
|
+
}
|
|
8570
|
+
}
|
|
8560
8571
|
if (scopeManager.isLocalSeriesVar(node.name)) {
|
|
8561
|
-
if (!hasArrayAccess
|
|
8572
|
+
if (!hasArrayAccess) {
|
|
8562
8573
|
const memberExpr2 = ASTFactory.createIdentifier(node.name);
|
|
8563
8574
|
const accessExpr = ASTFactory.createGetCall(memberExpr2, 0);
|
|
8564
8575
|
Object.assign(node, accessExpr);
|
|
@@ -8566,8 +8577,16 @@ function transformIdentifier(node, scopeManager) {
|
|
|
8566
8577
|
return;
|
|
8567
8578
|
}
|
|
8568
8579
|
const [scopedName, kind] = scopeManager.getVariable(node.name);
|
|
8569
|
-
|
|
8570
|
-
if (
|
|
8580
|
+
let memberExpr;
|
|
8581
|
+
if (isContextBoundVar) {
|
|
8582
|
+
memberExpr = ASTFactory.createIdentifier(node.name);
|
|
8583
|
+
} else {
|
|
8584
|
+
if (scopedName === node.name && !scopeManager.isContextBound(node.name)) {
|
|
8585
|
+
return;
|
|
8586
|
+
}
|
|
8587
|
+
memberExpr = ASTFactory.createContextVariableReference(kind, scopedName);
|
|
8588
|
+
}
|
|
8589
|
+
if (!hasArrayAccess) {
|
|
8571
8590
|
const accessExpr = ASTFactory.createGetCall(memberExpr, 0);
|
|
8572
8591
|
Object.assign(node, accessExpr);
|
|
8573
8592
|
} else {
|
|
@@ -8579,7 +8598,6 @@ function transformMemberExpression(memberNode, originalParamName, scopeManager)
|
|
|
8579
8598
|
if (memberNode.object && memberNode.object.type === "Identifier" && memberNode.object.name === "Math") {
|
|
8580
8599
|
return;
|
|
8581
8600
|
}
|
|
8582
|
-
const KNOWN_NAMESPACES = ["ta", "math", "request", "array", "input"];
|
|
8583
8601
|
const isDirectNamespaceMemberAccess = memberNode.object && memberNode.object.type === "Identifier" && KNOWN_NAMESPACES.includes(memberNode.object.name) && scopeManager.isContextBound(memberNode.object.name) && !memberNode.computed;
|
|
8584
8602
|
if (isDirectNamespaceMemberAccess) {
|
|
8585
8603
|
const isAlreadyBeingCalled = memberNode.parent && memberNode.parent.type === "CallExpression" && memberNode.parent.callee === memberNode;
|
|
@@ -8623,6 +8641,9 @@ function transformMemberExpression(memberNode, originalParamName, scopeManager)
|
|
|
8623
8641
|
if (memberNode.start) getCall.start = memberNode.start;
|
|
8624
8642
|
if (memberNode.end) getCall.end = memberNode.end;
|
|
8625
8643
|
Object.assign(memberNode, getCall);
|
|
8644
|
+
delete memberNode.object;
|
|
8645
|
+
delete memberNode.property;
|
|
8646
|
+
delete memberNode.computed;
|
|
8626
8647
|
}
|
|
8627
8648
|
}
|
|
8628
8649
|
function transformIdentifierForParam(node, scopeManager) {
|
|
@@ -8775,16 +8796,31 @@ function getParamFromConditionalExpression(node, scopeManager, namespace) {
|
|
|
8775
8796
|
}
|
|
8776
8797
|
},
|
|
8777
8798
|
ConditionalExpression(node2, state, c) {
|
|
8799
|
+
const newState = { ...state, parent: node2 };
|
|
8778
8800
|
if (node2.test) {
|
|
8779
|
-
c(node2.test,
|
|
8801
|
+
c(node2.test, newState);
|
|
8780
8802
|
}
|
|
8781
8803
|
if (node2.consequent) {
|
|
8782
|
-
c(node2.consequent,
|
|
8804
|
+
c(node2.consequent, newState);
|
|
8783
8805
|
}
|
|
8784
8806
|
if (node2.alternate) {
|
|
8785
|
-
c(node2.alternate,
|
|
8807
|
+
c(node2.alternate, newState);
|
|
8786
8808
|
}
|
|
8787
8809
|
},
|
|
8810
|
+
BinaryExpression(node2, state, c) {
|
|
8811
|
+
const newState = { ...state, parent: node2 };
|
|
8812
|
+
c(node2.left, newState);
|
|
8813
|
+
c(node2.right, newState);
|
|
8814
|
+
},
|
|
8815
|
+
LogicalExpression(node2, state, c) {
|
|
8816
|
+
const newState = { ...state, parent: node2 };
|
|
8817
|
+
c(node2.left, newState);
|
|
8818
|
+
c(node2.right, newState);
|
|
8819
|
+
},
|
|
8820
|
+
UnaryExpression(node2, state, c) {
|
|
8821
|
+
const newState = { ...state, parent: node2 };
|
|
8822
|
+
c(node2.argument, newState);
|
|
8823
|
+
},
|
|
8788
8824
|
CallExpression(node2, state, c) {
|
|
8789
8825
|
const isNamespaceCall = node2.callee && node2.callee.type === "MemberExpression" && node2.callee.object && node2.callee.object.type === "Identifier" && scopeManager.isContextBound(node2.callee.object.name);
|
|
8790
8826
|
transformCallExpression(node2, scopeManager);
|
|
@@ -8873,6 +8909,20 @@ function transformFunctionArgument(arg, namespace, scopeManager) {
|
|
|
8873
8909
|
if (arg.type === "ObjectExpression") {
|
|
8874
8910
|
arg.properties = arg.properties.map((prop) => {
|
|
8875
8911
|
if (prop.value.name) {
|
|
8912
|
+
if (scopeManager.isContextBound(prop.value.name) && !scopeManager.isRootParam(prop.value.name)) {
|
|
8913
|
+
return {
|
|
8914
|
+
type: "Property",
|
|
8915
|
+
key: {
|
|
8916
|
+
type: "Identifier",
|
|
8917
|
+
name: prop.key.name
|
|
8918
|
+
},
|
|
8919
|
+
value: ASTFactory.createIdentifier(prop.value.name),
|
|
8920
|
+
kind: "init",
|
|
8921
|
+
method: false,
|
|
8922
|
+
shorthand: false,
|
|
8923
|
+
computed: false
|
|
8924
|
+
};
|
|
8925
|
+
}
|
|
8876
8926
|
const [scopedName, kind] = scopeManager.getVariable(prop.value.name);
|
|
8877
8927
|
return {
|
|
8878
8928
|
type: "Property",
|
|
@@ -8941,6 +8991,12 @@ function transformCallExpression(node, scopeManager, namespace) {
|
|
|
8941
8991
|
if (node._transformed) {
|
|
8942
8992
|
return;
|
|
8943
8993
|
}
|
|
8994
|
+
if (node.callee && node.callee.type === "Identifier" && KNOWN_NAMESPACES.includes(node.callee.name) && scopeManager.isContextBound(node.callee.name)) {
|
|
8995
|
+
node.callee = ASTFactory.createMemberExpression(
|
|
8996
|
+
node.callee,
|
|
8997
|
+
ASTFactory.createIdentifier("any")
|
|
8998
|
+
);
|
|
8999
|
+
}
|
|
8944
9000
|
const isNamespaceCall = node.callee && node.callee.type === "MemberExpression" && node.callee.object && node.callee.object.type === "Identifier" && (scopeManager.isContextBound(node.callee.object.name) || node.callee.object.name === "math" || node.callee.object.name === "ta");
|
|
8945
9001
|
if (isNamespaceCall) {
|
|
8946
9002
|
if (node.callee.object.name === CONTEXT_NAME && ["get", "init", "param"].includes(node.callee.property.name)) {
|
|
@@ -8977,6 +9033,11 @@ function transformCallExpression(node, scopeManager, namespace) {
|
|
|
8977
9033
|
});
|
|
8978
9034
|
node._transformed = true;
|
|
8979
9035
|
}
|
|
9036
|
+
if (!isNamespaceCall && node.callee && node.callee.type === "MemberExpression") {
|
|
9037
|
+
if (node.callee.object.type === "Identifier") {
|
|
9038
|
+
transformIdentifier(node.callee.object, scopeManager);
|
|
9039
|
+
}
|
|
9040
|
+
}
|
|
8980
9041
|
node.arguments.forEach((arg) => {
|
|
8981
9042
|
recursive(
|
|
8982
9043
|
arg,
|
|
@@ -8998,6 +9059,20 @@ function transformCallExpression(node, scopeManager, namespace) {
|
|
|
8998
9059
|
}
|
|
8999
9060
|
}
|
|
9000
9061
|
},
|
|
9062
|
+
BinaryExpression(node2, state, c) {
|
|
9063
|
+
const newState = { ...state, parent: node2 };
|
|
9064
|
+
c(node2.left, newState);
|
|
9065
|
+
c(node2.right, newState);
|
|
9066
|
+
},
|
|
9067
|
+
LogicalExpression(node2, state, c) {
|
|
9068
|
+
const newState = { ...state, parent: node2 };
|
|
9069
|
+
c(node2.left, newState);
|
|
9070
|
+
c(node2.right, newState);
|
|
9071
|
+
},
|
|
9072
|
+
UnaryExpression(node2, state, c) {
|
|
9073
|
+
const newState = { ...state, parent: node2 };
|
|
9074
|
+
c(node2.argument, newState);
|
|
9075
|
+
},
|
|
9001
9076
|
CallExpression(node2, state, c) {
|
|
9002
9077
|
if (!node2._transformed) {
|
|
9003
9078
|
transformCallExpression(node2, scopeManager);
|
|
@@ -9139,7 +9214,8 @@ function transformVariableDeclaration(varNode, scopeManager) {
|
|
|
9139
9214
|
}
|
|
9140
9215
|
const newName = scopeManager.addVariable(decl.id.name, varNode.kind);
|
|
9141
9216
|
const kind = varNode.kind;
|
|
9142
|
-
|
|
9217
|
+
const isArrayPatternVar = scopeManager.isArrayPatternElement(decl.id.name);
|
|
9218
|
+
if (decl.init && !isArrowFunction && !isArrayPatternVar) {
|
|
9143
9219
|
if (decl.init.type === "CallExpression" && decl.init.callee.type === "MemberExpression" && decl.init.callee.object && decl.init.callee.object.type === "Identifier" && scopeManager.isContextBound(decl.init.callee.object.name)) {
|
|
9144
9220
|
transformCallExpression(decl.init, scopeManager);
|
|
9145
9221
|
} else {
|
|
@@ -9200,7 +9276,6 @@ function transformVariableDeclaration(varNode, scopeManager) {
|
|
|
9200
9276
|
}
|
|
9201
9277
|
}
|
|
9202
9278
|
const targetVarRef = ASTFactory.createContextVariableReference(kind, newName);
|
|
9203
|
-
const isArrayPatternVar = scopeManager.isArrayPatternElement(decl.id.name);
|
|
9204
9279
|
const isArrayInit = !isArrayPatternVar && decl.init && decl.init.type === "MemberExpression" && decl.init.computed && decl.init.property && (decl.init.property.type === "Literal" || decl.init.property.type === "MemberExpression");
|
|
9205
9280
|
if (decl.init?.property?.type === "MemberExpression") {
|
|
9206
9281
|
if (!decl.init.property._indexTransformed) {
|
|
@@ -9213,10 +9288,7 @@ function transformVariableDeclaration(varNode, scopeManager) {
|
|
|
9213
9288
|
if (isArrowFunction || isArrayPatternVar) {
|
|
9214
9289
|
rightSide = decl.init;
|
|
9215
9290
|
} else if (kind === "var") {
|
|
9216
|
-
rightSide = ASTFactory.createInitVarCall(
|
|
9217
|
-
targetVarRef,
|
|
9218
|
-
decl.init
|
|
9219
|
-
);
|
|
9291
|
+
rightSide = ASTFactory.createInitVarCall(targetVarRef, decl.init);
|
|
9220
9292
|
} else {
|
|
9221
9293
|
rightSide = ASTFactory.createInitCall(
|
|
9222
9294
|
targetVarRef,
|
|
@@ -9229,7 +9301,9 @@ function transformVariableDeclaration(varNode, scopeManager) {
|
|
|
9229
9301
|
}
|
|
9230
9302
|
const assignmentExpr = ASTFactory.createExpressionStatement(ASTFactory.createAssignmentExpression(targetVarRef, rightSide));
|
|
9231
9303
|
if (isArrayPatternVar) {
|
|
9232
|
-
const
|
|
9304
|
+
const tempVarName = decl.init.object.name;
|
|
9305
|
+
const [scopedTempName, tempKind] = scopeManager.getVariable(tempVarName);
|
|
9306
|
+
const tempVarRef = ASTFactory.createContextVariableReference(tempKind, scopedTempName);
|
|
9233
9307
|
const arrayIndex = decl.init.property.value;
|
|
9234
9308
|
const getCall = ASTFactory.createGetCall(tempVarRef, 0);
|
|
9235
9309
|
const arrayAccess = {
|
|
@@ -9426,6 +9500,9 @@ function transformReturnStatement(node, scopeManager) {
|
|
|
9426
9500
|
} else if (node.argument.type === "ObjectExpression") {
|
|
9427
9501
|
node.argument.properties = node.argument.properties.map((prop) => {
|
|
9428
9502
|
if (prop.shorthand) {
|
|
9503
|
+
if (scopeManager.isContextBound(prop.value.name)) {
|
|
9504
|
+
return prop;
|
|
9505
|
+
}
|
|
9429
9506
|
const [scopedName, kind] = scopeManager.getVariable(prop.value.name);
|
|
9430
9507
|
return {
|
|
9431
9508
|
type: "Property",
|
|
@@ -9438,9 +9515,7 @@ function transformReturnStatement(node, scopeManager) {
|
|
|
9438
9515
|
};
|
|
9439
9516
|
}
|
|
9440
9517
|
if (prop.value && prop.value.type === "Identifier") {
|
|
9441
|
-
if (scopeManager.isContextBound(prop.value.name) && !scopeManager.isRootParam(prop.value.name)) {
|
|
9442
|
-
prop.value = ASTFactory.createGetCall(prop.value, 0);
|
|
9443
|
-
} else if (!scopeManager.isContextBound(prop.value.name)) {
|
|
9518
|
+
if (scopeManager.isContextBound(prop.value.name) && !scopeManager.isRootParam(prop.value.name)) ; else if (!scopeManager.isContextBound(prop.value.name)) {
|
|
9444
9519
|
const [scopedName, kind] = scopeManager.getVariable(prop.value.name);
|
|
9445
9520
|
prop.value = ASTFactory.createContextVariableReference(kind, scopedName);
|
|
9446
9521
|
}
|
|
@@ -9625,72 +9700,207 @@ function transpile(fn, options = { debug: false, ln: false }) {
|
|
|
9625
9700
|
return _wraperFunction(this);
|
|
9626
9701
|
}
|
|
9627
9702
|
|
|
9628
|
-
class PineArrayObject {
|
|
9629
|
-
constructor(array) {
|
|
9630
|
-
this.array = array;
|
|
9631
|
-
}
|
|
9632
|
-
toString() {
|
|
9633
|
-
return "PineArrayObject:" + this.array.toString();
|
|
9634
|
-
}
|
|
9635
|
-
}
|
|
9636
|
-
|
|
9637
9703
|
function abs$1(context) {
|
|
9638
9704
|
return (id) => {
|
|
9639
|
-
return new PineArrayObject(
|
|
9705
|
+
return new PineArrayObject(
|
|
9706
|
+
id.array.map((val) => Math.abs(val)),
|
|
9707
|
+
id.type,
|
|
9708
|
+
context
|
|
9709
|
+
);
|
|
9640
9710
|
};
|
|
9641
9711
|
}
|
|
9642
9712
|
|
|
9643
|
-
function avg$
|
|
9713
|
+
function avg$2(context) {
|
|
9644
9714
|
return (id) => {
|
|
9645
|
-
|
|
9715
|
+
let mean = 0;
|
|
9716
|
+
let count = 0;
|
|
9717
|
+
for (const item of id.array) {
|
|
9718
|
+
const val = Number(item);
|
|
9719
|
+
if (!isNaN(val)) {
|
|
9720
|
+
count++;
|
|
9721
|
+
mean += (val - mean) / count;
|
|
9722
|
+
}
|
|
9723
|
+
}
|
|
9724
|
+
if (count === 0) return NaN;
|
|
9725
|
+
return context.precision(mean);
|
|
9646
9726
|
};
|
|
9647
9727
|
}
|
|
9648
9728
|
|
|
9649
|
-
function
|
|
9729
|
+
function binary_search(context) {
|
|
9730
|
+
return (id, value) => {
|
|
9731
|
+
const array = id.array;
|
|
9732
|
+
let low = 0;
|
|
9733
|
+
let high = array.length - 1;
|
|
9734
|
+
while (low <= high) {
|
|
9735
|
+
const mid = Math.floor((low + high) / 2);
|
|
9736
|
+
const midVal = array[mid];
|
|
9737
|
+
if (midVal === value) {
|
|
9738
|
+
return mid;
|
|
9739
|
+
}
|
|
9740
|
+
if (midVal < value) {
|
|
9741
|
+
low = mid + 1;
|
|
9742
|
+
} else {
|
|
9743
|
+
high = mid - 1;
|
|
9744
|
+
}
|
|
9745
|
+
}
|
|
9746
|
+
return -1;
|
|
9747
|
+
};
|
|
9748
|
+
}
|
|
9749
|
+
|
|
9750
|
+
function binary_search_leftmost(context) {
|
|
9751
|
+
return (id, value) => {
|
|
9752
|
+
const array = id.array;
|
|
9753
|
+
let low = 0;
|
|
9754
|
+
let high = array.length;
|
|
9755
|
+
while (low < high) {
|
|
9756
|
+
const mid = Math.floor((low + high) / 2);
|
|
9757
|
+
if (array[mid] < value) {
|
|
9758
|
+
low = mid + 1;
|
|
9759
|
+
} else {
|
|
9760
|
+
high = mid;
|
|
9761
|
+
}
|
|
9762
|
+
}
|
|
9763
|
+
if (low < array.length && array[low] === value) {
|
|
9764
|
+
return low;
|
|
9765
|
+
}
|
|
9766
|
+
return low - 1;
|
|
9767
|
+
};
|
|
9768
|
+
}
|
|
9769
|
+
|
|
9770
|
+
function binary_search_rightmost(context) {
|
|
9771
|
+
return (id, value) => {
|
|
9772
|
+
const array = id.array;
|
|
9773
|
+
let low = 0;
|
|
9774
|
+
let high = array.length;
|
|
9775
|
+
while (low < high) {
|
|
9776
|
+
const mid = Math.floor((low + high) / 2);
|
|
9777
|
+
if (array[mid] <= value) {
|
|
9778
|
+
low = mid + 1;
|
|
9779
|
+
} else {
|
|
9780
|
+
high = mid;
|
|
9781
|
+
}
|
|
9782
|
+
}
|
|
9783
|
+
if (low > 0 && array[low - 1] === value) {
|
|
9784
|
+
return low - 1;
|
|
9785
|
+
}
|
|
9786
|
+
return low;
|
|
9787
|
+
};
|
|
9788
|
+
}
|
|
9789
|
+
|
|
9790
|
+
function clear$1(context) {
|
|
9650
9791
|
return (id) => {
|
|
9651
9792
|
id.array.length = 0;
|
|
9652
9793
|
};
|
|
9653
9794
|
}
|
|
9654
9795
|
|
|
9655
|
-
function concat(context) {
|
|
9796
|
+
function concat$1(context) {
|
|
9656
9797
|
return (id, other) => {
|
|
9657
9798
|
id.array.push(...other.array);
|
|
9658
9799
|
return id;
|
|
9659
9800
|
};
|
|
9660
9801
|
}
|
|
9661
9802
|
|
|
9662
|
-
function copy(context) {
|
|
9803
|
+
function copy$2(context) {
|
|
9663
9804
|
return (id) => {
|
|
9664
|
-
return new PineArrayObject([...id.array]);
|
|
9805
|
+
return new PineArrayObject([...id.array], id.type, context);
|
|
9665
9806
|
};
|
|
9666
9807
|
}
|
|
9667
9808
|
|
|
9668
9809
|
function covariance(context) {
|
|
9669
9810
|
return (arr1, arr2, biased = true) => {
|
|
9670
|
-
|
|
9671
|
-
const
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
let
|
|
9675
|
-
|
|
9676
|
-
|
|
9811
|
+
const a1 = arr1.array;
|
|
9812
|
+
const a2 = arr2.array;
|
|
9813
|
+
if (a1.length !== a2.length) return NaN;
|
|
9814
|
+
let sum1 = 0;
|
|
9815
|
+
let sum2 = 0;
|
|
9816
|
+
let count = 0;
|
|
9817
|
+
const validIndices = [];
|
|
9818
|
+
for (let i = 0; i < a1.length; i++) {
|
|
9819
|
+
const v1 = Number(a1[i]);
|
|
9820
|
+
const v2 = Number(a2[i]);
|
|
9821
|
+
if (!isNaN(v1) && v1 !== null && v1 !== void 0 && !isNaN(v2) && v2 !== null && v2 !== void 0) {
|
|
9822
|
+
sum1 += v1;
|
|
9823
|
+
sum2 += v2;
|
|
9824
|
+
count++;
|
|
9825
|
+
validIndices.push(i);
|
|
9826
|
+
}
|
|
9677
9827
|
}
|
|
9678
|
-
|
|
9828
|
+
if (count === 0) return NaN;
|
|
9829
|
+
const mean1 = sum1 / count;
|
|
9830
|
+
const mean2 = sum2 / count;
|
|
9831
|
+
let sumProd = 0;
|
|
9832
|
+
for (const i of validIndices) {
|
|
9833
|
+
const v1 = Number(a1[i]);
|
|
9834
|
+
const v2 = Number(a2[i]);
|
|
9835
|
+
sumProd += (v1 - mean1) * (v2 - mean2);
|
|
9836
|
+
}
|
|
9837
|
+
const divisor = biased ? count : count - 1;
|
|
9838
|
+
if (divisor <= 0) return NaN;
|
|
9839
|
+
return context.precision(sumProd / divisor);
|
|
9679
9840
|
};
|
|
9680
9841
|
}
|
|
9681
9842
|
|
|
9682
9843
|
function every(context) {
|
|
9683
|
-
return (id
|
|
9684
|
-
return id.array.every(
|
|
9844
|
+
return (id) => {
|
|
9845
|
+
return id.array.every((value) => !isNaN(value) && value);
|
|
9685
9846
|
};
|
|
9686
9847
|
}
|
|
9687
9848
|
|
|
9688
|
-
function
|
|
9849
|
+
function inferArrayType(values) {
|
|
9850
|
+
if (values.every((value) => typeof value === "number")) {
|
|
9851
|
+
if (values.every((value) => (value | 0) === value)) {
|
|
9852
|
+
return PineArrayType.int;
|
|
9853
|
+
} else {
|
|
9854
|
+
return PineArrayType.float;
|
|
9855
|
+
}
|
|
9856
|
+
} else if (values.every((value) => typeof value === "string")) {
|
|
9857
|
+
return PineArrayType.string;
|
|
9858
|
+
} else if (values.every((value) => typeof value === "boolean")) {
|
|
9859
|
+
return PineArrayType.bool;
|
|
9860
|
+
} else {
|
|
9861
|
+
throw new Error("Cannot infer type from values");
|
|
9862
|
+
}
|
|
9863
|
+
}
|
|
9864
|
+
function inferValueType(value) {
|
|
9865
|
+
if (typeof value === "number") {
|
|
9866
|
+
if ((value | 0) === value) {
|
|
9867
|
+
return PineArrayType.int;
|
|
9868
|
+
} else {
|
|
9869
|
+
return PineArrayType.float;
|
|
9870
|
+
}
|
|
9871
|
+
} else if (typeof value === "string") {
|
|
9872
|
+
return PineArrayType.string;
|
|
9873
|
+
} else if (typeof value === "boolean") {
|
|
9874
|
+
return PineArrayType.bool;
|
|
9875
|
+
} else {
|
|
9876
|
+
throw new Error("Cannot infer type from value");
|
|
9877
|
+
}
|
|
9878
|
+
}
|
|
9879
|
+
function isValueOfType(value, type) {
|
|
9880
|
+
switch (type) {
|
|
9881
|
+
case PineArrayType.int:
|
|
9882
|
+
return typeof value === "number" && (value | 0) === value || isNaN(value);
|
|
9883
|
+
case PineArrayType.float:
|
|
9884
|
+
return typeof value === "number" || isNaN(value);
|
|
9885
|
+
case PineArrayType.string:
|
|
9886
|
+
return typeof value === "string";
|
|
9887
|
+
case PineArrayType.bool:
|
|
9888
|
+
return typeof value === "boolean";
|
|
9889
|
+
}
|
|
9890
|
+
return false;
|
|
9891
|
+
}
|
|
9892
|
+
|
|
9893
|
+
function fill$1(context) {
|
|
9689
9894
|
return (id, value, start = 0, end) => {
|
|
9690
9895
|
const length = id.array.length;
|
|
9691
9896
|
const adjustedEnd = end !== void 0 ? Math.min(end, length) : length;
|
|
9692
9897
|
for (let i = start; i < adjustedEnd; i++) {
|
|
9693
|
-
id.
|
|
9898
|
+
if (!isValueOfType(value, id.type)) {
|
|
9899
|
+
throw new Error(
|
|
9900
|
+
`Cannot call 'array.fill' with argument 'value'='${value}'. An argument of 'literal ${typeof value}' type was used but a '${id.type}' is expected.`
|
|
9901
|
+
);
|
|
9902
|
+
}
|
|
9903
|
+
id.array[i] = context.precision(value);
|
|
9694
9904
|
}
|
|
9695
9905
|
};
|
|
9696
9906
|
}
|
|
@@ -9701,13 +9911,7 @@ function first(context) {
|
|
|
9701
9911
|
};
|
|
9702
9912
|
}
|
|
9703
9913
|
|
|
9704
|
-
function
|
|
9705
|
-
return (...values) => {
|
|
9706
|
-
return new PineArrayObject([...values]);
|
|
9707
|
-
};
|
|
9708
|
-
}
|
|
9709
|
-
|
|
9710
|
-
function get(context) {
|
|
9914
|
+
function get$2(context) {
|
|
9711
9915
|
return (id, index) => {
|
|
9712
9916
|
return id.array[index];
|
|
9713
9917
|
};
|
|
@@ -9727,6 +9931,11 @@ function indexof(context) {
|
|
|
9727
9931
|
|
|
9728
9932
|
function insert(context) {
|
|
9729
9933
|
return (id, index, value) => {
|
|
9934
|
+
if (!isValueOfType(value, id.type)) {
|
|
9935
|
+
throw new Error(
|
|
9936
|
+
`Cannot call 'array.insert' with argument 'value'='${value}'. An argument of 'literal ${typeof value}' type was used but a '${id.type}' is expected.`
|
|
9937
|
+
);
|
|
9938
|
+
}
|
|
9730
9939
|
id.array.splice(index, 0, value);
|
|
9731
9940
|
};
|
|
9732
9941
|
}
|
|
@@ -9749,84 +9958,136 @@ function lastindexof(context) {
|
|
|
9749
9958
|
};
|
|
9750
9959
|
}
|
|
9751
9960
|
|
|
9752
|
-
function max$
|
|
9961
|
+
function max$2(context) {
|
|
9753
9962
|
return (id, nth = 0) => {
|
|
9754
9963
|
const sorted = [...id.array].sort((a, b) => b - a);
|
|
9755
9964
|
return sorted[nth] ?? context.NA;
|
|
9756
9965
|
};
|
|
9757
9966
|
}
|
|
9758
9967
|
|
|
9759
|
-
function
|
|
9760
|
-
return (id
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
|
|
9768
|
-
|
|
9968
|
+
function median$2(context) {
|
|
9969
|
+
return (id) => {
|
|
9970
|
+
if (id.array.length === 0) return NaN;
|
|
9971
|
+
const sorted = [...id.array].sort((a, b) => {
|
|
9972
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
9973
|
+
return a - b;
|
|
9974
|
+
}
|
|
9975
|
+
return 0;
|
|
9976
|
+
});
|
|
9977
|
+
const mid = Math.floor(sorted.length / 2);
|
|
9978
|
+
if (sorted.length % 2 !== 0) {
|
|
9979
|
+
return sorted[mid];
|
|
9980
|
+
}
|
|
9981
|
+
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
9769
9982
|
};
|
|
9770
9983
|
}
|
|
9771
9984
|
|
|
9772
|
-
function
|
|
9773
|
-
return (
|
|
9774
|
-
|
|
9985
|
+
function min$2(context) {
|
|
9986
|
+
return (id, nth = 0) => {
|
|
9987
|
+
const sorted = [...id.array].sort((a, b) => a - b);
|
|
9988
|
+
return sorted[nth] ?? context.NA;
|
|
9775
9989
|
};
|
|
9776
9990
|
}
|
|
9777
9991
|
|
|
9778
|
-
function
|
|
9779
|
-
return (
|
|
9780
|
-
|
|
9992
|
+
function mode$2(context) {
|
|
9993
|
+
return (id) => {
|
|
9994
|
+
if (id.array.length === 0) return NaN;
|
|
9995
|
+
const counts = /* @__PURE__ */ new Map();
|
|
9996
|
+
let maxFreq = 0;
|
|
9997
|
+
for (const val of id.array) {
|
|
9998
|
+
const count = (counts.get(val) || 0) + 1;
|
|
9999
|
+
counts.set(val, count);
|
|
10000
|
+
if (count > maxFreq) {
|
|
10001
|
+
maxFreq = count;
|
|
10002
|
+
}
|
|
10003
|
+
}
|
|
10004
|
+
const modes = [];
|
|
10005
|
+
for (const [val, count] of counts) {
|
|
10006
|
+
if (count === maxFreq) {
|
|
10007
|
+
modes.push(val);
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
10010
|
+
modes.sort((a, b) => {
|
|
10011
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
10012
|
+
return a - b;
|
|
10013
|
+
}
|
|
10014
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
10015
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
10016
|
+
}
|
|
10017
|
+
return 0;
|
|
10018
|
+
});
|
|
10019
|
+
return modes[0];
|
|
9781
10020
|
};
|
|
9782
10021
|
}
|
|
9783
10022
|
|
|
9784
|
-
function
|
|
9785
|
-
return (
|
|
9786
|
-
|
|
10023
|
+
function percentile_linear_interpolation$1(context) {
|
|
10024
|
+
return (id, percentage) => {
|
|
10025
|
+
const array = id.array;
|
|
10026
|
+
if (array.length === 0) return NaN;
|
|
10027
|
+
const validValues = [];
|
|
10028
|
+
for (const item of array) {
|
|
10029
|
+
const val = Number(item);
|
|
10030
|
+
if (isNaN(val) || val === null || val === void 0) {
|
|
10031
|
+
return NaN;
|
|
10032
|
+
}
|
|
10033
|
+
validValues.push(val);
|
|
10034
|
+
}
|
|
10035
|
+
validValues.sort((a, b) => a - b);
|
|
10036
|
+
if (percentage < 0) percentage = 0;
|
|
10037
|
+
if (percentage > 100) percentage = 100;
|
|
10038
|
+
const k = percentage / 100 * validValues.length - 0.5;
|
|
10039
|
+
if (k <= 0) return context.precision(validValues[0]);
|
|
10040
|
+
if (k >= validValues.length - 1) return context.precision(validValues[validValues.length - 1]);
|
|
10041
|
+
const i = Math.floor(k);
|
|
10042
|
+
const f = k - i;
|
|
10043
|
+
return context.precision(validValues[i] * (1 - f) + validValues[i + 1] * f);
|
|
9787
10044
|
};
|
|
9788
10045
|
}
|
|
9789
10046
|
|
|
9790
|
-
function
|
|
9791
|
-
return (
|
|
9792
|
-
|
|
10047
|
+
function percentile_nearest_rank$1(context) {
|
|
10048
|
+
return (id, percentage) => {
|
|
10049
|
+
const array = id.array;
|
|
10050
|
+
if (array.length === 0) return NaN;
|
|
10051
|
+
const validValues = [];
|
|
10052
|
+
for (const item of array) {
|
|
10053
|
+
const val = Number(item);
|
|
10054
|
+
if (!isNaN(val) && val !== null && val !== void 0) {
|
|
10055
|
+
validValues.push(val);
|
|
10056
|
+
}
|
|
10057
|
+
}
|
|
10058
|
+
if (validValues.length === 0) return NaN;
|
|
10059
|
+
validValues.sort((a, b) => a - b);
|
|
10060
|
+
if (percentage < 0) percentage = 0;
|
|
10061
|
+
if (percentage > 100) percentage = 100;
|
|
10062
|
+
const totalCount = array.length;
|
|
10063
|
+
const rank = Math.ceil(percentage / 100 * totalCount);
|
|
10064
|
+
if (rank <= 0) {
|
|
10065
|
+
return validValues[0];
|
|
10066
|
+
}
|
|
10067
|
+
if (rank > validValues.length) return NaN;
|
|
10068
|
+
return validValues[rank - 1];
|
|
9793
10069
|
};
|
|
9794
10070
|
}
|
|
9795
10071
|
|
|
9796
|
-
|
|
9797
|
-
|
|
9798
|
-
|
|
9799
|
-
|
|
9800
|
-
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
this.data[realIndex] = value;
|
|
10072
|
+
function percentrank$1(context) {
|
|
10073
|
+
return (id, index) => {
|
|
10074
|
+
if (id.array.length === 0) return NaN;
|
|
10075
|
+
const idx = Math.floor(index);
|
|
10076
|
+
if (idx < 0 || idx >= id.array.length) return NaN;
|
|
10077
|
+
const value = Number(id.array[idx]);
|
|
10078
|
+
if (isNaN(value) || value === null || value === void 0) return NaN;
|
|
10079
|
+
let lessThan = 0;
|
|
10080
|
+
for (const item of id.array) {
|
|
10081
|
+
const val = Number(item);
|
|
10082
|
+
if (!isNaN(val) && val !== null && val !== void 0) {
|
|
10083
|
+
if (val < value) {
|
|
10084
|
+
lessThan++;
|
|
10085
|
+
}
|
|
10086
|
+
}
|
|
9812
10087
|
}
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
return
|
|
9816
|
-
}
|
|
9817
|
-
toArray() {
|
|
9818
|
-
return this.data;
|
|
9819
|
-
}
|
|
9820
|
-
static from(source) {
|
|
9821
|
-
if (source instanceof Series) return source;
|
|
9822
|
-
if (Array.isArray(source)) return new Series(source);
|
|
9823
|
-
return new Series([source]);
|
|
9824
|
-
}
|
|
9825
|
-
}
|
|
9826
|
-
|
|
9827
|
-
function param$4(context) {
|
|
9828
|
-
return (source, index = 0) => {
|
|
9829
|
-
return Series.from(source).get(index);
|
|
10088
|
+
const divisor = id.array.length - 1;
|
|
10089
|
+
if (divisor <= 0) return NaN;
|
|
10090
|
+
return lessThan / divisor * 100;
|
|
9830
10091
|
};
|
|
9831
10092
|
}
|
|
9832
10093
|
|
|
@@ -9838,17 +10099,22 @@ function pop(context) {
|
|
|
9838
10099
|
|
|
9839
10100
|
function push(context) {
|
|
9840
10101
|
return (id, value) => {
|
|
9841
|
-
id.
|
|
10102
|
+
if (!isValueOfType(value, id.type)) {
|
|
10103
|
+
throw new Error(
|
|
10104
|
+
`Cannot call 'array.push' with argument 'value'='${value}'. An argument of 'literal ${typeof value}' type was used but a '${id.type}' is expected.`
|
|
10105
|
+
);
|
|
10106
|
+
}
|
|
10107
|
+
id.array.push(context.precision(value));
|
|
9842
10108
|
};
|
|
9843
10109
|
}
|
|
9844
10110
|
|
|
9845
10111
|
function range$1(context) {
|
|
9846
10112
|
return (id) => {
|
|
9847
|
-
return context.array.max(id) - context.array.min(id);
|
|
10113
|
+
return context.precision(context.pine.array.max(id) - context.pine.array.min(id));
|
|
9848
10114
|
};
|
|
9849
10115
|
}
|
|
9850
10116
|
|
|
9851
|
-
function remove(context) {
|
|
10117
|
+
function remove$1(context) {
|
|
9852
10118
|
return (id, index) => {
|
|
9853
10119
|
if (index >= 0 && index < id.array.length) {
|
|
9854
10120
|
return id.array.splice(index, 1)[0];
|
|
@@ -9857,15 +10123,20 @@ function remove(context) {
|
|
|
9857
10123
|
};
|
|
9858
10124
|
}
|
|
9859
10125
|
|
|
9860
|
-
function reverse(context) {
|
|
10126
|
+
function reverse$1(context) {
|
|
9861
10127
|
return (id) => {
|
|
9862
10128
|
id.array.reverse();
|
|
9863
10129
|
};
|
|
9864
10130
|
}
|
|
9865
10131
|
|
|
9866
|
-
function set(context) {
|
|
10132
|
+
function set$1(context) {
|
|
9867
10133
|
return (id, index, value) => {
|
|
9868
|
-
id.
|
|
10134
|
+
if (!isValueOfType(value, id.type)) {
|
|
10135
|
+
throw new Error(
|
|
10136
|
+
`Cannot call 'array.set' with argument 'value'='${value}'. An argument of 'literal ${typeof value}' type was used but a '${id.type}' is expected.`
|
|
10137
|
+
);
|
|
10138
|
+
}
|
|
10139
|
+
id.array[index] = context.precision(value);
|
|
9869
10140
|
};
|
|
9870
10141
|
}
|
|
9871
10142
|
|
|
@@ -9875,7 +10146,7 @@ function shift(context) {
|
|
|
9875
10146
|
};
|
|
9876
10147
|
}
|
|
9877
10148
|
|
|
9878
|
-
function size(context) {
|
|
10149
|
+
function size$1(context) {
|
|
9879
10150
|
return (id) => {
|
|
9880
10151
|
return id.array.length;
|
|
9881
10152
|
};
|
|
@@ -9883,32 +10154,116 @@ function size(context) {
|
|
|
9883
10154
|
|
|
9884
10155
|
function slice(context) {
|
|
9885
10156
|
return (id, start, end) => {
|
|
9886
|
-
const adjustedEnd = end !== void 0 ? end
|
|
9887
|
-
return new PineArrayObject(id.array.slice(start, adjustedEnd));
|
|
10157
|
+
const adjustedEnd = end !== void 0 ? end : void 0;
|
|
10158
|
+
return new PineArrayObject(id.array.slice(start, adjustedEnd), id.type, context);
|
|
9888
10159
|
};
|
|
9889
10160
|
}
|
|
9890
10161
|
|
|
9891
10162
|
function some(context) {
|
|
9892
|
-
return (id
|
|
9893
|
-
return id.array.some(
|
|
10163
|
+
return (id) => {
|
|
10164
|
+
return id.array.some((value) => !isNaN(value) && value);
|
|
9894
10165
|
};
|
|
9895
10166
|
}
|
|
9896
10167
|
|
|
9897
|
-
|
|
9898
|
-
|
|
9899
|
-
|
|
10168
|
+
var order = /* @__PURE__ */ ((order2) => {
|
|
10169
|
+
order2[order2["ascending"] = 1] = "ascending";
|
|
10170
|
+
order2[order2["descending"] = 0] = "descending";
|
|
10171
|
+
return order2;
|
|
10172
|
+
})(order || {});
|
|
10173
|
+
var currency = /* @__PURE__ */ ((currency2) => {
|
|
10174
|
+
currency2["AED"] = "AED";
|
|
10175
|
+
currency2["ARS"] = "ARS";
|
|
10176
|
+
currency2["AUD"] = "AUD";
|
|
10177
|
+
currency2["BDT"] = "BDT";
|
|
10178
|
+
currency2["BHD"] = "BHD";
|
|
10179
|
+
currency2["BRL"] = "BRL";
|
|
10180
|
+
currency2["BTC"] = "BTC";
|
|
10181
|
+
currency2["CAD"] = "CAD";
|
|
10182
|
+
currency2["CHF"] = "CHF";
|
|
10183
|
+
currency2["CLP"] = "CLP";
|
|
10184
|
+
currency2["CNY"] = "CNY";
|
|
10185
|
+
currency2["COP"] = "COP";
|
|
10186
|
+
currency2["CZK"] = "CZK";
|
|
10187
|
+
currency2["DKK"] = "DKK";
|
|
10188
|
+
currency2["EGP"] = "EGP";
|
|
10189
|
+
currency2["ETH"] = "ETH";
|
|
10190
|
+
currency2["EUR"] = "EUR";
|
|
10191
|
+
currency2["GBP"] = "GBP";
|
|
10192
|
+
currency2["HKD"] = "HKD";
|
|
10193
|
+
currency2["HUF"] = "HUF";
|
|
10194
|
+
currency2["IDR"] = "IDR";
|
|
10195
|
+
currency2["ILS"] = "ILS";
|
|
10196
|
+
currency2["INR"] = "INR";
|
|
10197
|
+
currency2["ISK"] = "ISK";
|
|
10198
|
+
currency2["JPY"] = "JPY";
|
|
10199
|
+
currency2["KES"] = "KES";
|
|
10200
|
+
currency2["KRW"] = "KRW";
|
|
10201
|
+
currency2["KWD"] = "KWD";
|
|
10202
|
+
currency2["LKR"] = "LKR";
|
|
10203
|
+
currency2["MAD"] = "MAD";
|
|
10204
|
+
currency2["MXN"] = "MXN";
|
|
10205
|
+
currency2["MYR"] = "MYR";
|
|
10206
|
+
currency2["NGN"] = "NGN";
|
|
10207
|
+
currency2["NOK"] = "NOK";
|
|
10208
|
+
currency2["NONE"] = "NONE";
|
|
10209
|
+
currency2["NZD"] = "NZD";
|
|
10210
|
+
currency2["PEN"] = "PEN";
|
|
10211
|
+
currency2["PHP"] = "PHP";
|
|
10212
|
+
currency2["PKR"] = "PKR";
|
|
10213
|
+
currency2["PLN"] = "PLN";
|
|
10214
|
+
currency2["QAR"] = "QAR";
|
|
10215
|
+
currency2["RON"] = "RON";
|
|
10216
|
+
currency2["RSD"] = "RSD";
|
|
10217
|
+
currency2["RUB"] = "RUB";
|
|
10218
|
+
currency2["SAR"] = "SAR";
|
|
10219
|
+
currency2["SEK"] = "SEK";
|
|
10220
|
+
currency2["SGD"] = "SGD";
|
|
10221
|
+
currency2["THB"] = "THB";
|
|
10222
|
+
currency2["TND"] = "TND";
|
|
10223
|
+
currency2["TRY"] = "TRY";
|
|
10224
|
+
currency2["TWD"] = "TWD";
|
|
10225
|
+
currency2["USD"] = "USD";
|
|
10226
|
+
currency2["USDT"] = "USDT";
|
|
10227
|
+
currency2["VES"] = "VES";
|
|
10228
|
+
currency2["VND"] = "VND";
|
|
10229
|
+
currency2["ZAR"] = "ZAR";
|
|
10230
|
+
return currency2;
|
|
10231
|
+
})(currency || {});
|
|
10232
|
+
var dayofweek = /* @__PURE__ */ ((dayofweek2) => {
|
|
10233
|
+
dayofweek2[dayofweek2["sunday"] = 1] = "sunday";
|
|
10234
|
+
dayofweek2[dayofweek2["monday"] = 2] = "monday";
|
|
10235
|
+
dayofweek2[dayofweek2["tuesday"] = 3] = "tuesday";
|
|
10236
|
+
dayofweek2[dayofweek2["wednesday"] = 4] = "wednesday";
|
|
10237
|
+
dayofweek2[dayofweek2["thursday"] = 5] = "thursday";
|
|
10238
|
+
dayofweek2[dayofweek2["friday"] = 6] = "friday";
|
|
10239
|
+
dayofweek2[dayofweek2["saturday"] = 7] = "saturday";
|
|
10240
|
+
return dayofweek2;
|
|
10241
|
+
})(dayofweek || {});
|
|
10242
|
+
const types = {
|
|
10243
|
+
order,
|
|
10244
|
+
currency,
|
|
10245
|
+
dayofweek
|
|
10246
|
+
};
|
|
10247
|
+
|
|
10248
|
+
function sort$1(context) {
|
|
10249
|
+
return (id, _order = order.ascending) => {
|
|
10250
|
+
id.array.sort((a, b) => {
|
|
10251
|
+
let _a = isNaN(a) ? Infinity : a;
|
|
10252
|
+
let _b = isNaN(b) ? Infinity : b;
|
|
10253
|
+
return _order === order.ascending ? _a - _b : _b - _a;
|
|
10254
|
+
});
|
|
9900
10255
|
};
|
|
9901
10256
|
}
|
|
9902
10257
|
|
|
9903
10258
|
function sort_indices(context) {
|
|
9904
|
-
return (id,
|
|
10259
|
+
return (id, _order = order.ascending) => {
|
|
9905
10260
|
const indices = id.array.map((_, index) => index);
|
|
9906
10261
|
indices.sort((a, b) => {
|
|
9907
|
-
const valA = id.array[a];
|
|
9908
|
-
const valB = id.array[b];
|
|
9909
|
-
return
|
|
10262
|
+
const valA = isNaN(id.array[a]) ? Infinity : id.array[a];
|
|
10263
|
+
const valB = isNaN(id.array[b]) ? Infinity : id.array[b];
|
|
10264
|
+
return _order === order.ascending ? valA - valB : valB - valA;
|
|
9910
10265
|
});
|
|
9911
|
-
return new PineArrayObject(indices);
|
|
10266
|
+
return new PineArrayObject(indices, PineArrayType.int, context);
|
|
9912
10267
|
};
|
|
9913
10268
|
}
|
|
9914
10269
|
|
|
@@ -9916,137 +10271,1885 @@ function standardize(context) {
|
|
|
9916
10271
|
return (id) => {
|
|
9917
10272
|
const mean = context.array.avg(id);
|
|
9918
10273
|
const stdev = context.array.stdev(id);
|
|
10274
|
+
if (isNaN(stdev)) {
|
|
10275
|
+
return new PineArrayObject(
|
|
10276
|
+
id.array.map(() => NaN),
|
|
10277
|
+
PineArrayType.int,
|
|
10278
|
+
context
|
|
10279
|
+
);
|
|
10280
|
+
}
|
|
9919
10281
|
if (stdev === 0) {
|
|
9920
|
-
return new PineArrayObject(
|
|
10282
|
+
return new PineArrayObject(
|
|
10283
|
+
id.array.map(() => 1),
|
|
10284
|
+
PineArrayType.int,
|
|
10285
|
+
context
|
|
10286
|
+
);
|
|
10287
|
+
}
|
|
10288
|
+
return new PineArrayObject(
|
|
10289
|
+
id.array.map((x) => (x - mean) / stdev),
|
|
10290
|
+
PineArrayType.int,
|
|
10291
|
+
context
|
|
10292
|
+
);
|
|
10293
|
+
};
|
|
10294
|
+
}
|
|
10295
|
+
|
|
10296
|
+
function stdev$1(context) {
|
|
10297
|
+
return (id, biased = true) => {
|
|
10298
|
+
const array = id.array;
|
|
10299
|
+
const n_total = array.length;
|
|
10300
|
+
if (n_total === 0) return NaN;
|
|
10301
|
+
let sum = 0;
|
|
10302
|
+
let sumSq = 0;
|
|
10303
|
+
let count = 0;
|
|
10304
|
+
for (let i = 0; i < n_total; i++) {
|
|
10305
|
+
const val = Number(array[i]);
|
|
10306
|
+
if (!isNaN(val) && val !== null && val !== void 0) {
|
|
10307
|
+
sum += val;
|
|
10308
|
+
sumSq += val * val;
|
|
10309
|
+
count++;
|
|
10310
|
+
}
|
|
10311
|
+
}
|
|
10312
|
+
if (count === 0) return NaN;
|
|
10313
|
+
const mean = sum / count;
|
|
10314
|
+
const meanSq = sumSq / count;
|
|
10315
|
+
let variance = meanSq - mean * mean;
|
|
10316
|
+
if (variance < 0) return NaN;
|
|
10317
|
+
if (!biased && count > 1) {
|
|
10318
|
+
variance = variance * count / (count - 1);
|
|
10319
|
+
}
|
|
10320
|
+
if (!biased && count === 1) return 0;
|
|
10321
|
+
return context.precision(Math.sqrt(variance));
|
|
10322
|
+
};
|
|
10323
|
+
}
|
|
10324
|
+
|
|
10325
|
+
function sum$2(context) {
|
|
10326
|
+
return (id) => {
|
|
10327
|
+
return context.precision(
|
|
10328
|
+
id.array.reduce((a, b) => {
|
|
10329
|
+
const val = Number(b);
|
|
10330
|
+
return isNaN(val) ? a : a + val;
|
|
10331
|
+
}, 0)
|
|
10332
|
+
);
|
|
10333
|
+
};
|
|
10334
|
+
}
|
|
10335
|
+
|
|
10336
|
+
function unshift(context) {
|
|
10337
|
+
return (id, value) => {
|
|
10338
|
+
if (!isValueOfType(value, id.type)) {
|
|
10339
|
+
throw new Error(
|
|
10340
|
+
`Cannot call 'array.unshift' with argument 'value'='${value}'. An argument of 'literal ${typeof value}' type was used but a '${id.type}' is expected.`
|
|
10341
|
+
);
|
|
10342
|
+
}
|
|
10343
|
+
id.array.unshift(context.precision(value));
|
|
10344
|
+
};
|
|
10345
|
+
}
|
|
10346
|
+
|
|
10347
|
+
function variance$1(context) {
|
|
10348
|
+
return (id, biased = true) => {
|
|
10349
|
+
let sum = 0;
|
|
10350
|
+
let count = 0;
|
|
10351
|
+
for (const item of id.array) {
|
|
10352
|
+
const val = Number(item);
|
|
10353
|
+
if (!isNaN(val) && val !== null && val !== void 0) {
|
|
10354
|
+
sum += val;
|
|
10355
|
+
count++;
|
|
10356
|
+
}
|
|
10357
|
+
}
|
|
10358
|
+
if (count === 0) return NaN;
|
|
10359
|
+
const mean = sum / count;
|
|
10360
|
+
let sumSqDiff = 0;
|
|
10361
|
+
for (const item of id.array) {
|
|
10362
|
+
const val = Number(item);
|
|
10363
|
+
if (!isNaN(val) && val !== null && val !== void 0) {
|
|
10364
|
+
sumSqDiff += (val - mean) * (val - mean);
|
|
10365
|
+
}
|
|
9921
10366
|
}
|
|
9922
|
-
|
|
10367
|
+
const divisor = biased ? count : count - 1;
|
|
10368
|
+
if (divisor <= 0) return NaN;
|
|
10369
|
+
return context.precision(sumSqDiff / divisor);
|
|
9923
10370
|
};
|
|
9924
10371
|
}
|
|
9925
10372
|
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
10373
|
+
var PineArrayType = /* @__PURE__ */ ((PineArrayType2) => {
|
|
10374
|
+
PineArrayType2["any"] = "";
|
|
10375
|
+
PineArrayType2["box"] = "box";
|
|
10376
|
+
PineArrayType2["bool"] = "bool";
|
|
10377
|
+
PineArrayType2["color"] = "color";
|
|
10378
|
+
PineArrayType2["float"] = "float";
|
|
10379
|
+
PineArrayType2["int"] = "int";
|
|
10380
|
+
PineArrayType2["label"] = "label";
|
|
10381
|
+
PineArrayType2["line"] = "line";
|
|
10382
|
+
PineArrayType2["linefill"] = "linefill";
|
|
10383
|
+
PineArrayType2["string"] = "string";
|
|
10384
|
+
PineArrayType2["table"] = "table";
|
|
10385
|
+
return PineArrayType2;
|
|
10386
|
+
})(PineArrayType || {});
|
|
10387
|
+
class PineArrayObject {
|
|
10388
|
+
constructor(array, type, context) {
|
|
10389
|
+
this.array = array;
|
|
10390
|
+
this.type = type;
|
|
10391
|
+
this.context = context;
|
|
10392
|
+
this._abs = abs$1(this.context);
|
|
10393
|
+
this._avg = avg$2(this.context);
|
|
10394
|
+
this._binary_search = binary_search(this.context);
|
|
10395
|
+
this._binary_search_leftmost = binary_search_leftmost(this.context);
|
|
10396
|
+
this._binary_search_rightmost = binary_search_rightmost(this.context);
|
|
10397
|
+
this._clear = clear$1(this.context);
|
|
10398
|
+
this._concat = concat$1(this.context);
|
|
10399
|
+
this._copy = copy$2(this.context);
|
|
10400
|
+
this._covariance = covariance(this.context);
|
|
10401
|
+
this._every = every(this.context);
|
|
10402
|
+
this._fill = fill$1(this.context);
|
|
10403
|
+
this._first = first(this.context);
|
|
10404
|
+
this._get = get$2(this.context);
|
|
10405
|
+
this._includes = includes(this.context);
|
|
10406
|
+
this._indexof = indexof(this.context);
|
|
10407
|
+
this._insert = insert(this.context);
|
|
10408
|
+
this._join = join(this.context);
|
|
10409
|
+
this._last = last(this.context);
|
|
10410
|
+
this._lastindexof = lastindexof(this.context);
|
|
10411
|
+
this._max = max$2(this.context);
|
|
10412
|
+
this._median = median$2(this.context);
|
|
10413
|
+
this._min = min$2(this.context);
|
|
10414
|
+
this._mode = mode$2(this.context);
|
|
10415
|
+
this._percentile_linear_interpolation = percentile_linear_interpolation$1(this.context);
|
|
10416
|
+
this._percentile_nearest_rank = percentile_nearest_rank$1(this.context);
|
|
10417
|
+
this._percentrank = percentrank$1(this.context);
|
|
10418
|
+
this._pop = pop(this.context);
|
|
10419
|
+
this._push = push(this.context);
|
|
10420
|
+
this._range = range$1(this.context);
|
|
10421
|
+
this._remove = remove$1(this.context);
|
|
10422
|
+
this._reverse = reverse$1(this.context);
|
|
10423
|
+
this._set = set$1(this.context);
|
|
10424
|
+
this._shift = shift(this.context);
|
|
10425
|
+
this._size = size$1(this.context);
|
|
10426
|
+
this._slice = slice(this.context);
|
|
10427
|
+
this._some = some(this.context);
|
|
10428
|
+
this._sort = sort$1(this.context);
|
|
10429
|
+
this._sort_indices = sort_indices(this.context);
|
|
10430
|
+
this._standardize = standardize(this.context);
|
|
10431
|
+
this._stdev = stdev$1(this.context);
|
|
10432
|
+
this._sum = sum$2(this.context);
|
|
10433
|
+
this._unshift = unshift(this.context);
|
|
10434
|
+
this._variance = variance$1(this.context);
|
|
10435
|
+
}
|
|
10436
|
+
_abs;
|
|
10437
|
+
_avg;
|
|
10438
|
+
_binary_search;
|
|
10439
|
+
_binary_search_leftmost;
|
|
10440
|
+
_binary_search_rightmost;
|
|
10441
|
+
_clear;
|
|
10442
|
+
_concat;
|
|
10443
|
+
_copy;
|
|
10444
|
+
_covariance;
|
|
10445
|
+
_every;
|
|
10446
|
+
_fill;
|
|
10447
|
+
_first;
|
|
10448
|
+
_get;
|
|
10449
|
+
_includes;
|
|
10450
|
+
_indexof;
|
|
10451
|
+
_insert;
|
|
10452
|
+
_join;
|
|
10453
|
+
_last;
|
|
10454
|
+
_lastindexof;
|
|
10455
|
+
_max;
|
|
10456
|
+
_median;
|
|
10457
|
+
_min;
|
|
10458
|
+
_mode;
|
|
10459
|
+
_percentile_linear_interpolation;
|
|
10460
|
+
_percentile_nearest_rank;
|
|
10461
|
+
_percentrank;
|
|
10462
|
+
_pop;
|
|
10463
|
+
_push;
|
|
10464
|
+
_range;
|
|
10465
|
+
_remove;
|
|
10466
|
+
_reverse;
|
|
10467
|
+
_set;
|
|
10468
|
+
_shift;
|
|
10469
|
+
_size;
|
|
10470
|
+
_slice;
|
|
10471
|
+
_some;
|
|
10472
|
+
_sort;
|
|
10473
|
+
_sort_indices;
|
|
10474
|
+
_standardize;
|
|
10475
|
+
_stdev;
|
|
10476
|
+
_sum;
|
|
10477
|
+
_unshift;
|
|
10478
|
+
_variance;
|
|
10479
|
+
toString() {
|
|
10480
|
+
return "[" + this.array.toString().replace(/,/g, ", ") + "]";
|
|
10481
|
+
}
|
|
10482
|
+
abs(...args) {
|
|
10483
|
+
return this._abs(this, ...args);
|
|
10484
|
+
}
|
|
10485
|
+
avg(...args) {
|
|
10486
|
+
return this._avg(this, ...args);
|
|
10487
|
+
}
|
|
10488
|
+
binary_search(...args) {
|
|
10489
|
+
return this._binary_search(this, ...args);
|
|
10490
|
+
}
|
|
10491
|
+
binary_search_leftmost(...args) {
|
|
10492
|
+
return this._binary_search_leftmost(this, ...args);
|
|
10493
|
+
}
|
|
10494
|
+
binary_search_rightmost(...args) {
|
|
10495
|
+
return this._binary_search_rightmost(this, ...args);
|
|
10496
|
+
}
|
|
10497
|
+
clear(...args) {
|
|
10498
|
+
return this._clear(this, ...args);
|
|
10499
|
+
}
|
|
10500
|
+
concat(...args) {
|
|
10501
|
+
return this._concat(this, ...args);
|
|
10502
|
+
}
|
|
10503
|
+
copy(...args) {
|
|
10504
|
+
return this._copy(this, ...args);
|
|
10505
|
+
}
|
|
10506
|
+
covariance(...args) {
|
|
10507
|
+
return this._covariance(this, ...args);
|
|
10508
|
+
}
|
|
10509
|
+
every(...args) {
|
|
10510
|
+
return this._every(this, ...args);
|
|
10511
|
+
}
|
|
10512
|
+
fill(...args) {
|
|
10513
|
+
return this._fill(this, ...args);
|
|
10514
|
+
}
|
|
10515
|
+
first(...args) {
|
|
10516
|
+
return this._first(this, ...args);
|
|
10517
|
+
}
|
|
10518
|
+
get(...args) {
|
|
10519
|
+
return this._get(this, ...args);
|
|
10520
|
+
}
|
|
10521
|
+
includes(...args) {
|
|
10522
|
+
return this._includes(this, ...args);
|
|
10523
|
+
}
|
|
10524
|
+
indexof(...args) {
|
|
10525
|
+
return this._indexof(this, ...args);
|
|
10526
|
+
}
|
|
10527
|
+
insert(...args) {
|
|
10528
|
+
return this._insert(this, ...args);
|
|
10529
|
+
}
|
|
10530
|
+
join(...args) {
|
|
10531
|
+
return this._join(this, ...args);
|
|
10532
|
+
}
|
|
10533
|
+
last(...args) {
|
|
10534
|
+
return this._last(this, ...args);
|
|
10535
|
+
}
|
|
10536
|
+
lastindexof(...args) {
|
|
10537
|
+
return this._lastindexof(this, ...args);
|
|
10538
|
+
}
|
|
10539
|
+
max(...args) {
|
|
10540
|
+
return this._max(this, ...args);
|
|
10541
|
+
}
|
|
10542
|
+
median(...args) {
|
|
10543
|
+
return this._median(this, ...args);
|
|
10544
|
+
}
|
|
10545
|
+
min(...args) {
|
|
10546
|
+
return this._min(this, ...args);
|
|
10547
|
+
}
|
|
10548
|
+
mode(...args) {
|
|
10549
|
+
return this._mode(this, ...args);
|
|
10550
|
+
}
|
|
10551
|
+
percentile_linear_interpolation(...args) {
|
|
10552
|
+
return this._percentile_linear_interpolation(this, ...args);
|
|
10553
|
+
}
|
|
10554
|
+
percentile_nearest_rank(...args) {
|
|
10555
|
+
return this._percentile_nearest_rank(this, ...args);
|
|
10556
|
+
}
|
|
10557
|
+
percentrank(...args) {
|
|
10558
|
+
return this._percentrank(this, ...args);
|
|
10559
|
+
}
|
|
10560
|
+
pop(...args) {
|
|
10561
|
+
return this._pop(this, ...args);
|
|
10562
|
+
}
|
|
10563
|
+
push(...args) {
|
|
10564
|
+
return this._push(this, ...args);
|
|
10565
|
+
}
|
|
10566
|
+
range(...args) {
|
|
10567
|
+
return this._range(this, ...args);
|
|
10568
|
+
}
|
|
10569
|
+
remove(...args) {
|
|
10570
|
+
return this._remove(this, ...args);
|
|
10571
|
+
}
|
|
10572
|
+
reverse(...args) {
|
|
10573
|
+
return this._reverse(this, ...args);
|
|
10574
|
+
}
|
|
10575
|
+
set(...args) {
|
|
10576
|
+
return this._set(this, ...args);
|
|
10577
|
+
}
|
|
10578
|
+
shift(...args) {
|
|
10579
|
+
return this._shift(this, ...args);
|
|
10580
|
+
}
|
|
10581
|
+
size(...args) {
|
|
10582
|
+
return this._size(this, ...args);
|
|
10583
|
+
}
|
|
10584
|
+
slice(...args) {
|
|
10585
|
+
return this._slice(this, ...args);
|
|
10586
|
+
}
|
|
10587
|
+
some(...args) {
|
|
10588
|
+
return this._some(this, ...args);
|
|
10589
|
+
}
|
|
10590
|
+
sort(...args) {
|
|
10591
|
+
return this._sort(this, ...args);
|
|
10592
|
+
}
|
|
10593
|
+
sort_indices(...args) {
|
|
10594
|
+
return this._sort_indices(this, ...args);
|
|
10595
|
+
}
|
|
10596
|
+
standardize(...args) {
|
|
10597
|
+
return this._standardize(this, ...args);
|
|
10598
|
+
}
|
|
10599
|
+
stdev(...args) {
|
|
10600
|
+
return this._stdev(this, ...args);
|
|
10601
|
+
}
|
|
10602
|
+
sum(...args) {
|
|
10603
|
+
return this._sum(this, ...args);
|
|
10604
|
+
}
|
|
10605
|
+
unshift(...args) {
|
|
10606
|
+
return this._unshift(this, ...args);
|
|
10607
|
+
}
|
|
10608
|
+
variance(...args) {
|
|
10609
|
+
return this._variance(this, ...args);
|
|
10610
|
+
}
|
|
10611
|
+
}
|
|
10612
|
+
|
|
10613
|
+
function from(context) {
|
|
10614
|
+
return (...values) => {
|
|
10615
|
+
return new PineArrayObject([...values], inferArrayType(values), context);
|
|
10616
|
+
};
|
|
10617
|
+
}
|
|
10618
|
+
|
|
10619
|
+
function new_fn$2(context) {
|
|
10620
|
+
return (size, initial_value) => {
|
|
10621
|
+
return new PineArrayObject(
|
|
10622
|
+
Array(size).fill(context.precision(initial_value || 0)),
|
|
10623
|
+
inferValueType(initial_value || 0),
|
|
10624
|
+
context
|
|
10625
|
+
);
|
|
10626
|
+
};
|
|
10627
|
+
}
|
|
10628
|
+
|
|
10629
|
+
function new_bool(context) {
|
|
10630
|
+
return (size, initial_value = false) => {
|
|
10631
|
+
return new PineArrayObject(Array(size).fill(initial_value), PineArrayType.bool, context);
|
|
10632
|
+
};
|
|
10633
|
+
}
|
|
10634
|
+
|
|
10635
|
+
function new_float(context) {
|
|
10636
|
+
return (size, initial_value = NaN) => {
|
|
10637
|
+
return new PineArrayObject(Array(size).fill(context.precision(initial_value)), PineArrayType.float, context);
|
|
10638
|
+
};
|
|
10639
|
+
}
|
|
10640
|
+
|
|
10641
|
+
function new_int(context) {
|
|
10642
|
+
return (size, initial_value = 0) => {
|
|
10643
|
+
return new PineArrayObject(Array(size).fill(context.precision(initial_value)), PineArrayType.int, context);
|
|
10644
|
+
};
|
|
10645
|
+
}
|
|
10646
|
+
|
|
10647
|
+
function new_string(context) {
|
|
10648
|
+
return (size, initial_value = "") => {
|
|
10649
|
+
return new PineArrayObject(Array(size).fill(initial_value), PineArrayType.string, context);
|
|
10650
|
+
};
|
|
10651
|
+
}
|
|
10652
|
+
|
|
10653
|
+
class Series {
|
|
10654
|
+
constructor(data, offset = 0) {
|
|
10655
|
+
this.data = data;
|
|
10656
|
+
this.offset = offset;
|
|
10657
|
+
}
|
|
10658
|
+
get(index) {
|
|
10659
|
+
const realIndex = this.data.length - 1 - (this.offset + index);
|
|
10660
|
+
if (realIndex < 0 || realIndex >= this.data.length) {
|
|
10661
|
+
return NaN;
|
|
10662
|
+
}
|
|
10663
|
+
return this.data[realIndex];
|
|
10664
|
+
}
|
|
10665
|
+
set(index, value) {
|
|
10666
|
+
const realIndex = this.data.length - 1 - (this.offset + index);
|
|
10667
|
+
if (realIndex >= 0 && realIndex < this.data.length) {
|
|
10668
|
+
this.data[realIndex] = value;
|
|
10669
|
+
}
|
|
10670
|
+
}
|
|
10671
|
+
get length() {
|
|
10672
|
+
return this.data.length;
|
|
10673
|
+
}
|
|
10674
|
+
toArray() {
|
|
10675
|
+
return this.data;
|
|
10676
|
+
}
|
|
10677
|
+
static from(source) {
|
|
10678
|
+
if (source instanceof Series) return source;
|
|
10679
|
+
if (Array.isArray(source)) return new Series(source);
|
|
10680
|
+
return new Series([source]);
|
|
10681
|
+
}
|
|
10682
|
+
}
|
|
10683
|
+
|
|
10684
|
+
function param$6(context) {
|
|
10685
|
+
return (source, index = 0) => {
|
|
10686
|
+
return Series.from(source).get(index);
|
|
10687
|
+
};
|
|
10688
|
+
}
|
|
10689
|
+
|
|
10690
|
+
class PineArray {
|
|
10691
|
+
constructor(context) {
|
|
10692
|
+
this.context = context;
|
|
10693
|
+
this.abs = (id, ...args) => id.abs(...args);
|
|
10694
|
+
this.avg = (id, ...args) => id.avg(...args);
|
|
10695
|
+
this.binary_search = (id, ...args) => id.binary_search(...args);
|
|
10696
|
+
this.binary_search_leftmost = (id, ...args) => id.binary_search_leftmost(...args);
|
|
10697
|
+
this.binary_search_rightmost = (id, ...args) => id.binary_search_rightmost(...args);
|
|
10698
|
+
this.clear = (id, ...args) => id.clear(...args);
|
|
10699
|
+
this.concat = (id, ...args) => id.concat(...args);
|
|
10700
|
+
this.copy = (id, ...args) => id.copy(...args);
|
|
10701
|
+
this.covariance = (id, ...args) => id.covariance(...args);
|
|
10702
|
+
this.every = (id, ...args) => id.every(...args);
|
|
10703
|
+
this.fill = (id, ...args) => id.fill(...args);
|
|
10704
|
+
this.first = (id, ...args) => id.first(...args);
|
|
10705
|
+
this.from = from(context);
|
|
10706
|
+
this.get = (id, ...args) => id.get(...args);
|
|
10707
|
+
this.includes = (id, ...args) => id.includes(...args);
|
|
10708
|
+
this.indexof = (id, ...args) => id.indexof(...args);
|
|
10709
|
+
this.insert = (id, ...args) => id.insert(...args);
|
|
10710
|
+
this.join = (id, ...args) => id.join(...args);
|
|
10711
|
+
this.last = (id, ...args) => id.last(...args);
|
|
10712
|
+
this.lastindexof = (id, ...args) => id.lastindexof(...args);
|
|
10713
|
+
this.max = (id, ...args) => id.max(...args);
|
|
10714
|
+
this.median = (id, ...args) => id.median(...args);
|
|
10715
|
+
this.min = (id, ...args) => id.min(...args);
|
|
10716
|
+
this.mode = (id, ...args) => id.mode(...args);
|
|
10717
|
+
this.new = new_fn$2(context);
|
|
10718
|
+
this.new_bool = new_bool(context);
|
|
10719
|
+
this.new_float = new_float(context);
|
|
10720
|
+
this.new_int = new_int(context);
|
|
10721
|
+
this.new_string = new_string(context);
|
|
10722
|
+
this.param = param$6();
|
|
10723
|
+
this.percentile_linear_interpolation = (id, ...args) => id.percentile_linear_interpolation(...args);
|
|
10724
|
+
this.percentile_nearest_rank = (id, ...args) => id.percentile_nearest_rank(...args);
|
|
10725
|
+
this.percentrank = (id, ...args) => id.percentrank(...args);
|
|
10726
|
+
this.pop = (id, ...args) => id.pop(...args);
|
|
10727
|
+
this.push = (id, ...args) => id.push(...args);
|
|
10728
|
+
this.range = (id, ...args) => id.range(...args);
|
|
10729
|
+
this.remove = (id, ...args) => id.remove(...args);
|
|
10730
|
+
this.reverse = (id, ...args) => id.reverse(...args);
|
|
10731
|
+
this.set = (id, ...args) => id.set(...args);
|
|
10732
|
+
this.shift = (id, ...args) => id.shift(...args);
|
|
10733
|
+
this.size = (id, ...args) => id.size(...args);
|
|
10734
|
+
this.slice = (id, ...args) => id.slice(...args);
|
|
10735
|
+
this.some = (id, ...args) => id.some(...args);
|
|
10736
|
+
this.sort = (id, ...args) => id.sort(...args);
|
|
10737
|
+
this.sort_indices = (id, ...args) => id.sort_indices(...args);
|
|
10738
|
+
this.standardize = (id, ...args) => id.standardize(...args);
|
|
10739
|
+
this.stdev = (id, ...args) => id.stdev(...args);
|
|
10740
|
+
this.sum = (id, ...args) => id.sum(...args);
|
|
10741
|
+
this.unshift = (id, ...args) => id.unshift(...args);
|
|
10742
|
+
this.variance = (id, ...args) => id.variance(...args);
|
|
10743
|
+
}
|
|
10744
|
+
}
|
|
10745
|
+
|
|
10746
|
+
function clear(context) {
|
|
10747
|
+
return (id) => {
|
|
10748
|
+
id.map.clear();
|
|
10749
|
+
};
|
|
10750
|
+
}
|
|
10751
|
+
|
|
10752
|
+
function contains(context) {
|
|
10753
|
+
return (id, key) => {
|
|
10754
|
+
return id.map.has(key);
|
|
10755
|
+
};
|
|
10756
|
+
}
|
|
10757
|
+
|
|
10758
|
+
function copy$1(context) {
|
|
10759
|
+
return (id) => {
|
|
10760
|
+
const newMap = new PineMapObject(id.keyType, id.valueType, context);
|
|
10761
|
+
newMap.map = new Map(id.map);
|
|
10762
|
+
return newMap;
|
|
10763
|
+
};
|
|
10764
|
+
}
|
|
10765
|
+
|
|
10766
|
+
function get$1(context) {
|
|
10767
|
+
return (id, key) => {
|
|
10768
|
+
const val = id.map.get(key);
|
|
10769
|
+
return val === void 0 ? NaN : val;
|
|
10770
|
+
};
|
|
10771
|
+
}
|
|
10772
|
+
|
|
10773
|
+
function keys(context) {
|
|
10774
|
+
return (id) => {
|
|
10775
|
+
const keysArray = Array.from(id.map.keys());
|
|
10776
|
+
return new PineArrayObject(keysArray, id.keyType, context);
|
|
10777
|
+
};
|
|
10778
|
+
}
|
|
10779
|
+
|
|
10780
|
+
function put(context) {
|
|
10781
|
+
return (id, key, value) => {
|
|
10782
|
+
const prev = id.map.get(key);
|
|
10783
|
+
id.map.set(key, value);
|
|
10784
|
+
return prev === void 0 ? NaN : prev;
|
|
10785
|
+
};
|
|
10786
|
+
}
|
|
10787
|
+
|
|
10788
|
+
function put_all(context) {
|
|
10789
|
+
return (id, id2) => {
|
|
10790
|
+
for (const [key, value] of id2.map) {
|
|
10791
|
+
id.map.set(key, value);
|
|
10792
|
+
}
|
|
10793
|
+
};
|
|
10794
|
+
}
|
|
10795
|
+
|
|
10796
|
+
function remove(context) {
|
|
10797
|
+
return (id, key) => {
|
|
10798
|
+
const val = id.map.get(key);
|
|
10799
|
+
const existed = id.map.delete(key);
|
|
10800
|
+
return existed ? val : NaN;
|
|
10801
|
+
};
|
|
10802
|
+
}
|
|
10803
|
+
|
|
10804
|
+
function size(context) {
|
|
10805
|
+
return (id) => {
|
|
10806
|
+
return id.map.size;
|
|
10807
|
+
};
|
|
10808
|
+
}
|
|
10809
|
+
|
|
10810
|
+
function values(context) {
|
|
10811
|
+
return (id) => {
|
|
10812
|
+
const valuesArray = Array.from(id.map.values());
|
|
10813
|
+
return new PineArrayObject(valuesArray, id.valueType, context);
|
|
10814
|
+
};
|
|
10815
|
+
}
|
|
10816
|
+
|
|
10817
|
+
class PineMapObject {
|
|
10818
|
+
constructor(keyType, valueType, context) {
|
|
10819
|
+
this.keyType = keyType;
|
|
10820
|
+
this.valueType = valueType;
|
|
10821
|
+
this.context = context;
|
|
10822
|
+
this.map = /* @__PURE__ */ new Map();
|
|
10823
|
+
this._clear = clear(this.context);
|
|
10824
|
+
this._contains = contains(this.context);
|
|
10825
|
+
this._copy = copy$1(this.context);
|
|
10826
|
+
this._get = get$1(this.context);
|
|
10827
|
+
this._keys = keys(this.context);
|
|
10828
|
+
this._put = put(this.context);
|
|
10829
|
+
this._put_all = put_all(this.context);
|
|
10830
|
+
this._remove = remove(this.context);
|
|
10831
|
+
this._size = size(this.context);
|
|
10832
|
+
this._values = values(this.context);
|
|
10833
|
+
}
|
|
10834
|
+
map;
|
|
10835
|
+
_clear;
|
|
10836
|
+
_contains;
|
|
10837
|
+
_copy;
|
|
10838
|
+
_get;
|
|
10839
|
+
_keys;
|
|
10840
|
+
_put;
|
|
10841
|
+
_put_all;
|
|
10842
|
+
_remove;
|
|
10843
|
+
_size;
|
|
10844
|
+
_values;
|
|
10845
|
+
toString() {
|
|
10846
|
+
return `PineMapObject<${this.keyType}, ${this.valueType}>(${this.map.size})`;
|
|
10847
|
+
}
|
|
10848
|
+
clear(...args) {
|
|
10849
|
+
return this._clear(this, ...args);
|
|
10850
|
+
}
|
|
10851
|
+
contains(...args) {
|
|
10852
|
+
return this._contains(this, ...args);
|
|
10853
|
+
}
|
|
10854
|
+
copy(...args) {
|
|
10855
|
+
return this._copy(this, ...args);
|
|
10856
|
+
}
|
|
10857
|
+
get(...args) {
|
|
10858
|
+
return this._get(this, ...args);
|
|
10859
|
+
}
|
|
10860
|
+
keys(...args) {
|
|
10861
|
+
return this._keys(this, ...args);
|
|
10862
|
+
}
|
|
10863
|
+
put(...args) {
|
|
10864
|
+
return this._put(this, ...args);
|
|
10865
|
+
}
|
|
10866
|
+
put_all(...args) {
|
|
10867
|
+
return this._put_all(this, ...args);
|
|
10868
|
+
}
|
|
10869
|
+
remove(...args) {
|
|
10870
|
+
return this._remove(this, ...args);
|
|
10871
|
+
}
|
|
10872
|
+
size(...args) {
|
|
10873
|
+
return this._size(this, ...args);
|
|
10874
|
+
}
|
|
10875
|
+
values(...args) {
|
|
10876
|
+
return this._values(this, ...args);
|
|
10877
|
+
}
|
|
10878
|
+
}
|
|
10879
|
+
|
|
10880
|
+
function new_fn$1(context) {
|
|
10881
|
+
return (keyType, valueType) => {
|
|
10882
|
+
return new PineMapObject(keyType, valueType, context);
|
|
10883
|
+
};
|
|
10884
|
+
}
|
|
10885
|
+
|
|
10886
|
+
function param$5(context) {
|
|
10887
|
+
return (source, index = 0) => {
|
|
10888
|
+
return Series.from(source).get(index);
|
|
10889
|
+
};
|
|
10890
|
+
}
|
|
10891
|
+
|
|
10892
|
+
class PineMap {
|
|
10893
|
+
constructor(context) {
|
|
10894
|
+
this.context = context;
|
|
10895
|
+
this.clear = (id, ...args) => id.clear(...args);
|
|
10896
|
+
this.contains = (id, ...args) => id.contains(...args);
|
|
10897
|
+
this.copy = (id, ...args) => id.copy(...args);
|
|
10898
|
+
this.get = (id, ...args) => id.get(...args);
|
|
10899
|
+
this.keys = (id, ...args) => id.keys(...args);
|
|
10900
|
+
this.new = new_fn$1(context);
|
|
10901
|
+
this.param = param$5();
|
|
10902
|
+
this.put = (id, ...args) => id.put(...args);
|
|
10903
|
+
this.put_all = (id, ...args) => id.put_all(...args);
|
|
10904
|
+
this.remove = (id, ...args) => id.remove(...args);
|
|
10905
|
+
this.size = (id, ...args) => id.size(...args);
|
|
10906
|
+
this.values = (id, ...args) => id.values(...args);
|
|
10907
|
+
}
|
|
10908
|
+
}
|
|
10909
|
+
|
|
10910
|
+
function add_col(context) {
|
|
10911
|
+
return (id, column_index, values) => {
|
|
10912
|
+
const rows = id.matrix.length;
|
|
10913
|
+
let colValues = [];
|
|
10914
|
+
if (values) {
|
|
10915
|
+
if (values instanceof PineArrayObject) {
|
|
10916
|
+
colValues = values.array;
|
|
10917
|
+
} else if (Array.isArray(values)) {
|
|
10918
|
+
colValues = values;
|
|
10919
|
+
} else {
|
|
10920
|
+
colValues = [values];
|
|
10921
|
+
}
|
|
10922
|
+
}
|
|
10923
|
+
if (rows === 0) {
|
|
10924
|
+
for (let i = 0; i < colValues.length; i++) {
|
|
10925
|
+
let val = colValues[i];
|
|
10926
|
+
if (val instanceof Series) val = val.get(0);
|
|
10927
|
+
id.matrix.push([val]);
|
|
10928
|
+
}
|
|
10929
|
+
return;
|
|
10930
|
+
}
|
|
10931
|
+
const cols = id.matrix[0].length;
|
|
10932
|
+
const index = column_index !== void 0 ? column_index : cols;
|
|
10933
|
+
for (let i = 0; i < rows; i++) {
|
|
10934
|
+
let val = i < colValues.length ? colValues[i] : NaN;
|
|
10935
|
+
if (val instanceof Series) val = val.get(0);
|
|
10936
|
+
id.matrix[i].splice(index, 0, val);
|
|
10937
|
+
}
|
|
10938
|
+
};
|
|
10939
|
+
}
|
|
10940
|
+
|
|
10941
|
+
function add_row(context) {
|
|
10942
|
+
return (id, row_index, values) => {
|
|
10943
|
+
const rows = id.matrix.length;
|
|
10944
|
+
let rowValues = [];
|
|
10945
|
+
if (values) {
|
|
10946
|
+
if (values instanceof PineArrayObject) {
|
|
10947
|
+
rowValues = values.array;
|
|
10948
|
+
} else if (Array.isArray(values)) {
|
|
10949
|
+
rowValues = values;
|
|
10950
|
+
} else {
|
|
10951
|
+
if (values instanceof Series) {
|
|
10952
|
+
const val = values.get(0);
|
|
10953
|
+
if (Array.isArray(val)) {
|
|
10954
|
+
rowValues = val;
|
|
10955
|
+
} else {
|
|
10956
|
+
rowValues = [val];
|
|
10957
|
+
}
|
|
10958
|
+
} else {
|
|
10959
|
+
rowValues = [values];
|
|
10960
|
+
}
|
|
10961
|
+
}
|
|
10962
|
+
}
|
|
10963
|
+
const cols = rows > 0 ? id.matrix[0].length : rowValues.length;
|
|
10964
|
+
const index = row_index !== void 0 ? row_index : rows;
|
|
10965
|
+
const newRow = [];
|
|
10966
|
+
for (let i = 0; i < cols; i++) {
|
|
10967
|
+
if (i < rowValues.length) {
|
|
10968
|
+
let val = rowValues[i];
|
|
10969
|
+
if (val instanceof Series) {
|
|
10970
|
+
val = val.get(0);
|
|
10971
|
+
}
|
|
10972
|
+
newRow.push(val);
|
|
10973
|
+
} else {
|
|
10974
|
+
newRow.push(NaN);
|
|
10975
|
+
}
|
|
10976
|
+
}
|
|
10977
|
+
id.matrix.splice(index, 0, newRow);
|
|
10978
|
+
};
|
|
10979
|
+
}
|
|
10980
|
+
|
|
10981
|
+
function avg$1(context) {
|
|
10982
|
+
return (id) => {
|
|
10983
|
+
const rows = id.matrix.length;
|
|
10984
|
+
if (rows === 0) return NaN;
|
|
10985
|
+
const cols = id.matrix[0].length;
|
|
10986
|
+
if (cols === 0) return NaN;
|
|
10987
|
+
let sum = 0;
|
|
10988
|
+
let count = 0;
|
|
10989
|
+
for (let i = 0; i < rows; i++) {
|
|
10990
|
+
for (let j = 0; j < cols; j++) {
|
|
10991
|
+
const val = id.matrix[i][j];
|
|
10992
|
+
if (!isNaN(val)) {
|
|
10993
|
+
sum += val;
|
|
10994
|
+
count++;
|
|
10995
|
+
}
|
|
10996
|
+
}
|
|
10997
|
+
}
|
|
10998
|
+
if (count === 0) return NaN;
|
|
10999
|
+
return sum / count;
|
|
11000
|
+
};
|
|
11001
|
+
}
|
|
11002
|
+
|
|
11003
|
+
function col(context) {
|
|
11004
|
+
return (id, column) => {
|
|
11005
|
+
const rows = id.matrix.length;
|
|
11006
|
+
const result = [];
|
|
11007
|
+
for (let i = 0; i < rows; i++) {
|
|
11008
|
+
result.push(id.matrix[i][column]);
|
|
11009
|
+
}
|
|
11010
|
+
return new PineArrayObject(result, id.type, context);
|
|
11011
|
+
};
|
|
11012
|
+
}
|
|
11013
|
+
|
|
11014
|
+
function columns(context) {
|
|
11015
|
+
return (id) => {
|
|
11016
|
+
if (id.matrix.length === 0) return 0;
|
|
11017
|
+
return id.matrix[0].length;
|
|
11018
|
+
};
|
|
11019
|
+
}
|
|
11020
|
+
|
|
11021
|
+
function concat(context) {
|
|
11022
|
+
return (id, id2) => {
|
|
11023
|
+
const rows1 = id.matrix.length;
|
|
11024
|
+
const rows2 = id2.matrix.length;
|
|
11025
|
+
if (rows1 === 0) {
|
|
11026
|
+
for (let i = 0; i < rows2; i++) {
|
|
11027
|
+
id.matrix.push([...id2.matrix[i]]);
|
|
11028
|
+
}
|
|
11029
|
+
return;
|
|
11030
|
+
}
|
|
11031
|
+
const cols1 = id.matrix[0].length;
|
|
11032
|
+
const cols2 = rows2 > 0 ? id2.matrix[0].length : 0;
|
|
11033
|
+
if (cols1 !== cols2 && rows2 > 0) {
|
|
11034
|
+
console.error(`matrix.concat: Column count mismatch ${cols1} vs ${cols2}`);
|
|
11035
|
+
return;
|
|
11036
|
+
}
|
|
11037
|
+
for (let i = 0; i < rows2; i++) {
|
|
11038
|
+
id.matrix.push([...id2.matrix[i]]);
|
|
11039
|
+
}
|
|
11040
|
+
};
|
|
11041
|
+
}
|
|
11042
|
+
|
|
11043
|
+
function copy(context) {
|
|
11044
|
+
return (id) => {
|
|
11045
|
+
const rows = id.matrix.length;
|
|
11046
|
+
const cols = rows > 0 ? id.matrix[0].length : 0;
|
|
11047
|
+
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11048
|
+
newMatrix.matrix = id.matrix.map((row) => [...row]);
|
|
11049
|
+
return newMatrix;
|
|
11050
|
+
};
|
|
11051
|
+
}
|
|
11052
|
+
|
|
11053
|
+
function determinant(matrix) {
|
|
11054
|
+
const n = matrix.length;
|
|
11055
|
+
if (n === 0) return 0;
|
|
11056
|
+
if (n === 1) return matrix[0][0];
|
|
11057
|
+
if (n === 2) return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
|
|
11058
|
+
const mat = matrix.map((row) => [...row]);
|
|
11059
|
+
let det2 = 1;
|
|
11060
|
+
for (let i = 0; i < n; i++) {
|
|
11061
|
+
let pivot = i;
|
|
11062
|
+
while (pivot < n && mat[pivot][i] === 0) pivot++;
|
|
11063
|
+
if (pivot === n) return 0;
|
|
11064
|
+
if (pivot !== i) {
|
|
11065
|
+
[mat[i], mat[pivot]] = [mat[pivot], mat[i]];
|
|
11066
|
+
det2 *= -1;
|
|
11067
|
+
}
|
|
11068
|
+
det2 *= mat[i][i];
|
|
11069
|
+
for (let j = i + 1; j < n; j++) {
|
|
11070
|
+
const factor = mat[j][i] / mat[i][i];
|
|
11071
|
+
for (let k = i; k < n; k++) {
|
|
11072
|
+
mat[j][k] -= factor * mat[i][k];
|
|
11073
|
+
}
|
|
11074
|
+
}
|
|
11075
|
+
}
|
|
11076
|
+
return det2;
|
|
11077
|
+
}
|
|
11078
|
+
function det(context) {
|
|
11079
|
+
return (id) => {
|
|
11080
|
+
const rows = id.matrix.length;
|
|
11081
|
+
const cols = rows > 0 ? id.matrix[0].length : 0;
|
|
11082
|
+
if (rows !== cols) return NaN;
|
|
11083
|
+
return determinant(id.matrix);
|
|
11084
|
+
};
|
|
11085
|
+
}
|
|
11086
|
+
|
|
11087
|
+
function diff(context) {
|
|
11088
|
+
return (id, id2) => {
|
|
11089
|
+
const rows = id.matrix.length;
|
|
11090
|
+
if (rows === 0) return new PineMatrixObject(id.type, 0, 0, NaN, context);
|
|
11091
|
+
const cols = id.matrix[0].length;
|
|
11092
|
+
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11093
|
+
if (id2 instanceof PineMatrixObject) {
|
|
11094
|
+
for (let i = 0; i < rows; i++) {
|
|
11095
|
+
for (let j = 0; j < cols; j++) {
|
|
11096
|
+
const v1 = id.matrix[i][j];
|
|
11097
|
+
const v2 = id2.matrix[i] && id2.matrix[i][j] !== void 0 ? id2.matrix[i][j] : NaN;
|
|
11098
|
+
newMatrix.matrix[i][j] = v1 - v2;
|
|
11099
|
+
}
|
|
11100
|
+
}
|
|
11101
|
+
} else {
|
|
11102
|
+
const scalar = id2;
|
|
11103
|
+
for (let i = 0; i < rows; i++) {
|
|
11104
|
+
for (let j = 0; j < cols; j++) {
|
|
11105
|
+
newMatrix.matrix[i][j] = id.matrix[i][j] - scalar;
|
|
11106
|
+
}
|
|
11107
|
+
}
|
|
11108
|
+
}
|
|
11109
|
+
return newMatrix;
|
|
11110
|
+
};
|
|
11111
|
+
}
|
|
11112
|
+
|
|
11113
|
+
function calculateEigenvalues(matrix) {
|
|
11114
|
+
const n = matrix.length;
|
|
11115
|
+
if (n !== 2) return Array(n).fill(NaN);
|
|
11116
|
+
const a = matrix[0][0];
|
|
11117
|
+
const b = matrix[0][1];
|
|
11118
|
+
const c = matrix[1][0];
|
|
11119
|
+
const d = matrix[1][1];
|
|
11120
|
+
const trace = a + d;
|
|
11121
|
+
const det = a * d - b * c;
|
|
11122
|
+
const delta = trace * trace - 4 * det;
|
|
11123
|
+
if (delta < 0) return [NaN, NaN];
|
|
11124
|
+
const l1 = (trace + Math.sqrt(delta)) / 2;
|
|
11125
|
+
const l2 = (trace - Math.sqrt(delta)) / 2;
|
|
11126
|
+
return [l1, l2];
|
|
11127
|
+
}
|
|
11128
|
+
function eigenvalues(context) {
|
|
11129
|
+
return (id) => {
|
|
11130
|
+
const rows = id.matrix.length;
|
|
11131
|
+
const cols = rows > 0 ? id.matrix[0].length : 0;
|
|
11132
|
+
if (rows !== cols) return new PineArrayObject([], id.type, context);
|
|
11133
|
+
const vals = calculateEigenvalues(id.matrix);
|
|
11134
|
+
return new PineArrayObject(vals, id.type, context);
|
|
11135
|
+
};
|
|
11136
|
+
}
|
|
11137
|
+
|
|
11138
|
+
function eigenvectors(context) {
|
|
11139
|
+
return (id) => {
|
|
11140
|
+
const rows = id.matrix.length;
|
|
11141
|
+
const cols = rows > 0 ? id.matrix[0].length : 0;
|
|
11142
|
+
if (rows !== cols) return new PineMatrixObject(id.type, 0, 0, NaN, context);
|
|
11143
|
+
const newMatrix = new PineMatrixObject(id.type, rows, cols, 0, context);
|
|
11144
|
+
for (let i = 0; i < rows; i++) newMatrix.matrix[i][i] = 1;
|
|
11145
|
+
return newMatrix;
|
|
11146
|
+
};
|
|
11147
|
+
}
|
|
11148
|
+
|
|
11149
|
+
function elements_count(context) {
|
|
11150
|
+
return (id) => {
|
|
11151
|
+
const rows = id.matrix.length;
|
|
11152
|
+
if (rows === 0) return 0;
|
|
11153
|
+
return rows * id.matrix[0].length;
|
|
11154
|
+
};
|
|
11155
|
+
}
|
|
11156
|
+
|
|
11157
|
+
function fill(context) {
|
|
11158
|
+
return (id, value, from_row, to_row, from_col, to_col) => {
|
|
11159
|
+
const rows = id.matrix.length;
|
|
11160
|
+
if (rows === 0) return;
|
|
11161
|
+
const cols = id.matrix[0].length;
|
|
11162
|
+
const r1 = from_row !== void 0 ? from_row : 0;
|
|
11163
|
+
const r2 = to_row !== void 0 ? to_row : rows;
|
|
11164
|
+
const c1 = from_col !== void 0 ? from_col : 0;
|
|
11165
|
+
const c2 = to_col !== void 0 ? to_col : cols;
|
|
11166
|
+
for (let i = r1; i < r2; i++) {
|
|
11167
|
+
if (i >= rows) break;
|
|
11168
|
+
for (let j = c1; j < c2; j++) {
|
|
11169
|
+
if (j >= cols) break;
|
|
11170
|
+
id.matrix[i][j] = value;
|
|
11171
|
+
}
|
|
11172
|
+
}
|
|
11173
|
+
};
|
|
11174
|
+
}
|
|
11175
|
+
|
|
11176
|
+
function get(context) {
|
|
11177
|
+
return (id, row, col) => {
|
|
11178
|
+
if (!id.matrix[row]) return NaN;
|
|
11179
|
+
const val = id.matrix[row][col];
|
|
11180
|
+
return val === void 0 ? NaN : val;
|
|
11181
|
+
};
|
|
11182
|
+
}
|
|
11183
|
+
|
|
11184
|
+
function inverse(matrix) {
|
|
11185
|
+
const n = matrix.length;
|
|
11186
|
+
if (n !== 2) return matrix.map((r) => r.map(() => NaN));
|
|
11187
|
+
const det = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
|
|
11188
|
+
if (det === 0)
|
|
11189
|
+
return [
|
|
11190
|
+
[NaN, NaN],
|
|
11191
|
+
[NaN, NaN]
|
|
11192
|
+
];
|
|
11193
|
+
return [
|
|
11194
|
+
[matrix[1][1] / det, -matrix[0][1] / det],
|
|
11195
|
+
[-matrix[1][0] / det, matrix[0][0] / det]
|
|
11196
|
+
];
|
|
11197
|
+
}
|
|
11198
|
+
function inv(context) {
|
|
11199
|
+
return (id) => {
|
|
11200
|
+
const rows = id.matrix.length;
|
|
11201
|
+
const cols = rows > 0 ? id.matrix[0].length : 0;
|
|
11202
|
+
if (rows !== cols) return new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11203
|
+
const invMat = inverse(id.matrix);
|
|
11204
|
+
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11205
|
+
newMatrix.matrix = invMat;
|
|
11206
|
+
return newMatrix;
|
|
11207
|
+
};
|
|
11208
|
+
}
|
|
11209
|
+
|
|
11210
|
+
function is_antidiagonal(context) {
|
|
11211
|
+
return (id) => {
|
|
11212
|
+
const rows = id.matrix.length;
|
|
11213
|
+
if (rows === 0) return false;
|
|
11214
|
+
const cols = id.matrix[0].length;
|
|
11215
|
+
if (rows !== cols) return false;
|
|
11216
|
+
for (let i = 0; i < rows; i++) {
|
|
11217
|
+
for (let j = 0; j < cols; j++) {
|
|
11218
|
+
if (i + j !== rows - 1) {
|
|
11219
|
+
if (id.matrix[i][j] !== 0) return false;
|
|
11220
|
+
}
|
|
11221
|
+
}
|
|
11222
|
+
}
|
|
11223
|
+
return true;
|
|
11224
|
+
};
|
|
11225
|
+
}
|
|
11226
|
+
|
|
11227
|
+
function is_antisymmetric(context) {
|
|
11228
|
+
return (id) => {
|
|
11229
|
+
const rows = id.matrix.length;
|
|
11230
|
+
if (rows === 0) return false;
|
|
11231
|
+
const cols = id.matrix[0].length;
|
|
11232
|
+
if (rows !== cols) return false;
|
|
11233
|
+
for (let i = 0; i < rows; i++) {
|
|
11234
|
+
for (let j = 0; j < cols; j++) {
|
|
11235
|
+
if (id.matrix[j][i] !== -id.matrix[i][j]) return false;
|
|
11236
|
+
}
|
|
11237
|
+
}
|
|
11238
|
+
return true;
|
|
11239
|
+
};
|
|
11240
|
+
}
|
|
11241
|
+
|
|
11242
|
+
function is_binary(context) {
|
|
11243
|
+
return (id) => {
|
|
11244
|
+
const rows = id.matrix.length;
|
|
11245
|
+
if (rows === 0) return false;
|
|
11246
|
+
const cols = id.matrix[0].length;
|
|
11247
|
+
for (let i = 0; i < rows; i++) {
|
|
11248
|
+
for (let j = 0; j < cols; j++) {
|
|
11249
|
+
const val = id.matrix[i][j];
|
|
11250
|
+
if (val !== 0 && val !== 1) return false;
|
|
11251
|
+
}
|
|
11252
|
+
}
|
|
11253
|
+
return true;
|
|
11254
|
+
};
|
|
11255
|
+
}
|
|
11256
|
+
|
|
11257
|
+
function is_diagonal(context) {
|
|
11258
|
+
return (id) => {
|
|
11259
|
+
const rows = id.matrix.length;
|
|
11260
|
+
if (rows === 0) return false;
|
|
11261
|
+
const cols = id.matrix[0].length;
|
|
11262
|
+
if (rows !== cols) return false;
|
|
11263
|
+
for (let i = 0; i < rows; i++) {
|
|
11264
|
+
for (let j = 0; j < cols; j++) {
|
|
11265
|
+
if (i !== j) {
|
|
11266
|
+
if (id.matrix[i][j] !== 0) return false;
|
|
11267
|
+
}
|
|
11268
|
+
}
|
|
11269
|
+
}
|
|
11270
|
+
return true;
|
|
11271
|
+
};
|
|
11272
|
+
}
|
|
11273
|
+
|
|
11274
|
+
function is_identity(context) {
|
|
11275
|
+
return (id) => {
|
|
11276
|
+
const rows = id.matrix.length;
|
|
11277
|
+
if (rows === 0) return false;
|
|
11278
|
+
const cols = id.matrix[0].length;
|
|
11279
|
+
if (rows !== cols) return false;
|
|
11280
|
+
for (let i = 0; i < rows; i++) {
|
|
11281
|
+
for (let j = 0; j < cols; j++) {
|
|
11282
|
+
if (i === j) {
|
|
11283
|
+
if (id.matrix[i][j] !== 1) return false;
|
|
11284
|
+
} else {
|
|
11285
|
+
if (id.matrix[i][j] !== 0) return false;
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
11288
|
+
}
|
|
11289
|
+
return true;
|
|
11290
|
+
};
|
|
11291
|
+
}
|
|
11292
|
+
|
|
11293
|
+
function is_square(context) {
|
|
11294
|
+
return (id) => {
|
|
11295
|
+
const rows = id.matrix.length;
|
|
11296
|
+
if (rows === 0) return false;
|
|
11297
|
+
const cols = id.matrix[0].length;
|
|
11298
|
+
return rows === cols;
|
|
11299
|
+
};
|
|
11300
|
+
}
|
|
11301
|
+
|
|
11302
|
+
function is_stochastic(context) {
|
|
11303
|
+
return (id) => {
|
|
11304
|
+
const rows = id.matrix.length;
|
|
11305
|
+
if (rows === 0) return false;
|
|
11306
|
+
const cols = id.matrix[0].length;
|
|
11307
|
+
for (let i = 0; i < rows; i++) {
|
|
11308
|
+
let sum = 0;
|
|
11309
|
+
for (let j = 0; j < cols; j++) {
|
|
11310
|
+
const val = id.matrix[i][j];
|
|
11311
|
+
if (val < 0) return false;
|
|
11312
|
+
sum += val;
|
|
11313
|
+
}
|
|
11314
|
+
if (Math.abs(sum - 1) > 1e-10) return false;
|
|
11315
|
+
}
|
|
11316
|
+
return true;
|
|
11317
|
+
};
|
|
11318
|
+
}
|
|
11319
|
+
|
|
11320
|
+
function is_symmetric(context) {
|
|
11321
|
+
return (id) => {
|
|
11322
|
+
const rows = id.matrix.length;
|
|
11323
|
+
if (rows === 0) return false;
|
|
11324
|
+
const cols = id.matrix[0].length;
|
|
11325
|
+
if (rows !== cols) return false;
|
|
11326
|
+
for (let i = 0; i < rows; i++) {
|
|
11327
|
+
for (let j = 0; j < i; j++) {
|
|
11328
|
+
if (id.matrix[i][j] !== id.matrix[j][i]) return false;
|
|
11329
|
+
}
|
|
11330
|
+
}
|
|
11331
|
+
return true;
|
|
11332
|
+
};
|
|
11333
|
+
}
|
|
11334
|
+
|
|
11335
|
+
function is_triangular(context) {
|
|
11336
|
+
return (id) => {
|
|
11337
|
+
const rows = id.matrix.length;
|
|
11338
|
+
if (rows === 0) return false;
|
|
11339
|
+
const cols = id.matrix[0].length;
|
|
11340
|
+
if (rows !== cols) return false;
|
|
11341
|
+
let isUpper = true;
|
|
11342
|
+
let isLower = true;
|
|
11343
|
+
for (let i = 0; i < rows; i++) {
|
|
11344
|
+
for (let j = 0; j < cols; j++) {
|
|
11345
|
+
if (i > j && id.matrix[i][j] !== 0) isUpper = false;
|
|
11346
|
+
if (i < j && id.matrix[i][j] !== 0) isLower = false;
|
|
11347
|
+
}
|
|
11348
|
+
}
|
|
11349
|
+
return isUpper || isLower;
|
|
11350
|
+
};
|
|
11351
|
+
}
|
|
11352
|
+
|
|
11353
|
+
function is_zero(context) {
|
|
11354
|
+
return (id) => {
|
|
11355
|
+
const rows = id.matrix.length;
|
|
11356
|
+
if (rows === 0) return true;
|
|
11357
|
+
const cols = id.matrix[0].length;
|
|
11358
|
+
for (let i = 0; i < rows; i++) {
|
|
11359
|
+
for (let j = 0; j < cols; j++) {
|
|
11360
|
+
if (id.matrix[i][j] !== 0) return false;
|
|
11361
|
+
}
|
|
11362
|
+
}
|
|
11363
|
+
return true;
|
|
11364
|
+
};
|
|
11365
|
+
}
|
|
11366
|
+
|
|
11367
|
+
function kron(context) {
|
|
11368
|
+
return (id, id2) => {
|
|
11369
|
+
const r1 = id.matrix.length;
|
|
11370
|
+
const c1 = r1 > 0 ? id.matrix[0].length : 0;
|
|
11371
|
+
const r2 = id2.matrix.length;
|
|
11372
|
+
const c2 = r2 > 0 ? id2.matrix[0].length : 0;
|
|
11373
|
+
const rows = r1 * r2;
|
|
11374
|
+
const cols = c1 * c2;
|
|
11375
|
+
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11376
|
+
for (let i = 0; i < r1; i++) {
|
|
11377
|
+
for (let j = 0; j < c1; j++) {
|
|
11378
|
+
const val1 = id.matrix[i][j];
|
|
11379
|
+
for (let k = 0; k < r2; k++) {
|
|
11380
|
+
for (let l = 0; l < c2; l++) {
|
|
11381
|
+
const val2 = id2.matrix[k][l];
|
|
11382
|
+
newMatrix.matrix[i * r2 + k][j * c2 + l] = val1 * val2;
|
|
11383
|
+
}
|
|
11384
|
+
}
|
|
11385
|
+
}
|
|
11386
|
+
}
|
|
11387
|
+
return newMatrix;
|
|
11388
|
+
};
|
|
11389
|
+
}
|
|
11390
|
+
|
|
11391
|
+
function max$1(context) {
|
|
11392
|
+
return (id) => {
|
|
11393
|
+
const rows = id.matrix.length;
|
|
11394
|
+
if (rows === 0) return NaN;
|
|
11395
|
+
const cols = id.matrix[0].length;
|
|
11396
|
+
let maxVal = -Infinity;
|
|
11397
|
+
let found = false;
|
|
11398
|
+
for (let i = 0; i < rows; i++) {
|
|
11399
|
+
for (let j = 0; j < cols; j++) {
|
|
11400
|
+
const val = id.matrix[i][j];
|
|
11401
|
+
if (!isNaN(val)) {
|
|
11402
|
+
if (val > maxVal) maxVal = val;
|
|
11403
|
+
found = true;
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
}
|
|
11407
|
+
return found ? maxVal : NaN;
|
|
11408
|
+
};
|
|
11409
|
+
}
|
|
11410
|
+
|
|
11411
|
+
function median$1(context) {
|
|
11412
|
+
return (id) => {
|
|
11413
|
+
const rows = id.matrix.length;
|
|
11414
|
+
if (rows === 0) return NaN;
|
|
11415
|
+
const cols = id.matrix[0].length;
|
|
11416
|
+
const values = [];
|
|
11417
|
+
for (let i = 0; i < rows; i++) {
|
|
11418
|
+
for (let j = 0; j < cols; j++) {
|
|
11419
|
+
const val = id.matrix[i][j];
|
|
11420
|
+
if (!isNaN(val)) {
|
|
11421
|
+
values.push(val);
|
|
11422
|
+
}
|
|
11423
|
+
}
|
|
11424
|
+
}
|
|
11425
|
+
if (values.length === 0) return NaN;
|
|
11426
|
+
values.sort((a, b) => a - b);
|
|
11427
|
+
const mid = Math.floor(values.length / 2);
|
|
11428
|
+
if (values.length % 2 !== 0) {
|
|
11429
|
+
return values[mid];
|
|
11430
|
+
} else {
|
|
11431
|
+
return (values[mid - 1] + values[mid]) / 2;
|
|
11432
|
+
}
|
|
11433
|
+
};
|
|
11434
|
+
}
|
|
11435
|
+
|
|
11436
|
+
function min$1(context) {
|
|
11437
|
+
return (id) => {
|
|
11438
|
+
const rows = id.matrix.length;
|
|
11439
|
+
if (rows === 0) return NaN;
|
|
11440
|
+
const cols = id.matrix[0].length;
|
|
11441
|
+
let minVal = Infinity;
|
|
11442
|
+
let found = false;
|
|
11443
|
+
for (let i = 0; i < rows; i++) {
|
|
11444
|
+
for (let j = 0; j < cols; j++) {
|
|
11445
|
+
const val = id.matrix[i][j];
|
|
11446
|
+
if (!isNaN(val)) {
|
|
11447
|
+
if (val < minVal) minVal = val;
|
|
11448
|
+
found = true;
|
|
11449
|
+
}
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
return found ? minVal : NaN;
|
|
11453
|
+
};
|
|
11454
|
+
}
|
|
11455
|
+
|
|
11456
|
+
function mode$1(context) {
|
|
11457
|
+
return (id) => {
|
|
11458
|
+
const rows = id.matrix.length;
|
|
11459
|
+
if (rows === 0) return NaN;
|
|
11460
|
+
const cols = id.matrix[0].length;
|
|
11461
|
+
const counts = /* @__PURE__ */ new Map();
|
|
11462
|
+
let maxCount = 0;
|
|
11463
|
+
let modeVal = NaN;
|
|
11464
|
+
for (let i = 0; i < rows; i++) {
|
|
11465
|
+
for (let j = 0; j < cols; j++) {
|
|
11466
|
+
const val = id.matrix[i][j];
|
|
11467
|
+
if (!isNaN(val)) {
|
|
11468
|
+
const count = (counts.get(val) || 0) + 1;
|
|
11469
|
+
counts.set(val, count);
|
|
11470
|
+
if (count > maxCount) {
|
|
11471
|
+
maxCount = count;
|
|
11472
|
+
modeVal = val;
|
|
11473
|
+
} else if (count === maxCount) {
|
|
11474
|
+
if (val < modeVal) modeVal = val;
|
|
11475
|
+
}
|
|
11476
|
+
}
|
|
11477
|
+
}
|
|
11478
|
+
}
|
|
11479
|
+
return modeVal;
|
|
11480
|
+
};
|
|
11481
|
+
}
|
|
11482
|
+
|
|
11483
|
+
function mult(context) {
|
|
11484
|
+
return (id, id2) => {
|
|
11485
|
+
const rows1 = id.matrix.length;
|
|
11486
|
+
const cols1 = rows1 > 0 ? id.matrix[0].length : 0;
|
|
11487
|
+
if (id2 instanceof PineMatrixObject) {
|
|
11488
|
+
const rows2 = id2.matrix.length;
|
|
11489
|
+
const cols2 = rows2 > 0 ? id2.matrix[0].length : 0;
|
|
11490
|
+
if (cols1 !== rows2) {
|
|
11491
|
+
return new PineMatrixObject(id.type, 0, 0, NaN, context);
|
|
11492
|
+
}
|
|
11493
|
+
const newMatrix = new PineMatrixObject(id.type, rows1, cols2, 0, context);
|
|
11494
|
+
for (let i = 0; i < rows1; i++) {
|
|
11495
|
+
for (let j = 0; j < cols2; j++) {
|
|
11496
|
+
let sum = 0;
|
|
11497
|
+
for (let k = 0; k < cols1; k++) {
|
|
11498
|
+
sum += id.matrix[i][k] * id2.matrix[k][j];
|
|
11499
|
+
}
|
|
11500
|
+
newMatrix.matrix[i][j] = sum;
|
|
11501
|
+
}
|
|
11502
|
+
}
|
|
11503
|
+
return newMatrix;
|
|
11504
|
+
} else if (id2 instanceof PineArrayObject || Array.isArray(id2.array || id2)) {
|
|
11505
|
+
const vec = id2.array || id2;
|
|
11506
|
+
if (cols1 !== vec.length) {
|
|
11507
|
+
return new PineMatrixObject(id.type, 0, 0, NaN, context);
|
|
11508
|
+
}
|
|
11509
|
+
const newMatrix = new PineMatrixObject(id.type, rows1, 1, 0, context);
|
|
11510
|
+
for (let i = 0; i < rows1; i++) {
|
|
11511
|
+
let sum = 0;
|
|
11512
|
+
for (let j = 0; j < cols1; j++) {
|
|
11513
|
+
sum += id.matrix[i][j] * vec[j];
|
|
11514
|
+
}
|
|
11515
|
+
newMatrix.matrix[i][0] = sum;
|
|
11516
|
+
}
|
|
11517
|
+
return newMatrix;
|
|
11518
|
+
} else {
|
|
11519
|
+
const scalar = id2;
|
|
11520
|
+
const newMatrix = new PineMatrixObject(id.type, rows1, cols1, NaN, context);
|
|
11521
|
+
for (let i = 0; i < rows1; i++) {
|
|
11522
|
+
for (let j = 0; j < cols1; j++) {
|
|
11523
|
+
newMatrix.matrix[i][j] = id.matrix[i][j] * scalar;
|
|
11524
|
+
}
|
|
11525
|
+
}
|
|
11526
|
+
return newMatrix;
|
|
11527
|
+
}
|
|
11528
|
+
};
|
|
11529
|
+
}
|
|
11530
|
+
|
|
11531
|
+
function pinv(context) {
|
|
11532
|
+
return (id) => {
|
|
11533
|
+
const rows = id.matrix.length;
|
|
11534
|
+
const cols = rows > 0 ? id.matrix[0].length : 0;
|
|
11535
|
+
if (rows === cols) {
|
|
11536
|
+
return new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11537
|
+
}
|
|
11538
|
+
return new PineMatrixObject(id.type, cols, rows, NaN, context);
|
|
11539
|
+
};
|
|
11540
|
+
}
|
|
11541
|
+
|
|
11542
|
+
function pow$1(context) {
|
|
11543
|
+
return (id, power) => {
|
|
11544
|
+
const rows = id.matrix.length;
|
|
11545
|
+
const cols = rows > 0 ? id.matrix[0].length : 0;
|
|
11546
|
+
if (rows !== cols) {
|
|
11547
|
+
return new PineMatrixObject(id.type, 0, 0, NaN, context);
|
|
11548
|
+
}
|
|
11549
|
+
let result = new PineMatrixObject(id.type, rows, cols, 0, context);
|
|
11550
|
+
for (let i = 0; i < rows; i++) result.matrix[i][i] = 1;
|
|
11551
|
+
let base = new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11552
|
+
for (let i = 0; i < rows; i++) base.matrix[i] = [...id.matrix[i]];
|
|
11553
|
+
let p = Math.floor(power);
|
|
11554
|
+
if (p < 0) return new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11555
|
+
while (p > 0) {
|
|
11556
|
+
if (p % 2 === 1) {
|
|
11557
|
+
const temp = new PineMatrixObject(id.type, rows, cols, 0, context);
|
|
11558
|
+
for (let i = 0; i < rows; i++) {
|
|
11559
|
+
for (let j = 0; j < cols; j++) {
|
|
11560
|
+
let sum = 0;
|
|
11561
|
+
for (let k = 0; k < rows; k++) {
|
|
11562
|
+
sum += result.matrix[i][k] * base.matrix[k][j];
|
|
11563
|
+
}
|
|
11564
|
+
temp.matrix[i][j] = sum;
|
|
11565
|
+
}
|
|
11566
|
+
}
|
|
11567
|
+
result = temp;
|
|
11568
|
+
}
|
|
11569
|
+
const tempBase = new PineMatrixObject(id.type, rows, cols, 0, context);
|
|
11570
|
+
for (let i = 0; i < rows; i++) {
|
|
11571
|
+
for (let j = 0; j < cols; j++) {
|
|
11572
|
+
let sum = 0;
|
|
11573
|
+
for (let k = 0; k < rows; k++) {
|
|
11574
|
+
sum += base.matrix[i][k] * base.matrix[k][j];
|
|
11575
|
+
}
|
|
11576
|
+
tempBase.matrix[i][j] = sum;
|
|
11577
|
+
}
|
|
11578
|
+
}
|
|
11579
|
+
base = tempBase;
|
|
11580
|
+
p = Math.floor(p / 2);
|
|
11581
|
+
}
|
|
11582
|
+
return result;
|
|
11583
|
+
};
|
|
11584
|
+
}
|
|
11585
|
+
|
|
11586
|
+
function rank(context) {
|
|
11587
|
+
return (id) => {
|
|
11588
|
+
const rows = id.matrix.length;
|
|
11589
|
+
if (rows === 0) return 0;
|
|
11590
|
+
const cols = id.matrix[0].length;
|
|
11591
|
+
const mat = id.matrix.map((r2) => [...r2]);
|
|
11592
|
+
let r = 0;
|
|
11593
|
+
for (let c = 0; c < cols && r < rows; c++) {
|
|
11594
|
+
let pivot = r;
|
|
11595
|
+
while (pivot < rows && Math.abs(mat[pivot][c]) < 1e-10) pivot++;
|
|
11596
|
+
if (pivot < rows) {
|
|
11597
|
+
[mat[r], mat[pivot]] = [mat[pivot], mat[r]];
|
|
11598
|
+
const val = mat[r][c];
|
|
11599
|
+
for (let j = c; j < cols; j++) mat[r][j] /= val;
|
|
11600
|
+
for (let i = 0; i < rows; i++) {
|
|
11601
|
+
if (i !== r) {
|
|
11602
|
+
const factor = mat[i][c];
|
|
11603
|
+
for (let j = c; j < cols; j++) mat[i][j] -= factor * mat[r][j];
|
|
11604
|
+
}
|
|
11605
|
+
}
|
|
11606
|
+
r++;
|
|
11607
|
+
}
|
|
11608
|
+
}
|
|
11609
|
+
return r;
|
|
11610
|
+
};
|
|
11611
|
+
}
|
|
11612
|
+
|
|
11613
|
+
function remove_col(context) {
|
|
11614
|
+
return (id, column_index) => {
|
|
11615
|
+
const rows = id.matrix.length;
|
|
11616
|
+
if (rows === 0) return new PineArrayObject([], id.type, context);
|
|
11617
|
+
const removedValues = [];
|
|
11618
|
+
for (let i = 0; i < rows; i++) {
|
|
11619
|
+
const removed = id.matrix[i].splice(column_index, 1);
|
|
11620
|
+
removedValues.push(removed[0]);
|
|
11621
|
+
}
|
|
11622
|
+
return new PineArrayObject(removedValues, id.type, context);
|
|
11623
|
+
};
|
|
11624
|
+
}
|
|
11625
|
+
|
|
11626
|
+
function remove_row(context) {
|
|
11627
|
+
return (id, row_index) => {
|
|
11628
|
+
const removed = id.matrix.splice(row_index, 1);
|
|
11629
|
+
return new PineArrayObject(removed[0] || [], id.type, context);
|
|
11630
|
+
};
|
|
11631
|
+
}
|
|
11632
|
+
|
|
11633
|
+
function reshape(context) {
|
|
11634
|
+
return (id, rows, cols) => {
|
|
11635
|
+
const currentRows = id.matrix.length;
|
|
11636
|
+
const currentCols = currentRows > 0 ? id.matrix[0].length : 0;
|
|
11637
|
+
const newSize = rows * cols;
|
|
11638
|
+
const elements = [];
|
|
11639
|
+
for (let i = 0; i < currentRows; i++) {
|
|
11640
|
+
for (let j = 0; j < currentCols; j++) {
|
|
11641
|
+
elements.push(id.matrix[i][j]);
|
|
11642
|
+
}
|
|
11643
|
+
}
|
|
11644
|
+
while (elements.length < newSize) elements.push(NaN);
|
|
11645
|
+
if (elements.length > newSize) elements.length = newSize;
|
|
11646
|
+
const newMatrix = [];
|
|
11647
|
+
let k = 0;
|
|
11648
|
+
for (let i = 0; i < rows; i++) {
|
|
11649
|
+
const row = [];
|
|
11650
|
+
for (let j = 0; j < cols; j++) {
|
|
11651
|
+
row.push(elements[k++]);
|
|
11652
|
+
}
|
|
11653
|
+
newMatrix.push(row);
|
|
11654
|
+
}
|
|
11655
|
+
id.matrix = newMatrix;
|
|
11656
|
+
};
|
|
11657
|
+
}
|
|
11658
|
+
|
|
11659
|
+
function reverse(context) {
|
|
11660
|
+
return (id) => {
|
|
11661
|
+
id.matrix.reverse();
|
|
11662
|
+
for (const row of id.matrix) {
|
|
11663
|
+
row.reverse();
|
|
11664
|
+
}
|
|
11665
|
+
};
|
|
11666
|
+
}
|
|
11667
|
+
|
|
11668
|
+
function row(context) {
|
|
11669
|
+
return (id, row2) => {
|
|
11670
|
+
if (!id.matrix[row2]) return new PineArrayObject([], id.type, context);
|
|
11671
|
+
return new PineArrayObject([...id.matrix[row2]], id.type, context);
|
|
11672
|
+
};
|
|
11673
|
+
}
|
|
11674
|
+
|
|
11675
|
+
function rows(context) {
|
|
11676
|
+
return (id) => {
|
|
11677
|
+
return id.matrix.length;
|
|
11678
|
+
};
|
|
11679
|
+
}
|
|
11680
|
+
|
|
11681
|
+
function set(context) {
|
|
11682
|
+
return (id, row, col, value) => {
|
|
11683
|
+
if (!id.matrix[row]) return;
|
|
11684
|
+
id.matrix[row][col] = value;
|
|
11685
|
+
};
|
|
11686
|
+
}
|
|
11687
|
+
|
|
11688
|
+
function sort(context) {
|
|
11689
|
+
return (id, column = 0, order = "asc") => {
|
|
11690
|
+
const rows = id.matrix.length;
|
|
11691
|
+
if (rows === 0) return;
|
|
11692
|
+
id.matrix.sort((a, b) => {
|
|
11693
|
+
const valA = a[column];
|
|
11694
|
+
const valB = b[column];
|
|
11695
|
+
if (valA < valB) return order === "asc" ? -1 : 1;
|
|
11696
|
+
if (valA > valB) return order === "asc" ? 1 : -1;
|
|
11697
|
+
return 0;
|
|
11698
|
+
});
|
|
11699
|
+
};
|
|
11700
|
+
}
|
|
11701
|
+
|
|
11702
|
+
function submatrix(context) {
|
|
11703
|
+
return (id, from_row, to_row, from_col, to_col) => {
|
|
11704
|
+
const rows = to_row - from_row;
|
|
11705
|
+
const cols = to_col - from_col;
|
|
11706
|
+
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11707
|
+
for (let i = 0; i < rows; i++) {
|
|
11708
|
+
const sourceRow = from_row + i;
|
|
11709
|
+
if (sourceRow >= id.matrix.length) break;
|
|
11710
|
+
for (let j = 0; j < cols; j++) {
|
|
11711
|
+
const sourceCol = from_col + j;
|
|
11712
|
+
if (sourceCol >= id.matrix[sourceRow].length) break;
|
|
11713
|
+
newMatrix.matrix[i][j] = id.matrix[sourceRow][sourceCol];
|
|
11714
|
+
}
|
|
11715
|
+
}
|
|
11716
|
+
return newMatrix;
|
|
11717
|
+
};
|
|
11718
|
+
}
|
|
11719
|
+
|
|
11720
|
+
function sum$1(context) {
|
|
11721
|
+
return (id, id2) => {
|
|
11722
|
+
const rows = id.matrix.length;
|
|
11723
|
+
if (rows === 0) return new PineMatrixObject(id.type, 0, 0, NaN, context);
|
|
11724
|
+
const cols = id.matrix[0].length;
|
|
11725
|
+
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
|
|
11726
|
+
if (id2 instanceof PineMatrixObject) {
|
|
11727
|
+
for (let i = 0; i < rows; i++) {
|
|
11728
|
+
for (let j = 0; j < cols; j++) {
|
|
11729
|
+
const v1 = id.matrix[i][j];
|
|
11730
|
+
const v2 = id2.matrix[i] && id2.matrix[i][j] !== void 0 ? id2.matrix[i][j] : NaN;
|
|
11731
|
+
newMatrix.matrix[i][j] = v1 + v2;
|
|
11732
|
+
}
|
|
11733
|
+
}
|
|
11734
|
+
} else {
|
|
11735
|
+
const scalar = id2;
|
|
11736
|
+
for (let i = 0; i < rows; i++) {
|
|
11737
|
+
for (let j = 0; j < cols; j++) {
|
|
11738
|
+
newMatrix.matrix[i][j] = id.matrix[i][j] + scalar;
|
|
11739
|
+
}
|
|
11740
|
+
}
|
|
11741
|
+
}
|
|
11742
|
+
return newMatrix;
|
|
11743
|
+
};
|
|
11744
|
+
}
|
|
11745
|
+
|
|
11746
|
+
function swap_columns(context) {
|
|
11747
|
+
return (id, col1, col2) => {
|
|
11748
|
+
const rows = id.matrix.length;
|
|
11749
|
+
for (let i = 0; i < rows; i++) {
|
|
11750
|
+
const temp = id.matrix[i][col1];
|
|
11751
|
+
id.matrix[i][col1] = id.matrix[i][col2];
|
|
11752
|
+
id.matrix[i][col2] = temp;
|
|
11753
|
+
}
|
|
11754
|
+
};
|
|
11755
|
+
}
|
|
11756
|
+
|
|
11757
|
+
function swap_rows(context) {
|
|
11758
|
+
return (id, row1, row2) => {
|
|
11759
|
+
const temp = id.matrix[row1];
|
|
11760
|
+
id.matrix[row1] = id.matrix[row2];
|
|
11761
|
+
id.matrix[row2] = temp;
|
|
11762
|
+
};
|
|
11763
|
+
}
|
|
11764
|
+
|
|
11765
|
+
function trace(context) {
|
|
11766
|
+
return (id) => {
|
|
11767
|
+
const rows = id.matrix.length;
|
|
11768
|
+
if (rows === 0) return 0;
|
|
11769
|
+
const cols = id.matrix[0].length;
|
|
11770
|
+
const n = Math.min(rows, cols);
|
|
11771
|
+
let sum = 0;
|
|
11772
|
+
for (let i = 0; i < n; i++) {
|
|
11773
|
+
sum += id.matrix[i][i];
|
|
11774
|
+
}
|
|
11775
|
+
return sum;
|
|
11776
|
+
};
|
|
11777
|
+
}
|
|
11778
|
+
|
|
11779
|
+
function transpose(context) {
|
|
11780
|
+
return (id) => {
|
|
11781
|
+
const rows = id.matrix.length;
|
|
11782
|
+
if (rows === 0) return new PineMatrixObject(id.type, 0, 0, NaN, context);
|
|
11783
|
+
const cols = id.matrix[0].length;
|
|
11784
|
+
const newMatrix = new PineMatrixObject(id.type, cols, rows, NaN, context);
|
|
11785
|
+
for (let i = 0; i < rows; i++) {
|
|
11786
|
+
for (let j = 0; j < cols; j++) {
|
|
11787
|
+
newMatrix.matrix[j][i] = id.matrix[i][j];
|
|
11788
|
+
}
|
|
11789
|
+
}
|
|
11790
|
+
return newMatrix;
|
|
11791
|
+
};
|
|
11792
|
+
}
|
|
11793
|
+
|
|
11794
|
+
class PineMatrixObject {
|
|
11795
|
+
constructor(type, rows$1 = 0, cols = 0, initialValue = NaN, context) {
|
|
11796
|
+
this.type = type;
|
|
11797
|
+
this.context = context;
|
|
11798
|
+
this.matrix = [];
|
|
11799
|
+
if (rows$1 > 0 && cols > 0) {
|
|
11800
|
+
for (let i = 0; i < rows$1; i++) {
|
|
11801
|
+
this.matrix.push(Array(cols).fill(initialValue));
|
|
11802
|
+
}
|
|
11803
|
+
}
|
|
11804
|
+
this._add_col = add_col(this.context);
|
|
11805
|
+
this._add_row = add_row(this.context);
|
|
11806
|
+
this._avg = avg$1(this.context);
|
|
11807
|
+
this._col = col(this.context);
|
|
11808
|
+
this._columns = columns(this.context);
|
|
11809
|
+
this._concat = concat(this.context);
|
|
11810
|
+
this._copy = copy(this.context);
|
|
11811
|
+
this._det = det(this.context);
|
|
11812
|
+
this._diff = diff(this.context);
|
|
11813
|
+
this._eigenvalues = eigenvalues(this.context);
|
|
11814
|
+
this._eigenvectors = eigenvectors(this.context);
|
|
11815
|
+
this._elements_count = elements_count(this.context);
|
|
11816
|
+
this._fill = fill(this.context);
|
|
11817
|
+
this._get = get(this.context);
|
|
11818
|
+
this._inv = inv(this.context);
|
|
11819
|
+
this._is_antidiagonal = is_antidiagonal(this.context);
|
|
11820
|
+
this._is_antisymmetric = is_antisymmetric(this.context);
|
|
11821
|
+
this._is_binary = is_binary(this.context);
|
|
11822
|
+
this._is_diagonal = is_diagonal(this.context);
|
|
11823
|
+
this._is_identity = is_identity(this.context);
|
|
11824
|
+
this._is_square = is_square(this.context);
|
|
11825
|
+
this._is_stochastic = is_stochastic(this.context);
|
|
11826
|
+
this._is_symmetric = is_symmetric(this.context);
|
|
11827
|
+
this._is_triangular = is_triangular(this.context);
|
|
11828
|
+
this._is_zero = is_zero(this.context);
|
|
11829
|
+
this._kron = kron(this.context);
|
|
11830
|
+
this._max = max$1(this.context);
|
|
11831
|
+
this._median = median$1(this.context);
|
|
11832
|
+
this._min = min$1(this.context);
|
|
11833
|
+
this._mode = mode$1(this.context);
|
|
11834
|
+
this._mult = mult(this.context);
|
|
11835
|
+
this._pinv = pinv(this.context);
|
|
11836
|
+
this._pow = pow$1(this.context);
|
|
11837
|
+
this._rank = rank(this.context);
|
|
11838
|
+
this._remove_col = remove_col(this.context);
|
|
11839
|
+
this._remove_row = remove_row(this.context);
|
|
11840
|
+
this._reshape = reshape(this.context);
|
|
11841
|
+
this._reverse = reverse(this.context);
|
|
11842
|
+
this._row = row(this.context);
|
|
11843
|
+
this._rows = rows(this.context);
|
|
11844
|
+
this._set = set(this.context);
|
|
11845
|
+
this._sort = sort(this.context);
|
|
11846
|
+
this._submatrix = submatrix(this.context);
|
|
11847
|
+
this._sum = sum$1(this.context);
|
|
11848
|
+
this._swap_columns = swap_columns(this.context);
|
|
11849
|
+
this._swap_rows = swap_rows(this.context);
|
|
11850
|
+
this._trace = trace(this.context);
|
|
11851
|
+
this._transpose = transpose(this.context);
|
|
11852
|
+
}
|
|
11853
|
+
matrix;
|
|
11854
|
+
_add_col;
|
|
11855
|
+
_add_row;
|
|
11856
|
+
_avg;
|
|
11857
|
+
_col;
|
|
11858
|
+
_columns;
|
|
11859
|
+
_concat;
|
|
11860
|
+
_copy;
|
|
11861
|
+
_det;
|
|
11862
|
+
_diff;
|
|
11863
|
+
_eigenvalues;
|
|
11864
|
+
_eigenvectors;
|
|
11865
|
+
_elements_count;
|
|
11866
|
+
_fill;
|
|
11867
|
+
_get;
|
|
11868
|
+
_inv;
|
|
11869
|
+
_is_antidiagonal;
|
|
11870
|
+
_is_antisymmetric;
|
|
11871
|
+
_is_binary;
|
|
11872
|
+
_is_diagonal;
|
|
11873
|
+
_is_identity;
|
|
11874
|
+
_is_square;
|
|
11875
|
+
_is_stochastic;
|
|
11876
|
+
_is_symmetric;
|
|
11877
|
+
_is_triangular;
|
|
11878
|
+
_is_zero;
|
|
11879
|
+
_kron;
|
|
11880
|
+
_max;
|
|
11881
|
+
_median;
|
|
11882
|
+
_min;
|
|
11883
|
+
_mode;
|
|
11884
|
+
_mult;
|
|
11885
|
+
_pinv;
|
|
11886
|
+
_pow;
|
|
11887
|
+
_rank;
|
|
11888
|
+
_remove_col;
|
|
11889
|
+
_remove_row;
|
|
11890
|
+
_reshape;
|
|
11891
|
+
_reverse;
|
|
11892
|
+
_row;
|
|
11893
|
+
_rows;
|
|
11894
|
+
_set;
|
|
11895
|
+
_sort;
|
|
11896
|
+
_submatrix;
|
|
11897
|
+
_sum;
|
|
11898
|
+
_swap_columns;
|
|
11899
|
+
_swap_rows;
|
|
11900
|
+
_trace;
|
|
11901
|
+
_transpose;
|
|
11902
|
+
toString() {
|
|
11903
|
+
let result = "";
|
|
11904
|
+
for (let i = 0; i < this.matrix.length; i++) {
|
|
11905
|
+
result += result === "" ? "" : "\n";
|
|
11906
|
+
result += "[" + this.matrix[i].join(", ") + "]";
|
|
11907
|
+
}
|
|
11908
|
+
return result;
|
|
11909
|
+
}
|
|
11910
|
+
add_col(...args) {
|
|
11911
|
+
return this._add_col(this, ...args);
|
|
11912
|
+
}
|
|
11913
|
+
add_row(...args) {
|
|
11914
|
+
return this._add_row(this, ...args);
|
|
11915
|
+
}
|
|
11916
|
+
avg(...args) {
|
|
11917
|
+
return this._avg(this, ...args);
|
|
11918
|
+
}
|
|
11919
|
+
col(...args) {
|
|
11920
|
+
return this._col(this, ...args);
|
|
11921
|
+
}
|
|
11922
|
+
columns(...args) {
|
|
11923
|
+
return this._columns(this, ...args);
|
|
11924
|
+
}
|
|
11925
|
+
concat(...args) {
|
|
11926
|
+
return this._concat(this, ...args);
|
|
11927
|
+
}
|
|
11928
|
+
copy(...args) {
|
|
11929
|
+
return this._copy(this, ...args);
|
|
11930
|
+
}
|
|
11931
|
+
det(...args) {
|
|
11932
|
+
return this._det(this, ...args);
|
|
11933
|
+
}
|
|
11934
|
+
diff(...args) {
|
|
11935
|
+
return this._diff(this, ...args);
|
|
11936
|
+
}
|
|
11937
|
+
eigenvalues(...args) {
|
|
11938
|
+
return this._eigenvalues(this, ...args);
|
|
11939
|
+
}
|
|
11940
|
+
eigenvectors(...args) {
|
|
11941
|
+
return this._eigenvectors(this, ...args);
|
|
11942
|
+
}
|
|
11943
|
+
elements_count(...args) {
|
|
11944
|
+
return this._elements_count(this, ...args);
|
|
11945
|
+
}
|
|
11946
|
+
fill(...args) {
|
|
11947
|
+
return this._fill(this, ...args);
|
|
11948
|
+
}
|
|
11949
|
+
get(...args) {
|
|
11950
|
+
return this._get(this, ...args);
|
|
11951
|
+
}
|
|
11952
|
+
inv(...args) {
|
|
11953
|
+
return this._inv(this, ...args);
|
|
11954
|
+
}
|
|
11955
|
+
is_antidiagonal(...args) {
|
|
11956
|
+
return this._is_antidiagonal(this, ...args);
|
|
11957
|
+
}
|
|
11958
|
+
is_antisymmetric(...args) {
|
|
11959
|
+
return this._is_antisymmetric(this, ...args);
|
|
11960
|
+
}
|
|
11961
|
+
is_binary(...args) {
|
|
11962
|
+
return this._is_binary(this, ...args);
|
|
11963
|
+
}
|
|
11964
|
+
is_diagonal(...args) {
|
|
11965
|
+
return this._is_diagonal(this, ...args);
|
|
11966
|
+
}
|
|
11967
|
+
is_identity(...args) {
|
|
11968
|
+
return this._is_identity(this, ...args);
|
|
11969
|
+
}
|
|
11970
|
+
is_square(...args) {
|
|
11971
|
+
return this._is_square(this, ...args);
|
|
11972
|
+
}
|
|
11973
|
+
is_stochastic(...args) {
|
|
11974
|
+
return this._is_stochastic(this, ...args);
|
|
11975
|
+
}
|
|
11976
|
+
is_symmetric(...args) {
|
|
11977
|
+
return this._is_symmetric(this, ...args);
|
|
11978
|
+
}
|
|
11979
|
+
is_triangular(...args) {
|
|
11980
|
+
return this._is_triangular(this, ...args);
|
|
11981
|
+
}
|
|
11982
|
+
is_zero(...args) {
|
|
11983
|
+
return this._is_zero(this, ...args);
|
|
11984
|
+
}
|
|
11985
|
+
kron(...args) {
|
|
11986
|
+
return this._kron(this, ...args);
|
|
11987
|
+
}
|
|
11988
|
+
max(...args) {
|
|
11989
|
+
return this._max(this, ...args);
|
|
11990
|
+
}
|
|
11991
|
+
median(...args) {
|
|
11992
|
+
return this._median(this, ...args);
|
|
11993
|
+
}
|
|
11994
|
+
min(...args) {
|
|
11995
|
+
return this._min(this, ...args);
|
|
11996
|
+
}
|
|
11997
|
+
mode(...args) {
|
|
11998
|
+
return this._mode(this, ...args);
|
|
11999
|
+
}
|
|
12000
|
+
mult(...args) {
|
|
12001
|
+
return this._mult(this, ...args);
|
|
12002
|
+
}
|
|
12003
|
+
pinv(...args) {
|
|
12004
|
+
return this._pinv(this, ...args);
|
|
12005
|
+
}
|
|
12006
|
+
pow(...args) {
|
|
12007
|
+
return this._pow(this, ...args);
|
|
12008
|
+
}
|
|
12009
|
+
rank(...args) {
|
|
12010
|
+
return this._rank(this, ...args);
|
|
12011
|
+
}
|
|
12012
|
+
remove_col(...args) {
|
|
12013
|
+
return this._remove_col(this, ...args);
|
|
12014
|
+
}
|
|
12015
|
+
remove_row(...args) {
|
|
12016
|
+
return this._remove_row(this, ...args);
|
|
12017
|
+
}
|
|
12018
|
+
reshape(...args) {
|
|
12019
|
+
return this._reshape(this, ...args);
|
|
12020
|
+
}
|
|
12021
|
+
reverse(...args) {
|
|
12022
|
+
return this._reverse(this, ...args);
|
|
12023
|
+
}
|
|
12024
|
+
row(...args) {
|
|
12025
|
+
return this._row(this, ...args);
|
|
12026
|
+
}
|
|
12027
|
+
rows(...args) {
|
|
12028
|
+
return this._rows(this, ...args);
|
|
12029
|
+
}
|
|
12030
|
+
set(...args) {
|
|
12031
|
+
return this._set(this, ...args);
|
|
12032
|
+
}
|
|
12033
|
+
sort(...args) {
|
|
12034
|
+
return this._sort(this, ...args);
|
|
12035
|
+
}
|
|
12036
|
+
submatrix(...args) {
|
|
12037
|
+
return this._submatrix(this, ...args);
|
|
12038
|
+
}
|
|
12039
|
+
sum(...args) {
|
|
12040
|
+
return this._sum(this, ...args);
|
|
12041
|
+
}
|
|
12042
|
+
swap_columns(...args) {
|
|
12043
|
+
return this._swap_columns(this, ...args);
|
|
12044
|
+
}
|
|
12045
|
+
swap_rows(...args) {
|
|
12046
|
+
return this._swap_rows(this, ...args);
|
|
12047
|
+
}
|
|
12048
|
+
trace(...args) {
|
|
12049
|
+
return this._trace(this, ...args);
|
|
12050
|
+
}
|
|
12051
|
+
transpose(...args) {
|
|
12052
|
+
return this._transpose(this, ...args);
|
|
12053
|
+
}
|
|
12054
|
+
}
|
|
12055
|
+
|
|
12056
|
+
function new_fn(context) {
|
|
12057
|
+
return (type, rows, cols, initial_value) => {
|
|
12058
|
+
return new PineMatrixObject(type, rows, cols, initial_value, context);
|
|
9932
12059
|
};
|
|
9933
12060
|
}
|
|
9934
12061
|
|
|
9935
|
-
function
|
|
9936
|
-
return (
|
|
9937
|
-
return
|
|
12062
|
+
function param$4(context) {
|
|
12063
|
+
return (source, index = 0) => {
|
|
12064
|
+
return Series.from(source).get(index);
|
|
9938
12065
|
};
|
|
9939
12066
|
}
|
|
9940
12067
|
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
|
|
9944
|
-
|
|
12068
|
+
class PineMatrix {
|
|
12069
|
+
constructor(context) {
|
|
12070
|
+
this.context = context;
|
|
12071
|
+
this.add_col = (id, ...args) => id.add_col(...args);
|
|
12072
|
+
this.add_row = (id, ...args) => id.add_row(...args);
|
|
12073
|
+
this.avg = (id, ...args) => id.avg(...args);
|
|
12074
|
+
this.col = (id, ...args) => id.col(...args);
|
|
12075
|
+
this.columns = (id, ...args) => id.columns(...args);
|
|
12076
|
+
this.concat = (id, ...args) => id.concat(...args);
|
|
12077
|
+
this.copy = (id, ...args) => id.copy(...args);
|
|
12078
|
+
this.det = (id, ...args) => id.det(...args);
|
|
12079
|
+
this.diff = (id, ...args) => id.diff(...args);
|
|
12080
|
+
this.eigenvalues = (id, ...args) => id.eigenvalues(...args);
|
|
12081
|
+
this.eigenvectors = (id, ...args) => id.eigenvectors(...args);
|
|
12082
|
+
this.elements_count = (id, ...args) => id.elements_count(...args);
|
|
12083
|
+
this.fill = (id, ...args) => id.fill(...args);
|
|
12084
|
+
this.get = (id, ...args) => id.get(...args);
|
|
12085
|
+
this.inv = (id, ...args) => id.inv(...args);
|
|
12086
|
+
this.is_antidiagonal = (id, ...args) => id.is_antidiagonal(...args);
|
|
12087
|
+
this.is_antisymmetric = (id, ...args) => id.is_antisymmetric(...args);
|
|
12088
|
+
this.is_binary = (id, ...args) => id.is_binary(...args);
|
|
12089
|
+
this.is_diagonal = (id, ...args) => id.is_diagonal(...args);
|
|
12090
|
+
this.is_identity = (id, ...args) => id.is_identity(...args);
|
|
12091
|
+
this.is_square = (id, ...args) => id.is_square(...args);
|
|
12092
|
+
this.is_stochastic = (id, ...args) => id.is_stochastic(...args);
|
|
12093
|
+
this.is_symmetric = (id, ...args) => id.is_symmetric(...args);
|
|
12094
|
+
this.is_triangular = (id, ...args) => id.is_triangular(...args);
|
|
12095
|
+
this.is_zero = (id, ...args) => id.is_zero(...args);
|
|
12096
|
+
this.kron = (id, ...args) => id.kron(...args);
|
|
12097
|
+
this.max = (id, ...args) => id.max(...args);
|
|
12098
|
+
this.median = (id, ...args) => id.median(...args);
|
|
12099
|
+
this.min = (id, ...args) => id.min(...args);
|
|
12100
|
+
this.mode = (id, ...args) => id.mode(...args);
|
|
12101
|
+
this.mult = (id, ...args) => id.mult(...args);
|
|
12102
|
+
this.new = new_fn(context);
|
|
12103
|
+
this.param = param$4();
|
|
12104
|
+
this.pinv = (id, ...args) => id.pinv(...args);
|
|
12105
|
+
this.pow = (id, ...args) => id.pow(...args);
|
|
12106
|
+
this.rank = (id, ...args) => id.rank(...args);
|
|
12107
|
+
this.remove_col = (id, ...args) => id.remove_col(...args);
|
|
12108
|
+
this.remove_row = (id, ...args) => id.remove_row(...args);
|
|
12109
|
+
this.reshape = (id, ...args) => id.reshape(...args);
|
|
12110
|
+
this.reverse = (id, ...args) => id.reverse(...args);
|
|
12111
|
+
this.row = (id, ...args) => id.row(...args);
|
|
12112
|
+
this.rows = (id, ...args) => id.rows(...args);
|
|
12113
|
+
this.set = (id, ...args) => id.set(...args);
|
|
12114
|
+
this.sort = (id, ...args) => id.sort(...args);
|
|
12115
|
+
this.submatrix = (id, ...args) => id.submatrix(...args);
|
|
12116
|
+
this.sum = (id, ...args) => id.sum(...args);
|
|
12117
|
+
this.swap_columns = (id, ...args) => id.swap_columns(...args);
|
|
12118
|
+
this.swap_rows = (id, ...args) => id.swap_rows(...args);
|
|
12119
|
+
this.trace = (id, ...args) => id.trace(...args);
|
|
12120
|
+
this.transpose = (id, ...args) => id.transpose(...args);
|
|
12121
|
+
}
|
|
9945
12122
|
}
|
|
9946
12123
|
|
|
9947
|
-
|
|
9948
|
-
return (id, biased = true) => {
|
|
9949
|
-
const mean = context.array.avg(id);
|
|
9950
|
-
const deviations = id.array.map((x) => Math.pow(x - mean, 2));
|
|
9951
|
-
const divisor = biased ? id.array.length : id.array.length - 1;
|
|
9952
|
-
return context.array.sum(new PineArrayObject(deviations)) / divisor;
|
|
9953
|
-
};
|
|
9954
|
-
}
|
|
9955
|
-
|
|
9956
|
-
const methods$4 = {
|
|
9957
|
-
abs: abs$1,
|
|
9958
|
-
avg: avg$1,
|
|
9959
|
-
clear,
|
|
9960
|
-
concat,
|
|
9961
|
-
copy,
|
|
9962
|
-
covariance,
|
|
9963
|
-
every,
|
|
9964
|
-
fill,
|
|
9965
|
-
first,
|
|
9966
|
-
from,
|
|
9967
|
-
get,
|
|
9968
|
-
includes,
|
|
9969
|
-
indexof,
|
|
9970
|
-
insert,
|
|
9971
|
-
join,
|
|
9972
|
-
last,
|
|
9973
|
-
lastindexof,
|
|
9974
|
-
max: max$1,
|
|
9975
|
-
min: min$1,
|
|
9976
|
-
new: new_fn,
|
|
9977
|
-
new_bool,
|
|
9978
|
-
new_float,
|
|
9979
|
-
new_int,
|
|
9980
|
-
new_string,
|
|
9981
|
-
param: param$4,
|
|
9982
|
-
pop,
|
|
9983
|
-
push,
|
|
9984
|
-
range: range$1,
|
|
9985
|
-
remove,
|
|
9986
|
-
reverse,
|
|
9987
|
-
set,
|
|
9988
|
-
shift,
|
|
9989
|
-
size,
|
|
9990
|
-
slice,
|
|
9991
|
-
some,
|
|
9992
|
-
sort,
|
|
9993
|
-
sort_indices,
|
|
9994
|
-
standardize,
|
|
9995
|
-
stdev: stdev$1,
|
|
9996
|
-
sum: sum$1,
|
|
9997
|
-
unshift,
|
|
9998
|
-
variance: variance$1
|
|
9999
|
-
};
|
|
10000
|
-
class PineArray {
|
|
12124
|
+
class Barstate {
|
|
10001
12125
|
constructor(context) {
|
|
10002
12126
|
this.context = context;
|
|
10003
|
-
Object.entries(methods$4).forEach(([name, factory]) => {
|
|
10004
|
-
this[name] = factory(context);
|
|
10005
|
-
});
|
|
10006
12127
|
}
|
|
10007
|
-
|
|
10008
|
-
|
|
10009
|
-
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
10017
|
-
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
|
|
10021
|
-
|
|
10022
|
-
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
param;
|
|
10033
|
-
pop;
|
|
10034
|
-
push;
|
|
10035
|
-
range;
|
|
10036
|
-
remove;
|
|
10037
|
-
reverse;
|
|
10038
|
-
set;
|
|
10039
|
-
shift;
|
|
10040
|
-
size;
|
|
10041
|
-
slice;
|
|
10042
|
-
some;
|
|
10043
|
-
sort;
|
|
10044
|
-
sort_indices;
|
|
10045
|
-
standardize;
|
|
10046
|
-
stdev;
|
|
10047
|
-
sum;
|
|
10048
|
-
unshift;
|
|
10049
|
-
variance;
|
|
12128
|
+
_live = false;
|
|
12129
|
+
setLive() {
|
|
12130
|
+
this._live = true;
|
|
12131
|
+
}
|
|
12132
|
+
get isnew() {
|
|
12133
|
+
return !this._live;
|
|
12134
|
+
}
|
|
12135
|
+
get islast() {
|
|
12136
|
+
return this.context.idx === this.context.data.close.data.length - 1;
|
|
12137
|
+
}
|
|
12138
|
+
get isfirst() {
|
|
12139
|
+
return this.context.idx === 0;
|
|
12140
|
+
}
|
|
12141
|
+
get ishistory() {
|
|
12142
|
+
return this.context.idx < this.context.data.close.data.length - 1;
|
|
12143
|
+
}
|
|
12144
|
+
get isrealtime() {
|
|
12145
|
+
return this.context.idx === this.context.data.close.data.length - 1;
|
|
12146
|
+
}
|
|
12147
|
+
get isconfirmed() {
|
|
12148
|
+
return this.context.data.closeTime[this.context.data.closeTime.length - 1] <= (/* @__PURE__ */ new Date()).getTime();
|
|
12149
|
+
}
|
|
12150
|
+
get islastconfirmedhistory() {
|
|
12151
|
+
return this.context.data.closeTime[this.context.data.closeTime.length - 1] <= (/* @__PURE__ */ new Date()).getTime();
|
|
12152
|
+
}
|
|
10050
12153
|
}
|
|
10051
12154
|
|
|
10052
12155
|
class Core {
|
|
@@ -10075,7 +12178,22 @@ class Core {
|
|
|
10075
12178
|
maroon: "maroon",
|
|
10076
12179
|
black: "black",
|
|
10077
12180
|
gray: "gray",
|
|
10078
|
-
blue: "blue"
|
|
12181
|
+
blue: "blue",
|
|
12182
|
+
yellow: "yellow",
|
|
12183
|
+
orange: "orange",
|
|
12184
|
+
purple: "purple",
|
|
12185
|
+
pink: "pink",
|
|
12186
|
+
brown: "brown",
|
|
12187
|
+
teal: "teal",
|
|
12188
|
+
cyan: "cyan",
|
|
12189
|
+
navy: "navy",
|
|
12190
|
+
indigo: "indigo",
|
|
12191
|
+
violet: "violet",
|
|
12192
|
+
magenta: "magenta",
|
|
12193
|
+
rose: "rose",
|
|
12194
|
+
gold: "gold",
|
|
12195
|
+
silver: "silver",
|
|
12196
|
+
bronze: "bronze"
|
|
10079
12197
|
};
|
|
10080
12198
|
extractPlotOptions(options) {
|
|
10081
12199
|
const _options = {};
|
|
@@ -10122,94 +12240,155 @@ class Core {
|
|
|
10122
12240
|
}
|
|
10123
12241
|
}
|
|
10124
12242
|
|
|
12243
|
+
const INPUT_ARGS_OPTIONS = [
|
|
12244
|
+
["defval", "title", "tooltip", "inline", "group", "display"],
|
|
12245
|
+
["defval", "title", "tooltip", "group", "confirm", "display"],
|
|
12246
|
+
["defval", "title", "tooltip", "inline", "group", "confirm", "display"],
|
|
12247
|
+
["defval", "title", "options", "tooltip", "inline", "group", "confirm", "display"],
|
|
12248
|
+
["defval", "title", "minval", "maxval", "step", "tooltip", "inline", "group", "confirm", "display"]
|
|
12249
|
+
];
|
|
12250
|
+
const INPUT_ARGS_TYPE_CHECK = {
|
|
12251
|
+
defval: (arg) => typeof arg !== "object",
|
|
12252
|
+
title: (arg) => typeof arg === "string",
|
|
12253
|
+
tooltip: (arg) => typeof arg === "string",
|
|
12254
|
+
inline: (arg) => typeof arg === "string",
|
|
12255
|
+
group: (arg) => typeof arg === "string",
|
|
12256
|
+
display: (arg) => typeof arg === "string",
|
|
12257
|
+
confirm: (arg) => typeof arg === "boolean",
|
|
12258
|
+
options: (arg) => Array.isArray(arg),
|
|
12259
|
+
minval: (arg) => typeof arg === "number",
|
|
12260
|
+
maxval: (arg) => typeof arg === "number",
|
|
12261
|
+
step: (arg) => typeof arg === "number"
|
|
12262
|
+
};
|
|
12263
|
+
function parseInputOptions(args) {
|
|
12264
|
+
const options = {};
|
|
12265
|
+
let options_arg = {};
|
|
12266
|
+
const valid = new Array(INPUT_ARGS_OPTIONS.length).fill(true);
|
|
12267
|
+
for (let i = 0; i < args.length; i++) {
|
|
12268
|
+
const arg = args[i];
|
|
12269
|
+
if (typeof arg === "object") {
|
|
12270
|
+
options_arg = arg;
|
|
12271
|
+
break;
|
|
12272
|
+
}
|
|
12273
|
+
const curOptions = INPUT_ARGS_OPTIONS.map((e, idx) => valid[idx] ? e[i] : void 0);
|
|
12274
|
+
for (let o = 0; o < curOptions.length; o++) {
|
|
12275
|
+
const optionName = curOptions[o];
|
|
12276
|
+
if (optionName === void 0) {
|
|
12277
|
+
valid[o] = false;
|
|
12278
|
+
continue;
|
|
12279
|
+
}
|
|
12280
|
+
if (INPUT_ARGS_TYPE_CHECK[optionName](arg)) {
|
|
12281
|
+
options[optionName] = arg;
|
|
12282
|
+
} else {
|
|
12283
|
+
valid[o] = false;
|
|
12284
|
+
}
|
|
12285
|
+
}
|
|
12286
|
+
}
|
|
12287
|
+
return { ...options_arg, ...options };
|
|
12288
|
+
}
|
|
12289
|
+
|
|
10125
12290
|
function any(context) {
|
|
10126
|
-
return (
|
|
10127
|
-
|
|
12291
|
+
return (...args) => {
|
|
12292
|
+
const options = parseInputOptions(args);
|
|
12293
|
+
return options.defval;
|
|
10128
12294
|
};
|
|
10129
12295
|
}
|
|
10130
12296
|
|
|
10131
12297
|
function bool(context) {
|
|
10132
|
-
return (
|
|
10133
|
-
|
|
12298
|
+
return (...args) => {
|
|
12299
|
+
const options = parseInputOptions(args);
|
|
12300
|
+
return options.defval;
|
|
10134
12301
|
};
|
|
10135
12302
|
}
|
|
10136
12303
|
|
|
10137
12304
|
function color(context) {
|
|
10138
|
-
return (
|
|
10139
|
-
|
|
12305
|
+
return (...args) => {
|
|
12306
|
+
const options = parseInputOptions(args);
|
|
12307
|
+
return options.defval;
|
|
10140
12308
|
};
|
|
10141
12309
|
}
|
|
10142
12310
|
|
|
10143
12311
|
function enum_fn(context) {
|
|
10144
|
-
return (
|
|
10145
|
-
|
|
12312
|
+
return (...args) => {
|
|
12313
|
+
const options = parseInputOptions(args);
|
|
12314
|
+
return options.defval;
|
|
10146
12315
|
};
|
|
10147
12316
|
}
|
|
10148
12317
|
|
|
10149
12318
|
function float(context) {
|
|
10150
|
-
return (
|
|
10151
|
-
|
|
12319
|
+
return (...args) => {
|
|
12320
|
+
const options = parseInputOptions(args);
|
|
12321
|
+
return options.defval;
|
|
10152
12322
|
};
|
|
10153
12323
|
}
|
|
10154
12324
|
|
|
10155
12325
|
function int(context) {
|
|
10156
|
-
return (
|
|
10157
|
-
|
|
12326
|
+
return (...args) => {
|
|
12327
|
+
const options = parseInputOptions(args);
|
|
12328
|
+
return options.defval;
|
|
10158
12329
|
};
|
|
10159
12330
|
}
|
|
10160
12331
|
|
|
10161
12332
|
function param$3(context) {
|
|
10162
12333
|
return (source, index = 0) => {
|
|
10163
12334
|
const val = Series.from(source).get(index);
|
|
10164
|
-
return
|
|
12335
|
+
return val;
|
|
10165
12336
|
};
|
|
10166
12337
|
}
|
|
10167
12338
|
|
|
10168
12339
|
function price(context) {
|
|
10169
|
-
return (
|
|
10170
|
-
|
|
12340
|
+
return (...args) => {
|
|
12341
|
+
const options = parseInputOptions(args);
|
|
12342
|
+
return options.defval;
|
|
10171
12343
|
};
|
|
10172
12344
|
}
|
|
10173
12345
|
|
|
10174
12346
|
function session(context) {
|
|
10175
|
-
return (
|
|
10176
|
-
|
|
12347
|
+
return (...args) => {
|
|
12348
|
+
const options = parseInputOptions(args);
|
|
12349
|
+
return options.defval;
|
|
10177
12350
|
};
|
|
10178
12351
|
}
|
|
10179
12352
|
|
|
10180
12353
|
function source(context) {
|
|
10181
|
-
return (
|
|
10182
|
-
|
|
12354
|
+
return (...args) => {
|
|
12355
|
+
const options = parseInputOptions(args);
|
|
12356
|
+
return options.defval;
|
|
10183
12357
|
};
|
|
10184
12358
|
}
|
|
10185
12359
|
|
|
10186
12360
|
function string(context) {
|
|
10187
|
-
return (
|
|
10188
|
-
|
|
12361
|
+
return (...args) => {
|
|
12362
|
+
const options = parseInputOptions(args);
|
|
12363
|
+
return options.defval;
|
|
10189
12364
|
};
|
|
10190
12365
|
}
|
|
10191
12366
|
|
|
10192
12367
|
function symbol(context) {
|
|
10193
|
-
return (
|
|
10194
|
-
|
|
12368
|
+
return (...args) => {
|
|
12369
|
+
const options = parseInputOptions(args);
|
|
12370
|
+
return options.defval;
|
|
10195
12371
|
};
|
|
10196
12372
|
}
|
|
10197
12373
|
|
|
10198
12374
|
function text_area(context) {
|
|
10199
|
-
return (
|
|
10200
|
-
|
|
12375
|
+
return (...args) => {
|
|
12376
|
+
const options = parseInputOptions(args);
|
|
12377
|
+
return options.defval;
|
|
10201
12378
|
};
|
|
10202
12379
|
}
|
|
10203
12380
|
|
|
10204
12381
|
function time(context) {
|
|
10205
|
-
return (
|
|
10206
|
-
|
|
12382
|
+
return (...args) => {
|
|
12383
|
+
const options = parseInputOptions(args);
|
|
12384
|
+
return options.defval;
|
|
10207
12385
|
};
|
|
10208
12386
|
}
|
|
10209
12387
|
|
|
10210
12388
|
function timeframe(context) {
|
|
10211
|
-
return (
|
|
10212
|
-
|
|
12389
|
+
return (...args) => {
|
|
12390
|
+
const options = parseInputOptions(args);
|
|
12391
|
+
return options.defval;
|
|
10213
12392
|
};
|
|
10214
12393
|
}
|
|
10215
12394
|
|
|
@@ -10300,6 +12479,12 @@ function cos(context) {
|
|
|
10300
12479
|
};
|
|
10301
12480
|
}
|
|
10302
12481
|
|
|
12482
|
+
function e(context) {
|
|
12483
|
+
return () => {
|
|
12484
|
+
return Math.E;
|
|
12485
|
+
};
|
|
12486
|
+
}
|
|
12487
|
+
|
|
10303
12488
|
function exp(context) {
|
|
10304
12489
|
return (source) => {
|
|
10305
12490
|
return Math.exp(Series.from(source).get(0));
|
|
@@ -10368,6 +12553,18 @@ function param$2(context) {
|
|
|
10368
12553
|
};
|
|
10369
12554
|
}
|
|
10370
12555
|
|
|
12556
|
+
function phi(context) {
|
|
12557
|
+
return () => {
|
|
12558
|
+
return 1.618033988749895;
|
|
12559
|
+
};
|
|
12560
|
+
}
|
|
12561
|
+
|
|
12562
|
+
function pi(context) {
|
|
12563
|
+
return () => {
|
|
12564
|
+
return Math.PI;
|
|
12565
|
+
};
|
|
12566
|
+
}
|
|
12567
|
+
|
|
10371
12568
|
function pow(context) {
|
|
10372
12569
|
return (source, power) => {
|
|
10373
12570
|
return Math.pow(Series.from(source).get(0), Series.from(power).get(0));
|
|
@@ -10386,6 +12583,24 @@ function round(context) {
|
|
|
10386
12583
|
};
|
|
10387
12584
|
}
|
|
10388
12585
|
|
|
12586
|
+
function round_to_mintick(context) {
|
|
12587
|
+
return (source) => {
|
|
12588
|
+
return context.precision(Math.round(Series.from(source).get(0) / context.pine.syminfo.mintick) * context.pine.syminfo.mintick);
|
|
12589
|
+
};
|
|
12590
|
+
}
|
|
12591
|
+
|
|
12592
|
+
function rphi(context) {
|
|
12593
|
+
return () => {
|
|
12594
|
+
return 0.6180339887498948;
|
|
12595
|
+
};
|
|
12596
|
+
}
|
|
12597
|
+
|
|
12598
|
+
function sign(context) {
|
|
12599
|
+
return (source) => {
|
|
12600
|
+
return Math.sign(Series.from(source).get(0));
|
|
12601
|
+
};
|
|
12602
|
+
}
|
|
12603
|
+
|
|
10389
12604
|
function sin(context) {
|
|
10390
12605
|
return (source) => {
|
|
10391
12606
|
return Math.sin(Series.from(source).get(0));
|
|
@@ -10435,6 +12650,7 @@ const methods$2 = {
|
|
|
10435
12650
|
avg,
|
|
10436
12651
|
ceil,
|
|
10437
12652
|
cos,
|
|
12653
|
+
e,
|
|
10438
12654
|
exp,
|
|
10439
12655
|
floor,
|
|
10440
12656
|
ln,
|
|
@@ -10443,9 +12659,14 @@ const methods$2 = {
|
|
|
10443
12659
|
max,
|
|
10444
12660
|
min,
|
|
10445
12661
|
param: param$2,
|
|
12662
|
+
phi,
|
|
12663
|
+
pi,
|
|
10446
12664
|
pow,
|
|
10447
12665
|
random,
|
|
10448
12666
|
round,
|
|
12667
|
+
round_to_mintick,
|
|
12668
|
+
rphi,
|
|
12669
|
+
sign,
|
|
10449
12670
|
sin,
|
|
10450
12671
|
sqrt,
|
|
10451
12672
|
sum,
|
|
@@ -10467,6 +12688,7 @@ class PineMath {
|
|
|
10467
12688
|
avg;
|
|
10468
12689
|
ceil;
|
|
10469
12690
|
cos;
|
|
12691
|
+
e;
|
|
10470
12692
|
exp;
|
|
10471
12693
|
floor;
|
|
10472
12694
|
ln;
|
|
@@ -10475,9 +12697,14 @@ class PineMath {
|
|
|
10475
12697
|
max;
|
|
10476
12698
|
min;
|
|
10477
12699
|
param;
|
|
12700
|
+
phi;
|
|
12701
|
+
pi;
|
|
10478
12702
|
pow;
|
|
10479
12703
|
random;
|
|
10480
12704
|
round;
|
|
12705
|
+
round_to_mintick;
|
|
12706
|
+
rphi;
|
|
12707
|
+
sign;
|
|
10481
12708
|
sin;
|
|
10482
12709
|
sqrt;
|
|
10483
12710
|
sum;
|
|
@@ -10640,9 +12867,65 @@ function security(context) {
|
|
|
10640
12867
|
};
|
|
10641
12868
|
}
|
|
10642
12869
|
|
|
12870
|
+
function security_lower_tf(context) {
|
|
12871
|
+
return async (symbol, timeframe, expression, ignore_invalid_symbol = false, currency = null, ignore_invalid_timeframe = false, calc_bars_count = 0) => {
|
|
12872
|
+
const _symbol = symbol[0];
|
|
12873
|
+
const _timeframe = timeframe[0];
|
|
12874
|
+
const _expression = expression[0];
|
|
12875
|
+
const _expression_name = expression[1];
|
|
12876
|
+
Array.isArray(ignore_invalid_symbol) ? ignore_invalid_symbol[0] : ignore_invalid_symbol;
|
|
12877
|
+
const _ignore_invalid_timeframe = Array.isArray(ignore_invalid_timeframe) ? ignore_invalid_timeframe[0] : ignore_invalid_timeframe;
|
|
12878
|
+
if (context.isSecondaryContext) {
|
|
12879
|
+
return Array.isArray(_expression) ? [_expression] : _expression;
|
|
12880
|
+
}
|
|
12881
|
+
const ctxTimeframeIdx = TIMEFRAMES.indexOf(context.timeframe);
|
|
12882
|
+
const reqTimeframeIdx = TIMEFRAMES.indexOf(_timeframe);
|
|
12883
|
+
if (ctxTimeframeIdx === -1 || reqTimeframeIdx === -1) {
|
|
12884
|
+
if (_ignore_invalid_timeframe) return NaN;
|
|
12885
|
+
throw new Error("Invalid timeframe");
|
|
12886
|
+
}
|
|
12887
|
+
if (reqTimeframeIdx > ctxTimeframeIdx) {
|
|
12888
|
+
if (_ignore_invalid_timeframe) return NaN;
|
|
12889
|
+
throw new Error(`Timeframe ${_timeframe} is not lower than or equal to chart timeframe ${context.timeframe}`);
|
|
12890
|
+
}
|
|
12891
|
+
if (reqTimeframeIdx === ctxTimeframeIdx) {
|
|
12892
|
+
return [[_expression]];
|
|
12893
|
+
}
|
|
12894
|
+
const cacheKey = `${_symbol}_${_timeframe}_${_expression_name}_lower`;
|
|
12895
|
+
if (!context.cache[cacheKey]) {
|
|
12896
|
+
const buffer = 1e3 * 60 * 60 * 24 * 30;
|
|
12897
|
+
const adjustedSDate = context.sDate ? context.sDate - buffer : void 0;
|
|
12898
|
+
const limit = context.sDate && context.eDate ? void 0 : context.limit || 1e3;
|
|
12899
|
+
const pineTS = new PineTS(context.source, _symbol, _timeframe, limit, adjustedSDate, context.eDate);
|
|
12900
|
+
pineTS.markAsSecondary();
|
|
12901
|
+
const secContext2 = await pineTS.run(context.pineTSCode);
|
|
12902
|
+
context.cache[cacheKey] = secContext2;
|
|
12903
|
+
}
|
|
12904
|
+
const secContext = context.cache[cacheKey];
|
|
12905
|
+
const myOpenTime = Series.from(context.data.openTime).get(0);
|
|
12906
|
+
const myCloseTime = Series.from(context.data.closeTime).get(0);
|
|
12907
|
+
const secOpenTimes = secContext.data.openTime.data;
|
|
12908
|
+
const secCloseTimes = secContext.data.closeTime.data;
|
|
12909
|
+
const secValues = secContext.params[_expression_name];
|
|
12910
|
+
if (!secValues) return [];
|
|
12911
|
+
const result = [];
|
|
12912
|
+
for (let i = 0; i < secOpenTimes.length; i++) {
|
|
12913
|
+
const sOpen = secOpenTimes[i];
|
|
12914
|
+
const sClose = secCloseTimes[i];
|
|
12915
|
+
if (sClose <= myOpenTime) continue;
|
|
12916
|
+
if (sOpen >= myCloseTime) break;
|
|
12917
|
+
if (sOpen >= myOpenTime && sOpen < myCloseTime) {
|
|
12918
|
+
result.push(secValues[i]);
|
|
12919
|
+
}
|
|
12920
|
+
}
|
|
12921
|
+
return [result];
|
|
12922
|
+
};
|
|
12923
|
+
}
|
|
12924
|
+
|
|
10643
12925
|
const methods$1 = {
|
|
10644
12926
|
param: param$1,
|
|
10645
|
-
security
|
|
12927
|
+
security,
|
|
12928
|
+
security_lower_tf
|
|
10646
12929
|
};
|
|
10647
12930
|
class PineRequest {
|
|
10648
12931
|
constructor(context) {
|
|
@@ -10654,6 +12937,7 @@ class PineRequest {
|
|
|
10654
12937
|
_cache = {};
|
|
10655
12938
|
param;
|
|
10656
12939
|
security;
|
|
12940
|
+
security_lower_tf;
|
|
10657
12941
|
}
|
|
10658
12942
|
|
|
10659
12943
|
function accdist(context) {
|
|
@@ -12452,10 +14736,10 @@ function tr(context) {
|
|
|
12452
14736
|
const low0 = context.get(context.data.low, 0);
|
|
12453
14737
|
const close1 = context.get(context.data.close, 1);
|
|
12454
14738
|
if (isNaN(close1)) {
|
|
12455
|
-
return handleNa ? high0 - low0 : NaN;
|
|
14739
|
+
return handleNa ? context.precision(high0 - low0) : NaN;
|
|
12456
14740
|
}
|
|
12457
14741
|
const val = Math.max(high0 - low0, Math.abs(high0 - close1), Math.abs(low0 - close1));
|
|
12458
|
-
return val;
|
|
14742
|
+
return context.precision(val);
|
|
12459
14743
|
};
|
|
12460
14744
|
}
|
|
12461
14745
|
|
|
@@ -12944,6 +15228,189 @@ class TechnicalAnalysis {
|
|
|
12944
15228
|
wvad;
|
|
12945
15229
|
}
|
|
12946
15230
|
|
|
15231
|
+
class Log {
|
|
15232
|
+
constructor(context) {
|
|
15233
|
+
this.context = context;
|
|
15234
|
+
}
|
|
15235
|
+
logFormat(message, ...args) {
|
|
15236
|
+
return message.replace(/{(\d+)}/g, (match, index) => args[index]);
|
|
15237
|
+
}
|
|
15238
|
+
param(source, index = 0, name) {
|
|
15239
|
+
return Series.from(source).get(index);
|
|
15240
|
+
}
|
|
15241
|
+
warning(message, ...args) {
|
|
15242
|
+
console.warn(this.logFormat(message, ...args));
|
|
15243
|
+
}
|
|
15244
|
+
error(message, ...args) {
|
|
15245
|
+
console.error(this.logFormat(message, ...args));
|
|
15246
|
+
}
|
|
15247
|
+
info(message, ...args) {
|
|
15248
|
+
console.log(this.logFormat(message, ...args));
|
|
15249
|
+
}
|
|
15250
|
+
}
|
|
15251
|
+
|
|
15252
|
+
class Str {
|
|
15253
|
+
constructor(context) {
|
|
15254
|
+
this.context = context;
|
|
15255
|
+
}
|
|
15256
|
+
param(source, index = 0, name) {
|
|
15257
|
+
return Series.from(source).get(index);
|
|
15258
|
+
}
|
|
15259
|
+
tostring(value) {
|
|
15260
|
+
return String(value);
|
|
15261
|
+
}
|
|
15262
|
+
tonumber(value) {
|
|
15263
|
+
return Number(value);
|
|
15264
|
+
}
|
|
15265
|
+
lower(value) {
|
|
15266
|
+
return String(value).toLowerCase();
|
|
15267
|
+
}
|
|
15268
|
+
upper(value) {
|
|
15269
|
+
return String(value).toUpperCase();
|
|
15270
|
+
}
|
|
15271
|
+
trim(value) {
|
|
15272
|
+
return String(value).trim();
|
|
15273
|
+
}
|
|
15274
|
+
repeat(source, repeat, separator = "") {
|
|
15275
|
+
return Array(repeat).fill(source).join(separator || "");
|
|
15276
|
+
}
|
|
15277
|
+
replace_all(source, target, replacement) {
|
|
15278
|
+
return String(source).replaceAll(target, replacement);
|
|
15279
|
+
}
|
|
15280
|
+
//occurense is the nth occurrence to replace
|
|
15281
|
+
replace(source, target, replacement, occurrence = 0) {
|
|
15282
|
+
const str = String(source);
|
|
15283
|
+
const tgt = String(target);
|
|
15284
|
+
const repl = String(replacement);
|
|
15285
|
+
const occ = Math.floor(Number(occurrence)) || 0;
|
|
15286
|
+
if (tgt === "") return str;
|
|
15287
|
+
let pos = 0;
|
|
15288
|
+
let found = 0;
|
|
15289
|
+
while (true) {
|
|
15290
|
+
const idx = str.indexOf(tgt, pos);
|
|
15291
|
+
if (idx === -1) return str;
|
|
15292
|
+
if (found === occ) {
|
|
15293
|
+
return str.substring(0, idx) + repl + str.substring(idx + tgt.length);
|
|
15294
|
+
}
|
|
15295
|
+
found++;
|
|
15296
|
+
pos = idx + tgt.length;
|
|
15297
|
+
}
|
|
15298
|
+
}
|
|
15299
|
+
contains(source, target) {
|
|
15300
|
+
return String(source).includes(target);
|
|
15301
|
+
}
|
|
15302
|
+
endswith(source, target) {
|
|
15303
|
+
return String(source).endsWith(target);
|
|
15304
|
+
}
|
|
15305
|
+
startswith(source, target) {
|
|
15306
|
+
return String(source).startsWith(target);
|
|
15307
|
+
}
|
|
15308
|
+
pos(source, target) {
|
|
15309
|
+
const idx = String(source).indexOf(target);
|
|
15310
|
+
return idx === -1 ? NaN : idx;
|
|
15311
|
+
}
|
|
15312
|
+
length(source) {
|
|
15313
|
+
return String(source).length;
|
|
15314
|
+
}
|
|
15315
|
+
match(source, pattern) {
|
|
15316
|
+
return String(source).match(new RegExp(pattern));
|
|
15317
|
+
}
|
|
15318
|
+
split(source, separator) {
|
|
15319
|
+
return [String(source).split(separator)];
|
|
15320
|
+
}
|
|
15321
|
+
substring(source, begin_pos, end_pos) {
|
|
15322
|
+
return String(source).substring(begin_pos, end_pos);
|
|
15323
|
+
}
|
|
15324
|
+
format(message, ...args) {
|
|
15325
|
+
return message.replace(/{(\d+)}/g, (match, index) => args[index]);
|
|
15326
|
+
}
|
|
15327
|
+
}
|
|
15328
|
+
|
|
15329
|
+
class Timeframe {
|
|
15330
|
+
constructor(context) {
|
|
15331
|
+
this.context = context;
|
|
15332
|
+
}
|
|
15333
|
+
param(source, index = 0, name) {
|
|
15334
|
+
return Series.from(source).get(index);
|
|
15335
|
+
}
|
|
15336
|
+
//Note : current PineTS implementation does not differentiate between main_period and period because the timeframe is always taken from the main execution context.
|
|
15337
|
+
//once we implement indicator() function, the main_period can be overridden by the indicator's timeframe.
|
|
15338
|
+
get main_period() {
|
|
15339
|
+
return this.context.timeframe;
|
|
15340
|
+
}
|
|
15341
|
+
get period() {
|
|
15342
|
+
return this.context.timeframe;
|
|
15343
|
+
}
|
|
15344
|
+
get multiplier() {
|
|
15345
|
+
const val = parseInt(this.context.timeframe);
|
|
15346
|
+
return isNaN(val) ? 1 : val;
|
|
15347
|
+
}
|
|
15348
|
+
get isdwm() {
|
|
15349
|
+
return ["D", "W", "M"].includes(this.context.timeframe.slice(-1));
|
|
15350
|
+
}
|
|
15351
|
+
get isdaily() {
|
|
15352
|
+
return this.context.timeframe.slice(-1) === "D";
|
|
15353
|
+
}
|
|
15354
|
+
get isweekly() {
|
|
15355
|
+
return this.context.timeframe.slice(-1) === "W";
|
|
15356
|
+
}
|
|
15357
|
+
get ismonthly() {
|
|
15358
|
+
return this.context.timeframe.slice(-1) === "M";
|
|
15359
|
+
}
|
|
15360
|
+
get isseconds() {
|
|
15361
|
+
return this.context.timeframe.slice(-1) === "S";
|
|
15362
|
+
}
|
|
15363
|
+
get isminutes() {
|
|
15364
|
+
return parseInt(this.context.timeframe).toString() == this.context.timeframe.trim();
|
|
15365
|
+
}
|
|
15366
|
+
get isintraday() {
|
|
15367
|
+
return !this.isdwm;
|
|
15368
|
+
}
|
|
15369
|
+
// public change(timeframe: string) {
|
|
15370
|
+
// const prevOpenTime = this.context.data.openTime.get(this.context.data.openTime.length - 2);
|
|
15371
|
+
// const currentOpenTime = this.context.data.openTime.get(this.context.data.openTime.length - 1);
|
|
15372
|
+
// }
|
|
15373
|
+
from_seconds(seconds) {
|
|
15374
|
+
if (seconds < 60) {
|
|
15375
|
+
const roundedSeconds = Math.ceil(seconds / 5) * 5;
|
|
15376
|
+
return roundedSeconds + "S";
|
|
15377
|
+
}
|
|
15378
|
+
if (seconds < 60 * 60 * 24) {
|
|
15379
|
+
const roundedMinutes = Math.ceil(seconds / 60);
|
|
15380
|
+
return roundedMinutes;
|
|
15381
|
+
}
|
|
15382
|
+
if (seconds <= 60 * 60 * 24 * 7 * 52) {
|
|
15383
|
+
if (seconds % (60 * 60 * 24 * 7) === 0) {
|
|
15384
|
+
const roundedWeeks = Math.ceil(seconds / (60 * 60 * 24 * 7));
|
|
15385
|
+
return roundedWeeks + "W";
|
|
15386
|
+
}
|
|
15387
|
+
const roundedHours = Math.ceil(seconds / (60 * 60 * 24));
|
|
15388
|
+
return roundedHours + "D";
|
|
15389
|
+
}
|
|
15390
|
+
return "12M";
|
|
15391
|
+
}
|
|
15392
|
+
in_seconds(timeframe) {
|
|
15393
|
+
const multiplier = parseInt(timeframe);
|
|
15394
|
+
const unit = timeframe.slice(-1);
|
|
15395
|
+
if (unit === "S") {
|
|
15396
|
+
return multiplier;
|
|
15397
|
+
}
|
|
15398
|
+
if (unit === "D") {
|
|
15399
|
+
return multiplier * 60 * 60 * 24;
|
|
15400
|
+
}
|
|
15401
|
+
if (unit === "W") {
|
|
15402
|
+
return multiplier * 60 * 60 * 24 * 7;
|
|
15403
|
+
}
|
|
15404
|
+
if (unit === "M") {
|
|
15405
|
+
return multiplier * 60 * 60 * 24 * 30;
|
|
15406
|
+
}
|
|
15407
|
+
if (!isNaN(multiplier)) {
|
|
15408
|
+
return multiplier * 60;
|
|
15409
|
+
}
|
|
15410
|
+
return 0;
|
|
15411
|
+
}
|
|
15412
|
+
}
|
|
15413
|
+
|
|
12947
15414
|
class Context {
|
|
12948
15415
|
data = {
|
|
12949
15416
|
open: new Series([]),
|
|
@@ -12953,7 +15420,8 @@ class Context {
|
|
|
12953
15420
|
volume: new Series([]),
|
|
12954
15421
|
hl2: new Series([]),
|
|
12955
15422
|
hlc3: new Series([]),
|
|
12956
|
-
ohlc4: new Series([])
|
|
15423
|
+
ohlc4: new Series([]),
|
|
15424
|
+
hlcc4: new Series([])
|
|
12957
15425
|
};
|
|
12958
15426
|
cache = {};
|
|
12959
15427
|
taState = {};
|
|
@@ -12980,6 +15448,7 @@ class Context {
|
|
|
12980
15448
|
limit;
|
|
12981
15449
|
sDate;
|
|
12982
15450
|
eDate;
|
|
15451
|
+
fullContext;
|
|
12983
15452
|
pineTSCode;
|
|
12984
15453
|
constructor({
|
|
12985
15454
|
marketData,
|
|
@@ -12988,7 +15457,8 @@ class Context {
|
|
|
12988
15457
|
timeframe,
|
|
12989
15458
|
limit,
|
|
12990
15459
|
sDate,
|
|
12991
|
-
eDate
|
|
15460
|
+
eDate,
|
|
15461
|
+
fullContext
|
|
12992
15462
|
}) {
|
|
12993
15463
|
this.marketData = marketData;
|
|
12994
15464
|
this.source = source;
|
|
@@ -12997,6 +15467,7 @@ class Context {
|
|
|
12997
15467
|
this.limit = limit;
|
|
12998
15468
|
this.sDate = sDate;
|
|
12999
15469
|
this.eDate = eDate;
|
|
15470
|
+
this.fullContext = fullContext || this;
|
|
13000
15471
|
const core = new Core(this);
|
|
13001
15472
|
const coreFunctions = {
|
|
13002
15473
|
plotchar: core.plotchar.bind(core),
|
|
@@ -13012,14 +15483,33 @@ class Context {
|
|
|
13012
15483
|
math: new PineMath(this),
|
|
13013
15484
|
request: new PineRequest(this),
|
|
13014
15485
|
array: new PineArray(this),
|
|
15486
|
+
map: new PineMap(this),
|
|
15487
|
+
matrix: new PineMatrix(this),
|
|
13015
15488
|
na: coreFunctions.na,
|
|
13016
15489
|
plotchar: coreFunctions.plotchar,
|
|
13017
15490
|
color: coreFunctions.color,
|
|
13018
15491
|
plot: coreFunctions.plot,
|
|
13019
15492
|
nz: coreFunctions.nz,
|
|
15493
|
+
syminfo: null,
|
|
15494
|
+
timeframe: new Timeframe(this),
|
|
15495
|
+
//FIXME : this is a temporary solution to get the barstate values,
|
|
15496
|
+
//we need to implement a better way to handle realtime states
|
|
15497
|
+
barstate: new Barstate(this),
|
|
13020
15498
|
get bar_index() {
|
|
13021
15499
|
return _this.idx;
|
|
13022
|
-
}
|
|
15500
|
+
},
|
|
15501
|
+
get last_bar_index() {
|
|
15502
|
+
return _this.data.close.length - 1;
|
|
15503
|
+
},
|
|
15504
|
+
get last_bar_time() {
|
|
15505
|
+
return _this.data.openTime.get(_this.data.openTime.length - 1);
|
|
15506
|
+
},
|
|
15507
|
+
get timenow() {
|
|
15508
|
+
return (/* @__PURE__ */ new Date()).getTime();
|
|
15509
|
+
},
|
|
15510
|
+
log: new Log(this),
|
|
15511
|
+
str: new Str(this),
|
|
15512
|
+
...types
|
|
13023
15513
|
};
|
|
13024
15514
|
}
|
|
13025
15515
|
//#region [Runtime functions] ===========================
|
|
@@ -13039,10 +15529,10 @@ class Context {
|
|
|
13039
15529
|
if (Array.isArray(src[0])) {
|
|
13040
15530
|
value = src[0];
|
|
13041
15531
|
} else {
|
|
13042
|
-
value =
|
|
15532
|
+
value = src[src.length - 1 + idx];
|
|
13043
15533
|
}
|
|
13044
15534
|
} else {
|
|
13045
|
-
value =
|
|
15535
|
+
value = src;
|
|
13046
15536
|
}
|
|
13047
15537
|
if (!trg) {
|
|
13048
15538
|
return new Series([value]);
|
|
@@ -13090,9 +15580,9 @@ class Context {
|
|
|
13090
15580
|
* @param decimals - the number of decimals to precision to
|
|
13091
15581
|
* @returns the precision number
|
|
13092
15582
|
*/
|
|
13093
|
-
precision(
|
|
13094
|
-
|
|
13095
|
-
return
|
|
15583
|
+
precision(value, decimals = 10) {
|
|
15584
|
+
const epsilon = 10 ** decimals;
|
|
15585
|
+
return typeof value === "number" ? Math.round(value * epsilon) / epsilon : value;
|
|
13096
15586
|
}
|
|
13097
15587
|
/**
|
|
13098
15588
|
* This function is used to apply special transformation to internal PineTS parameters and handle them as time-series
|
|
@@ -13253,6 +15743,7 @@ class PineTS {
|
|
|
13253
15743
|
const _hlc3 = marketData.map((d) => (d.high + d.low + d.close) / 3);
|
|
13254
15744
|
const _hl2 = marketData.map((d) => (d.high + d.low) / 2);
|
|
13255
15745
|
const _ohlc4 = marketData.map((d) => (d.high + d.low + d.open + d.close) / 4);
|
|
15746
|
+
const _hlcc4 = marketData.map((d) => (d.high + d.low + d.close + d.close) / 4);
|
|
13256
15747
|
const _openTime = marketData.map((d) => d.openTime);
|
|
13257
15748
|
const _closeTime = marketData.map((d) => d.closeTime);
|
|
13258
15749
|
this.open = _open;
|
|
@@ -13263,10 +15754,23 @@ class PineTS {
|
|
|
13263
15754
|
this.hl2 = _hl2;
|
|
13264
15755
|
this.hlc3 = _hlc3;
|
|
13265
15756
|
this.ohlc4 = _ohlc4;
|
|
15757
|
+
this.hlcc4 = _hlcc4;
|
|
13266
15758
|
this.openTime = _openTime;
|
|
13267
15759
|
this.closeTime = _closeTime;
|
|
13268
|
-
|
|
13269
|
-
|
|
15760
|
+
if (source && source.getSymbolInfo) {
|
|
15761
|
+
source.getSymbolInfo(tickerId).then((symbolInfo2) => {
|
|
15762
|
+
this._syminfo = symbolInfo2;
|
|
15763
|
+
this._ready = true;
|
|
15764
|
+
resolve(true);
|
|
15765
|
+
}).catch((error) => {
|
|
15766
|
+
console.warn("Failed to get symbol info, using default values:", error);
|
|
15767
|
+
this._ready = true;
|
|
15768
|
+
resolve(true);
|
|
15769
|
+
});
|
|
15770
|
+
} else {
|
|
15771
|
+
this._ready = true;
|
|
15772
|
+
resolve(true);
|
|
15773
|
+
}
|
|
13270
15774
|
});
|
|
13271
15775
|
});
|
|
13272
15776
|
}
|
|
@@ -13280,6 +15784,7 @@ class PineTS {
|
|
|
13280
15784
|
hl2 = [];
|
|
13281
15785
|
hlc3 = [];
|
|
13282
15786
|
ohlc4 = [];
|
|
15787
|
+
hlcc4 = [];
|
|
13283
15788
|
openTime = [];
|
|
13284
15789
|
closeTime = [];
|
|
13285
15790
|
//#endregion
|
|
@@ -13304,6 +15809,7 @@ class PineTS {
|
|
|
13304
15809
|
markAsSecondary() {
|
|
13305
15810
|
this._isSecondaryContext = true;
|
|
13306
15811
|
}
|
|
15812
|
+
_syminfo;
|
|
13307
15813
|
setDebugSettings({ ln, debug }) {
|
|
13308
15814
|
this._debugSettings.ln = ln;
|
|
13309
15815
|
this._debugSettings.debug = debug;
|
|
@@ -13384,6 +15890,7 @@ class PineTS {
|
|
|
13384
15890
|
}
|
|
13385
15891
|
this._removeLastResult(context);
|
|
13386
15892
|
processedUpToIdx = this.data.length - (newCandles + 1);
|
|
15893
|
+
context.pine.barstate.setLive();
|
|
13387
15894
|
}
|
|
13388
15895
|
}
|
|
13389
15896
|
/**
|
|
@@ -13413,7 +15920,8 @@ class PineTS {
|
|
|
13413
15920
|
timeframe: this.timeframe,
|
|
13414
15921
|
limit: this.limit,
|
|
13415
15922
|
sDate: this.sDate,
|
|
13416
|
-
eDate: this.eDate
|
|
15923
|
+
eDate: this.eDate,
|
|
15924
|
+
fullContext
|
|
13417
15925
|
});
|
|
13418
15926
|
pageContext.pineTSCode = fullContext.pineTSCode;
|
|
13419
15927
|
pageContext.idx = fullContext.idx;
|
|
@@ -13486,6 +15994,7 @@ class PineTS {
|
|
|
13486
15994
|
this.hl2[index] = (candle.high + candle.low) / 2;
|
|
13487
15995
|
this.hlc3[index] = (candle.high + candle.low + candle.close) / 3;
|
|
13488
15996
|
this.ohlc4[index] = (candle.high + candle.low + candle.open + candle.close) / 4;
|
|
15997
|
+
this.hlcc4[index] = (candle.high + candle.low + candle.close + candle.close) / 4;
|
|
13489
15998
|
this.openTime[index] = candle.openTime;
|
|
13490
15999
|
this.closeTime[index] = candle.closeTime;
|
|
13491
16000
|
}
|
|
@@ -13503,6 +16012,7 @@ class PineTS {
|
|
|
13503
16012
|
this.hl2.push((candle.high + candle.low) / 2);
|
|
13504
16013
|
this.hlc3.push((candle.high + candle.low + candle.close) / 3);
|
|
13505
16014
|
this.ohlc4.push((candle.high + candle.low + candle.open + candle.close) / 4);
|
|
16015
|
+
this.hlcc4.push((candle.high + candle.low + candle.close + candle.close) / 4);
|
|
13506
16016
|
this.openTime.push(candle.openTime);
|
|
13507
16017
|
this.closeTime.push(candle.closeTime);
|
|
13508
16018
|
}
|
|
@@ -13528,6 +16038,7 @@ class PineTS {
|
|
|
13528
16038
|
context.data.hl2.data.pop();
|
|
13529
16039
|
context.data.hlc3.data.pop();
|
|
13530
16040
|
context.data.ohlc4.data.pop();
|
|
16041
|
+
context.data.hlcc4.data.pop();
|
|
13531
16042
|
context.data.openTime.data.pop();
|
|
13532
16043
|
if (context.data.closeTime) {
|
|
13533
16044
|
context.data.closeTime.data.pop();
|
|
@@ -13547,6 +16058,7 @@ class PineTS {
|
|
|
13547
16058
|
sDate: this.sDate,
|
|
13548
16059
|
eDate: this.eDate
|
|
13549
16060
|
});
|
|
16061
|
+
context.pine.syminfo = this._syminfo;
|
|
13550
16062
|
context.pineTSCode = pineTSCode;
|
|
13551
16063
|
context.isSecondaryContext = isSecondary;
|
|
13552
16064
|
context.data.close = new Series([]);
|
|
@@ -13557,6 +16069,7 @@ class PineTS {
|
|
|
13557
16069
|
context.data.hl2 = new Series([]);
|
|
13558
16070
|
context.data.hlc3 = new Series([]);
|
|
13559
16071
|
context.data.ohlc4 = new Series([]);
|
|
16072
|
+
context.data.hlcc4 = new Series([]);
|
|
13560
16073
|
context.data.openTime = new Series([]);
|
|
13561
16074
|
context.data.closeTime = new Series([]);
|
|
13562
16075
|
return context;
|
|
@@ -13585,6 +16098,7 @@ class PineTS {
|
|
|
13585
16098
|
context.data.hl2.data.push(this.hl2[i]);
|
|
13586
16099
|
context.data.hlc3.data.push(this.hlc3[i]);
|
|
13587
16100
|
context.data.ohlc4.data.push(this.ohlc4[i]);
|
|
16101
|
+
context.data.hlcc4.data.push(this.hlcc4[i]);
|
|
13588
16102
|
context.data.openTime.data.push(this.openTime[i]);
|
|
13589
16103
|
context.data.closeTime.data.push(this.closeTime[i]);
|
|
13590
16104
|
const result = await transpiledFn(context);
|
|
@@ -13760,10 +16274,13 @@ class BinanceProvider {
|
|
|
13760
16274
|
}
|
|
13761
16275
|
async getMarketData(tickerId, timeframe, limit, sDate, eDate) {
|
|
13762
16276
|
try {
|
|
16277
|
+
const shouldCache = eDate !== void 0;
|
|
13763
16278
|
const cacheParams = { tickerId, timeframe, limit, sDate, eDate };
|
|
13764
|
-
|
|
13765
|
-
|
|
13766
|
-
|
|
16279
|
+
if (shouldCache) {
|
|
16280
|
+
const cachedData = this.cacheManager.get(cacheParams);
|
|
16281
|
+
if (cachedData) {
|
|
16282
|
+
return cachedData;
|
|
16283
|
+
}
|
|
13767
16284
|
}
|
|
13768
16285
|
const interval = timeframe_to_binance[timeframe.toUpperCase()];
|
|
13769
16286
|
if (!interval) {
|
|
@@ -13808,7 +16325,9 @@ class BinanceProvider {
|
|
|
13808
16325
|
ignore: item[11]
|
|
13809
16326
|
};
|
|
13810
16327
|
});
|
|
13811
|
-
|
|
16328
|
+
if (shouldCache) {
|
|
16329
|
+
this.cacheManager.set(cacheParams, data);
|
|
16330
|
+
}
|
|
13812
16331
|
return data;
|
|
13813
16332
|
} catch (error) {
|
|
13814
16333
|
console.error("Error in binance.klines:", error);
|
|
@@ -13845,12 +16364,113 @@ class BinanceProvider {
|
|
|
13845
16364
|
}
|
|
13846
16365
|
return false;
|
|
13847
16366
|
}
|
|
16367
|
+
async getSymbolInfo(tickerId) {
|
|
16368
|
+
try {
|
|
16369
|
+
let marketType = "crypto";
|
|
16370
|
+
let apiUrl = BINANCE_API_URL;
|
|
16371
|
+
let apiSymbol = tickerId;
|
|
16372
|
+
let contractType = "";
|
|
16373
|
+
if (tickerId.endsWith(".P")) {
|
|
16374
|
+
marketType = "futures";
|
|
16375
|
+
apiSymbol = tickerId.replace(".P", "");
|
|
16376
|
+
apiUrl = "https://fapi.binance.com/fapi/v1";
|
|
16377
|
+
contractType = "Perpetual";
|
|
16378
|
+
} else if (tickerId.includes("_")) {
|
|
16379
|
+
marketType = "futures";
|
|
16380
|
+
apiSymbol = tickerId;
|
|
16381
|
+
apiUrl = "https://dapi.binance.com/dapi/v1";
|
|
16382
|
+
contractType = "Delivery";
|
|
16383
|
+
}
|
|
16384
|
+
const url = marketType === "crypto" ? `${apiUrl}/exchangeInfo?symbol=${apiSymbol}` : `${apiUrl}/exchangeInfo`;
|
|
16385
|
+
const response = await fetch(url);
|
|
16386
|
+
if (!response.ok) {
|
|
16387
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
16388
|
+
}
|
|
16389
|
+
const result = await response.json();
|
|
16390
|
+
const symbols = result.symbols;
|
|
16391
|
+
if (!symbols || symbols.length === 0) {
|
|
16392
|
+
console.error(`Symbol ${tickerId} not found`);
|
|
16393
|
+
return null;
|
|
16394
|
+
}
|
|
16395
|
+
const symbolData = marketType === "futures" ? symbols.find((s) => s.symbol === apiSymbol) : symbols[0];
|
|
16396
|
+
if (!symbolData) {
|
|
16397
|
+
console.error(`Symbol ${apiSymbol} not found in exchange info`);
|
|
16398
|
+
return null;
|
|
16399
|
+
}
|
|
16400
|
+
const priceFilter = symbolData.filters?.find((f) => f.filterType === "PRICE_FILTER");
|
|
16401
|
+
const lotSizeFilter = symbolData.filters?.find((f) => f.filterType === "LOT_SIZE");
|
|
16402
|
+
const tickSize = priceFilter ? parseFloat(priceFilter.tickSize) : 0.01;
|
|
16403
|
+
const minQty = lotSizeFilter ? parseFloat(lotSizeFilter.minQty) : 0;
|
|
16404
|
+
const pricescale = Math.round(1 / tickSize);
|
|
16405
|
+
const baseAsset = symbolData.baseAsset;
|
|
16406
|
+
const quoteAsset = symbolData.quoteAsset;
|
|
16407
|
+
const typeLabel = contractType ? ` ${contractType}` : "";
|
|
16408
|
+
const description = `${baseAsset} / ${quoteAsset}${typeLabel}`;
|
|
16409
|
+
const symbolInfo = {
|
|
16410
|
+
// Symbol Identification
|
|
16411
|
+
ticker: tickerId,
|
|
16412
|
+
// KEEP ORIGINAL including .P if present!
|
|
16413
|
+
tickerid: `BINANCE:${tickerId}`,
|
|
16414
|
+
// Also keep .P here
|
|
16415
|
+
prefix: "BINANCE",
|
|
16416
|
+
root: baseAsset,
|
|
16417
|
+
// Just the base asset: "BTC"
|
|
16418
|
+
description,
|
|
16419
|
+
type: marketType,
|
|
16420
|
+
main_tickerid: `BINANCE:${tickerId}`,
|
|
16421
|
+
current_contract: contractType,
|
|
16422
|
+
isin: "",
|
|
16423
|
+
// Currency & Location
|
|
16424
|
+
basecurrency: baseAsset,
|
|
16425
|
+
currency: quoteAsset,
|
|
16426
|
+
timezone: "Etc/UTC",
|
|
16427
|
+
country: "",
|
|
16428
|
+
// Price & Contract Info
|
|
16429
|
+
mintick: tickSize,
|
|
16430
|
+
pricescale,
|
|
16431
|
+
minmove: 1,
|
|
16432
|
+
pointvalue: symbolData.contractSize || 1,
|
|
16433
|
+
mincontract: minQty,
|
|
16434
|
+
// Session & Market
|
|
16435
|
+
session: "24x7",
|
|
16436
|
+
volumetype: "base",
|
|
16437
|
+
expiration_date: symbolData.deliveryDate || 0,
|
|
16438
|
+
// Company Data (N/A for crypto)
|
|
16439
|
+
employees: 0,
|
|
16440
|
+
industry: "",
|
|
16441
|
+
sector: "",
|
|
16442
|
+
shareholders: 0,
|
|
16443
|
+
shares_outstanding_float: 0,
|
|
16444
|
+
shares_outstanding_total: 0,
|
|
16445
|
+
// Analyst Ratings (N/A for crypto)
|
|
16446
|
+
recommendations_buy: 0,
|
|
16447
|
+
recommendations_buy_strong: 0,
|
|
16448
|
+
recommendations_date: 0,
|
|
16449
|
+
recommendations_hold: 0,
|
|
16450
|
+
recommendations_sell: 0,
|
|
16451
|
+
recommendations_sell_strong: 0,
|
|
16452
|
+
recommendations_total: 0,
|
|
16453
|
+
// Price Targets (N/A for crypto)
|
|
16454
|
+
target_price_average: 0,
|
|
16455
|
+
target_price_date: 0,
|
|
16456
|
+
target_price_estimates: 0,
|
|
16457
|
+
target_price_high: 0,
|
|
16458
|
+
target_price_low: 0,
|
|
16459
|
+
target_price_median: 0
|
|
16460
|
+
};
|
|
16461
|
+
return symbolInfo;
|
|
16462
|
+
} catch (error) {
|
|
16463
|
+
console.error("Error in binance.exchangeInfo:", error);
|
|
16464
|
+
return null;
|
|
16465
|
+
}
|
|
16466
|
+
}
|
|
13848
16467
|
}
|
|
13849
16468
|
|
|
13850
16469
|
const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || new URL('pinets.dev.cjs', document.baseURI).href)));
|
|
13851
16470
|
const __dirname$1 = path__namespace.dirname(__filename$1);
|
|
13852
16471
|
class MockProvider {
|
|
13853
16472
|
dataCache = /* @__PURE__ */ new Map();
|
|
16473
|
+
exchangeInfoCache = {};
|
|
13854
16474
|
dataDirectory;
|
|
13855
16475
|
constructor(dataDirectory) {
|
|
13856
16476
|
if (dataDirectory) {
|
|
@@ -13987,11 +16607,132 @@ class MockProvider {
|
|
|
13987
16607
|
return [];
|
|
13988
16608
|
}
|
|
13989
16609
|
}
|
|
16610
|
+
/**
|
|
16611
|
+
* Loads exchange info from JSON file
|
|
16612
|
+
*/
|
|
16613
|
+
loadExchangeInfo(type) {
|
|
16614
|
+
if (this.exchangeInfoCache[type]) {
|
|
16615
|
+
return this.exchangeInfoCache[type];
|
|
16616
|
+
}
|
|
16617
|
+
const fileName = type === "spot" ? "api-exchangeInfo.json" : "fapi-exchangeInfo.json";
|
|
16618
|
+
const filePath = path__namespace.join(this.dataDirectory, fileName);
|
|
16619
|
+
if (!fs__namespace.existsSync(filePath)) {
|
|
16620
|
+
console.warn(`Exchange info file not found: ${filePath}`);
|
|
16621
|
+
return null;
|
|
16622
|
+
}
|
|
16623
|
+
try {
|
|
16624
|
+
const fileContent = fs__namespace.readFileSync(filePath, "utf-8");
|
|
16625
|
+
const data = JSON.parse(fileContent);
|
|
16626
|
+
this.exchangeInfoCache[type] = data;
|
|
16627
|
+
return data;
|
|
16628
|
+
} catch (error) {
|
|
16629
|
+
console.error(`Error loading exchange info from ${fileName}:`, error);
|
|
16630
|
+
return null;
|
|
16631
|
+
}
|
|
16632
|
+
}
|
|
16633
|
+
/**
|
|
16634
|
+
* Implements IProvider.getSymbolInfo
|
|
16635
|
+
*
|
|
16636
|
+
* @param tickerId - Symbol name (e.g., 'BTCUSDT' or 'BTCUSDT.P')
|
|
16637
|
+
* @returns Promise<ISymbolInfo> - Symbol information
|
|
16638
|
+
*/
|
|
16639
|
+
async getSymbolInfo(tickerId) {
|
|
16640
|
+
try {
|
|
16641
|
+
let marketType = "crypto";
|
|
16642
|
+
let apiSymbol = tickerId;
|
|
16643
|
+
let contractType = "";
|
|
16644
|
+
if (tickerId.endsWith(".P")) {
|
|
16645
|
+
marketType = "futures";
|
|
16646
|
+
apiSymbol = tickerId.replace(".P", "");
|
|
16647
|
+
contractType = "Perpetual";
|
|
16648
|
+
} else if (tickerId.includes("_")) {
|
|
16649
|
+
marketType = "futures";
|
|
16650
|
+
apiSymbol = tickerId;
|
|
16651
|
+
contractType = "Delivery";
|
|
16652
|
+
}
|
|
16653
|
+
const exchangeInfo = this.loadExchangeInfo(marketType === "futures" ? "futures" : "spot");
|
|
16654
|
+
if (!exchangeInfo || !exchangeInfo.symbols) {
|
|
16655
|
+
console.error(`Exchange info not available for ${marketType}`);
|
|
16656
|
+
return null;
|
|
16657
|
+
}
|
|
16658
|
+
const symbolData = exchangeInfo.symbols.find((s) => s.symbol === apiSymbol);
|
|
16659
|
+
if (!symbolData) {
|
|
16660
|
+
console.error(`Symbol ${apiSymbol} not found in ${marketType} exchange info`);
|
|
16661
|
+
return null;
|
|
16662
|
+
}
|
|
16663
|
+
const priceFilter = symbolData.filters?.find((f) => f.filterType === "PRICE_FILTER");
|
|
16664
|
+
const lotSizeFilter = symbolData.filters?.find((f) => f.filterType === "LOT_SIZE");
|
|
16665
|
+
const tickSize = priceFilter ? parseFloat(priceFilter.tickSize) : 0.01;
|
|
16666
|
+
const minQty = lotSizeFilter ? parseFloat(lotSizeFilter.minQty) : 0;
|
|
16667
|
+
const pricescale = Math.round(1 / tickSize);
|
|
16668
|
+
const baseAsset = symbolData.baseAsset;
|
|
16669
|
+
const quoteAsset = symbolData.quoteAsset;
|
|
16670
|
+
const typeLabel = contractType ? ` ${contractType}` : "";
|
|
16671
|
+
const description = `${baseAsset} / ${quoteAsset}${typeLabel}`;
|
|
16672
|
+
const symbolInfo = {
|
|
16673
|
+
// Symbol Identification
|
|
16674
|
+
ticker: tickerId,
|
|
16675
|
+
// KEEP ORIGINAL including .P if present!
|
|
16676
|
+
tickerid: `BINANCE:${tickerId}`,
|
|
16677
|
+
// Also keep .P here
|
|
16678
|
+
prefix: "BINANCE",
|
|
16679
|
+
root: baseAsset,
|
|
16680
|
+
// Just the base asset: "BTC"
|
|
16681
|
+
description,
|
|
16682
|
+
type: marketType,
|
|
16683
|
+
main_tickerid: `BINANCE:${tickerId}`,
|
|
16684
|
+
current_contract: contractType,
|
|
16685
|
+
isin: "",
|
|
16686
|
+
// Currency & Location
|
|
16687
|
+
basecurrency: baseAsset,
|
|
16688
|
+
currency: quoteAsset,
|
|
16689
|
+
timezone: "Etc/UTC",
|
|
16690
|
+
country: "",
|
|
16691
|
+
// Price & Contract Info
|
|
16692
|
+
mintick: tickSize,
|
|
16693
|
+
pricescale,
|
|
16694
|
+
minmove: 1,
|
|
16695
|
+
pointvalue: symbolData.contractSize || 1,
|
|
16696
|
+
mincontract: minQty,
|
|
16697
|
+
// Session & Market
|
|
16698
|
+
session: "24x7",
|
|
16699
|
+
volumetype: "base",
|
|
16700
|
+
expiration_date: symbolData.deliveryDate || 0,
|
|
16701
|
+
// Company Data (N/A for crypto)
|
|
16702
|
+
employees: 0,
|
|
16703
|
+
industry: "",
|
|
16704
|
+
sector: "",
|
|
16705
|
+
shareholders: 0,
|
|
16706
|
+
shares_outstanding_float: 0,
|
|
16707
|
+
shares_outstanding_total: 0,
|
|
16708
|
+
// Analyst Ratings (N/A for crypto)
|
|
16709
|
+
recommendations_buy: 0,
|
|
16710
|
+
recommendations_buy_strong: 0,
|
|
16711
|
+
recommendations_date: 0,
|
|
16712
|
+
recommendations_hold: 0,
|
|
16713
|
+
recommendations_sell: 0,
|
|
16714
|
+
recommendations_sell_strong: 0,
|
|
16715
|
+
recommendations_total: 0,
|
|
16716
|
+
// Price Targets (N/A for crypto)
|
|
16717
|
+
target_price_average: 0,
|
|
16718
|
+
target_price_date: 0,
|
|
16719
|
+
target_price_estimates: 0,
|
|
16720
|
+
target_price_high: 0,
|
|
16721
|
+
target_price_low: 0,
|
|
16722
|
+
target_price_median: 0
|
|
16723
|
+
};
|
|
16724
|
+
return symbolInfo;
|
|
16725
|
+
} catch (error) {
|
|
16726
|
+
console.error("Error in MockProvider.getSymbolInfo:", error);
|
|
16727
|
+
return null;
|
|
16728
|
+
}
|
|
16729
|
+
}
|
|
13990
16730
|
/**
|
|
13991
16731
|
* Clears the data cache
|
|
13992
16732
|
*/
|
|
13993
16733
|
clearCache() {
|
|
13994
16734
|
this.dataCache.clear();
|
|
16735
|
+
this.exchangeInfoCache = {};
|
|
13995
16736
|
}
|
|
13996
16737
|
/**
|
|
13997
16738
|
* Sets a custom data directory
|