Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(formula): supplement ISBETWEEN/AVERAGE.WEIGHTED/MARGINOFERROR formula (#3998)
wpxp1234560dc0027c3231
diff --git a/packages/engine-formula/src/functions/information/function-map.ts b/packages/engine-formula/src/functions/information/function-map.tsindex 6ec0bb781b..e9a10c51d1 100644--- a/packages/engine-formula/src/functions/information/function-map.ts+++ b/packages/engine-formula/src/functions/information/function-map.ts@@ -17,6 +17,7 @@import { Cell } from './cell';import { ErrorType } from './error-type';import { FUNCTION_NAMES_INFORMATION } from './function-names';+import { Isbetween } from './isbetween';import { Isblank } from './isblank';import { Isdate } from './isdate';import { Isemail } from './isemail';@@ -41,6 +42,7 @@ import { Type } from './type';export const functionInformation = [[Cell, FUNCTION_NAMES_INFORMATION.CELL],[ErrorType, FUNCTION_NAMES_INFORMATION.ERROR_TYPE],+ [Isbetween, FUNCTION_NAMES_INFORMATION.ISBETWEEN],[Isblank, FUNCTION_NAMES_INFORMATION.ISBLANK],[Isdate, FUNCTION_NAMES_INFORMATION.ISDATE],[Isemail, FUNCTION_NAMES_INFORMATION.ISEMAIL],diff --git a/packages/engine-formula/src/functions/information/function-names.ts b/packages/engine-formula/src/functions/information/function-names.tsindex 2b4e40e914..9084a0a2e3 100644--- a/packages/engine-formula/src/functions/information/function-names.ts+++ b/packages/engine-formula/src/functions/information/function-names.ts@@ -18,6 +18,7 @@ export enum FUNCTION_NAMES_INFORMATION {CELL = 'CELL',ERROR_TYPE = 'ERROR.TYPE',INFO = 'INFO',+ ISBETWEEN = 'ISBETWEEN',ISBLANK = 'ISBLANK',ISDATE = 'ISDATE',ISEMAIL = 'ISEMAIL',diff --git a/packages/engine-formula/src/functions/information/isbetween/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isbetween/__tests__/index.spec.tsnew file mode 100644index 0000000000..f7e71f92b1--- /dev/null+++ b/packages/engine-formula/src/functions/information/isbetween/__tests__/index.spec.ts@@ -0,0 +1,104 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';+import { Isbetween } from '../index';++describe('Test isbetween function', () => {+ const testFunction = new Isbetween(FUNCTION_NAMES_INFORMATION.ISBETWEEN);++ describe('Isbetween', () => {+ it('Value is normal', () => {+ const valueToCompare = NumberValueObject.create(7.9);+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(true);+ });++ it('LowerValue > upperValue', () => {+ const valueToCompare = NumberValueObject.create(7.9);+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(-12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const valueToCompare = StringValueObject.create('7.9');+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is normal string', () => {+ const valueToCompare = StringValueObject.create('test');+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is blank cell', () => {+ const valueToCompare = NullValueObject.create();+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(false);+ });++ it('Value is boolean', () => {+ const valueToCompare = BooleanValueObject.create(true);+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(false);+ });++ it('Value is error', () => {+ const valueToCompare = ErrorValueObject.create(ErrorType.NAME);+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueToCompare = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3],+ ]),+ rowCount: 1,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const lowerValue = NumberValueObject.create(1.2);+ const upperValue = NumberValueObject.create(12.45);+ const result = testFunction.calculate(valueToCompare, lowerValue, upperValue);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/information/isbetween/index.ts b/packages/engine-formula/src/functions/information/isbetween/index.tsnew file mode 100644index 0000000000..7e47ac9bdd--- /dev/null+++ b/packages/engine-formula/src/functions/information/isbetween/index.ts@@ -0,0 +1,72 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../basics/error-type';+import { checkVariantsErrorIsArray } from '../../../engine/utils/check-variant-error';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Isbetween extends BaseFunction {+ override minParams = 3;++ override maxParams = 5;++ override calculate(+ valueToCompare: BaseValueObject,+ lowerValue: BaseValueObject,+ upperValue: BaseValueObject,+ lowerValueIsInclusive?: BaseValueObject,+ upperValueIsInclusive?: BaseValueObject+ ): BaseValueObject {+ const _lowerValueIsInclusive = lowerValueIsInclusive ?? BooleanValueObject.create(true);+ const _upperValueIsInclusive = upperValueIsInclusive ?? BooleanValueObject.create(true);++ const { isError, errorObject, variants } = checkVariantsErrorIsArray(valueToCompare, lowerValue, upperValue, _lowerValueIsInclusive, _upperValueIsInclusive);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [valueToCompareObject, lowerValueObject, upperValueObject, lowerValueIsInclusiveObject, upperValueIsInclusiveObject] = variants as BaseValueObject[];++ if (+ valueToCompareObject.isString() ||+ lowerValueObject.isString() ||+ upperValueObject.isString() ||+ lowerValueIsInclusiveObject.isString() ||+ upperValueIsInclusiveObject.isString()+ ) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const valueToCompareValue = +valueToCompareObject.getValue();+ const lowerValueValue = +lowerValueObject.getValue();+ const upperValueValue = +upperValueObject.getValue();+ const lowerValueIsInclusiveValue = +lowerValueIsInclusiveObject.getValue();+ const upperValueIsInclusiveValue = +upperValueIsInclusiveObject.getValue();++ if (lowerValueValue > upperValueValue) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const lowerComparison = lowerValueIsInclusiveValue ? valueToCompareValue >= lowerValueValue : valueToCompareValue > lowerValueValue;+ const upperComparison = upperValueIsInclusiveValue ? valueToCompareValue <= upperValueValue : valueToCompareValue < upperValueValue;++ return BooleanValueObject.create(lowerComparison && upperComparison);+ }+}diff --git a/packages/engine-formula/src/functions/statistical/average-weighted/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/average-weighted/__tests__/index.spec.tsnew file mode 100644index 0000000000..55d9c5dec1--- /dev/null+++ b/packages/engine-formula/src/functions/statistical/average-weighted/__tests__/index.spec.ts@@ -0,0 +1,128 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';+import { AverageWeighted } from '../index';++describe('Test averageWeighted function', () => {+ const testFunction = new AverageWeighted(FUNCTION_NAMES_STATISTICAL.AVERAGE_WEIGHTED);++ describe('AverageWeighted', () => {+ it('Value is normal', () => {+ const value1 = NumberValueObject.create(1);+ const weight1 = NumberValueObject.create(3);+ const value2 = NumberValueObject.create(2);+ const weight2 = NumberValueObject.create(4);+ const result = testFunction.calculate(value1, weight1, value2, weight2);+ expect(getObjectValue(result)).toBe(1.5714285714285714);+ });++ it('Value is not paired', () => {+ const value1 = NumberValueObject.create(1);+ const weight1 = NumberValueObject.create(3);+ const value2 = NumberValueObject.create(2);+ const result = testFunction.calculate(value1, weight1, value2);+ expect(getObjectValue(result)).toBe(ErrorType.NA);+ });++ it('Weight is negative', () => {+ const value1 = NumberValueObject.create(1);+ const weight1 = NumberValueObject.create(3);+ const value2 = NumberValueObject.create(2);+ const weight2 = NumberValueObject.create(-4);+ const result = testFunction.calculate(value1, weight1, value2, weight2);+ expect(getObjectValue(result)).toBe(ErrorType.VALUE);+ });++ it('Value is error', () => {+ const value1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2.34, true, false, null],+ [0, '100', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 5,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const weight1 = NumberValueObject.create(3);+ const result = testFunction.calculate(value1, weight1);+ expect(getObjectValue(result)).toBe(ErrorType.NAME);++ const value2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3, 4, 5],+ [6, 7, 8, 9, 10],+ ]),+ rowCount: 2,+ columnCount: 5,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const weight2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2.34, true, false, null],+ [0, '100', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 5,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(value2, weight2);+ expect(getObjectValue(result2)).toBe(ErrorType.NAME);+ });++ it('Value and weight is different length', () => {+ const value1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3, 4],+ ]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const weight1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3],+ ]),+ rowCount: 1,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(value1, weight1);+ expect(getObjectValue(result)).toBe(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/statistical/average-weighted/index.ts b/packages/engine-formula/src/functions/statistical/average-weighted/index.tsnew file mode 100644index 0000000000..c3a56853d4--- /dev/null+++ b/packages/engine-formula/src/functions/statistical/average-weighted/index.ts@@ -0,0 +1,134 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class AverageWeighted extends BaseFunction {+ override minParams = 2;++ override maxParams = 254;++ // eslint-disable-next-line+ override calculate(...variants: BaseValueObject[]): BaseValueObject {+ let isOtherError = false;+ let otherErrorObject: ErrorValueObject | undefined;++ if (variants.length % 2 !== 0) {+ isOtherError = true;+ otherErrorObject = ErrorValueObject.create(ErrorType.NA);+ }++ const values: number[] = [];+ const weights: number[] = [];++ for (let i = 0; i < variants.length; i += 2) {+ const valueObject = variants[i];+ const valueObjectRowCount = valueObject.isArray() ? (valueObject as ArrayValueObject).getRowCount() : 1;+ const valueObjectColumnCount = valueObject.isArray() ? (valueObject as ArrayValueObject).getColumnCount() : 1;++ for (let r = 0; r < valueObjectRowCount; r++) {+ for (let c = 0; c < valueObjectColumnCount; c++) {+ const obj = valueObject.isArray() ? (valueObject as ArrayValueObject).get(r, c) as BaseValueObject : valueObject;++ if (obj.isError()) {+ return obj;+ }++ if (isOtherError) {+ continue;+ }++ if (obj.isNull() || obj.isBoolean() || obj.isString()) {+ isOtherError = true;+ otherErrorObject = ErrorValueObject.create(ErrorType.VALUE);+ continue;+ }++ values.push(+obj.getValue());+ }+ }++ if (i + 1 >= variants.length) {+ continue;+ }++ const weightObject = variants[i + 1];+ const weightObjectRowCount = weightObject.isArray() ? (weightObject as ArrayValueObject).getRowCount() : 1;+ const weightObjectColumnCount = weightObject.isArray() ? (weightObject as ArrayValueObject).getColumnCount() : 1;++ if (weightObjectRowCount !== valueObjectRowCount || weightObjectColumnCount !== valueObjectColumnCount) {+ isOtherError = true;+ otherErrorObject = ErrorValueObject.create(ErrorType.VALUE);+ }++ for (let r = 0; r < weightObjectRowCount; r++) {+ for (let c = 0; c < weightObjectColumnCount; c++) {+ const obj = weightObject.isArray() ? (weightObject as ArrayValueObject).get(r, c) as BaseValueObject : weightObject;++ if (obj.isError()) {+ return obj;+ }++ if (isOtherError) {+ continue;+ }++ if (obj.isNull() || obj.isBoolean() || obj.isString()) {+ isOtherError = true;+ otherErrorObject = ErrorValueObject.create(ErrorType.VALUE);+ continue;+ }++ const weight = +obj.getValue();++ if (weight < 0) {+ isOtherError = true;+ otherErrorObject = ErrorValueObject.create(ErrorType.VALUE);+ continue;+ }++ weights.push(weight);+ }+ }+ }++ if (isOtherError) {+ return otherErrorObject as ErrorValueObject;+ }++ return this._getResult(values, weights);+ }++ private _getResult(values: number[], weights: number[]): BaseValueObject {+ const n = values.length;++ let sum = 0;+ let sumWeight = 0;++ for (let i = 0; i < n; i++) {+ sum += values[i] * weights[i];+ sumWeight += weights[i];+ }++ const result = sum / sumWeight;++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/statistical/function-map.ts b/packages/engine-formula/src/functions/statistical/function-map.tsindex aa1073cf67..ba07de1b89 100644--- a/packages/engine-formula/src/functions/statistical/function-map.ts+++ b/packages/engine-formula/src/functions/statistical/function-map.ts@@ -16,6 +16,7 @@import { Avedev } from './avedev';import { Average } from './average';+import { AverageWeighted } from './average-weighted';import { Averagea } from './averagea';import { Averageif } from './averageif';import { Averageifs } from './averageifs';@@ -67,6 +68,7 @@ import { Linest } from './linest';import { Logest } from './logest';import { LognormDist } from './lognorm-dist';import { LognormInv } from './lognorm-inv';+import { Marginoferror } from './marginoferror';import { Max } from './max';import { Maxa } from './maxa';import { Maxifs } from './maxifs';@@ -124,6 +126,7 @@ import { ZTest } from './z-test';export const functionStatistical = [[Avedev, FUNCTION_NAMES_STATISTICAL.AVEDEV],[Average, FUNCTION_NAMES_STATISTICAL.AVERAGE],+ [AverageWeighted, FUNCTION_NAMES_STATISTICAL.AVERAGE_WEIGHTED],[Averagea, FUNCTION_NAMES_STATISTICAL.AVERAGEA],[Averageif, FUNCTION_NAMES_STATISTICAL.AVERAGEIF],[Averageifs, FUNCTION_NAMES_STATISTICAL.AVERAGEIFS],@@ -176,6 +179,7 @@ export const functionStatistical = [[Logest, FUNCTION_NAMES_STATISTICAL.LOGEST],[LognormDist, FUNCTION_NAMES_STATISTICAL.LOGNORM_DIST],[LognormInv, FUNCTION_NAMES_STATISTICAL.LOGNORM_INV],+ [Marginoferror, FUNCTION_NAMES_STATISTICAL.MARGINOFERROR],[Max, FUNCTION_NAMES_STATISTICAL.MAX],[Maxa, FUNCTION_NAMES_STATISTICAL.MAXA],[Maxifs, FUNCTION_NAMES_STATISTICAL.MAXIFS],diff --git a/packages/engine-formula/src/functions/statistical/function-names.ts b/packages/engine-formula/src/functions/statistical/function-names.tsindex 5b08f88bf9..b41a323088 100644--- a/packages/engine-formula/src/functions/statistical/function-names.ts+++ b/packages/engine-formula/src/functions/statistical/function-names.ts@@ -17,6 +17,7 @@export enum FUNCTION_NAMES_STATISTICAL {AVEDEV = 'AVEDEV',AVERAGE = 'AVERAGE',+ AVERAGE_WEIGHTED = 'AVERAGE.WEIGHTED',AVERAGEA = 'AVERAGEA',AVERAGEIF = 'AVERAGEIF',AVERAGEIFS = 'AVERAGEIFS',@@ -73,6 +74,7 @@ export enum FUNCTION_NAMES_STATISTICAL {LOGEST = 'LOGEST',LOGNORM_DIST = 'LOGNORM.DIST',LOGNORM_INV = 'LOGNORM.INV',+ MARGINOFERROR = 'MARGINOFERROR',MAX = 'MAX',MAXA = 'MAXA',MAXIFS = 'MAXIFS',diff --git a/packages/engine-formula/src/functions/statistical/marginoferror/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/marginoferror/__tests__/index.spec.tsnew file mode 100644index 0000000000..0ba87b327f--- /dev/null+++ b/packages/engine-formula/src/functions/statistical/marginoferror/__tests__/index.spec.ts@@ -0,0 +1,143 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';+import { Marginoferror } from '../index';++describe('Test marginoferror function', () => {+ const testFunction = new Marginoferror(FUNCTION_NAMES_STATISTICAL.MARGINOFERROR);++ describe('Marginoferror', () => {+ it('Value is normal', () => {+ const range = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2],+ [3, 4],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const confidence = NumberValueObject.create(0.1);+ const result = testFunction.calculate(range, confidence);+ expect(getObjectValue(result)).toBe(0.0881737585364693);+ });++ it('Range value test', () => {+ const range = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2.34, true, false, null],+ [0, '100', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 5,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const confidence = NumberValueObject.create(0.1);+ const result = testFunction.calculate(range, confidence);+ expect(getObjectValue(result)).toBe(ErrorType.NAME);++ const range2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ [true, false],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(range2, confidence);+ expect(getObjectValue(result2)).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('Confidence value test', () => {+ const range = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2],+ [3, 4],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const confidence = NumberValueObject.create(-0.1);+ const result = testFunction.calculate(range, confidence);+ expect(getObjectValue(result)).toBe(ErrorType.NUM);++ const confidence2 = NullValueObject.create();+ const result2 = testFunction.calculate(range, confidence2);+ expect(getObjectValue(result2)).toBe(ErrorType.NUM);++ const confidence3 = BooleanValueObject.create(true);+ const result3 = testFunction.calculate(range, confidence3);+ expect(getObjectValue(result3)).toBe(ErrorType.NUM);++ const confidence4 = StringValueObject.create('test');+ const result4 = testFunction.calculate(range, confidence4);+ expect(getObjectValue(result4)).toBe(ErrorType.VALUE);++ const confidence5 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [0.1, 0.2],+ ]),+ rowCount: 1,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result5 = testFunction.calculate(range, confidence5);+ expect(getObjectValue(result5)).toBe(ErrorType.VALUE);+ });++ it('Value stdev is 0', () => {+ const range = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 1],+ [1, 1],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const confidence = NumberValueObject.create(0.1);+ const result = testFunction.calculate(range, confidence);+ expect(getObjectValue(result)).toBe(ErrorType.NUM);+ });+ });+});diff --git a/packages/engine-formula/src/functions/statistical/marginoferror/index.ts b/packages/engine-formula/src/functions/statistical/marginoferror/index.tsnew file mode 100644index 0000000000..16d6430d43--- /dev/null+++ b/packages/engine-formula/src/functions/statistical/marginoferror/index.ts@@ -0,0 +1,101 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../basics/error-type';+import { studentTINV } from '../../../basics/statistical';+import { checkVariantErrorIsArray, checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Marginoferror extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(range: BaseValueObject, confidence: BaseValueObject): BaseValueObject {+ const rangeValues = this._getRangeValues(range);++ if (rangeValues instanceof ErrorValueObject) {+ return rangeValues;+ }++ const _confidence = checkVariantErrorIsArray(confidence);++ if (_confidence.isError()) {+ return _confidence;+ }++ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(_confidence);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [confidenceObject] = variants as BaseValueObject[];++ const confidenceValue = +confidenceObject.getValue();++ if (confidenceValue <= 0 || confidenceValue >= 1) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ if (rangeValues.length < 2) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ const alpha = 1 - confidenceValue;+ const size = rangeValues.length;+ const mean = rangeValues.reduce((acc, value) => acc + value, 0) / size;+ const variance = rangeValues.reduce((acc, value) => acc + (value - mean) ** 2, 0) / (size - 1);+ const standardDev = Math.sqrt(variance);++ if (standardDev <= 0) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const result = Math.abs(studentTINV(alpha / 2, size - 1) * standardDev / Math.sqrt(size));++ return NumberValueObject.create(result);+ }++ private _getRangeValues(range: BaseValueObject): number[] | ErrorValueObject {+ const rangeValues: number[] = [];++ const rowCount = range.isArray() ? (range as ArrayValueObject).getRowCount() : 1;+ const columnCount = range.isArray() ? (range as ArrayValueObject).getColumnCount() : 1;++ for (let r = 0; r < rowCount; r++) {+ for (let c = 0; c < columnCount; c++) {+ const valueObject = range.isArray() ? (range as ArrayValueObject).get(r, c) as BaseValueObject : range;++ if (valueObject.isError()) {+ return valueObject as ErrorValueObject;+ }++ if (valueObject.isNull() || valueObject.isBoolean() || valueObject.isString()) {+ continue;+ }++ rangeValues.push(+valueObject.getValue());+ }+ }++ return rangeValues;+ }+}diff --git a/packages/sheets-formula-ui/src/locale/function-list/information/en-US.ts b/packages/sheets-formula-ui/src/locale/function-list/information/en-US.tsindex 38036ad6e5..b4a89b3a4b 100644--- a/packages/sheets-formula-ui/src/locale/function-list/information/en-US.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/information/en-US.ts@@ -56,6 +56,23 @@ export default {number2: { name: 'number2', detail: 'second' },},},+ ISBETWEEN: {+ description: 'Checks whether a provided number is between two other numbers either inclusively or exclusively.',+ abstract: 'Checks whether a provided number is between two other numbers either inclusively or exclusively.',+ links: [+ {+ title: 'Instruction',+ url: 'https://support.google.com/docs/answer/10538337?hl=en&sjid=7730820672019533290-AP',+ },+ ],+ functionParameter: {+ valueToCompare: { name: 'value_to_compare', detail: 'The value to test as being between `lower_value` and `upper_value`.' },+ lowerValue: { name: 'lower_value', detail: 'The lower boundary of the range of values that `value_to_compare` can fall within.' },+ upperValue: { name: 'upper_value', detail: 'The upper boundary of the range of values that `value_to_compare` can fall within.' },+ lowerValueIsInclusive: { name: 'lower_value_is_inclusive', detail: 'Whether the range of values includes the `lower_value`. By default this is TRUE.' },+ upperValueIsInclusive: { name: 'upper_value_is_inclusive', detail: 'Whether the range of values includes the `upper_value`. By default this is TRUE.' },+ },+ },ISBLANK: {description: 'Returns TRUE if the value is blank',abstract: 'Returns TRUE if the value is blank',diff --git a/packages/sheets-formula-ui/src/locale/function-list/information/ja-JP.ts b/packages/sheets-formula-ui/src/locale/function-list/information/ja-JP.tsindex bf740930b3..7022d7ac8a 100644--- a/packages/sheets-formula-ui/src/locale/function-list/information/ja-JP.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/information/ja-JP.ts@@ -56,6 +56,23 @@ export default {number2: { name: 'number2', detail: 'second' },},},+ ISBETWEEN: {+ description: '指定した値が他の 2 つの値の範囲内にあるかどうかを確認します',+ abstract: '指定した値が他の 2 つの値の範囲内にあるかどうかを確認します',+ links: [+ {+ title: '指導',+ url: 'https://support.google.com/docs/answer/10538337?hl=ja&sjid=7730820672019533290-AP',+ },+ ],+ functionParameter: {+ valueToCompare: { name: '比較する値', detail: '\'最小値\' と \'最大値\' の範囲内にあるかどうかを確認する値です。' },+ lowerValue: { name: '最小値', detail: '\'比較する値\' が含まれる可能性のある値の範囲の下限を指定します。' },+ upperValue: { name: '最大値', detail: '\'比較する値\' が含まれる可能性のある値の範囲の上限を指定します。' },+ lowerValueIsInclusive: { name: '最小値を含む', detail: '値の範囲に \'最小値\' を含めるかどうかを指定します(デフォルトは TRUE)。' },+ upperValueIsInclusive: { name: '最大値を含む', detail: '値の範囲に \'最大値\' を含めるかどうかを指定します(デフォルトは TRUE)。' },+ },+ },ISBLANK: {description: '対象が空白セルを参照するときに TRUE を返します。',abstract: '対象が空白セルを参照するときに TRUE を返します。',diff --git a/packages/sheets-formula-ui/src/locale/function-list/information/vi-VN.ts b/packages/sheets-formula-ui/src/locale/function-list/information/vi-VN.tsindex fe55fb8efe..8696a8fc3f 100644--- a/packages/sheets-formula-ui/src/locale/function-list/information/vi-VN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/information/vi-VN.ts@@ -42,6 +42,23 @@ export default {errorVal: { name: 'Giá trị lỗi', detail: 'Giá trị lỗi có số nhận dạng mà bạn muốn tìm.' },},},+ ISBETWEEN: {+ description: 'Kiểm tra xem một số đã cho có nằm giữa hai số khác',+ abstract: 'Kiểm tra xem một số đã cho có nằm giữa hai số khác',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.google.com/docs/answer/10538337?hl=vi&sjid=7730820672019533290-AP',+ },+ ],+ functionParameter: {+ valueToCompare: { name: 'giá_trị_muốn_so_sánh', detail: 'Giá trị muốn kiểm tra khi nằm trong khoảng từ `giới_hạn_dưới` đến `giới_hạn_trên`.' },+ lowerValue: { name: 'giới_hạn_dưới', detail: 'Cận dưới của miền giá trị mà `giá_trị_muốn_so_sánh` có thể thuộc miền đó.' },+ upperValue: { name: 'giới_hạn_trên', detail: 'Cận trên của miền giá trị mà `giá_trị_muốn_so_sánh` có thể thuộc miền đó.' },+ lowerValueIsInclusive: { name: 'bao_gồm_cả_giới_hạn_dưới', detail: 'Liệu miền giá trị có bao gồm `giới_hạn_trên` hay không. Theo mặc định, hàm sẽ trả về TRUE.' },+ upperValueIsInclusive: { name: 'bao_gồm_cả_giới_hạn_trên', detail: 'Liệu miền giá trị có bao gồm `giới_hạn_trên` hay không. Theo mặc định, hàm sẽ trả về TRUE.' },+ },+ },ISBLANK: {description: 'Trả về TRUE nếu giá trị trống',abstract: 'Trả về TRUE nếu giá trị trống',diff --git a/packages/sheets-formula-ui/src/locale/function-list/information/zh-CN.ts b/packages/sheets-formula-ui/src/locale/function-list/information/zh-CN.tsindex 1569c79e86..eab78bdbe1 100644--- a/packages/sheets-formula-ui/src/locale/function-list/information/zh-CN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/information/zh-CN.ts@@ -56,6 +56,23 @@ export default {number2: { name: 'number2', detail: 'second' },},},+ ISBETWEEN: {+ description: '检查所提供的数值是否介于其他两个数字之间',+ abstract: '检查所提供的数值是否介于其他两个数字之间',+ links: [+ {+ title: '教学',+ url: 'https://support.google.com/docs/answer/10538337?hl=zh-Hans&sjid=7730820672019533290-AP',+ },+ ],+ functionParameter: {+ valueToCompare: { name: '比较值', detail: '要测试的值,看是否介于“最小值”和“最大值”之间。' },+ lowerValue: { name: '最小值', detail: '范围的下限值,“比较值”的值可能落入这个范围内。' },+ upperValue: { name: '最大值', detail: '范围的上限值,“比较值”的值可能落入这个范围内。' },+ lowerValueIsInclusive: { name: '包括最小值', detail: '用于指定值的范围是否包含“最小值”。默认情况下为“TRUE”。' },+ upperValueIsInclusive: { name: '包括最大值', detail: '用于指定值的范围是否包含“最大值”。默认情况下为“TRUE”。' },+ },+ },ISBLANK: {description: '如果值为空,则返回 TRUE',abstract: '如果值为空,则返回 TRUE',diff --git a/packages/sheets-formula-ui/src/locale/function-list/information/zh-TW.ts b/packages/sheets-formula-ui/src/locale/function-list/information/zh-TW.tsindex 57e73f0eff..31128a8b7f 100644--- a/packages/sheets-formula-ui/src/locale/function-list/information/zh-TW.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/information/zh-TW.ts@@ -56,6 +56,23 @@ export default {number2: { name: 'number2', detail: 'second' },},},+ ISBETWEEN: {+ description: '檢查提供的數字是否介於另外兩個值之間',+ abstract: '檢查提供的數字是否介於另外兩個值之間',+ links: [+ {+ title: '教導',+ url: 'https://support.google.com/docs/answer/10538337?hl=zh-Hant&sjid=7730820672019533290-AP',+ },+ ],+ functionParameter: {+ valueToCompare: { name: '比較值', detail: '要比較的值,以查看該值是否介於「最小值」和「最大值」之間。' },+ lowerValue: { name: '最小值', detail: '範圍的下限值,「比較值」可能落在這個範圍內。' },+ upperValue: { name: '最大值', detail: '範圍的上限值,「比較值」可能落在這個範圍內。' },+ lowerValueIsInclusive: { name: '包括最小值', detail: '用於指定「最小值」這個值是否包含在範圍中 (預設是 TRUE)。' },+ upperValueIsInclusive: { name: '包括最大值', detail: '用於指定「最大值」這個值是否包含在範圍中 (預設是 TRUE)。' },+ },+ },ISBLANK: {description: '如果值為空,則傳回 TRUE',abstract: '若值為空,則傳回 TRUE',diff --git a/packages/sheets-formula-ui/src/locale/function-list/statistical/en-US.ts b/packages/sheets-formula-ui/src/locale/function-list/statistical/en-US.tsindex d8f47f7ad0..ea2aa2d134 100644--- a/packages/sheets-formula-ui/src/locale/function-list/statistical/en-US.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/statistical/en-US.ts@@ -49,6 +49,22 @@ export default {},},},+ AVERAGE_WEIGHTED: {+ description: 'Finds the weighted average of a set of values, given the values and the corresponding weights.',+ abstract: 'Finds the weighted average of a set of values, given the values and the corresponding weights.',+ links: [+ {+ title: 'Instruction',+ url: 'https://support.google.com/docs/answer/9084098?hl=en&ref_topic=3105600&sjid=2155433538747546473-AP',+ },+ ],+ functionParameter: {+ values: { name: 'values', detail: '要计算平均数的值。' },+ weights: { name: 'weights', detail: '要应用的相应权重列表。' },+ additionalValues: { name: 'additional_values', detail: '要计算平均数的其他值。' },+ additionalWeights: { name: 'additional_weights', detail: '要应用的其他权重。' },+ },+ },AVERAGEA: {description: 'Returns the average of its arguments, including numbers, text, and logical values.',abstract: 'Returns the average of its arguments, including numbers, text, and logical values',@@ -889,6 +905,20 @@ export default {standardDev: { name: 'standard_dev', detail: 'The standard deviation of the distribution.' },},},+ MARGINOFERROR: {+ description: 'Calculates the margin of error from a range of values and a confidence level.',+ abstract: 'Calculates the margin of error from a range of values and a confidence level.',+ links: [+ {+ title: 'Instruction',+ url: 'https://support.google.com/docs/answer/12487850?hl=en&sjid=11250989209896695200-AP',+ },+ ],+ functionParameter: {+ range: { name: 'range', detail: 'The range of values used to calculate the margin of error.' },+ confidence: { name: 'confidence', detail: 'The desired confidence level between (0, 1).' },+ },+ },MAX: {description: 'Returns the largest value in a set of values.',abstract: 'Returns the maximum value in a list of arguments',diff --git a/packages/sheets-formula-ui/src/locale/function-list/statistical/ja-JP.ts b/packages/sheets-formula-ui/src/locale/function-list/statistical/ja-JP.tsindex 4922946465..163a7400c1 100644--- a/packages/sheets-formula-ui/src/locale/function-list/statistical/ja-JP.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/statistical/ja-JP.ts@@ -43,6 +43,22 @@ export default {number2: { name: '数値 2', detail: '平均を求める追加の数値、セル参照、または範囲 (最大 255)。' },},},+ AVERAGE_WEIGHTED: {+ description: '指定した値と対応するウェイトに基づいて、一連の値の加重平均値を求めます。',+ abstract: '指定した値と対応するウェイトに基づいて、一連の値の加重平均値を求めます。',+ links: [+ {+ title: '指導',+ url: 'https://support.google.com/docs/answer/9084098?hl=ja&ref_topic=3105600&sjid=2155433538747546473-AP',+ },+ ],+ functionParameter: {+ values: { name: '値', detail: '平均化する値を指定します。' },+ weights: { name: 'ウェイト', detail: '適用するウェイトの対応するリストを指定します。' },+ additionalValues: { name: '追加の値', detail: '平均化する追加の値を指定します。' },+ additionalWeights: { name: '追加のウェイト', detail: '適用する追加のウェイトを指定します。' },+ },+ },AVERAGEA: {description: '数値、文字列、および論理値を含む引数の平均値を返します。',abstract: '数値、文字列、および論理値を含む引数の平均値を返します',@@ -864,6 +880,20 @@ export default {standardDev: { name: '標準偏差', detail: '対象となる分布の標準偏差を指定します。' },},},+ MARGINOFERROR: {+ description: 'この関数は、値の範囲と信頼レベルから誤差の範囲を計算します。',+ abstract: 'この関数は、値の範囲と信頼レベルから誤差の範囲を計算します。',+ links: [+ {+ title: '指導',+ url: 'https://support.google.com/docs/answer/12487850?hl=ja&sjid=11250989209896695200-AP',+ },+ ],+ functionParameter: {+ range: { name: '範囲', detail: '許容誤差の計算に使用される値の範囲。' },+ confidence: { name: '信頼レベル', detail: '0 ~ 1 の信頼レベル。' },+ },+ },MAX: {description: '引数リストに含まれる最大の数値を返します。',abstract: '引数リストに含まれる最大の数値を返します',diff --git a/packages/sheets-formula-ui/src/locale/function-list/statistical/vi-VN.ts b/packages/sheets-formula-ui/src/locale/function-list/statistical/vi-VN.tsindex 7b66b7ef66..38c5d4d739 100644--- a/packages/sheets-formula-ui/src/locale/function-list/statistical/vi-VN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/statistical/vi-VN.ts@@ -43,6 +43,22 @@ export default {number2: { name: 'số 2', detail: 'Các số khác, tham chiếu ô hoặc phạm vi cần tính giá trị trung bình, tối đa là 255.' },},},+ AVERAGE_WEIGHTED: {+ description: 'Tìm trung bình cộng gia quyền của một tập giá trị khi biết các giá trị và trọng số tương ứng.',+ abstract: 'Tìm trung bình cộng gia quyền của một tập giá trị khi biết các giá trị và trọng số tương ứng.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.google.com/docs/answer/9084098?hl=vi&ref_topic=3105600&sjid=2155433538747546473-AP',+ },+ ],+ functionParameter: {+ values: { name: 'giá_trị', detail: 'Giá trị cần tính trung bình.' },+ weights: { name: 'trọng_số', detail: 'Danh sách trọng số tương ứng để áp dụng.' },+ additionalValues: { name: 'giá_trị_bổ_sung', detail: 'Các giá trị bổ sung cần tính trung bình.' },+ additionalWeights: { name: 'trọng_số_bổ_sung', detail: 'Các trọng số bổ sung để áp dụng.' },+ },+ },AVERAGEA: {description: 'Trả về giá trị trung bình của các tham số, bao gồm số, văn bản và giá trị logic.',abstract: 'Trả về giá trị trung bình của các tham số, bao gồm số, văn bản và giá trị logic.',@@ -821,6 +837,20 @@ export default {standardDev: { name: 'Độ lệch chuẩn', detail: 'Độ lệch chuẩn của phân phối.' },},},+ MARGINOFERROR: {+ description: 'Tính biên độ sai số của một dải giá trị và mức tin cậy.',+ abstract: 'Tính biên độ sai số của một dải giá trị và mức tin cậy.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.google.com/docs/answer/12487850?hl=vi&sjid=11250989209896695200-AP',+ },+ ],+ functionParameter: {+ range: { name: 'dải_ô', detail: 'Dải giá trị dùng để tính biên độ sai số.' },+ confidence: { name: 'mức_tin_cậy', detail: 'Mức tin cậy mong muốn trong khoảng (0, 1).' },+ },+ },MAX: {description: 'Trả về giá trị lớn nhất trong tập giá trị.',abstract: 'Trả về giá trị lớn nhất trong tập giá trị.',diff --git a/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-CN.ts b/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-CN.tsindex 85af1b2170..859c765404 100644--- a/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-CN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-CN.ts@@ -49,6 +49,22 @@ export default {},},},+ AVERAGE_WEIGHTED: {+ description: '在已知数值和相应权重的情况下,计算出一组值的加权平均值',+ abstract: '在已知数值和相应权重的情况下,计算出一组值的加权平均值',+ links: [+ {+ title: '教学',+ url: 'https://support.google.com/docs/answer/9084098?hl=zh-Hans&ref_topic=3105600&sjid=2155433538747546473-AP',+ },+ ],+ functionParameter: {+ values: { name: '值', detail: '要计算平均数的值。' },+ weights: { name: '权重', detail: '要应用的相应权重列表。' },+ additionalValues: { name: '其他值', detail: '要计算平均数的其他值。' },+ additionalWeights: { name: '其他权重', detail: '要应用的其他权重。' },+ },+ },AVERAGEA: {description: '返回其参数的平均值,包括数字、文本和逻辑值。',abstract: '返回其参数的平均值,包括数字、文本和逻辑值',@@ -889,6 +905,20 @@ export default {standardDev: { name: '标准偏差', detail: '分布的标准偏差。' },},},+ MARGINOFERROR: {+ description: '根据一系列值和置信水平计算误差范围',+ abstract: '根据一系列值和置信水平计算误差范围',+ links: [+ {+ title: '教学',+ url: 'https://support.google.com/docs/answer/12487850?hl=zh-Hans&sjid=11250989209896695200-AP',+ },+ ],+ functionParameter: {+ range: { name: '范围', detail: '用于计算误差范围的值范围。' },+ confidence: { name: '置信度', detail: '所需的置信度介于 0 与 1 之间。' },+ },+ },MAX: {description: '返回一组值中的最大值。',abstract: '返回参数列表中的最大值',diff --git a/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-TW.ts b/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-TW.tsindex 03fc2e0522..b6884ed82d 100644--- a/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-TW.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/statistical/zh-TW.ts@@ -49,6 +49,22 @@ export default {},},},+ AVERAGE_WEIGHTED: {+ description: '可在已知實際數值和對應權重的情況下,用來求得多項數值的加權平均值',+ abstract: '可在已知實際數值和對應權重的情況下,用來求得多項數值的加權平均值',+ links: [+ {+ title: '教導',+ url: 'https://support.google.com/docs/answer/9084098?hl=zh-Hant&ref_topic=3105600&sjid=2155433538747546473-AP',+ },+ ],+ functionParameter: {+ values: { name: '值', detail: '要計算平均值的數值。' },+ weights: { name: '權重', detail: '要套用的權重對應清單。' },+ additionalValues: { name: '其他值', detail: '要計算平均值的其他值。' },+ additionalWeights: { name: '其他權重', detail: '要套用的其他權重。' },+ },+ },AVERAGEA: {description: '傳回其參數的平均值,包括數字、文字和邏輯值。 ',abstract: '傳回其參數的平均值,包括數字、文字和邏輯值',@@ -889,6 +905,20 @@ export default {standardDev: { name: '標準差', detail: '分佈的標準差。' },},},+ MARGINOFERROR: {+ description: '計算特定值範圍和信賴水準的誤差範圍',+ abstract: '計算特定值範圍和信賴水準的誤差範圍',+ links: [+ {+ title: '教導',+ url: 'https://support.google.com/docs/answer/12487850?hl=zh-Hant&sjid=11250989209896695200-AP',+ },+ ],+ functionParameter: {+ range: { name: '範圍', detail: '用來計算誤差範圍的值範圍。' },+ confidence: { name: '信賴水準', detail: '想要的信賴水準介於 (0, 1) 之間。' },+ },+ },MAX: {description: '傳回一組值中的最大值。 ',abstract: '傳回參數清單中的最大值',diff --git a/packages/sheets-formula/src/services/function-list/information.ts b/packages/sheets-formula/src/services/function-list/information.tsindex ed5102c60c..cb8a3e829f 100644--- a/packages/sheets-formula/src/services/function-list/information.ts+++ b/packages/sheets-formula/src/services/function-list/information.ts@@ -76,6 +76,49 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [},],},+ {+ functionName: FUNCTION_NAMES_INFORMATION.ISBETWEEN,+ functionType: FunctionType.Information,+ description: 'formula.functionList.ISBETWEEN.description',+ abstract: 'formula.functionList.ISBETWEEN.abstract',+ functionParameter: [+ {+ name: 'formula.functionList.ISBETWEEN.functionParameter.valueToCompare.name',+ detail: 'formula.functionList.ISBETWEEN.functionParameter.valueToCompare.detail',+ example: '7.9',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.ISBETWEEN.functionParameter.lowerValue.name',+ detail: 'formula.functionList.ISBETWEEN.functionParameter.lowerValue.detail',+ example: '1.2',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.ISBETWEEN.functionParameter.upperValue.name',+ detail: 'formula.functionList.ISBETWEEN.functionParameter.upperValue.detail',+ example: '12.45',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.ISBETWEEN.functionParameter.lowerValueIsInclusive.name',+ detail: 'formula.functionList.ISBETWEEN.functionParameter.lowerValueIsInclusive.detail',+ example: 'true',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.ISBETWEEN.functionParameter.upperValueIsInclusive.name',+ detail: 'formula.functionList.ISBETWEEN.functionParameter.upperValueIsInclusive.detail',+ example: 'true',+ require: 0,+ repeat: 0,+ },+ ],+ },{functionName: FUNCTION_NAMES_INFORMATION.ISBLANK,functionType: FunctionType.Information,diff --git a/packages/sheets-formula/src/services/function-list/statistical.ts b/packages/sheets-formula/src/services/function-list/statistical.tsindex ee7782974a..a2f04f7c0b 100644--- a/packages/sheets-formula/src/services/function-list/statistical.ts+++ b/packages/sheets-formula/src/services/function-list/statistical.ts@@ -63,6 +63,43 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [},],},+ {+ functionName: FUNCTION_NAMES_STATISTICAL.AVERAGE_WEIGHTED,+ aliasFunctionName: 'formula.functionList.AVERAGE_WEIGHTED.aliasFunctionName',+ functionType: FunctionType.Statistical,+ description: 'formula.functionList.AVERAGE_WEIGHTED.description',+ abstract: 'formula.functionList.AVERAGE_WEIGHTED.abstract',+ functionParameter: [+ {+ name: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.values.name',+ detail: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.values.detail',+ example: '10',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.weights.name',+ detail: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.weights.detail',+ example: '1',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.additionalValues.name',+ detail: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.additionalValues.detail',+ example: '20',+ require: 0,+ repeat: 1,+ },+ {+ name: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.additionalWeights.name',+ detail: 'formula.functionList.AVERAGE_WEIGHTED.functionParameter.additionalWeights.detail',+ example: '3',+ require: 0,+ repeat: 1,+ },+ ],+ },{functionName: FUNCTION_NAMES_STATISTICAL.AVERAGEA,functionType: FunctionType.Statistical,@@ -1556,6 +1593,29 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [},],},+ {+ functionName: FUNCTION_NAMES_STATISTICAL.MARGINOFERROR,+ aliasFunctionName: 'formula.functionList.MARGINOFERROR.aliasFunctionName',+ functionType: FunctionType.Statistical,+ description: 'formula.functionList.MARGINOFERROR.description',+ abstract: 'formula.functionList.MARGINOFERROR.abstract',+ functionParameter: [+ {+ name: 'formula.functionList.MARGINOFERROR.functionParameter.range.name',+ detail: 'formula.functionList.MARGINOFERROR.functionParameter.range.detail',+ example: 'A1:A4',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.MARGINOFERROR.functionParameter.confidence.name',+ detail: 'formula.functionList.MARGINOFERROR.functionParameter.confidence.detail',+ example: '0.95',+ require: 1,+ repeat: 0,+ },+ ],+ },{functionName: FUNCTION_NAMES_STATISTICAL.MAX,aliasFunctionName: 'formula.functionList.MAX.aliasFunctionName',