@syncfusion/ej2-calculate 35.1.37
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/.eslintrc.json +263 -0
- package/README.md +132 -0
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/common.d.ts +4 -0
- package/common.js +4 -0
- package/dist/ej2-calculate.umd.min.js +11 -0
- package/dist/ej2-calculate.umd.min.js.map +1 -0
- package/dist/es6/ej2-calculate.es2015.js +24801 -0
- package/dist/es6/ej2-calculate.es2015.js.map +1 -0
- package/dist/es6/ej2-calculate.es5.js +27229 -0
- package/dist/es6/ej2-calculate.es5.js.map +1 -0
- package/dist/global/ej2-calculate.min.js +11 -0
- package/dist/global/ej2-calculate.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/formulas.d.ts +4 -0
- package/formulas.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -0
- package/src/base/calculate-model.d.ts +4 -0
- package/src/base/calculate-model.js +0 -0
- package/src/base/calculate.d.ts +1105 -0
- package/src/base/calculate.js +4720 -0
- package/src/base/index.d.ts +8 -0
- package/src/base/index.js +7 -0
- package/src/base/parser.d.ts +208 -0
- package/src/base/parser.js +1512 -0
- package/src/common/address.d.ts +59 -0
- package/src/common/address.js +96 -0
- package/src/common/cell-ref.d.ts +32 -0
- package/src/common/cell-ref.js +112 -0
- package/src/common/common.d.ts +44 -0
- package/src/common/common.js +134 -0
- package/src/common/enum.d.ts +94 -0
- package/src/common/enum.js +97 -0
- package/src/common/index.d.ts +9 -0
- package/src/common/index.js +8 -0
- package/src/common/interface.d.ts +122 -0
- package/src/common/interface.js +0 -0
- package/src/common/l10n.d.ts +24 -0
- package/src/common/l10n.js +54 -0
- package/src/common/number-date.d.ts +26 -0
- package/src/common/number-date.js +38 -0
- package/src/common/sheet-info.d.ts +10 -0
- package/src/common/sheet-info.js +17 -0
- package/src/common/sort.d.ts +17 -0
- package/src/common/sort.js +44 -0
- package/src/formulas/array.d.ts +47 -0
- package/src/formulas/array.js +718 -0
- package/src/formulas/basic.d.ts +47 -0
- package/src/formulas/basic.js +181 -0
- package/src/formulas/complex-numbers.d.ts +207 -0
- package/src/formulas/complex-numbers.js +549 -0
- package/src/formulas/database.d.ts +152 -0
- package/src/formulas/database.js +579 -0
- package/src/formulas/date-time-extra.d.ts +97 -0
- package/src/formulas/date-time-extra.js +415 -0
- package/src/formulas/date-time-intl.d.ts +57 -0
- package/src/formulas/date-time-intl.js +309 -0
- package/src/formulas/date-time.d.ts +164 -0
- package/src/formulas/date-time.js +1021 -0
- package/src/formulas/engineering-base.d.ts +150 -0
- package/src/formulas/engineering-base.js +404 -0
- package/src/formulas/engineering-bessel.d.ts +65 -0
- package/src/formulas/engineering-bessel.js +167 -0
- package/src/formulas/engineering-convert.d.ts +35 -0
- package/src/formulas/engineering-convert.js +120 -0
- package/src/formulas/engineering-misc.d.ts +64 -0
- package/src/formulas/engineering-misc.js +168 -0
- package/src/formulas/financial-amortization-ecma.d.ts +87 -0
- package/src/formulas/financial-amortization-ecma.js +288 -0
- package/src/formulas/financial-annuity.d.ts +104 -0
- package/src/formulas/financial-annuity.js +419 -0
- package/src/formulas/financial-bond-helpers.d.ts +106 -0
- package/src/formulas/financial-bond-helpers.js +190 -0
- package/src/formulas/financial-cashflow.d.ts +47 -0
- package/src/formulas/financial-cashflow.js +203 -0
- package/src/formulas/financial-coupons.d.ts +227 -0
- package/src/formulas/financial-coupons.js +810 -0
- package/src/formulas/financial-depreciation.d.ts +64 -0
- package/src/formulas/financial-depreciation.js +247 -0
- package/src/formulas/financial-rates.d.ts +54 -0
- package/src/formulas/financial-rates.js +140 -0
- package/src/formulas/financial-securities.d.ts +126 -0
- package/src/formulas/financial-securities.js +488 -0
- package/src/formulas/formula-math-helpers.d.ts +212 -0
- package/src/formulas/formula-math-helpers.js +599 -0
- package/src/formulas/formula-module-base.d.ts +54 -0
- package/src/formulas/formula-module-base.js +125 -0
- package/src/formulas/formula-owner.d.ts +17 -0
- package/src/formulas/formula-owner.js +0 -0
- package/src/formulas/index.d.ts +68 -0
- package/src/formulas/index.js +67 -0
- package/src/formulas/information-advanced.d.ts +44 -0
- package/src/formulas/information-advanced.js +157 -0
- package/src/formulas/information-ecma.d.ts +33 -0
- package/src/formulas/information-ecma.js +88 -0
- package/src/formulas/information-extra.d.ts +146 -0
- package/src/formulas/information-extra.js +351 -0
- package/src/formulas/information.d.ts +34 -0
- package/src/formulas/information.js +78 -0
- package/src/formulas/logical-extra.d.ts +75 -0
- package/src/formulas/logical-extra.js +217 -0
- package/src/formulas/logical.d.ts +83 -0
- package/src/formulas/logical.js +296 -0
- package/src/formulas/lookup-array.d.ts +98 -0
- package/src/formulas/lookup-array.js +364 -0
- package/src/formulas/lookup-ref-extra.d.ts +64 -0
- package/src/formulas/lookup-ref-extra.js +180 -0
- package/src/formulas/lookup-ref.d.ts +84 -0
- package/src/formulas/lookup-ref.js +263 -0
- package/src/formulas/lookup.d.ts +114 -0
- package/src/formulas/lookup.js +881 -0
- package/src/formulas/math-aggregate.d.ts +74 -0
- package/src/formulas/math-aggregate.js +376 -0
- package/src/formulas/math-ceiling-ecma.d.ts +42 -0
- package/src/formulas/math-ceiling-ecma.js +123 -0
- package/src/formulas/math-combinatorics.d.ts +75 -0
- package/src/formulas/math-combinatorics.js +290 -0
- package/src/formulas/math-misc.d.ts +164 -0
- package/src/formulas/math-misc.js +889 -0
- package/src/formulas/math-number.d.ts +76 -0
- package/src/formulas/math-number.js +261 -0
- package/src/formulas/math-rounding.d.ts +115 -0
- package/src/formulas/math-rounding.js +728 -0
- package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
- package/src/formulas/math-trig-hyperbolic.js +113 -0
- package/src/formulas/math-trig.d.ts +165 -0
- package/src/formulas/math-trig.js +334 -0
- package/src/formulas/matrix-base.d.ts +13 -0
- package/src/formulas/matrix-base.js +169 -0
- package/src/formulas/matrix.d.ts +64 -0
- package/src/formulas/matrix.js +161 -0
- package/src/formulas/regression-ecma.d.ts +66 -0
- package/src/formulas/regression-ecma.js +234 -0
- package/src/formulas/statistical-advanced.d.ts +125 -0
- package/src/formulas/statistical-advanced.js +756 -0
- package/src/formulas/statistical-correlation.d.ts +75 -0
- package/src/formulas/statistical-correlation.js +198 -0
- package/src/formulas/statistical-dispersion.d.ts +108 -0
- package/src/formulas/statistical-dispersion.js +337 -0
- package/src/formulas/statistical-distribution-extended.d.ts +176 -0
- package/src/formulas/statistical-distribution-extended.js +668 -0
- package/src/formulas/statistical-distribution.d.ts +104 -0
- package/src/formulas/statistical-distribution.js +368 -0
- package/src/formulas/statistical-ecma.d.ts +95 -0
- package/src/formulas/statistical-ecma.js +392 -0
- package/src/formulas/statistical-extended.d.ts +136 -0
- package/src/formulas/statistical-extended.js +340 -0
- package/src/formulas/statistical-ifs.d.ts +46 -0
- package/src/formulas/statistical-ifs.js +180 -0
- package/src/formulas/statistical-moments.d.ts +84 -0
- package/src/formulas/statistical-moments.js +269 -0
- package/src/formulas/statistical-percentile.d.ts +56 -0
- package/src/formulas/statistical-percentile.js +195 -0
- package/src/formulas/statistical-sample-base.d.ts +14 -0
- package/src/formulas/statistical-sample-base.js +124 -0
- package/src/formulas/statistical.d.ts +135 -0
- package/src/formulas/statistical.js +542 -0
- package/src/formulas/text-advanced.d.ts +64 -0
- package/src/formulas/text-advanced.js +222 -0
- package/src/formulas/text-ecma.d.ts +54 -0
- package/src/formulas/text-ecma.js +106 -0
- package/src/formulas/text-extra.d.ts +216 -0
- package/src/formulas/text-extra.js +657 -0
- package/src/formulas/text.d.ts +125 -0
- package/src/formulas/text.js +628 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +14 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { FormulasErrorsStrings, CommonErrors } from '../common/index';
|
|
15
|
+
import { isNullOrUndefined } from '@syncfusion/ej2-base';
|
|
16
|
+
import { StatisticalSampleBase } from './statistical-sample-base';
|
|
17
|
+
/**
|
|
18
|
+
* Distribution shape metrics: skewness, kurtosis, and moment-based descriptive statistics.
|
|
19
|
+
*
|
|
20
|
+
* Registered functions: AVEDEV, DEVSQ, HARMEAN, SKEW, KURT, STANDARDIZE.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var StatisticalMomentsFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(StatisticalMomentsFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function StatisticalMomentsFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'AVEDEV', category: 'Statistical', description: 'Returns the average of the absolute deviations of data points from their mean.' },
|
|
35
|
+
{ formulaName: 'DEVSQ', category: 'Statistical', description: 'Returns the sum of squares of deviations.' },
|
|
36
|
+
{ formulaName: 'HARMEAN', category: 'Statistical', description: 'Returns the harmonic mean.' },
|
|
37
|
+
{ formulaName: 'SKEW', category: 'Statistical', description: 'Returns the skewness of a distribution.' },
|
|
38
|
+
{ formulaName: 'KURT', category: 'Statistical', description: 'Returns the kurtosis of a data set.' },
|
|
39
|
+
{ formulaName: 'STANDARDIZE', category: 'Statistical', description: 'Returns a normalized value from a distribution.' }
|
|
40
|
+
];
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the average of the absolute deviations of data points from their mean.
|
|
45
|
+
*
|
|
46
|
+
* Excel: `AVEDEV(...)`.
|
|
47
|
+
*
|
|
48
|
+
* @hidden
|
|
49
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
50
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* engine.computeFormula('=AVEDEV(1)');
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
StatisticalMomentsFormulas.prototype.ComputeAVEDEV = function () {
|
|
58
|
+
var args = [];
|
|
59
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
60
|
+
args[_i] = arguments[_i];
|
|
61
|
+
}
|
|
62
|
+
var errCollection = this.parent.getErrorStrings();
|
|
63
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
64
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
65
|
+
}
|
|
66
|
+
var nums = this.collectSample(args);
|
|
67
|
+
if (typeof nums === 'string') {
|
|
68
|
+
return nums;
|
|
69
|
+
}
|
|
70
|
+
if (nums.length === 0) {
|
|
71
|
+
return errCollection[CommonErrors.DivZero];
|
|
72
|
+
}
|
|
73
|
+
var avg = this.mean(nums);
|
|
74
|
+
var sum = 0;
|
|
75
|
+
for (var i = 0; i < nums.length; i++) {
|
|
76
|
+
sum += Math.abs(nums[i] - avg);
|
|
77
|
+
}
|
|
78
|
+
return (sum / nums.length).toString();
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Returns the sum of squares of deviations.
|
|
82
|
+
*
|
|
83
|
+
* Excel: `DEVSQ(...)`.
|
|
84
|
+
*
|
|
85
|
+
* @hidden
|
|
86
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
87
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
88
|
+
*/
|
|
89
|
+
StatisticalMomentsFormulas.prototype.ComputeDEVSQ = function () {
|
|
90
|
+
var args = [];
|
|
91
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
92
|
+
args[_i] = arguments[_i];
|
|
93
|
+
}
|
|
94
|
+
var errCollection = this.parent.getErrorStrings();
|
|
95
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
96
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
97
|
+
}
|
|
98
|
+
var nums = this.collectSample(args);
|
|
99
|
+
if (typeof nums === 'string') {
|
|
100
|
+
return nums;
|
|
101
|
+
}
|
|
102
|
+
if (nums.length === 0) {
|
|
103
|
+
return errCollection[CommonErrors.DivZero];
|
|
104
|
+
}
|
|
105
|
+
var avg = this.mean(nums);
|
|
106
|
+
var sum = 0;
|
|
107
|
+
for (var i = 0; i < nums.length; i++) {
|
|
108
|
+
var d = nums[i] - avg;
|
|
109
|
+
sum += d * d;
|
|
110
|
+
}
|
|
111
|
+
return sum.toString();
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Returns the harmonic mean.
|
|
115
|
+
*
|
|
116
|
+
* Excel: `HARMEAN(...)`.
|
|
117
|
+
*
|
|
118
|
+
* @hidden
|
|
119
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
120
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
121
|
+
*/
|
|
122
|
+
StatisticalMomentsFormulas.prototype.ComputeHARMEAN = function () {
|
|
123
|
+
var args = [];
|
|
124
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
125
|
+
args[_i] = arguments[_i];
|
|
126
|
+
}
|
|
127
|
+
var errCollection = this.parent.getErrorStrings();
|
|
128
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
129
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
130
|
+
}
|
|
131
|
+
var nums = this.collectSample(args);
|
|
132
|
+
if (typeof nums === 'string') {
|
|
133
|
+
return nums;
|
|
134
|
+
}
|
|
135
|
+
if (nums.length === 0) {
|
|
136
|
+
return errCollection[CommonErrors.DivZero];
|
|
137
|
+
}
|
|
138
|
+
var sumInv = 0;
|
|
139
|
+
for (var i = 0; i < nums.length; i++) {
|
|
140
|
+
if (nums[i] <= 0) {
|
|
141
|
+
return errCollection[CommonErrors.Num];
|
|
142
|
+
}
|
|
143
|
+
sumInv += 1 / nums[i];
|
|
144
|
+
}
|
|
145
|
+
return (nums.length / sumInv).toString();
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Returns the skewness of a distribution.
|
|
149
|
+
*
|
|
150
|
+
* Excel: `SKEW(...)`.
|
|
151
|
+
*
|
|
152
|
+
* @hidden
|
|
153
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
154
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
155
|
+
*/
|
|
156
|
+
StatisticalMomentsFormulas.prototype.ComputeSKEW = function () {
|
|
157
|
+
var args = [];
|
|
158
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
159
|
+
args[_i] = arguments[_i];
|
|
160
|
+
}
|
|
161
|
+
var errCollection = this.parent.getErrorStrings();
|
|
162
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
163
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
164
|
+
}
|
|
165
|
+
var nums = this.collectSample(args);
|
|
166
|
+
if (typeof nums === 'string') {
|
|
167
|
+
return nums;
|
|
168
|
+
}
|
|
169
|
+
var n = nums.length;
|
|
170
|
+
if (n < 3) {
|
|
171
|
+
return errCollection[CommonErrors.DivZero];
|
|
172
|
+
}
|
|
173
|
+
var avg = this.mean(nums);
|
|
174
|
+
var m2 = 0;
|
|
175
|
+
var m3 = 0;
|
|
176
|
+
for (var i = 0; i < n; i++) {
|
|
177
|
+
var d = nums[i] - avg;
|
|
178
|
+
m2 += d * d;
|
|
179
|
+
m3 += d * d * d;
|
|
180
|
+
}
|
|
181
|
+
m2 /= n;
|
|
182
|
+
m3 /= n;
|
|
183
|
+
if (m2 === 0) {
|
|
184
|
+
return errCollection[CommonErrors.DivZero];
|
|
185
|
+
}
|
|
186
|
+
var skew = m3 / Math.pow(m2, 1.5) * Math.sqrt(n * (n - 1)) / (n - 2);
|
|
187
|
+
return skew.toString();
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Returns the kurtosis of a data set.
|
|
191
|
+
*
|
|
192
|
+
* Excel: `KURT(...)`.
|
|
193
|
+
*
|
|
194
|
+
* @hidden
|
|
195
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
196
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
197
|
+
*/
|
|
198
|
+
StatisticalMomentsFormulas.prototype.ComputeKURT = function () {
|
|
199
|
+
var args = [];
|
|
200
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
201
|
+
args[_i] = arguments[_i];
|
|
202
|
+
}
|
|
203
|
+
var errCollection = this.parent.getErrorStrings();
|
|
204
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
205
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
206
|
+
}
|
|
207
|
+
var nums = this.collectSample(args);
|
|
208
|
+
if (typeof nums === 'string') {
|
|
209
|
+
return nums;
|
|
210
|
+
}
|
|
211
|
+
var n = nums.length;
|
|
212
|
+
if (n < 4) {
|
|
213
|
+
return errCollection[CommonErrors.DivZero];
|
|
214
|
+
}
|
|
215
|
+
var avg = this.mean(nums);
|
|
216
|
+
var m2 = 0;
|
|
217
|
+
var m4 = 0;
|
|
218
|
+
for (var i = 0; i < n; i++) {
|
|
219
|
+
var d = nums[i] - avg;
|
|
220
|
+
m2 += d * d;
|
|
221
|
+
m4 += d * d * d * d;
|
|
222
|
+
}
|
|
223
|
+
m2 /= n;
|
|
224
|
+
m4 /= n;
|
|
225
|
+
if (m2 === 0) {
|
|
226
|
+
return errCollection[CommonErrors.DivZero];
|
|
227
|
+
}
|
|
228
|
+
var kurt = (n * (n + 1) / ((n - 1) * (n - 2) * (n - 3))) * (m4 / (m2 * m2))
|
|
229
|
+
- (3 * (n - 1) * (n - 1)) / ((n - 2) * (n - 3));
|
|
230
|
+
return kurt.toString();
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Returns a normalized value from a distribution.
|
|
234
|
+
*
|
|
235
|
+
* Excel: `STANDARDIZE(...)`.
|
|
236
|
+
*
|
|
237
|
+
* @hidden
|
|
238
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
239
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
240
|
+
*/
|
|
241
|
+
StatisticalMomentsFormulas.prototype.ComputeSTANDARDIZE = function () {
|
|
242
|
+
var args = [];
|
|
243
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
244
|
+
args[_i] = arguments[_i];
|
|
245
|
+
}
|
|
246
|
+
var errCollection = this.parent.getErrorStrings();
|
|
247
|
+
if (isNullOrUndefined(args) || args.length !== 3) {
|
|
248
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
249
|
+
}
|
|
250
|
+
var x = this.resolveNumberArg(args[0]);
|
|
251
|
+
var mean = this.resolveNumberArg(args[1]);
|
|
252
|
+
var std = this.resolveNumberArg(args[2]);
|
|
253
|
+
if (typeof x === 'string') {
|
|
254
|
+
return x;
|
|
255
|
+
}
|
|
256
|
+
if (typeof mean === 'string') {
|
|
257
|
+
return mean;
|
|
258
|
+
}
|
|
259
|
+
if (typeof std === 'string') {
|
|
260
|
+
return std;
|
|
261
|
+
}
|
|
262
|
+
if (std <= 0) {
|
|
263
|
+
return errCollection[CommonErrors.Num];
|
|
264
|
+
}
|
|
265
|
+
return ((x - mean) / std).toString();
|
|
266
|
+
};
|
|
267
|
+
return StatisticalMomentsFormulas;
|
|
268
|
+
}(StatisticalSampleBase));
|
|
269
|
+
export { StatisticalMomentsFormulas };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { StatisticalSampleBase } from './statistical-sample-base';
|
|
4
|
+
/**
|
|
5
|
+
* Percentile, quartile, and rank position functions for ordered data sets.
|
|
6
|
+
*
|
|
7
|
+
* Registered functions: PERCENTILE, PERCENTRANK, QUARTILE.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class StatisticalPercentileFormulas extends StatisticalSampleBase {
|
|
12
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
13
|
+
formulas: IBasicFormula[];
|
|
14
|
+
/**
|
|
15
|
+
* @hidden
|
|
16
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
17
|
+
*/
|
|
18
|
+
constructor(owner: FormulaOwner);
|
|
19
|
+
private sortedSample;
|
|
20
|
+
private percentile;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the k-th percentile of values in a range.
|
|
23
|
+
*
|
|
24
|
+
* Excel: `PERCENTILE(...)`.
|
|
25
|
+
*
|
|
26
|
+
* @hidden
|
|
27
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
28
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* engine.computeFormula('=PERCENTILE(1)');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
ComputePERCENTILE(...args: string[]): string | number;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the percentage rank of a value in a data set.
|
|
38
|
+
*
|
|
39
|
+
* Excel: `PERCENTRANK(...)`.
|
|
40
|
+
*
|
|
41
|
+
* @hidden
|
|
42
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
43
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
44
|
+
*/
|
|
45
|
+
ComputePERCENTRANK(...args: string[]): string | number;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the quartile of a data set.
|
|
48
|
+
*
|
|
49
|
+
* Excel: `QUARTILE(...)`.
|
|
50
|
+
*
|
|
51
|
+
* @hidden
|
|
52
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
53
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
54
|
+
*/
|
|
55
|
+
ComputeQUARTILE(...args: string[]): string | number;
|
|
56
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { FormulasErrorsStrings, CommonErrors } from '../common/index';
|
|
15
|
+
import { isNullOrUndefined } from '@syncfusion/ej2-base';
|
|
16
|
+
import { StatisticalSampleBase } from './statistical-sample-base';
|
|
17
|
+
/**
|
|
18
|
+
* Percentile, quartile, and rank position functions for ordered data sets.
|
|
19
|
+
*
|
|
20
|
+
* Registered functions: PERCENTILE, PERCENTRANK, QUARTILE.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var StatisticalPercentileFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(StatisticalPercentileFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function StatisticalPercentileFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'PERCENTILE', category: 'Statistical', description: 'Returns the k-th percentile of values in a range.' },
|
|
35
|
+
{ formulaName: 'PERCENTRANK', category: 'Statistical', description: 'Returns the percentage rank of a value in a data set.' },
|
|
36
|
+
{ formulaName: 'QUARTILE', category: 'Statistical', description: 'Returns the quartile of a data set.' }
|
|
37
|
+
];
|
|
38
|
+
return _this;
|
|
39
|
+
}
|
|
40
|
+
StatisticalPercentileFormulas.prototype.sortedSample = function (args) {
|
|
41
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
42
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
43
|
+
}
|
|
44
|
+
var nums = this.collectSample(args);
|
|
45
|
+
if (typeof nums === 'string') {
|
|
46
|
+
return nums;
|
|
47
|
+
}
|
|
48
|
+
return nums.slice().sort(function (a, b) { return a - b; });
|
|
49
|
+
};
|
|
50
|
+
StatisticalPercentileFormulas.prototype.percentile = function (sorted, k) {
|
|
51
|
+
var errCollection = this.parent.getErrorStrings();
|
|
52
|
+
if (k < 0 || k > 1) {
|
|
53
|
+
return errCollection[CommonErrors.Num];
|
|
54
|
+
}
|
|
55
|
+
if (sorted.length === 0) {
|
|
56
|
+
return errCollection[CommonErrors.Num];
|
|
57
|
+
}
|
|
58
|
+
var n = sorted.length;
|
|
59
|
+
var pos = k * (n - 1);
|
|
60
|
+
var lower = Math.floor(pos);
|
|
61
|
+
var frac = pos - lower;
|
|
62
|
+
if (lower >= n - 1) {
|
|
63
|
+
return sorted[n - 1];
|
|
64
|
+
}
|
|
65
|
+
return sorted[lower] + frac * (sorted[lower + 1] - sorted[lower]);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Returns the k-th percentile of values in a range.
|
|
69
|
+
*
|
|
70
|
+
* Excel: `PERCENTILE(...)`.
|
|
71
|
+
*
|
|
72
|
+
* @hidden
|
|
73
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
74
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* engine.computeFormula('=PERCENTILE(1)');
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
StatisticalPercentileFormulas.prototype.ComputePERCENTILE = function () {
|
|
82
|
+
var args = [];
|
|
83
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
84
|
+
args[_i] = arguments[_i];
|
|
85
|
+
}
|
|
86
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
87
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
88
|
+
}
|
|
89
|
+
var k = this.resolveNumberArg(args[1]);
|
|
90
|
+
if (typeof k === 'string') {
|
|
91
|
+
return k;
|
|
92
|
+
}
|
|
93
|
+
var sorted = this.sortedSample([args[0]]);
|
|
94
|
+
if (typeof sorted === 'string') {
|
|
95
|
+
return sorted;
|
|
96
|
+
}
|
|
97
|
+
var result = this.percentile(sorted, k);
|
|
98
|
+
return typeof result === 'string' ? result : result.toString();
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Returns the percentage rank of a value in a data set.
|
|
102
|
+
*
|
|
103
|
+
* Excel: `PERCENTRANK(...)`.
|
|
104
|
+
*
|
|
105
|
+
* @hidden
|
|
106
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
107
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
108
|
+
*/
|
|
109
|
+
StatisticalPercentileFormulas.prototype.ComputePERCENTRANK = function () {
|
|
110
|
+
var args = [];
|
|
111
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
112
|
+
args[_i] = arguments[_i];
|
|
113
|
+
}
|
|
114
|
+
var errCollection = this.parent.getErrorStrings();
|
|
115
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
116
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
117
|
+
}
|
|
118
|
+
var x = this.resolveNumberArg(args[0]);
|
|
119
|
+
if (typeof x === 'string') {
|
|
120
|
+
return x;
|
|
121
|
+
}
|
|
122
|
+
var sorted = this.sortedSample([args[1]]);
|
|
123
|
+
if (typeof sorted === 'string') {
|
|
124
|
+
return sorted;
|
|
125
|
+
}
|
|
126
|
+
if (sorted.length === 0) {
|
|
127
|
+
return errCollection[CommonErrors.Num];
|
|
128
|
+
}
|
|
129
|
+
var lower = 0;
|
|
130
|
+
var upper = 1;
|
|
131
|
+
if (args.length === 3) {
|
|
132
|
+
var sig = this.resolveNumberArg(args[2]);
|
|
133
|
+
if (typeof sig === 'string') {
|
|
134
|
+
return sig;
|
|
135
|
+
}
|
|
136
|
+
lower = sig;
|
|
137
|
+
upper = 1 - sig;
|
|
138
|
+
}
|
|
139
|
+
if (x < sorted[0]) {
|
|
140
|
+
return lower.toString();
|
|
141
|
+
}
|
|
142
|
+
if (x > sorted[sorted.length - 1]) {
|
|
143
|
+
return upper.toString();
|
|
144
|
+
}
|
|
145
|
+
var rank = 0;
|
|
146
|
+
for (var i = 0; i < sorted.length; i++) {
|
|
147
|
+
if (sorted[i] === x) {
|
|
148
|
+
rank = i / (sorted.length - 1 || 1);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
if (sorted[i] > x) {
|
|
152
|
+
var frac = (x - sorted[i - 1]) / (sorted[i] - sorted[i - 1]);
|
|
153
|
+
rank = (i - 1 + frac) / (sorted.length - 1);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return rank.toString();
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Returns the quartile of a data set.
|
|
161
|
+
*
|
|
162
|
+
* Excel: `QUARTILE(...)`.
|
|
163
|
+
*
|
|
164
|
+
* @hidden
|
|
165
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
166
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
167
|
+
*/
|
|
168
|
+
StatisticalPercentileFormulas.prototype.ComputeQUARTILE = function () {
|
|
169
|
+
var args = [];
|
|
170
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
171
|
+
args[_i] = arguments[_i];
|
|
172
|
+
}
|
|
173
|
+
var errCollection = this.parent.getErrorStrings();
|
|
174
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
175
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
176
|
+
}
|
|
177
|
+
var quart = this.resolveNumberArg(args[1]);
|
|
178
|
+
if (typeof quart === 'string') {
|
|
179
|
+
return quart;
|
|
180
|
+
}
|
|
181
|
+
var q = Math.floor(quart);
|
|
182
|
+
if (q < 0 || q > 4) {
|
|
183
|
+
return errCollection[CommonErrors.Num];
|
|
184
|
+
}
|
|
185
|
+
var kMap = { 0: 0, 1: 0.25, 2: 0.5, 3: 0.75, 4: 1 };
|
|
186
|
+
var sorted = this.sortedSample([args[0]]);
|
|
187
|
+
if (typeof sorted === 'string') {
|
|
188
|
+
return sorted;
|
|
189
|
+
}
|
|
190
|
+
var result = this.percentile(sorted, kMap[q]);
|
|
191
|
+
return typeof result === 'string' ? result : result.toString();
|
|
192
|
+
};
|
|
193
|
+
return StatisticalPercentileFormulas;
|
|
194
|
+
}(StatisticalSampleBase));
|
|
195
|
+
export { StatisticalPercentileFormulas };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
2
|
+
/**
|
|
3
|
+
* Shared sample collection for statistical formula modules.
|
|
4
|
+
*
|
|
5
|
+
* @hidden
|
|
6
|
+
*/
|
|
7
|
+
export declare class StatisticalSampleBase extends FormulaModuleBase {
|
|
8
|
+
protected collectSample(args: string[], includeTextAsZero?: boolean): number[] | string;
|
|
9
|
+
protected collectPair(args: string[]): {
|
|
10
|
+
x: number[];
|
|
11
|
+
y: number[];
|
|
12
|
+
} | string;
|
|
13
|
+
protected mean(nums: number[]): number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { FormulasErrorsStrings, CommonErrors } from '../common/index';
|
|
15
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
16
|
+
/**
|
|
17
|
+
* Shared sample collection for statistical formula modules.
|
|
18
|
+
*
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
var StatisticalSampleBase = /** @class */ (function (_super) {
|
|
22
|
+
__extends(StatisticalSampleBase, _super);
|
|
23
|
+
function StatisticalSampleBase() {
|
|
24
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
25
|
+
}
|
|
26
|
+
StatisticalSampleBase.prototype.collectSample = function (args, includeTextAsZero) {
|
|
27
|
+
if (includeTextAsZero === void 0) { includeTextAsZero = false; }
|
|
28
|
+
var errCollection = this.parent.getErrorStrings();
|
|
29
|
+
var nums = [];
|
|
30
|
+
for (var i = 0; i < args.length; i++) {
|
|
31
|
+
var arg = args[i];
|
|
32
|
+
if (arg === '') {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (this.parent.isCellReference(arg) && arg.indexOf(':') > -1) {
|
|
36
|
+
var cells = this.parent.getCellCollection(arg);
|
|
37
|
+
var list = Array.isArray(cells) ? cells : [cells];
|
|
38
|
+
for (var c = 0; c < list.length; c++) {
|
|
39
|
+
var val = this.parent.getValueFromArg(list[c]);
|
|
40
|
+
if (errCollection.indexOf(val) > -1) {
|
|
41
|
+
return val;
|
|
42
|
+
}
|
|
43
|
+
if (val === '') {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
var upper = val.toUpperCase();
|
|
47
|
+
if (upper === this.parent.trueValue) {
|
|
48
|
+
nums.push(1);
|
|
49
|
+
}
|
|
50
|
+
else if (upper === this.parent.falseValue) {
|
|
51
|
+
nums.push(0);
|
|
52
|
+
}
|
|
53
|
+
else if (this.parent.isNumber(val)) {
|
|
54
|
+
nums.push(this.parent.parseFloat(val));
|
|
55
|
+
}
|
|
56
|
+
else if (includeTextAsZero) {
|
|
57
|
+
nums.push(0);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
var val = this.parent.getValueFromArg(arg);
|
|
63
|
+
if (errCollection.indexOf(val) > -1) {
|
|
64
|
+
return val;
|
|
65
|
+
}
|
|
66
|
+
var upper = val.toUpperCase();
|
|
67
|
+
if (upper === this.parent.trueValue) {
|
|
68
|
+
nums.push(1);
|
|
69
|
+
}
|
|
70
|
+
else if (upper === this.parent.falseValue) {
|
|
71
|
+
nums.push(0);
|
|
72
|
+
}
|
|
73
|
+
else if (val === '') {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
else if (this.parent.isNumber(this.parent.removeTics(val))) {
|
|
77
|
+
nums.push(this.parent.parseFloat(this.parent.removeTics(val)));
|
|
78
|
+
}
|
|
79
|
+
else if (includeTextAsZero) {
|
|
80
|
+
nums.push(0);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return errCollection[CommonErrors.Value];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return nums;
|
|
88
|
+
};
|
|
89
|
+
StatisticalSampleBase.prototype.collectPair = function (args) {
|
|
90
|
+
var errCollection = this.parent.getErrorStrings();
|
|
91
|
+
if (args.length !== 2) {
|
|
92
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
93
|
+
}
|
|
94
|
+
var xCells = this.parent.getCellCollection(args[0]);
|
|
95
|
+
var yCells = this.parent.getCellCollection(args[1]);
|
|
96
|
+
var xList = Array.isArray(xCells) ? xCells : [xCells];
|
|
97
|
+
var yList = Array.isArray(yCells) ? yCells : [yCells];
|
|
98
|
+
if (xList.length !== yList.length) {
|
|
99
|
+
return errCollection[CommonErrors.NA];
|
|
100
|
+
}
|
|
101
|
+
var x = [];
|
|
102
|
+
var y = [];
|
|
103
|
+
for (var i = 0; i < xList.length; i++) {
|
|
104
|
+
var xv = this.parent.getValueFromArg(xList[i]);
|
|
105
|
+
var yv = this.parent.getValueFromArg(yList[i]);
|
|
106
|
+
if (errCollection.indexOf(xv) > -1) {
|
|
107
|
+
return xv;
|
|
108
|
+
}
|
|
109
|
+
if (errCollection.indexOf(yv) > -1) {
|
|
110
|
+
return yv;
|
|
111
|
+
}
|
|
112
|
+
if (xv !== '' && yv !== '' && this.parent.isNumber(xv) && this.parent.isNumber(yv)) {
|
|
113
|
+
x.push(this.parent.parseFloat(xv));
|
|
114
|
+
y.push(this.parent.parseFloat(yv));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { x: x, y: y };
|
|
118
|
+
};
|
|
119
|
+
StatisticalSampleBase.prototype.mean = function (nums) {
|
|
120
|
+
return nums.reduce(function (a, b) { return a + b; }, 0) / nums.length;
|
|
121
|
+
};
|
|
122
|
+
return StatisticalSampleBase;
|
|
123
|
+
}(FormulaModuleBase));
|
|
124
|
+
export { StatisticalSampleBase };
|