@odoo/o-spreadsheet 14.0.0 → 14.0.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/.eslintrc.json +20 -0
- package/.husky/post-checkout +9 -0
- package/.husky/pre-commit +39 -0
- package/.prettierignore +1 -0
- package/astToFormula.patch +0 -0
- package/demo/data.js +255 -0
- package/demo/index.html +9 -0
- package/demo/libs/Chart.bundle.js +20755 -0
- package/demo/main.js +101 -0
- package/doc/readme.md +46 -0
- package/package.json +3 -17
- package/rollup.config.js +23 -0
- package/src/base_plugin.ts +102 -0
- package/src/components/autofill.ts +146 -0
- package/src/components/bottom_bar.ts +199 -0
- package/src/components/color_picker.ts +150 -0
- package/src/components/composer/autocomplete_dropdown.ts +135 -0
- package/src/components/composer/composer.ts +487 -0
- package/src/components/composer/content_editable_helper.ts +146 -0
- package/src/components/figures/chart.ts +70 -0
- package/src/components/figures/container.ts +268 -0
- package/src/components/figures/text_figure.ts +36 -0
- package/src/components/grid.ts +635 -0
- package/src/components/helpers/dom_helpers.ts +7 -0
- package/src/components/helpers/drag_and_drop.ts +17 -0
- package/src/components/icons.ts +36 -0
- package/src/components/index.ts +1 -0
- package/src/components/menu.ts +288 -0
- package/src/components/overlay.ts +457 -0
- package/src/components/scrollbar.ts +22 -0
- package/src/components/selection_input.ts +168 -0
- package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
- package/src/components/side_panel/chart_panel.ts +104 -0
- package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
- package/src/components/side_panel/conditional_formatting.ts +396 -0
- package/src/components/side_panel/side_panel.ts +127 -0
- package/src/components/side_panel/translations_terms.ts +45 -0
- package/src/components/spreadsheet.ts +198 -0
- package/src/components/top_bar.ts +535 -0
- package/src/constants.ts +26 -0
- package/src/data.ts +149 -0
- package/src/fonts.ts +41 -0
- package/src/formulas/compiler.ts +258 -0
- package/src/formulas/composer_tokenizer.ts +70 -0
- package/src/formulas/index.ts +15 -0
- package/src/formulas/normalize.ts +52 -0
- package/src/formulas/parser.ts +280 -0
- package/src/formulas/range_tokenizer.ts +97 -0
- package/src/formulas/tokenizer.ts +242 -0
- package/src/functions/arguments.ts +114 -0
- package/src/functions/dates.ts +302 -0
- package/src/functions/helpers.ts +592 -0
- package/src/functions/index.ts +52 -0
- package/src/functions/module_database.ts +282 -0
- package/src/functions/module_date.ts +743 -0
- package/src/functions/module_info.ts +69 -0
- package/src/functions/module_logical.ts +208 -0
- package/src/functions/module_lookup.ts +185 -0
- package/src/functions/module_math.ts +1252 -0
- package/src/functions/module_operators.ts +291 -0
- package/src/functions/module_statistical.ts +882 -0
- package/src/functions/module_text.ts +370 -0
- package/src/helpers/color.ts +30 -0
- package/src/helpers/coordinates.ts +71 -0
- package/src/helpers/grid_manipulation.ts +68 -0
- package/src/helpers/index.ts +7 -0
- package/src/helpers/misc.ts +76 -0
- package/src/helpers/numbers.ts +117 -0
- package/src/helpers/uuid.ts +19 -0
- package/src/helpers/zones.ts +263 -0
- package/src/history.ts +186 -0
- package/src/index.ts +84 -0
- package/src/model.ts +261 -0
- package/src/plugins/autofill.ts +412 -0
- package/src/plugins/chart.ts +404 -0
- package/src/plugins/clipboard.ts +461 -0
- package/src/plugins/conditional_format.ts +445 -0
- package/src/plugins/core.ts +1502 -0
- package/src/plugins/edition.ts +157 -0
- package/src/plugins/evaluation.ts +428 -0
- package/src/plugins/figures.ts +123 -0
- package/src/plugins/formatting.ts +630 -0
- package/src/plugins/highlight.ts +187 -0
- package/src/plugins/index.ts +32 -0
- package/src/plugins/merge.ts +524 -0
- package/src/plugins/renderer.ts +571 -0
- package/src/plugins/selection.ts +562 -0
- package/src/plugins/selection_inputs.ts +326 -0
- package/src/registries/autofill_modifiers.ts +76 -0
- package/src/registries/autofill_rules.ts +98 -0
- package/src/registries/figure_registry.ts +30 -0
- package/src/registries/index.ts +7 -0
- package/src/registries/menu_items_registry.ts +110 -0
- package/src/registries/menus/cell_menu_registry.ts +79 -0
- package/src/registries/menus/col_menu_registry.ts +63 -0
- package/src/registries/menus/index.ts +6 -0
- package/src/registries/menus/menu_items_actions.ts +425 -0
- package/src/registries/menus/row_menu_registry.ts +63 -0
- package/src/registries/menus/sheet_menu_registry.ts +75 -0
- package/src/registries/menus/topbar_menu_registry.ts +204 -0
- package/src/registries/side_panel_registry.ts +26 -0
- package/src/registries/topbar_component_registry.ts +12 -0
- package/src/registry.ts +51 -0
- package/src/translation.ts +44 -0
- package/src/types/autofill.ts +48 -0
- package/src/types/chart.ts +26 -0
- package/src/types/commands.ts +716 -0
- package/src/types/conditional_formatting.ts +124 -0
- package/src/types/env.ts +13 -0
- package/src/types/functions.ts +35 -0
- package/src/types/getters.ts +103 -0
- package/src/types/index.ts +20 -0
- package/src/types/misc.ts +143 -0
- package/src/types/rendering.ts +41 -0
- package/src/types/workbook_data.ts +62 -0
- package/tests/__mocks__/uuid.ts +7 -0
- package/tests/canvas.mock.ts +34 -0
- package/tests/components/__mocks__/content_editable_helper.ts +79 -0
- package/tests/components/__mocks__/scrollbar.ts +18 -0
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
- package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
- package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
- package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
- package/tests/components/autocomplete_dropdown_test.ts +315 -0
- package/tests/components/autofill_test.ts +167 -0
- package/tests/components/bottom_bar_test.ts +262 -0
- package/tests/components/chart_side_panel_test.ts +123 -0
- package/tests/components/composer_test.ts +400 -0
- package/tests/components/context_menu_test.ts +825 -0
- package/tests/components/grid_manipulation_test.ts +163 -0
- package/tests/components/grid_test.ts +581 -0
- package/tests/components/overlay_test.ts +541 -0
- package/tests/components/selection_input_test.ts +259 -0
- package/tests/components/side_panel_test.ts +148 -0
- package/tests/components/spreadsheet_test.ts +194 -0
- package/tests/components/top_bar_test.ts +427 -0
- package/tests/data_test.ts +175 -0
- package/tests/dom_helper.ts +42 -0
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
- package/tests/formulas/compiler_test.ts +266 -0
- package/tests/formulas/composer_tokenizer_test.ts +137 -0
- package/tests/formulas/expressions_test.ts +57 -0
- package/tests/formulas/formulas_test.ts +80 -0
- package/tests/formulas/normalize_test.ts +82 -0
- package/tests/formulas/parser_test.ts +224 -0
- package/tests/formulas/range_tokenizer_test.ts +187 -0
- package/tests/formulas/tokenizer_test.ts +164 -0
- package/tests/functions/arguments_test.ts +141 -0
- package/tests/functions/dates_test.ts +1081 -0
- package/tests/functions/functions_test.ts +53 -0
- package/tests/functions/helper_test.ts +98 -0
- package/tests/functions/module_database_test.ts +311 -0
- package/tests/functions/module_date_test.ts +941 -0
- package/tests/functions/module_info_test.ts +139 -0
- package/tests/functions/module_logical_test.ts +369 -0
- package/tests/functions/module_lookup_test.ts +541 -0
- package/tests/functions/module_math_test.ts +2482 -0
- package/tests/functions/module_operators_test.ts +955 -0
- package/tests/functions/module_statistical_test.ts +2014 -0
- package/tests/functions/module_text_test.ts +667 -0
- package/tests/helpers/coordinates_test.ts +25 -0
- package/tests/helpers/misc_test.ts +95 -0
- package/tests/helpers/numbers_test.ts +196 -0
- package/tests/helpers/zones_test.ts +97 -0
- package/tests/helpers.ts +384 -0
- package/tests/menu_items_registry_test.ts +540 -0
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
- package/tests/model/plugins/chart_test.ts +562 -0
- package/tests/model_test.ts +82 -0
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
- package/tests/plugins/autofill_test.ts +457 -0
- package/tests/plugins/borders_test.ts +295 -0
- package/tests/plugins/clipboard_test.ts +1180 -0
- package/tests/plugins/conditional_formatting_test.ts +1253 -0
- package/tests/plugins/core_test.ts +614 -0
- package/tests/plugins/edition_test.ts +100 -0
- package/tests/plugins/evaluation_async_test.ts +332 -0
- package/tests/plugins/evaluation_dates_test.ts +79 -0
- package/tests/plugins/evaluation_test.ts +901 -0
- package/tests/plugins/figures_test.ts +327 -0
- package/tests/plugins/formatting_test.ts +391 -0
- package/tests/plugins/grid_manipulation_test.ts +1366 -0
- package/tests/plugins/highlight_test.ts +413 -0
- package/tests/plugins/history_test.ts +142 -0
- package/tests/plugins/import_export_test.ts +276 -0
- package/tests/plugins/merges_test.ts +490 -0
- package/tests/plugins/navigation_test.ts +181 -0
- package/tests/plugins/plugins/evaluation_test.ts +111 -0
- package/tests/plugins/renderer_test.ts +598 -0
- package/tests/plugins/resizing_test.ts +152 -0
- package/tests/plugins/selection_input_test.ts +409 -0
- package/tests/plugins/selection_test.ts +442 -0
- package/tests/plugins/sheets_test.ts +643 -0
- package/tests/plugins/style_test.ts +90 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import { isNumber } from "../helpers/index";
|
|
2
|
+
import { _lt } from "../translation";
|
|
3
|
+
import { FunctionDescription } from "../types";
|
|
4
|
+
import { args } from "./arguments";
|
|
5
|
+
import { parseDateTime } from "./dates";
|
|
6
|
+
import {
|
|
7
|
+
dichotomicPredecessorSearch,
|
|
8
|
+
extractDateValue,
|
|
9
|
+
reduceArgs,
|
|
10
|
+
reduceNumbers,
|
|
11
|
+
reduceNumbersTextAs0,
|
|
12
|
+
toNumber,
|
|
13
|
+
visitAny,
|
|
14
|
+
visitMatchingRanges,
|
|
15
|
+
} from "./helpers";
|
|
16
|
+
|
|
17
|
+
// Note: dataY and dataX may not have the same dimension
|
|
18
|
+
function covariance(dataY: any[], dataX: any[], isSample: boolean): number {
|
|
19
|
+
let flatDataY: any[] = [];
|
|
20
|
+
let flatDataX: any[] = [];
|
|
21
|
+
let lenY = 0;
|
|
22
|
+
let lenX = 0;
|
|
23
|
+
|
|
24
|
+
visitAny(dataY, (y) => {
|
|
25
|
+
flatDataY.push(y);
|
|
26
|
+
lenY += 1;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
visitAny(dataX, (x) => {
|
|
30
|
+
flatDataX.push(x);
|
|
31
|
+
lenX += 1;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (lenY !== lenX) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
_lt(
|
|
37
|
+
"[[FUNCTION_NAME]] has mismatched argument count %s vs %s.",
|
|
38
|
+
lenY.toString(),
|
|
39
|
+
lenX.toString()
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let count = 0;
|
|
45
|
+
let sumY = 0;
|
|
46
|
+
let sumX = 0;
|
|
47
|
+
for (let i = 0; i < lenY; i++) {
|
|
48
|
+
const valueY = flatDataY[i];
|
|
49
|
+
const valueX = flatDataX[i];
|
|
50
|
+
if (typeof valueY === "number" && typeof valueX === "number") {
|
|
51
|
+
count += 1;
|
|
52
|
+
sumY += valueY;
|
|
53
|
+
sumX += valueX;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (count === 0 || (isSample && count === 1)) {
|
|
58
|
+
throw new Error(_lt(`Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.`));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const averageY = sumY / count;
|
|
62
|
+
const averageX = sumX / count;
|
|
63
|
+
|
|
64
|
+
let acc = 0;
|
|
65
|
+
for (let i = 0; i < lenY; i++) {
|
|
66
|
+
const valueY = flatDataY[i];
|
|
67
|
+
const valueX = flatDataX[i];
|
|
68
|
+
if (typeof valueY === "number" && typeof valueX === "number") {
|
|
69
|
+
acc += (valueY - averageY) * (valueX - averageX);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return acc / (count - (isSample ? 1 : 0));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function variance(args: IArguments | any[], isSample: boolean, textAs0: boolean): number {
|
|
77
|
+
let count = 0;
|
|
78
|
+
let sum = 0;
|
|
79
|
+
const reduceFuction = textAs0 ? reduceNumbersTextAs0 : reduceNumbers;
|
|
80
|
+
|
|
81
|
+
sum = reduceFuction(
|
|
82
|
+
args,
|
|
83
|
+
(acc, a) => {
|
|
84
|
+
count += 1;
|
|
85
|
+
return acc + a;
|
|
86
|
+
},
|
|
87
|
+
0
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (count === 0 || (isSample && count === 1)) {
|
|
91
|
+
throw new Error(_lt(`Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error.`));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const average = sum / count;
|
|
95
|
+
return (
|
|
96
|
+
reduceFuction(args, (acc, a) => acc + Math.pow(a - average, 2), 0) /
|
|
97
|
+
(count - (isSample ? 1 : 0))
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// -----------------------------------------------------------------------------
|
|
102
|
+
// AVEDEV
|
|
103
|
+
// -----------------------------------------------------------------------------
|
|
104
|
+
export const AVEDEV: FunctionDescription = {
|
|
105
|
+
description: _lt("Average magnitude of deviations from mean."),
|
|
106
|
+
args: args(`
|
|
107
|
+
value1 (number, range<number>) ${_lt("The first value or range of the sample.")}
|
|
108
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
109
|
+
"Additional values or ranges to include in the sample."
|
|
110
|
+
)}
|
|
111
|
+
`),
|
|
112
|
+
returns: ["NUMBER"],
|
|
113
|
+
compute: function (): number {
|
|
114
|
+
let count = 0;
|
|
115
|
+
const sum = reduceNumbers(
|
|
116
|
+
arguments,
|
|
117
|
+
(acc, a) => {
|
|
118
|
+
count += 1;
|
|
119
|
+
return acc + a;
|
|
120
|
+
},
|
|
121
|
+
0
|
|
122
|
+
);
|
|
123
|
+
if (count === 0) {
|
|
124
|
+
throw new Error(_lt(`Evaluation of function AVEDEV caused a divide by zero error.`));
|
|
125
|
+
}
|
|
126
|
+
const average = sum / count;
|
|
127
|
+
return reduceNumbers(arguments, (acc, a) => acc + Math.abs(average - a), 0) / count;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// -----------------------------------------------------------------------------
|
|
132
|
+
// AVERAGE
|
|
133
|
+
// -----------------------------------------------------------------------------
|
|
134
|
+
export const AVERAGE: FunctionDescription = {
|
|
135
|
+
description: _lt(`Numerical average value in a dataset, ignoring text.`),
|
|
136
|
+
args: args(`
|
|
137
|
+
value1 (number, range<number>) ${_lt(
|
|
138
|
+
"The first value or range to consider when calculating the average value."
|
|
139
|
+
)}
|
|
140
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
141
|
+
"Additional values or ranges to consider when calculating the average value."
|
|
142
|
+
)}
|
|
143
|
+
`),
|
|
144
|
+
returns: ["NUMBER"],
|
|
145
|
+
compute: function (): number {
|
|
146
|
+
let count = 0;
|
|
147
|
+
const sum = reduceNumbers(
|
|
148
|
+
arguments,
|
|
149
|
+
(acc, a) => {
|
|
150
|
+
count += 1;
|
|
151
|
+
return acc + a;
|
|
152
|
+
},
|
|
153
|
+
0
|
|
154
|
+
);
|
|
155
|
+
if (count === 0) {
|
|
156
|
+
throw new Error(_lt(`Evaluation of function AVERAGE caused a divide by zero error.`));
|
|
157
|
+
}
|
|
158
|
+
return sum / count;
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// -----------------------------------------------------------------------------
|
|
163
|
+
// AVERAGE.WEIGHTED
|
|
164
|
+
// -----------------------------------------------------------------------------
|
|
165
|
+
const rangeError = _lt(`AVERAGE.WEIGHTED has mismatched range sizes.`);
|
|
166
|
+
const negativeWeightError = _lt(
|
|
167
|
+
`AVERAGE.WEIGHTED expects the weight to be positive or equal to 0.`
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
export const AVERAGE_WEIGHTED: FunctionDescription = {
|
|
171
|
+
description: _lt(`Weighted average.`),
|
|
172
|
+
args: args(`
|
|
173
|
+
values (number, range<number>) ${_lt("Values to average.")}
|
|
174
|
+
weights (number, range<number>) ${_lt("Weights for each corresponding value.")}
|
|
175
|
+
additional_values (number, range<number>, optional, repeating) ${_lt(
|
|
176
|
+
"Additional values to average with weights."
|
|
177
|
+
)}
|
|
178
|
+
`),
|
|
179
|
+
// @compatibility: on google sheets, args difinitions are next:
|
|
180
|
+
// additional_values (number, range<number>, optional, repeating) Additional values to average.
|
|
181
|
+
// additional_weights (number, range<number>, optional, repeating) Additional weights.
|
|
182
|
+
returns: ["NUMBER"],
|
|
183
|
+
compute: function (): number {
|
|
184
|
+
let sum = 0;
|
|
185
|
+
let count = 0;
|
|
186
|
+
let value;
|
|
187
|
+
let weight;
|
|
188
|
+
if (arguments.length % 2 === 1) {
|
|
189
|
+
throw new Error(_lt(`Wrong number of arguments. Expected an even number of arguments.`));
|
|
190
|
+
}
|
|
191
|
+
for (let n = 0; n < arguments.length - 1; n += 2) {
|
|
192
|
+
value = arguments[n];
|
|
193
|
+
weight = arguments[n + 1];
|
|
194
|
+
// if (typeof value != typeof weight) {
|
|
195
|
+
// throw new Error(rangeError);
|
|
196
|
+
// }
|
|
197
|
+
if (Array.isArray(value)) {
|
|
198
|
+
if (!Array.isArray(weight)) {
|
|
199
|
+
throw new Error(rangeError);
|
|
200
|
+
}
|
|
201
|
+
let dimColValue = value.length;
|
|
202
|
+
let dimLinValue = value[0].length;
|
|
203
|
+
if (dimColValue !== weight.length || dimLinValue != weight[0].length) {
|
|
204
|
+
throw new Error(rangeError);
|
|
205
|
+
}
|
|
206
|
+
for (let i = 0; i < dimColValue; i++) {
|
|
207
|
+
for (let j = 0; j < dimLinValue; j++) {
|
|
208
|
+
let subValue = value[i][j];
|
|
209
|
+
let subWeight = weight[i][j];
|
|
210
|
+
let subValueIsNumber = typeof subValue === "number";
|
|
211
|
+
let subWeightIsNumber = typeof subWeight === "number";
|
|
212
|
+
// typeof subValue or subWeight can be 'number' or 'undefined'
|
|
213
|
+
if (subValueIsNumber !== subWeightIsNumber) {
|
|
214
|
+
throw new Error(_lt(`AVERAGE.WEIGHTED expects number values.`));
|
|
215
|
+
}
|
|
216
|
+
if (subWeightIsNumber) {
|
|
217
|
+
if (subWeight < 0) {
|
|
218
|
+
throw new Error(negativeWeightError);
|
|
219
|
+
}
|
|
220
|
+
sum += subValue * subWeight;
|
|
221
|
+
count += subWeight;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
weight = toNumber(weight);
|
|
227
|
+
value = toNumber(value);
|
|
228
|
+
if (weight < 0) {
|
|
229
|
+
throw new Error(negativeWeightError);
|
|
230
|
+
}
|
|
231
|
+
sum += value * weight;
|
|
232
|
+
count += weight;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (count === 0) {
|
|
236
|
+
throw new Error(
|
|
237
|
+
_lt(`Evaluation of function AVERAGE.WEIGHTED caused a divide by zero error.`)
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
return sum / count;
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// -----------------------------------------------------------------------------
|
|
245
|
+
// AVERAGEA
|
|
246
|
+
// -----------------------------------------------------------------------------
|
|
247
|
+
export const AVERAGEA: FunctionDescription = {
|
|
248
|
+
description: _lt(`Numerical average value in a dataset.`),
|
|
249
|
+
args: args(`
|
|
250
|
+
value1 (number, range<number>) ${_lt(
|
|
251
|
+
"The first value or range to consider when calculating the average value."
|
|
252
|
+
)}
|
|
253
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
254
|
+
"Additional values or ranges to consider when calculating the average value."
|
|
255
|
+
)}
|
|
256
|
+
`),
|
|
257
|
+
returns: ["NUMBER"],
|
|
258
|
+
compute: function (): number {
|
|
259
|
+
let count = 0;
|
|
260
|
+
const sum = reduceNumbersTextAs0(
|
|
261
|
+
arguments,
|
|
262
|
+
(acc, a) => {
|
|
263
|
+
count += 1;
|
|
264
|
+
return acc + a;
|
|
265
|
+
},
|
|
266
|
+
0
|
|
267
|
+
);
|
|
268
|
+
if (count === 0) {
|
|
269
|
+
throw new Error(_lt(`Evaluation of function AVERAGEA caused a divide by zero error.`));
|
|
270
|
+
}
|
|
271
|
+
return sum / count;
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// -----------------------------------------------------------------------------
|
|
276
|
+
// AVERAGEIF
|
|
277
|
+
// -----------------------------------------------------------------------------
|
|
278
|
+
export const AVERAGEIF: FunctionDescription = {
|
|
279
|
+
description: _lt(`Average of values depending on criteria.`),
|
|
280
|
+
args: args(`
|
|
281
|
+
criteria_range (range) ${_lt("The range to check against criterion.")}
|
|
282
|
+
criterion (string) ${_lt("The pattern or test to apply to criteria_range.")}
|
|
283
|
+
average_range (range, optional, default=criteria_range) ${_lt(
|
|
284
|
+
"The range to average. If not included, criteria_range is used for the average instead."
|
|
285
|
+
)}
|
|
286
|
+
`),
|
|
287
|
+
returns: ["NUMBER"],
|
|
288
|
+
compute: function (criteria_range: any, criterion: any, average_range: any = undefined): number {
|
|
289
|
+
if (average_range === undefined) {
|
|
290
|
+
average_range = criteria_range;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
let count = 0;
|
|
294
|
+
let sum = 0;
|
|
295
|
+
|
|
296
|
+
visitMatchingRanges([criteria_range, criterion], (i, j) => {
|
|
297
|
+
const value = average_range[i][j];
|
|
298
|
+
if (typeof value === "number") {
|
|
299
|
+
count += 1;
|
|
300
|
+
sum += value;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
if (count === 0) {
|
|
305
|
+
throw new Error(_lt(`Evaluation of function AVERAGEIF caused a divide by zero error.`));
|
|
306
|
+
}
|
|
307
|
+
return sum / count;
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// -----------------------------------------------------------------------------
|
|
312
|
+
// AVERAGEIFS
|
|
313
|
+
// -----------------------------------------------------------------------------
|
|
314
|
+
export const AVERAGEIFS: FunctionDescription = {
|
|
315
|
+
description: _lt(`Average of values depending on multiple criteria.`),
|
|
316
|
+
args: args(`
|
|
317
|
+
average_range (range) ${_lt("The range to average.")}
|
|
318
|
+
criteria_range1 (range) ${_lt("The range to check against criterion1.")}
|
|
319
|
+
criterion1 (string) ${_lt("The pattern or test to apply to criteria_range1.")}
|
|
320
|
+
additional_values (any, range, optional, repeating) ${_lt(
|
|
321
|
+
"Additional criteria_range and criterion to check."
|
|
322
|
+
)}
|
|
323
|
+
`),
|
|
324
|
+
// @compatibility: on google sheets, args definitions are next:
|
|
325
|
+
// average_range (any, range) The range to average.
|
|
326
|
+
// criteria_range1 (any, range) The range to check against criterion1.
|
|
327
|
+
// criterion1 (string) The pattern or test to apply to criteria_range1.
|
|
328
|
+
// criteria_range2 (any, range, optional, repeating) Additional ranges to check.
|
|
329
|
+
// criterion2 (string, optional, repeating) Additional criteria to check.
|
|
330
|
+
returns: ["NUMBER"],
|
|
331
|
+
compute: function (average_range, ...args): number {
|
|
332
|
+
let count = 0;
|
|
333
|
+
let sum = 0;
|
|
334
|
+
visitMatchingRanges(args, (i, j) => {
|
|
335
|
+
const value = average_range[i][j];
|
|
336
|
+
if (typeof value === "number") {
|
|
337
|
+
count += 1;
|
|
338
|
+
sum += value;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
if (count === 0) {
|
|
342
|
+
throw new Error(_lt(`Evaluation of function AVERAGEIFS caused a divide by zero error.`));
|
|
343
|
+
}
|
|
344
|
+
return sum / count;
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// -----------------------------------------------------------------------------
|
|
349
|
+
// COUNT
|
|
350
|
+
// -----------------------------------------------------------------------------
|
|
351
|
+
export const COUNT: FunctionDescription = {
|
|
352
|
+
description: _lt(`The number of numeric values in dataset.`),
|
|
353
|
+
args: args(`
|
|
354
|
+
value1 (number, range<number>) ${_lt("The first value or range to consider when counting.")}
|
|
355
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
356
|
+
"Additional values or ranges to consider when counting."
|
|
357
|
+
)}
|
|
358
|
+
`),
|
|
359
|
+
returns: ["NUMBER"],
|
|
360
|
+
compute: function (): number {
|
|
361
|
+
let count = 0;
|
|
362
|
+
for (let n of arguments) {
|
|
363
|
+
if (Array.isArray(n)) {
|
|
364
|
+
for (let i of n) {
|
|
365
|
+
for (let j of i) {
|
|
366
|
+
if (typeof j === "number" || (typeof j === "object" && j !== null && j.jsDate)) {
|
|
367
|
+
count += 1;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
} else if (typeof n !== "string" || isNumber(n) || parseDateTime(n)) {
|
|
372
|
+
count += 1;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return count;
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// -----------------------------------------------------------------------------
|
|
380
|
+
// COUNTA
|
|
381
|
+
// -----------------------------------------------------------------------------
|
|
382
|
+
export const COUNTA: FunctionDescription = {
|
|
383
|
+
description: _lt(`The number of values in a dataset.`),
|
|
384
|
+
args: args(`
|
|
385
|
+
value1 (any, range) ${_lt("The first value or range to consider when counting.")}
|
|
386
|
+
value2 (any, range, optional, repeating) ${_lt(
|
|
387
|
+
"Additional values or ranges to consider when counting."
|
|
388
|
+
)}
|
|
389
|
+
`),
|
|
390
|
+
returns: ["NUMBER"],
|
|
391
|
+
compute: function (): number {
|
|
392
|
+
return reduceArgs(arguments, (acc, a) => (a !== undefined && a !== null ? acc + 1 : acc), 0);
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// -----------------------------------------------------------------------------
|
|
397
|
+
// COVAR
|
|
398
|
+
// -----------------------------------------------------------------------------
|
|
399
|
+
|
|
400
|
+
// Note: Unlike the VAR function which corresponds to the variance over a sample (VAR.S),
|
|
401
|
+
// the COVAR function corresponds to the covariance over an entire population (COVAR.P)
|
|
402
|
+
export const COVAR: FunctionDescription = {
|
|
403
|
+
description: _lt(`The covariance of a dataset.`),
|
|
404
|
+
args: args(`
|
|
405
|
+
data_y (any, range) ${_lt("The range representing the array or matrix of dependent data.")}
|
|
406
|
+
data_x (any, range) ${_lt("The range representing the array or matrix of independent data.")}
|
|
407
|
+
`),
|
|
408
|
+
returns: ["NUMBER"],
|
|
409
|
+
compute: function (data_y: any[], data_x: any[]): number {
|
|
410
|
+
return covariance(data_y, data_x, false);
|
|
411
|
+
},
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// -----------------------------------------------------------------------------
|
|
415
|
+
// COVARIANCE.P
|
|
416
|
+
// -----------------------------------------------------------------------------
|
|
417
|
+
export const COVARIANCE_P: FunctionDescription = {
|
|
418
|
+
description: _lt(`The covariance of a dataset.`),
|
|
419
|
+
args: args(`
|
|
420
|
+
data_y (any, range) ${_lt("The range representing the array or matrix of dependent data.")}
|
|
421
|
+
data_x (any, range) ${_lt("The range representing the array or matrix of independent data.")}
|
|
422
|
+
`),
|
|
423
|
+
returns: ["NUMBER"],
|
|
424
|
+
compute: function (data_y: any[], data_x: any[]): number {
|
|
425
|
+
return covariance(data_y, data_x, false);
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// -----------------------------------------------------------------------------
|
|
430
|
+
// COVARIANCE.S
|
|
431
|
+
// -----------------------------------------------------------------------------
|
|
432
|
+
export const COVARIANCE_S: FunctionDescription = {
|
|
433
|
+
description: _lt(`The sample covariance of a dataset.`),
|
|
434
|
+
args: args(`
|
|
435
|
+
data_y (any, range) ${_lt("The range representing the array or matrix of dependent data.")}
|
|
436
|
+
data_x (any, range) ${_lt("The range representing the array or matrix of independent data.")}
|
|
437
|
+
`),
|
|
438
|
+
returns: ["NUMBER"],
|
|
439
|
+
compute: function (data_y: any[], data_x: any[]): number {
|
|
440
|
+
return covariance(data_y, data_x, true);
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// -----------------------------------------------------------------------------
|
|
445
|
+
// LARGE
|
|
446
|
+
// -----------------------------------------------------------------------------
|
|
447
|
+
export const LARGE: FunctionDescription = {
|
|
448
|
+
description: _lt("Nth largest element from a data set."),
|
|
449
|
+
args: args(`
|
|
450
|
+
data (any, range) ${_lt("Array or range containing the dataset to consider.")}
|
|
451
|
+
n (number) ${_lt("The rank from largest to smallest of the element to return.")}
|
|
452
|
+
`),
|
|
453
|
+
returns: ["NUMBER"],
|
|
454
|
+
compute: function (data: any, n: any): number {
|
|
455
|
+
n = Math.trunc(toNumber(n));
|
|
456
|
+
let largests: number[] = [];
|
|
457
|
+
let index: number;
|
|
458
|
+
let count = 0;
|
|
459
|
+
visitAny(data, (d) => {
|
|
460
|
+
d = extractDateValue(d);
|
|
461
|
+
if (typeof d === "number") {
|
|
462
|
+
index = dichotomicPredecessorSearch(largests, d);
|
|
463
|
+
largests.splice(index + 1, 0, d);
|
|
464
|
+
count++;
|
|
465
|
+
if (count > n) {
|
|
466
|
+
largests.shift();
|
|
467
|
+
count--;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
const result = largests.shift();
|
|
472
|
+
if (result === undefined) {
|
|
473
|
+
throw new Error(_lt(`LARGE has no valid input data.`));
|
|
474
|
+
}
|
|
475
|
+
if (count < n) {
|
|
476
|
+
throw new Error(_lt("Function LARGE parameter 2 value %s is out of range.", n.toString()));
|
|
477
|
+
}
|
|
478
|
+
return result;
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// -----------------------------------------------------------------------------
|
|
483
|
+
// MAX
|
|
484
|
+
// -----------------------------------------------------------------------------
|
|
485
|
+
export const MAX: FunctionDescription = {
|
|
486
|
+
description: _lt("Maximum value in a numeric dataset."),
|
|
487
|
+
args: args(`
|
|
488
|
+
value1 (number, range<number>) ${_lt(
|
|
489
|
+
"The first value or range to consider when calculating the maximum value."
|
|
490
|
+
)}
|
|
491
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
492
|
+
"Additional values or ranges to consider when calculating the maximum value."
|
|
493
|
+
)}
|
|
494
|
+
`),
|
|
495
|
+
returns: ["NUMBER"],
|
|
496
|
+
compute: function (): number {
|
|
497
|
+
const result = reduceNumbers(arguments, (acc, a) => (acc < a ? a : acc), -Infinity);
|
|
498
|
+
return result === -Infinity ? 0 : result;
|
|
499
|
+
},
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// -----------------------------------------------------------------------------
|
|
503
|
+
// MAXA
|
|
504
|
+
// -----------------------------------------------------------------------------
|
|
505
|
+
export const MAXA: FunctionDescription = {
|
|
506
|
+
description: _lt("Maximum numeric value in a dataset."),
|
|
507
|
+
args: args(`
|
|
508
|
+
value1 (any, range) ${_lt(
|
|
509
|
+
"The first value or range to consider when calculating the maximum value."
|
|
510
|
+
)}
|
|
511
|
+
value2 (any, range, optional, repeating) ${_lt(
|
|
512
|
+
"Additional values or ranges to consider when calculating the maximum value."
|
|
513
|
+
)}
|
|
514
|
+
`),
|
|
515
|
+
returns: ["NUMBER"],
|
|
516
|
+
compute: function (): number {
|
|
517
|
+
const maxa = reduceNumbersTextAs0(
|
|
518
|
+
arguments,
|
|
519
|
+
(acc, a) => {
|
|
520
|
+
return Math.max(a, acc);
|
|
521
|
+
},
|
|
522
|
+
-Infinity
|
|
523
|
+
);
|
|
524
|
+
return maxa === -Infinity ? 0 : maxa;
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// -----------------------------------------------------------------------------
|
|
529
|
+
// MAXIFS
|
|
530
|
+
// -----------------------------------------------------------------------------
|
|
531
|
+
export const MAXIFS: FunctionDescription = {
|
|
532
|
+
description: _lt("Returns the maximum value in a range of cells, filtered by a set of criteria."),
|
|
533
|
+
args: args(`
|
|
534
|
+
range (range) ${_lt("The range of cells from which the maximum will be determined.")}
|
|
535
|
+
criteria_range1 (range) ${_lt("The range of cells over which to evaluate criterion1.")}
|
|
536
|
+
criterion1 (string) ${_lt(
|
|
537
|
+
"The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set."
|
|
538
|
+
)}
|
|
539
|
+
additional_values (any, range, optional, repeating) ${_lt(
|
|
540
|
+
"Additional criteria_range and criterion to check."
|
|
541
|
+
)}
|
|
542
|
+
`),
|
|
543
|
+
// @compatibility: on google sheets, args definitions are next:
|
|
544
|
+
// range (any, range) The range of cells from which the maximum will be determined.
|
|
545
|
+
// criteria_range1 (any, range) The range of cells over which to evaluate criterion1.
|
|
546
|
+
// criterion1 (string) The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.
|
|
547
|
+
// criteria_range2 (any, range, optional, repeating) Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.
|
|
548
|
+
// criterion2 (string, optional, repeating) The pattern or test to apply to criteria_range2.
|
|
549
|
+
returns: ["NUMBER"],
|
|
550
|
+
compute: function (range, ...args): number {
|
|
551
|
+
let result = -Infinity;
|
|
552
|
+
visitMatchingRanges(args, (i, j) => {
|
|
553
|
+
const value = range[i][j];
|
|
554
|
+
if (typeof value === "number") {
|
|
555
|
+
result = result < value ? value : result;
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
return result === -Infinity ? 0 : result;
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// -----------------------------------------------------------------------------
|
|
563
|
+
// MIN
|
|
564
|
+
// -----------------------------------------------------------------------------
|
|
565
|
+
export const MIN: FunctionDescription = {
|
|
566
|
+
description: _lt("Minimum value in a numeric dataset."),
|
|
567
|
+
args: args(`
|
|
568
|
+
value1 (number, range<number>) ${_lt(
|
|
569
|
+
"The first value or range to consider when calculating the minimum value."
|
|
570
|
+
)}
|
|
571
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
572
|
+
"Additional values or ranges to consider when calculating the minimum value."
|
|
573
|
+
)}
|
|
574
|
+
`),
|
|
575
|
+
returns: ["NUMBER"],
|
|
576
|
+
compute: function (): number {
|
|
577
|
+
const result = reduceNumbers(arguments, (acc, a) => (a < acc ? a : acc), Infinity);
|
|
578
|
+
return result === Infinity ? 0 : result;
|
|
579
|
+
},
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// -----------------------------------------------------------------------------
|
|
583
|
+
// MINA
|
|
584
|
+
// -----------------------------------------------------------------------------
|
|
585
|
+
export const MINA: FunctionDescription = {
|
|
586
|
+
description: _lt("Minimum numeric value in a dataset."),
|
|
587
|
+
args: args(`
|
|
588
|
+
value1 (number, range<number>) ${_lt(
|
|
589
|
+
"The first value or range to consider when calculating the minimum value."
|
|
590
|
+
)}
|
|
591
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
592
|
+
"Additional values or ranges to consider when calculating the minimum value."
|
|
593
|
+
)}
|
|
594
|
+
`),
|
|
595
|
+
returns: ["NUMBER"],
|
|
596
|
+
compute: function (): number {
|
|
597
|
+
const mina: number = reduceNumbersTextAs0(
|
|
598
|
+
arguments,
|
|
599
|
+
(acc, a) => {
|
|
600
|
+
return Math.min(a, acc);
|
|
601
|
+
},
|
|
602
|
+
Infinity
|
|
603
|
+
);
|
|
604
|
+
return mina === Infinity ? 0 : mina;
|
|
605
|
+
},
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// -----------------------------------------------------------------------------
|
|
609
|
+
// MINIFS
|
|
610
|
+
// -----------------------------------------------------------------------------
|
|
611
|
+
export const MINIFS: FunctionDescription = {
|
|
612
|
+
description: _lt("Returns the minimum value in a range of cells, filtered by a set of criteria."),
|
|
613
|
+
args: args(`
|
|
614
|
+
range (range) ${_lt("The range of cells from which the minimum will be determined.")}
|
|
615
|
+
criteria_range1 (range) ${_lt("The range of cells over which to evaluate criterion1.")}
|
|
616
|
+
criterion1 (string) ${_lt(
|
|
617
|
+
"The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set."
|
|
618
|
+
)}
|
|
619
|
+
additional_values (any, range, optional, repeating) ${_lt(
|
|
620
|
+
"Additional criteria_range and criterion to check."
|
|
621
|
+
)}
|
|
622
|
+
`),
|
|
623
|
+
// @compatibility: on google sheets, args definitions are next:
|
|
624
|
+
// range (any, range) The range of cells from which the minimum will be determined.
|
|
625
|
+
// criteria_range1 (any, range) The range of cells over which to evaluate criterion1.
|
|
626
|
+
// criterion1 (string) The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.
|
|
627
|
+
// criteria_range2 (any, range, optional, repeating) Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.
|
|
628
|
+
// criterion2 (string, optional, repeating) The pattern or test to apply to criteria_range2.
|
|
629
|
+
returns: ["NUMBER"],
|
|
630
|
+
compute: function (range, ...args): number {
|
|
631
|
+
let result = Infinity;
|
|
632
|
+
visitMatchingRanges(args, (i, j) => {
|
|
633
|
+
const value = range[i][j];
|
|
634
|
+
if (typeof value === "number") {
|
|
635
|
+
result = result > value ? value : result;
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
return result === Infinity ? 0 : result;
|
|
639
|
+
},
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// -----------------------------------------------------------------------------
|
|
643
|
+
// SMALL
|
|
644
|
+
// -----------------------------------------------------------------------------
|
|
645
|
+
export const SMALL: FunctionDescription = {
|
|
646
|
+
description: _lt("Nth smallest element in a data set."),
|
|
647
|
+
args: args(`
|
|
648
|
+
data (any, range) ${_lt("The array or range containing the dataset to consider.")}
|
|
649
|
+
n (number) ${_lt("The rank from smallest to largest of the element to return.")}
|
|
650
|
+
`),
|
|
651
|
+
returns: ["NUMBER"],
|
|
652
|
+
compute: function (data: any, n: any): number {
|
|
653
|
+
n = Math.trunc(toNumber(n));
|
|
654
|
+
let largests: number[] = [];
|
|
655
|
+
let index: number;
|
|
656
|
+
let count = 0;
|
|
657
|
+
visitAny(data, (d) => {
|
|
658
|
+
d = extractDateValue(d);
|
|
659
|
+
if (typeof d === "number") {
|
|
660
|
+
index = dichotomicPredecessorSearch(largests, d);
|
|
661
|
+
largests.splice(index + 1, 0, d);
|
|
662
|
+
count++;
|
|
663
|
+
if (count > n) {
|
|
664
|
+
largests.pop();
|
|
665
|
+
count--;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
const result = largests.pop();
|
|
670
|
+
if (result === undefined) {
|
|
671
|
+
throw new Error(_lt(`SMALL has no valid input data.`));
|
|
672
|
+
}
|
|
673
|
+
if (count < n) {
|
|
674
|
+
throw new Error(_lt("Function SMALL parameter 2 value %s is out of range.", n.toString()));
|
|
675
|
+
}
|
|
676
|
+
return result;
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
// -----------------------------------------------------------------------------
|
|
681
|
+
// STDEV
|
|
682
|
+
// -----------------------------------------------------------------------------
|
|
683
|
+
export const STDEV: FunctionDescription = {
|
|
684
|
+
description: _lt("Standard deviation."),
|
|
685
|
+
args: args(`
|
|
686
|
+
value1 (number, range<number>) ${_lt("The first value or range of the sample.")}
|
|
687
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
688
|
+
"Additional values or ranges to include in the sample."
|
|
689
|
+
)}
|
|
690
|
+
`),
|
|
691
|
+
returns: ["NUMBER"],
|
|
692
|
+
compute: function (): number {
|
|
693
|
+
return Math.sqrt(VAR.compute(...arguments));
|
|
694
|
+
},
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
// -----------------------------------------------------------------------------
|
|
698
|
+
// STDEV.P
|
|
699
|
+
// -----------------------------------------------------------------------------
|
|
700
|
+
export const STDEV_P: FunctionDescription = {
|
|
701
|
+
description: _lt("Standard deviation of entire population."),
|
|
702
|
+
args: args(`
|
|
703
|
+
value1 (number, range<number>) ${_lt("The first value or range of the population.")}
|
|
704
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
705
|
+
"Additional values or ranges to include in the population."
|
|
706
|
+
)}
|
|
707
|
+
`),
|
|
708
|
+
returns: ["NUMBER"],
|
|
709
|
+
compute: function (): number {
|
|
710
|
+
return Math.sqrt(VAR_P.compute(...arguments));
|
|
711
|
+
},
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
// -----------------------------------------------------------------------------
|
|
715
|
+
// STDEV.S
|
|
716
|
+
// -----------------------------------------------------------------------------
|
|
717
|
+
export const STDEV_S: FunctionDescription = {
|
|
718
|
+
description: _lt("Standard deviation."),
|
|
719
|
+
args: args(`
|
|
720
|
+
value1 (number, range<number>) ${_lt("The first value or range of the sample.")}
|
|
721
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
722
|
+
"Additional values or ranges to include in the sample."
|
|
723
|
+
)}
|
|
724
|
+
`),
|
|
725
|
+
returns: ["NUMBER"],
|
|
726
|
+
compute: function (): number {
|
|
727
|
+
return Math.sqrt(VAR_S.compute(...arguments));
|
|
728
|
+
},
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
// -----------------------------------------------------------------------------
|
|
732
|
+
// STDEVA
|
|
733
|
+
// -----------------------------------------------------------------------------
|
|
734
|
+
export const STDEVA: FunctionDescription = {
|
|
735
|
+
description: _lt("Standard deviation of sample (text as 0)."),
|
|
736
|
+
args: args(`
|
|
737
|
+
value1 (number, range<number>) ${_lt("The first value or range of the sample.")}
|
|
738
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
739
|
+
"Additional values or ranges to include in the sample."
|
|
740
|
+
)}
|
|
741
|
+
`),
|
|
742
|
+
returns: ["NUMBER"],
|
|
743
|
+
compute: function (): number {
|
|
744
|
+
return Math.sqrt(VARA.compute(...arguments));
|
|
745
|
+
},
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
// -----------------------------------------------------------------------------
|
|
749
|
+
// STDEVP
|
|
750
|
+
// -----------------------------------------------------------------------------
|
|
751
|
+
export const STDEVP: FunctionDescription = {
|
|
752
|
+
description: _lt("Standard deviation of entire population."),
|
|
753
|
+
args: args(`
|
|
754
|
+
value1 (number, range<number>) ${_lt("The first value or range of the population.")}
|
|
755
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
756
|
+
"Additional values or ranges to include in the population."
|
|
757
|
+
)}
|
|
758
|
+
`),
|
|
759
|
+
returns: ["NUMBER"],
|
|
760
|
+
compute: function (): number {
|
|
761
|
+
return Math.sqrt(VARP.compute(...arguments));
|
|
762
|
+
},
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
// -----------------------------------------------------------------------------
|
|
766
|
+
// STDEVPA
|
|
767
|
+
// -----------------------------------------------------------------------------
|
|
768
|
+
export const STDEVPA: FunctionDescription = {
|
|
769
|
+
description: _lt("Standard deviation of entire population (text as 0)."),
|
|
770
|
+
args: args(`
|
|
771
|
+
value1 (number, range<number>) ${_lt("The first value or range of the population.")}
|
|
772
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
773
|
+
"Additional values or ranges to include in the population."
|
|
774
|
+
)}
|
|
775
|
+
`),
|
|
776
|
+
returns: ["NUMBER"],
|
|
777
|
+
compute: function (): number {
|
|
778
|
+
return Math.sqrt(VARPA.compute(...arguments));
|
|
779
|
+
},
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
// -----------------------------------------------------------------------------
|
|
783
|
+
// VAR
|
|
784
|
+
// -----------------------------------------------------------------------------
|
|
785
|
+
export const VAR: FunctionDescription = {
|
|
786
|
+
description: _lt("Variance."),
|
|
787
|
+
args: args(`
|
|
788
|
+
value1 (number, range<number>) ${_lt("The first value or range of the sample.")}
|
|
789
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
790
|
+
"Additional values or ranges to include in the sample."
|
|
791
|
+
)}
|
|
792
|
+
`),
|
|
793
|
+
returns: ["NUMBER"],
|
|
794
|
+
compute: function (): number {
|
|
795
|
+
return variance(arguments, true, false);
|
|
796
|
+
},
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// -----------------------------------------------------------------------------
|
|
800
|
+
// VAR.P
|
|
801
|
+
// -----------------------------------------------------------------------------
|
|
802
|
+
export const VAR_P: FunctionDescription = {
|
|
803
|
+
description: _lt("Variance of entire population."),
|
|
804
|
+
args: args(`
|
|
805
|
+
value1 (number, range<number>) ${_lt("The first value or range of the population.")}
|
|
806
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
807
|
+
"Additional values or ranges to include in the population."
|
|
808
|
+
)}
|
|
809
|
+
`),
|
|
810
|
+
returns: ["NUMBER"],
|
|
811
|
+
compute: function (): number {
|
|
812
|
+
return variance(arguments, false, false);
|
|
813
|
+
},
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
// -----------------------------------------------------------------------------
|
|
817
|
+
// VAR.S
|
|
818
|
+
// -----------------------------------------------------------------------------
|
|
819
|
+
export const VAR_S: FunctionDescription = {
|
|
820
|
+
description: _lt("Variance."),
|
|
821
|
+
args: args(`
|
|
822
|
+
value1 (number, range<number>) ${_lt("The first value or range of the sample.")}
|
|
823
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
824
|
+
"Additional values or ranges to include in the sample."
|
|
825
|
+
)}
|
|
826
|
+
`),
|
|
827
|
+
returns: ["NUMBER"],
|
|
828
|
+
compute: function (): number {
|
|
829
|
+
return variance(arguments, true, false);
|
|
830
|
+
},
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
// -----------------------------------------------------------------------------
|
|
834
|
+
// VARA
|
|
835
|
+
// -----------------------------------------------------------------------------
|
|
836
|
+
export const VARA: FunctionDescription = {
|
|
837
|
+
description: _lt("Variance of sample (text as 0)."),
|
|
838
|
+
args: args(`
|
|
839
|
+
value1 (number, range<number>) ${_lt("The first value or range of the sample.")}
|
|
840
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
841
|
+
"Additional values or ranges to include in the sample."
|
|
842
|
+
)}
|
|
843
|
+
`),
|
|
844
|
+
returns: ["NUMBER"],
|
|
845
|
+
compute: function (): number {
|
|
846
|
+
return variance(arguments, true, true);
|
|
847
|
+
},
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// -----------------------------------------------------------------------------
|
|
851
|
+
// VARP
|
|
852
|
+
// -----------------------------------------------------------------------------
|
|
853
|
+
export const VARP: FunctionDescription = {
|
|
854
|
+
description: _lt("Variance of entire population."),
|
|
855
|
+
args: args(`
|
|
856
|
+
value1 (number, range<number>) ${_lt("The first value or range of the population.")}
|
|
857
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
858
|
+
"Additional values or ranges to include in the population."
|
|
859
|
+
)}
|
|
860
|
+
`),
|
|
861
|
+
returns: ["NUMBER"],
|
|
862
|
+
compute: function (): number {
|
|
863
|
+
return variance(arguments, false, false);
|
|
864
|
+
},
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
// -----------------------------------------------------------------------------
|
|
868
|
+
// VARPA
|
|
869
|
+
// -----------------------------------------------------------------------------
|
|
870
|
+
export const VARPA: FunctionDescription = {
|
|
871
|
+
description: _lt("Variance of entire population (text as 0)."),
|
|
872
|
+
args: args(`
|
|
873
|
+
value1 (number, range<number>) ${_lt("The first value or range of the population.")}
|
|
874
|
+
value2 (number, range<number>, optional, repeating) ${_lt(
|
|
875
|
+
"Additional values or ranges to include in the population."
|
|
876
|
+
)}
|
|
877
|
+
`),
|
|
878
|
+
returns: ["NUMBER"],
|
|
879
|
+
compute: function (): number {
|
|
880
|
+
return variance(arguments, false, true);
|
|
881
|
+
},
|
|
882
|
+
};
|