@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,579 @@
|
|
|
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 { getAlphalabel } from '../base/index';
|
|
17
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
18
|
+
/**
|
|
19
|
+
* Database-style conditional aggregates (DSUM, DCOUNT, DGET) over structured table ranges.
|
|
20
|
+
*
|
|
21
|
+
* Registers 12 functions including DAVERAGE, DCOUNT, DCOUNTA, DGET, DMAX, and others.
|
|
22
|
+
*
|
|
23
|
+
* @hidden
|
|
24
|
+
*/
|
|
25
|
+
var DatabaseFormulas = /** @class */ (function (_super) {
|
|
26
|
+
__extends(DatabaseFormulas, _super);
|
|
27
|
+
/**
|
|
28
|
+
* @hidden
|
|
29
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
30
|
+
*/
|
|
31
|
+
function DatabaseFormulas(owner) {
|
|
32
|
+
var _this = _super.call(this, owner) || this;
|
|
33
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
34
|
+
_this.formulas = [
|
|
35
|
+
{ formulaName: 'DAVERAGE', category: 'Database', description: 'Averages the values in a column of a list or database that match criteria.' },
|
|
36
|
+
{ formulaName: 'DCOUNT', category: 'Database', description: 'Counts the cells that contain numbers in a column of a list or database that match criteria.' },
|
|
37
|
+
{ formulaName: 'DCOUNTA', category: 'Database', description: 'Counts nonblank cells in a column of a list or database that match criteria.' },
|
|
38
|
+
{ formulaName: 'DGET', category: 'Database', description: 'Extracts a single value from a column of a list or database that matches criteria.' },
|
|
39
|
+
{ formulaName: 'DMAX', category: 'Database', description: 'Returns the maximum value from a column of a list or database that matches criteria.' },
|
|
40
|
+
{ formulaName: 'DMIN', category: 'Database', description: 'Returns the minimum value from a column of a list or database that matches criteria.' },
|
|
41
|
+
{ formulaName: 'DPRODUCT', category: 'Database', description: 'Multiplies values in a column of a list or database that match criteria.' },
|
|
42
|
+
{ formulaName: 'DSTDEV', category: 'Database', description: 'Estimates the standard deviation of a population based on a sample of entries that match criteria.' },
|
|
43
|
+
{ formulaName: 'DSTDEVP', category: 'Database', description: 'Calculates the standard deviation of a population based on entries that match criteria.' },
|
|
44
|
+
{ formulaName: 'DSUM', category: 'Database', description: 'Adds the numbers in the field column of records in the database that match the criteria.' },
|
|
45
|
+
{ formulaName: 'DVAR', category: 'Database', description: 'Estimates variance based on a sample of entries that match criteria.' },
|
|
46
|
+
{ formulaName: 'DVARP', category: 'Database', description: 'Calculates variance based on the entire population of entries that match criteria.' }
|
|
47
|
+
];
|
|
48
|
+
return _this;
|
|
49
|
+
}
|
|
50
|
+
DatabaseFormulas.prototype.readRange = function (rangeArg) {
|
|
51
|
+
var errCollection = this.parent.getErrorStrings();
|
|
52
|
+
if (!this.parent.isCellReference(rangeArg)) {
|
|
53
|
+
return errCollection[CommonErrors.Value];
|
|
54
|
+
}
|
|
55
|
+
var parts = rangeArg.indexOf(':') > -1 ? rangeArg.split(':') : [rangeArg, rangeArg];
|
|
56
|
+
var r1 = this.parent.rowIndex(parts[0]);
|
|
57
|
+
var c1 = this.parent.colIndex(parts[0]);
|
|
58
|
+
var r2 = this.parent.rowIndex(parts[1]);
|
|
59
|
+
var c2 = this.parent.colIndex(parts[1]);
|
|
60
|
+
var rowStart = Math.min(r1, r2);
|
|
61
|
+
var rowEnd = Math.max(r1, r2);
|
|
62
|
+
var colStart = Math.min(c1, c2);
|
|
63
|
+
var colEnd = Math.max(c1, c2);
|
|
64
|
+
var grid = [];
|
|
65
|
+
for (var r = rowStart; r <= rowEnd; r++) {
|
|
66
|
+
var row = [];
|
|
67
|
+
for (var c = colStart; c <= colEnd; c++) {
|
|
68
|
+
var addr = getAlphalabel(c) + r;
|
|
69
|
+
row.push(this.parent.getValueFromArg(addr));
|
|
70
|
+
}
|
|
71
|
+
grid.push(row);
|
|
72
|
+
}
|
|
73
|
+
return grid;
|
|
74
|
+
};
|
|
75
|
+
DatabaseFormulas.prototype.fieldIndex = function (fieldArg, headers) {
|
|
76
|
+
var errCollection = this.parent.getErrorStrings();
|
|
77
|
+
var fieldVal = this.resolveTextArg(fieldArg);
|
|
78
|
+
if (errCollection.indexOf(fieldVal) > -1) {
|
|
79
|
+
return fieldVal;
|
|
80
|
+
}
|
|
81
|
+
var num = this.parent.parseFloat(fieldVal);
|
|
82
|
+
if (!isNaN(num) && num >= 1 && num <= headers.length) {
|
|
83
|
+
return Math.floor(num) - 1;
|
|
84
|
+
}
|
|
85
|
+
var upper = fieldVal.toUpperCase();
|
|
86
|
+
for (var i = 0; i < headers.length; i++) {
|
|
87
|
+
if (headers[i].toUpperCase() === upper) {
|
|
88
|
+
return i;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return errCollection[CommonErrors.Value];
|
|
92
|
+
};
|
|
93
|
+
DatabaseFormulas.prototype.matchCriteria = function (row, criteriaRows, headers) {
|
|
94
|
+
for (var cr = 0; cr < criteriaRows.length; cr++) {
|
|
95
|
+
var crit = criteriaRows[cr];
|
|
96
|
+
var rowMatch = true;
|
|
97
|
+
for (var c = 0; c < headers.length; c++) {
|
|
98
|
+
var criterion = crit[c];
|
|
99
|
+
if (criterion === undefined || criterion === '') {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
var cellVal = row[c];
|
|
103
|
+
if (!this.matchesCriterion(cellVal, criterion)) {
|
|
104
|
+
rowMatch = false;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (rowMatch) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
};
|
|
114
|
+
DatabaseFormulas.prototype.matchesCriterion = function (value, criterion) {
|
|
115
|
+
var crit = criterion.trim();
|
|
116
|
+
if (crit === '') {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
var ops = ['>=', '<=', '<>', '>', '<', '='];
|
|
120
|
+
for (var i = 0; i < ops.length; i++) {
|
|
121
|
+
var op = ops[i];
|
|
122
|
+
if (crit.startsWith(op)) {
|
|
123
|
+
var rhs = crit.substring(op.length).trim();
|
|
124
|
+
var lv = this.parent.parseFloat(value);
|
|
125
|
+
var rv = this.parent.parseFloat(rhs);
|
|
126
|
+
if (!isNaN(lv) && !isNaN(rv)) {
|
|
127
|
+
switch (op) {
|
|
128
|
+
case '>=':
|
|
129
|
+
return lv >= rv;
|
|
130
|
+
case '<=':
|
|
131
|
+
return lv <= rv;
|
|
132
|
+
case '<>':
|
|
133
|
+
return lv !== rv;
|
|
134
|
+
case '>':
|
|
135
|
+
return lv > rv;
|
|
136
|
+
case '<':
|
|
137
|
+
return lv < rv;
|
|
138
|
+
case '=':
|
|
139
|
+
return lv === rv;
|
|
140
|
+
default: {
|
|
141
|
+
var _exhaustive = op;
|
|
142
|
+
return _exhaustive;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (op === '=' || op === '') {
|
|
147
|
+
return value.toUpperCase() === rhs.toUpperCase();
|
|
148
|
+
}
|
|
149
|
+
if (op === '<>') {
|
|
150
|
+
return value.toUpperCase() !== rhs.toUpperCase();
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (crit.includes('*') || crit.includes('?')) {
|
|
156
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
157
|
+
var regex = new RegExp('^' + crit.replace(/\*/g, '.*').replace(/\?/g, '.') + '$', 'i');
|
|
158
|
+
return regex.test(value);
|
|
159
|
+
}
|
|
160
|
+
return value.toUpperCase() === crit.toUpperCase();
|
|
161
|
+
};
|
|
162
|
+
DatabaseFormulas.prototype.collectMatching = function (databaseArg, fieldArg, criteriaArg, numbersOnly) {
|
|
163
|
+
var db = this.readRange(databaseArg);
|
|
164
|
+
if (typeof db === 'string') {
|
|
165
|
+
return db;
|
|
166
|
+
}
|
|
167
|
+
if (db.length < 2) {
|
|
168
|
+
return this.parent.getErrorStrings()[CommonErrors.Value];
|
|
169
|
+
}
|
|
170
|
+
var headers = db[0];
|
|
171
|
+
var fieldIdx = this.fieldIndex(fieldArg, headers);
|
|
172
|
+
if (typeof fieldIdx === 'string') {
|
|
173
|
+
return fieldIdx;
|
|
174
|
+
}
|
|
175
|
+
var critGrid = this.readRange(criteriaArg);
|
|
176
|
+
if (typeof critGrid === 'string') {
|
|
177
|
+
return critGrid;
|
|
178
|
+
}
|
|
179
|
+
if (critGrid.length < 2) {
|
|
180
|
+
return this.parent.getErrorStrings()[CommonErrors.Value];
|
|
181
|
+
}
|
|
182
|
+
var critHeaders = critGrid[0];
|
|
183
|
+
var critRows = critGrid.slice(1);
|
|
184
|
+
var nums = [];
|
|
185
|
+
var _loop_1 = function (r) {
|
|
186
|
+
var row = db[r];
|
|
187
|
+
var aligned = headers.map(function (_h, i) { return row[i] || ''; });
|
|
188
|
+
var critAligned = critRows.map(function (cr) {
|
|
189
|
+
return critHeaders.map(function (_h, i) { return cr[i] || ''; });
|
|
190
|
+
});
|
|
191
|
+
if (!this_1.matchCriteria(aligned, critAligned, headers)) {
|
|
192
|
+
return "continue";
|
|
193
|
+
}
|
|
194
|
+
var val = row[fieldIdx] || '';
|
|
195
|
+
if (numbersOnly) {
|
|
196
|
+
if (val !== '' && this_1.parent.isNumber(val)) {
|
|
197
|
+
nums.push(this_1.parent.parseFloat(val));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (val !== '') {
|
|
201
|
+
if (this_1.parent.isNumber(val)) {
|
|
202
|
+
nums.push(this_1.parent.parseFloat(val));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var this_1 = this;
|
|
207
|
+
for (var r = 1; r < db.length; r++) {
|
|
208
|
+
_loop_1(r);
|
|
209
|
+
}
|
|
210
|
+
return nums;
|
|
211
|
+
};
|
|
212
|
+
DatabaseFormulas.prototype.requireThree = function (args) {
|
|
213
|
+
if (isNullOrUndefined(args) || args.length !== 3) {
|
|
214
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
};
|
|
218
|
+
DatabaseFormulas.prototype.mean = function (nums) {
|
|
219
|
+
return nums.reduce(function (a, b) { return a + b; }, 0) / nums.length;
|
|
220
|
+
};
|
|
221
|
+
DatabaseFormulas.prototype.variance = function (nums, population) {
|
|
222
|
+
var m = this.mean(nums);
|
|
223
|
+
var sum = 0;
|
|
224
|
+
for (var i = 0; i < nums.length; i++) {
|
|
225
|
+
sum += Math.pow(nums[i] - m, 2);
|
|
226
|
+
}
|
|
227
|
+
return sum / (population ? nums.length : nums.length - 1);
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Averages the values in a column of a list or database that match criteria.
|
|
231
|
+
*
|
|
232
|
+
* Excel: `DAVERAGE(...)`.
|
|
233
|
+
*
|
|
234
|
+
* @hidden
|
|
235
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
236
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* engine.computeFormula('=DAVERAGE(1)');
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
DatabaseFormulas.prototype.ComputeDAVERAGE = function () {
|
|
244
|
+
var args = [];
|
|
245
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
246
|
+
args[_i] = arguments[_i];
|
|
247
|
+
}
|
|
248
|
+
var bad = this.requireThree(args);
|
|
249
|
+
if (bad) {
|
|
250
|
+
return bad;
|
|
251
|
+
}
|
|
252
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
253
|
+
if (typeof nums === 'string') {
|
|
254
|
+
return nums;
|
|
255
|
+
}
|
|
256
|
+
if (nums.length === 0) {
|
|
257
|
+
return this.parent.getErrorStrings()[CommonErrors.DivZero];
|
|
258
|
+
}
|
|
259
|
+
return this.mean(nums).toString();
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Counts the cells that contain numbers in a column of a list or database that match criteria.
|
|
263
|
+
*
|
|
264
|
+
* Excel: `DCOUNT(...)`.
|
|
265
|
+
*
|
|
266
|
+
* @hidden
|
|
267
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
268
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
269
|
+
*/
|
|
270
|
+
DatabaseFormulas.prototype.ComputeDCOUNT = function () {
|
|
271
|
+
var args = [];
|
|
272
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
273
|
+
args[_i] = arguments[_i];
|
|
274
|
+
}
|
|
275
|
+
var bad = this.requireThree(args);
|
|
276
|
+
if (bad) {
|
|
277
|
+
return bad;
|
|
278
|
+
}
|
|
279
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
280
|
+
if (typeof nums === 'string') {
|
|
281
|
+
return nums;
|
|
282
|
+
}
|
|
283
|
+
return nums.length.toString();
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Counts nonblank cells in a column of a list or database that match criteria.
|
|
287
|
+
*
|
|
288
|
+
* Excel: `DCOUNTA(...)`.
|
|
289
|
+
*
|
|
290
|
+
* @hidden
|
|
291
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
292
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
293
|
+
*/
|
|
294
|
+
DatabaseFormulas.prototype.ComputeDCOUNTA = function () {
|
|
295
|
+
var args = [];
|
|
296
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
297
|
+
args[_i] = arguments[_i];
|
|
298
|
+
}
|
|
299
|
+
var bad = this.requireThree(args);
|
|
300
|
+
if (bad) {
|
|
301
|
+
return bad;
|
|
302
|
+
}
|
|
303
|
+
var db = this.readRange(args[0]);
|
|
304
|
+
if (typeof db === 'string') {
|
|
305
|
+
return db;
|
|
306
|
+
}
|
|
307
|
+
var headers = db[0];
|
|
308
|
+
var fieldIdx = this.fieldIndex(args[1], headers);
|
|
309
|
+
if (typeof fieldIdx === 'string') {
|
|
310
|
+
return fieldIdx;
|
|
311
|
+
}
|
|
312
|
+
var critGrid = this.readRange(args[2]);
|
|
313
|
+
if (typeof critGrid === 'string') {
|
|
314
|
+
return critGrid;
|
|
315
|
+
}
|
|
316
|
+
var critRows = critGrid.slice(1);
|
|
317
|
+
var count = 0;
|
|
318
|
+
for (var r = 1; r < db.length; r++) {
|
|
319
|
+
var row = db[r];
|
|
320
|
+
var critAligned = critRows.map(function (cr) {
|
|
321
|
+
return critGrid[0].map(function (_h, i) { return cr[i] || ''; });
|
|
322
|
+
});
|
|
323
|
+
if (this.matchCriteria(row, critAligned, headers) && (row[fieldIdx] || '') !== '') {
|
|
324
|
+
count++;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return count.toString();
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Extracts a single value from a column of a list or database that matches criteria.
|
|
331
|
+
*
|
|
332
|
+
* Excel: `DGET(...)`.
|
|
333
|
+
*
|
|
334
|
+
* @hidden
|
|
335
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
336
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
337
|
+
*/
|
|
338
|
+
DatabaseFormulas.prototype.ComputeDGET = function () {
|
|
339
|
+
var args = [];
|
|
340
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
341
|
+
args[_i] = arguments[_i];
|
|
342
|
+
}
|
|
343
|
+
var bad = this.requireThree(args);
|
|
344
|
+
if (bad) {
|
|
345
|
+
return bad;
|
|
346
|
+
}
|
|
347
|
+
var errCollection = this.parent.getErrorStrings();
|
|
348
|
+
var nums = this.collectMatching(args[0], args[1], args[2], false);
|
|
349
|
+
if (typeof nums === 'string') {
|
|
350
|
+
return nums;
|
|
351
|
+
}
|
|
352
|
+
if (nums.length === 0) {
|
|
353
|
+
return errCollection[CommonErrors.NA];
|
|
354
|
+
}
|
|
355
|
+
if (nums.length > 1) {
|
|
356
|
+
return errCollection[CommonErrors.Num];
|
|
357
|
+
}
|
|
358
|
+
return nums[0].toString();
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Returns the maximum value from a column of a list or database that matches criteria.
|
|
362
|
+
*
|
|
363
|
+
* Excel: `DMAX(...)`.
|
|
364
|
+
*
|
|
365
|
+
* @hidden
|
|
366
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
367
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
368
|
+
*/
|
|
369
|
+
DatabaseFormulas.prototype.ComputeDMAX = function () {
|
|
370
|
+
var args = [];
|
|
371
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
372
|
+
args[_i] = arguments[_i];
|
|
373
|
+
}
|
|
374
|
+
var bad = this.requireThree(args);
|
|
375
|
+
if (bad) {
|
|
376
|
+
return bad;
|
|
377
|
+
}
|
|
378
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
379
|
+
if (typeof nums === 'string') {
|
|
380
|
+
return nums;
|
|
381
|
+
}
|
|
382
|
+
if (nums.length === 0) {
|
|
383
|
+
return this.parent.getErrorStrings()[CommonErrors.NA];
|
|
384
|
+
}
|
|
385
|
+
return Math.max.apply(Math, nums).toString();
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* Returns the minimum value from a column of a list or database that matches criteria.
|
|
389
|
+
*
|
|
390
|
+
* Excel: `DMIN(...)`.
|
|
391
|
+
*
|
|
392
|
+
* @hidden
|
|
393
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
394
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
395
|
+
*/
|
|
396
|
+
DatabaseFormulas.prototype.ComputeDMIN = function () {
|
|
397
|
+
var args = [];
|
|
398
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
399
|
+
args[_i] = arguments[_i];
|
|
400
|
+
}
|
|
401
|
+
var bad = this.requireThree(args);
|
|
402
|
+
if (bad) {
|
|
403
|
+
return bad;
|
|
404
|
+
}
|
|
405
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
406
|
+
if (typeof nums === 'string') {
|
|
407
|
+
return nums;
|
|
408
|
+
}
|
|
409
|
+
if (nums.length === 0) {
|
|
410
|
+
return this.parent.getErrorStrings()[CommonErrors.NA];
|
|
411
|
+
}
|
|
412
|
+
return Math.min.apply(Math, nums).toString();
|
|
413
|
+
};
|
|
414
|
+
/**
|
|
415
|
+
* Multiplies values in a column of a list or database that match criteria.
|
|
416
|
+
*
|
|
417
|
+
* Excel: `DPRODUCT(...)`.
|
|
418
|
+
*
|
|
419
|
+
* @hidden
|
|
420
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
421
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
422
|
+
*/
|
|
423
|
+
DatabaseFormulas.prototype.ComputeDPRODUCT = function () {
|
|
424
|
+
var args = [];
|
|
425
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
426
|
+
args[_i] = arguments[_i];
|
|
427
|
+
}
|
|
428
|
+
var bad = this.requireThree(args);
|
|
429
|
+
if (bad) {
|
|
430
|
+
return bad;
|
|
431
|
+
}
|
|
432
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
433
|
+
if (typeof nums === 'string') {
|
|
434
|
+
return nums;
|
|
435
|
+
}
|
|
436
|
+
if (nums.length === 0) {
|
|
437
|
+
return '0';
|
|
438
|
+
}
|
|
439
|
+
return nums.reduce(function (a, b) { return a * b; }, 1).toString();
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* Adds the numbers in the field column of records in the database that match the criteria.
|
|
443
|
+
*
|
|
444
|
+
* Excel: `DSUM(...)`.
|
|
445
|
+
*
|
|
446
|
+
* @hidden
|
|
447
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
448
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
449
|
+
*/
|
|
450
|
+
DatabaseFormulas.prototype.ComputeDSUM = function () {
|
|
451
|
+
var args = [];
|
|
452
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
453
|
+
args[_i] = arguments[_i];
|
|
454
|
+
}
|
|
455
|
+
var bad = this.requireThree(args);
|
|
456
|
+
if (bad) {
|
|
457
|
+
return bad;
|
|
458
|
+
}
|
|
459
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
460
|
+
if (typeof nums === 'string') {
|
|
461
|
+
return nums;
|
|
462
|
+
}
|
|
463
|
+
return nums.reduce(function (a, b) { return a + b; }, 0).toString();
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Estimates the standard deviation of a population based on a sample of entries that match criteria.
|
|
467
|
+
*
|
|
468
|
+
* Excel: `DSTDEV(...)`.
|
|
469
|
+
*
|
|
470
|
+
* @hidden
|
|
471
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
472
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
473
|
+
*/
|
|
474
|
+
DatabaseFormulas.prototype.ComputeDSTDEV = function () {
|
|
475
|
+
var args = [];
|
|
476
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
477
|
+
args[_i] = arguments[_i];
|
|
478
|
+
}
|
|
479
|
+
var bad = this.requireThree(args);
|
|
480
|
+
if (bad) {
|
|
481
|
+
return bad;
|
|
482
|
+
}
|
|
483
|
+
var errCollection = this.parent.getErrorStrings();
|
|
484
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
485
|
+
if (typeof nums === 'string') {
|
|
486
|
+
return nums;
|
|
487
|
+
}
|
|
488
|
+
if (nums.length < 2) {
|
|
489
|
+
return errCollection[CommonErrors.DivZero];
|
|
490
|
+
}
|
|
491
|
+
return Math.sqrt(this.variance(nums, false)).toString();
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Calculates the standard deviation of a population based on entries that match criteria.
|
|
495
|
+
*
|
|
496
|
+
* Excel: `DSTDEVP(...)`.
|
|
497
|
+
*
|
|
498
|
+
* @hidden
|
|
499
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
500
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
501
|
+
*/
|
|
502
|
+
DatabaseFormulas.prototype.ComputeDSTDEVP = function () {
|
|
503
|
+
var args = [];
|
|
504
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
505
|
+
args[_i] = arguments[_i];
|
|
506
|
+
}
|
|
507
|
+
var bad = this.requireThree(args);
|
|
508
|
+
if (bad) {
|
|
509
|
+
return bad;
|
|
510
|
+
}
|
|
511
|
+
var errCollection = this.parent.getErrorStrings();
|
|
512
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
513
|
+
if (typeof nums === 'string') {
|
|
514
|
+
return nums;
|
|
515
|
+
}
|
|
516
|
+
if (nums.length < 1) {
|
|
517
|
+
return errCollection[CommonErrors.DivZero];
|
|
518
|
+
}
|
|
519
|
+
return Math.sqrt(this.variance(nums, true)).toString();
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Estimates variance based on a sample of entries that match criteria.
|
|
523
|
+
*
|
|
524
|
+
* Excel: `DVAR(...)`.
|
|
525
|
+
*
|
|
526
|
+
* @hidden
|
|
527
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
528
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
529
|
+
*/
|
|
530
|
+
DatabaseFormulas.prototype.ComputeDVAR = function () {
|
|
531
|
+
var args = [];
|
|
532
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
533
|
+
args[_i] = arguments[_i];
|
|
534
|
+
}
|
|
535
|
+
var bad = this.requireThree(args);
|
|
536
|
+
if (bad) {
|
|
537
|
+
return bad;
|
|
538
|
+
}
|
|
539
|
+
var errCollection = this.parent.getErrorStrings();
|
|
540
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
541
|
+
if (typeof nums === 'string') {
|
|
542
|
+
return nums;
|
|
543
|
+
}
|
|
544
|
+
if (nums.length < 2) {
|
|
545
|
+
return errCollection[CommonErrors.DivZero];
|
|
546
|
+
}
|
|
547
|
+
return this.variance(nums, false).toString();
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* Calculates variance based on the entire population of entries that match criteria.
|
|
551
|
+
*
|
|
552
|
+
* Excel: `DVARP(...)`.
|
|
553
|
+
*
|
|
554
|
+
* @hidden
|
|
555
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
556
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
557
|
+
*/
|
|
558
|
+
DatabaseFormulas.prototype.ComputeDVARP = function () {
|
|
559
|
+
var args = [];
|
|
560
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
561
|
+
args[_i] = arguments[_i];
|
|
562
|
+
}
|
|
563
|
+
var bad = this.requireThree(args);
|
|
564
|
+
if (bad) {
|
|
565
|
+
return bad;
|
|
566
|
+
}
|
|
567
|
+
var errCollection = this.parent.getErrorStrings();
|
|
568
|
+
var nums = this.collectMatching(args[0], args[1], args[2], true);
|
|
569
|
+
if (typeof nums === 'string') {
|
|
570
|
+
return nums;
|
|
571
|
+
}
|
|
572
|
+
if (nums.length < 1) {
|
|
573
|
+
return errCollection[CommonErrors.DivZero];
|
|
574
|
+
}
|
|
575
|
+
return this.variance(nums, true).toString();
|
|
576
|
+
};
|
|
577
|
+
return DatabaseFormulas;
|
|
578
|
+
}(FormulaModuleBase));
|
|
579
|
+
export { DatabaseFormulas };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Additional date/time utilities: workdays, network days, week numbers, and calendar offsets.
|
|
6
|
+
*
|
|
7
|
+
* Registered functions: YEAR, WEEKNUM, TIMEVALUE, DAYS360, YEARFRAC, NETWORKDAYS, WORKDAY.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class DateTimeExtraFormulas extends FormulaModuleBase {
|
|
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 toSerial;
|
|
20
|
+
/**
|
|
21
|
+
* Converts a serial number to a year.
|
|
22
|
+
*
|
|
23
|
+
* Excel: `YEAR(...)`.
|
|
24
|
+
*
|
|
25
|
+
* @hidden
|
|
26
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
27
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* engine.computeFormula('=YEAR(1)');
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
ComputeYEAR(...args: string[]): string | number;
|
|
35
|
+
/**
|
|
36
|
+
* Converts a serial number to a number representing where the week falls numerically within a year.
|
|
37
|
+
*
|
|
38
|
+
* Excel: `WEEKNUM(...)`.
|
|
39
|
+
*
|
|
40
|
+
* @hidden
|
|
41
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
42
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
43
|
+
*/
|
|
44
|
+
ComputeWEEKNUM(...args: string[]): string | number;
|
|
45
|
+
/**
|
|
46
|
+
* Converts a time in the form of text to a serial number.
|
|
47
|
+
*
|
|
48
|
+
* Excel: `TIMEVALUE(...)`.
|
|
49
|
+
*
|
|
50
|
+
* @hidden
|
|
51
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
52
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
53
|
+
*/
|
|
54
|
+
ComputeTIMEVALUE(...args: string[]): string | number;
|
|
55
|
+
/**
|
|
56
|
+
* Calculates the number of days between two dates based on a 360-day year.
|
|
57
|
+
*
|
|
58
|
+
* Excel: `DAYS360(...)`.
|
|
59
|
+
*
|
|
60
|
+
* @hidden
|
|
61
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
62
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
63
|
+
*/
|
|
64
|
+
ComputeDAYS360(...args: string[]): string | number;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the year fraction representing the number of whole days between start_date and end_date.
|
|
67
|
+
*
|
|
68
|
+
* Excel: `YEARFRAC(...)`.
|
|
69
|
+
*
|
|
70
|
+
* @hidden
|
|
71
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
72
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
73
|
+
*/
|
|
74
|
+
ComputeYEARFRAC(...args: string[]): string | number;
|
|
75
|
+
private isWeekend;
|
|
76
|
+
private holidaySet;
|
|
77
|
+
/**
|
|
78
|
+
* Returns the number of whole workdays between two dates.
|
|
79
|
+
*
|
|
80
|
+
* Excel: `NETWORKDAYS(...)`.
|
|
81
|
+
*
|
|
82
|
+
* @hidden
|
|
83
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
84
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
85
|
+
*/
|
|
86
|
+
ComputeNETWORKDAYS(...args: string[]): string | number;
|
|
87
|
+
/**
|
|
88
|
+
* Returns the serial number of the date before or after a specified number of workdays.
|
|
89
|
+
*
|
|
90
|
+
* Excel: `WORKDAY(...)`.
|
|
91
|
+
*
|
|
92
|
+
* @hidden
|
|
93
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
94
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
95
|
+
*/
|
|
96
|
+
ComputeWORKDAY(...args: string[]): string | number;
|
|
97
|
+
}
|