Skip to content

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.

feat(formula): support database-related formulas (#3749)

wpxp1234563b8af5a75fb6
diff --git a/packages/engine-formula/src/basics/database.ts b/packages/engine-formula/src/basics/database.ts
new file mode 100644
index 0000000000..aba63ed65b
--- /dev/null
+++ b/packages/engine-formula/src/basics/database.ts
@@ -0,0 +1,274 @@
+/**
+ * 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 { isRealNum } from '@univerjs/core';
+import { findCompareToken } from '../engine/utils/object-compare';
+import { type ArrayValueObject, ValueObjectFactory } from '../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';
+import { ErrorType } from './error-type';
+
+type DatabaseValueType = string | number | null;
+
+export function checkDatabase(database: BaseValueObject) {
+ const databaseValues: DatabaseValueType[][] = [];
+
+ if (database.isError()) {
+ return {
+ isError: true,
+ errorObject: database as ErrorValueObject,
+ databaseValues,
+ };
+ }
+
+ const rowCount = database.isArray() ? (database as ArrayValueObject).getRowCount() : 1;
+ const columnCount = database.isArray() ? (database as ArrayValueObject).getColumnCount() : 1;
+
+ if (rowCount < 2) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.VALUE),
+ databaseValues,
+ };
+ }
+
+ for (let r = 0; r < rowCount; r++) {
+ const row: DatabaseValueType[] = [];
+
+ for (let c = 0; c < columnCount; c++) {
+ const valueObject = (database as ArrayValueObject).get(r, c) as BaseValueObject;
+
+ if (valueObject.isNull()) {
+ row.push(null);
+ continue;
+ }
+
+ let value = `${valueObject.getValue()}`;
+
+ if (valueObject.isBoolean()) {
+ value = value.toLocaleUpperCase();
+ }
+
+ if (valueObject.isNumber() || isRealNum(value)) {
+ row.push(+value);
+ continue;
+ }
+
+ row.push(value);
+ }
+
+ databaseValues.push(row);
+ }
+
+ return {
+ isError: false,
+ errorObject: null,
+ databaseValues,
+ };
+}
+
+export function checkField(field: BaseValueObject, database: DatabaseValueType[][]) {
+ let fieldIndex: number = -1;
+
+ if (field.isError()) {
+ return {
+ isError: true,
+ errorObject: field as ErrorValueObject,
+ fieldIndex,
+ };
+ }
+
+ const rowCount = field.isArray() ? (field as ArrayValueObject).getRowCount() : 1;
+ const columnCount = field.isArray() ? (field as ArrayValueObject).getColumnCount() : 1;
+
+ if (rowCount > 1 || columnCount > 1) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.VALUE),
+ fieldIndex,
+ };
+ }
+
+ const fieldObject = field.isArray() ? (field as ArrayValueObject).get(0, 0) as BaseValueObject : field;
+
+ let fieldValue: number | string = `${fieldObject.getValue()}`;
+
+ if (fieldObject.isNull()) {
+ fieldValue = 0;
+ } else if (fieldObject.isBoolean()) {
+ fieldValue = fieldObject.getValue() ? 1 : 0;
+ } else if (fieldObject.isNumber() || isRealNum(fieldValue)) {
+ fieldValue = Math.floor(+fieldValue);
+ }
+
+ if (typeof fieldValue === 'number') {
+ if (fieldValue < 1 || fieldValue > database[0].length) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.VALUE),
+ fieldIndex,
+ };
+ }
+
+ fieldIndex = fieldValue - 1;
+ } else {
+ fieldIndex = database[0].findIndex((value) => {
+ if (value === null) {
+ return false;
+ }
+
+ return `${value}`.toLocaleLowerCase() === fieldValue.toLocaleLowerCase();
+ });
+
+ if (fieldIndex === -1) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.VALUE),
+ fieldIndex,
+ };
+ }
+ }
+
+ return {
+ isError: false,
+ errorObject: null,
+ fieldIndex,
+ };
+}
+
+export function checkCriteria(criteria: BaseValueObject) {
+ const criteriaValues: DatabaseValueType[][] = [];
+
+ if (criteria.isError()) {
+ return {
+ isError: true,
+ errorObject: criteria as ErrorValueObject,
+ criteriaValues,
+ };
+ }
+
+ const rowCount = criteria.isArray() ? (criteria as ArrayValueObject).getRowCount() : 1;
+ const columnCount = criteria.isArray() ? (criteria as ArrayValueObject).getColumnCount() : 1;
+
+ if (rowCount < 2) {
+ return {
+ isError: true,
+ errorObject: ErrorValueObject.create(ErrorType.VALUE),
+ criteriaValues,
+ };
+ }
+
+ for (let r = 0; r < rowCount; r++) {
+ const row: DatabaseValueType[] = [];
+
+ for (let c = 0; c < columnCount; c++) {
+ const valueObject = (criteria as ArrayValueObject).get(r, c) as BaseValueObject;
+
+ if (valueObject.isNull()) {
+ row.push(null);
+ continue;
+ }
+
+ const value = `${valueObject.getValue()}`;
+
+ if (valueObject.isBoolean()) {
+ row.push(valueObject.getValue() ? 1 : 0);
+ continue;
+ }
+
+ if (valueObject.isNumber() || isRealNum(value)) {
+ row.push(+value);
+ continue;
+ }
+
+ row.push(value);
+ }
+
+ criteriaValues.push(row);
+ }
+
+ return {
+ isError: false,
+ errorObject: null,
+ criteriaValues,
+ };
+}
+
+/*
+ * Criteria match logic:
+ * Boolean AND in row direction, then Boolean OR in column direction
+ */
+export function isCriteriaMatch(criteria: DatabaseValueType[][], database: DatabaseValueType[][], databaseRowIndex: number) {
+ const rowCount = criteria.length;
+ const columnCount = criteria[0].length;
+
+ const criteriaTitleIndexCache: Record<number, number> = {};
+
+ let isMatch = false;
+
+ for (let r = 1; r < rowCount; r++) {
+ let isRowMatch = true;
+
+ for (let c = 0; c < columnCount; c++) {
+ const criteriaValue = criteria[r][c];
+
+ if (criteriaValue === null) {
+ continue;
+ }
+
+ let criteriaTitleIndex = criteriaTitleIndexCache[c];
+
+ if (criteriaTitleIndex === undefined) {
+ const criteriaTitleValue = criteria[0][c];
+ criteriaTitleIndex = database[0].findIndex((value) => {
+ if (value === null || criteriaTitleValue === null) {
+ return false;
+ }
+
+ return `${value}`.toLocaleLowerCase() === `${criteriaTitleValue}`.toLocaleLowerCase();
+ });
+ criteriaTitleIndexCache[c] = criteriaTitleIndex;
+ }
+
+ if (criteriaTitleIndex === -1 && (typeof criteriaValue === 'string' || criteriaValue === 0)) {
+ isRowMatch = false;
+ break;
+ } else if (criteriaTitleIndex > -1) {
+ const databaseValue = database[databaseRowIndex][criteriaTitleIndex];
+
+ if (databaseValue === null) {
+ isRowMatch = false;
+ break;
+ }
+
+ const [compareToken, criteriaObject] = findCompareToken(`${criteriaValue}`);
+ const compareObject = ValueObjectFactory.create(`${databaseValue}`).compare(criteriaObject, compareToken);
+ const compareValue = compareObject.getValue();
+
+ if (!compareValue) {
+ isRowMatch = false;
+ break;
+ }
+ }
+ }
+
+ if (isRowMatch) {
+ isMatch = true;
+ break;
+ }
+ }
+
+ return isMatch;
+}
diff --git a/packages/engine-formula/src/functions/database/daverage/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/daverage/__tests__/index.spec.ts
new file mode 100644
index 0000000000..6aed404c7a
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/daverage/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Daverage } from '../index';
+
+describe('Test daverage function', () => {
+ const testFunction = new Daverage(FUNCTION_NAMES_DATABASE.DAVERAGE);
+
+ describe('Daverage', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(12);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(10);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(10);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(10);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(12);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(9.5);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(9.5);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/daverage/index.ts b/packages/engine-formula/src/functions/database/daverage/index.ts
new file mode 100644
index 0000000000..0cf7740a4c
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/daverage/index.ts
@@ -0,0 +1,70 @@
+/**
+ * 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 { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Daverage extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let sum = 0;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ sum += value;
+ count++;
+ }
+ }
+
+ if (count === 0) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ return NumberValueObject.create(sum / count);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dcount/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dcount/__tests__/index.spec.ts
new file mode 100644
index 0000000000..ec1468d88b
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dcount/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dcount } from '../index';
+
+describe('Test dcount function', () => {
+ const testFunction = new Dcount(FUNCTION_NAMES_DATABASE.DCOUNT);
+
+ describe('Dcount', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(1);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(1);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(1);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(6);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(6);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dcount/index.ts b/packages/engine-formula/src/functions/database/dcount/index.ts
new file mode 100644
index 0000000000..a7e5a5607e
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dcount/index.ts
@@ -0,0 +1,62 @@
+/**
+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dcount extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ count++;
+ }
+ }
+
+ return NumberValueObject.create(count);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dcounta/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dcounta/__tests__/index.spec.ts
new file mode 100644
index 0000000000..33266967d4
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dcounta/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dcounta } from '../index';
+
+describe('Test dcounta function', () => {
+ const testFunction = new Dcounta(FUNCTION_NAMES_DATABASE.DCOUNTA);
+
+ describe('Dcounta', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(1);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(2);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(1);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(2);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(6);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(6);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dcounta/index.ts b/packages/engine-formula/src/functions/database/dcounta/index.ts
new file mode 100644
index 0000000000..578aa96b97
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dcounta/index.ts
@@ -0,0 +1,62 @@
+/**
+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dcounta extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (value === null || value === undefined) {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ count++;
+ }
+ }
+
+ return NumberValueObject.create(count);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dget/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dget/__tests__/index.spec.ts
new file mode 100644
index 0000000000..6c7ed7b830
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dget/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dget } from '../index';
+
+describe('Test dget function', () => {
+ const testFunction = new Dget(FUNCTION_NAMES_DATABASE.DGET);
+
+ describe('Dget', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>15'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(14);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(10);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.NUM);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(10);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NUM);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.NUM);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NUM);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NUM);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dget/index.ts b/packages/engine-formula/src/functions/database/dget/index.ts
new file mode 100644
index 0000000000..0b9a9cd7fb
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dget/index.ts
@@ -0,0 +1,74 @@
+/**
+ * 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 { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dget extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let count = 0;
+ let resultRowIndex = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (value === null || value === undefined) {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ count++;
+ resultRowIndex = r;
+ }
+ }
+
+ if (count === 0) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (count > 1) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return (database as ArrayValueObject).get(resultRowIndex, fieldIndex) as BaseValueObject;
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dmax/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dmax/__tests__/index.spec.ts
new file mode 100644
index 0000000000..90aef409ba
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dmax/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dmax } from '../index';
+
+describe('Test dmax function', () => {
+ const testFunction = new Dmax(FUNCTION_NAMES_DATABASE.DMAX);
+
+ describe('Dmax', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(14);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(10);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(10);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(10);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(14);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(14);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(14);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dmax/index.ts b/packages/engine-formula/src/functions/database/dmax/index.ts
new file mode 100644
index 0000000000..454608c4fb
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dmax/index.ts
@@ -0,0 +1,68 @@
+/**
+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dmax extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let result = -Infinity;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ result = Math.max(result, value);
+ count++;
+ }
+ }
+
+ if (count === 0) {
+ return NumberValueObject.create(0);
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dmin/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dmin/__tests__/index.spec.ts
new file mode 100644
index 0000000000..8b4ed5023a
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dmin/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dmin } from '../index';
+
+describe('Test dmin function', () => {
+ const testFunction = new Dmin(FUNCTION_NAMES_DATABASE.DMIN);
+
+ describe('Dmin', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(10);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(10);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(10);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(10);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(10);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(6);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(6);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dmin/index.ts b/packages/engine-formula/src/functions/database/dmin/index.ts
new file mode 100644
index 0000000000..eb018634dd
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dmin/index.ts
@@ -0,0 +1,68 @@
+/**
+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dmin extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let result = Infinity;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ result = Math.min(result, value);
+ count++;
+ }
+ }
+
+ if (count === 0) {
+ return NumberValueObject.create(0);
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dproduct/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dproduct/__tests__/index.spec.ts
new file mode 100644
index 0000000000..82530e8d0a
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dproduct/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dproduct } from '../index';
+
+describe('Test dproduct function', () => {
+ const testFunction = new Dproduct(FUNCTION_NAMES_DATABASE.DPRODUCT);
+
+ describe('Dproduct', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(140);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(10);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(10);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(10);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(140);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(604800);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(604800);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dproduct/index.ts b/packages/engine-formula/src/functions/database/dproduct/index.ts
new file mode 100644
index 0000000000..4429134f6e
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dproduct/index.ts
@@ -0,0 +1,68 @@
+/**
+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dproduct extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let result = 1;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ result *= value;
+ count++;
+ }
+ }
+
+ if (count === 0) {
+ return NumberValueObject.create(0);
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dstdev/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dstdev/__tests__/index.spec.ts
new file mode 100644
index 0000000000..83f509b3fb
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dstdev/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dstdev } from '../index';
+
+describe('Test dstdev function', () => {
+ const testFunction = new Dstdev(FUNCTION_NAMES_DATABASE.DSTDEV);
+
+ describe('Dstdev', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2.8284271247461903);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2.8284271247461903);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2.6645825188948455);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(2.6645825188948455);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dstdev/index.ts b/packages/engine-formula/src/functions/database/dstdev/index.ts
new file mode 100644
index 0000000000..8c58cbcfb1
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dstdev/index.ts
@@ -0,0 +1,83 @@
+/**
+ * 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 { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dstdev extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ const values = [];
+
+ let sum = 0;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ values.push(value);
+ sum += value;
+ count++;
+ }
+ }
+
+ if (count <= 1) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const mean = sum / count;
+
+ let sumOfSquaresDifferences = 0;
+
+ for (let i = 0; i < count; i++) {
+ sumOfSquaresDifferences += (values[i] - mean) ** 2;
+ }
+
+ const result = Math.sqrt(sumOfSquaresDifferences / (count - 1));
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dstdevp/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dstdevp/__tests__/index.spec.ts
new file mode 100644
index 0000000000..c9edf98beb
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dstdevp/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dstdevp } from '../index';
+
+describe('Test dstdevp function', () => {
+ const testFunction = new Dstdevp(FUNCTION_NAMES_DATABASE.DSTDEVP);
+
+ describe('Dstdevp', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(0);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(0);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(2.4324199198877374);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(2.4324199198877374);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dstdevp/index.ts b/packages/engine-formula/src/functions/database/dstdevp/index.ts
new file mode 100644
index 0000000000..7143253f6c
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dstdevp/index.ts
@@ -0,0 +1,83 @@
+/**
+ * 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 { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dstdevp extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ const values = [];
+
+ let sum = 0;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ values.push(value);
+ sum += value;
+ count++;
+ }
+ }
+
+ if (count === 0) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const mean = sum / count;
+
+ let sumOfSquaresDifferences = 0;
+
+ for (let i = 0; i < count; i++) {
+ sumOfSquaresDifferences += (values[i] - mean) ** 2;
+ }
+
+ const result = Math.sqrt(sumOfSquaresDifferences / count);
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dsum/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dsum/__tests__/index.spec.ts
new file mode 100644
index 0000000000..fc2baa9eb3
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dsum/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dsum } from '../index';
+
+describe('Test dsum function', () => {
+ const testFunction = new Dsum(FUNCTION_NAMES_DATABASE.DSUM);
+
+ describe('Dsum', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(24);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(10);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(10);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(10);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(24);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(57);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(57);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dsum/index.ts b/packages/engine-formula/src/functions/database/dsum/index.ts
new file mode 100644
index 0000000000..2dc996de16
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dsum/index.ts
@@ -0,0 +1,62 @@
+/**
+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dsum extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ let result = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ result += value;
+ }
+ }
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dvar/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dvar/__tests__/index.spec.ts
new file mode 100644
index 0000000000..9028043c69
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dvar/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dvar } from '../index';
+
+describe('Test dvar function', () => {
+ const testFunction = new Dvar(FUNCTION_NAMES_DATABASE.DVAR);
+
+ describe('Dvar', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(8);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(8);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(7.1);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(7.1);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dvar/index.ts b/packages/engine-formula/src/functions/database/dvar/index.ts
new file mode 100644
index 0000000000..c1753f73d5
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dvar/index.ts
@@ -0,0 +1,83 @@
+/**
+ * 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 { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dvar extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ const values = [];
+
+ let sum = 0;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ values.push(value);
+ sum += value;
+ count++;
+ }
+ }
+
+ if (count <= 1) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const mean = sum / count;
+
+ let sumOfSquaresDifferences = 0;
+
+ for (let i = 0; i < count; i++) {
+ sumOfSquaresDifferences += (values[i] - mean) ** 2;
+ }
+
+ const result = sumOfSquaresDifferences / (count - 1);
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/dvarp/__tests__/index.spec.ts b/packages/engine-formula/src/functions/database/dvarp/__tests__/index.spec.ts
new file mode 100644
index 0000000000..388aab1df5
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dvarp/__tests__/index.spec.ts
@@ -0,0 +1,290 @@
+/**
+ * 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 { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_DATABASE } from '../../function-names';
+import { Dvarp } from '../index';
+
+describe('Test dvarp function', () => {
+ const testFunction = new Dvarp(FUNCTION_NAMES_DATABASE.DVARP);
+
+ describe('Dvarp', () => {
+ it('Value is normal', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(4);
+ });
+
+ it('Database value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);
+
+ const database2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', null, true, false, ErrorType.NAME],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 6,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database2, field, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(0);
+
+ const database3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 'test', 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database3, field, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(0);
+
+ const database4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, null, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database4, field, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(0);
+ });
+
+ it('Field value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = NumberValueObject.create(4);
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ['苹果树', '>10'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(4);
+
+ const field2 = NullValueObject.create();
+ const result2 = testFunction.calculate(database, field2, criteria);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const field3 = BooleanValueObject.create(true);
+ const result3 = testFunction.calculate(database, field3, criteria);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const field4 = StringValueObject.create('test');
+ const result4 = testFunction.calculate(database, field4, criteria);
+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);
+
+ const field5 = ErrorValueObject.create(ErrorType.NAME);
+ const result5 = testFunction.calculate(database, field5, criteria);
+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.NAME);
+
+ const field6 = ArrayValueObject.create('{1,2,3}');
+ const result6 = testFunction.calculate(database, field6, criteria);
+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Criteria value test', () => {
+ const database = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度', '年数', '产量', '利润'],
+ ['苹果树', 18, 20, 14, 105],
+ ['梨树', 1.2, 1.2, 10, 96],
+ ['樱桃树', 1.3, 14, 9, 105],
+ ['苹果树', 14, 15, 10, 75],
+ ['梨树', 9, 8, 8, 76.8],
+ ['苹果树', 8, 9, 6, 45],
+ ]),
+ rowCount: 7,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const field = StringValueObject.create('产量');
+ const criteria = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, null],
+ [null, null],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(database, field, criteria);
+ expect(getObjectValue(result)).toStrictEqual(5.916666666666667);
+
+ const criteria2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['树种', '高度'],
+ ]),
+ rowCount: 1,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = testFunction.calculate(database, field, criteria2);
+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);
+
+ const criteria3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result3 = testFunction.calculate(database, field, criteria3);
+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.DIV_BY_ZERO);
+
+ const criteria4 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [null, '高度'],
+ [true, null],
+ [null, false],
+ ]),
+ rowCount: 3,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result4 = testFunction.calculate(database, field, criteria4);
+ expect(getObjectValue(result4)).toStrictEqual(5.916666666666667);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/database/dvarp/index.ts b/packages/engine-formula/src/functions/database/dvarp/index.ts
new file mode 100644
index 0000000000..7f724b8438
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/dvarp/index.ts
@@ -0,0 +1,83 @@
+/**
+ * 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 { checkCriteria, checkDatabase, checkField, isCriteriaMatch } from '../../../basics/database';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Dvarp extends BaseFunction {
+ override minParams = 3;
+
+ override maxParams = 3;
+
+ override calculate(database: BaseValueObject, field: BaseValueObject, criteria: BaseValueObject) {
+ const { isError: databaseIsError, errorObject: databaseErrorObject, databaseValues } = checkDatabase(database);
+
+ if (databaseIsError) {
+ return databaseErrorObject as ErrorValueObject;
+ }
+
+ const { isError: fieldIsError, errorObject: filedErrorObject, fieldIndex } = checkField(field, databaseValues);
+
+ if (fieldIsError) {
+ return filedErrorObject as ErrorValueObject;
+ }
+
+ const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
+
+ if (criteriaIsError) {
+ return criteriaErrorObject as ErrorValueObject;
+ }
+
+ const values = [];
+
+ let sum = 0;
+ let count = 0;
+
+ for (let r = 1; r < databaseValues.length; r++) {
+ const value = databaseValues[r][fieldIndex];
+
+ if (typeof value !== 'number') {
+ continue;
+ }
+
+ if (isCriteriaMatch(criteriaValues, databaseValues, r)) {
+ values.push(value);
+ sum += value;
+ count++;
+ }
+ }
+
+ if (count === 0) {
+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
+ }
+
+ const mean = sum / count;
+
+ let sumOfSquaresDifferences = 0;
+
+ for (let i = 0; i < count; i++) {
+ sumOfSquaresDifferences += (values[i] - mean) ** 2;
+ }
+
+ const result = sumOfSquaresDifferences / count;
+
+ return NumberValueObject.create(result);
+ }
+}
diff --git a/packages/engine-formula/src/functions/database/function-map.ts b/packages/engine-formula/src/functions/database/function-map.ts
index 389a75e8b7..2cf04260a9 100644
--- a/packages/engine-formula/src/functions/database/function-map.ts
+++ b/packages/engine-formula/src/functions/database/function-map.ts
@@ -14,4 +14,31 @@
* limitations under the License.
*/
-export const functionDatabase = [];
+import { Daverage } from './daverage';
+import { Dcount } from './dcount';
+import { Dcounta } from './dcounta';
+import { Dget } from './dget';
+import { Dmax } from './dmax';
+import { Dmin } from './dmin';
+import { Dproduct } from './dproduct';
+import { Dstdev } from './dstdev';
+import { Dstdevp } from './dstdevp';
+import { Dsum } from './dsum';
+import { Dvar } from './dvar';
+import { Dvarp } from './dvarp';
+import { FUNCTION_NAMES_DATABASE } from './function-names';
+
+export const functionDatabase = [
+ [Daverage, FUNCTION_NAMES_DATABASE.DAVERAGE],
+ [Dcount, FUNCTION_NAMES_DATABASE.DCOUNT],
+ [Dcounta, FUNCTION_NAMES_DATABASE.DCOUNTA],
+ [Dget, FUNCTION_NAMES_DATABASE.DGET],
+ [Dmax, FUNCTION_NAMES_DATABASE.DMAX],
+ [Dmin, FUNCTION_NAMES_DATABASE.DMIN],
+ [Dproduct, FUNCTION_NAMES_DATABASE.DPRODUCT],
+ [Dstdev, FUNCTION_NAMES_DATABASE.DSTDEV],
+ [Dstdevp, FUNCTION_NAMES_DATABASE.DSTDEVP],
+ [Dsum, FUNCTION_NAMES_DATABASE.DSUM],
+ [Dvar, FUNCTION_NAMES_DATABASE.DVAR],
+ [Dvarp, FUNCTION_NAMES_DATABASE.DVARP],
+];
diff --git a/packages/engine-formula/src/functions/logical/if/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/if/__tests__/index.spec.ts
index 57aeba6cef..a16be0793b 100644
--- a/packages/engine-formula/src/functions/logical/if/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/logical/if/__tests__/index.spec.ts
@@ -16,10 +16,11 @@
import { describe, expect, it } from 'vitest';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
import { If } from '../index';
-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
-import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
describe('Test if function', () => {
const testFunction = new If(FUNCTION_NAMES_LOGICAL.IF);
@@ -29,7 +30,7 @@ describe('Test if function', () => {
const logicTest = BooleanValueObject.create(true);
const valueIfTrue = NumberValueObject.create(1);
const result = testFunction.calculate(logicTest, valueIfTrue);
- expect(result.getValue()).toBe(1);
+ expect(getObjectValue(result)).toBe(1);
});
it('LogicalTest and valueIfTrue and valueIfFalse', () => {
@@ -37,7 +38,7 @@ describe('Test if function', () => {
const valueIfTrue = NumberValueObject.create(1);
const valueIfFalse = NumberValueObject.create(2);
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(result.getValue()).toBe(2);
+ expect(getObjectValue(result)).toBe(2);
});
it('LogicalTest is array', () => {
@@ -56,7 +57,7 @@ describe('Test if function', () => {
});
const valueIfTrue = NumberValueObject.create(1);
const result = testFunction.calculate(logicTest, valueIfTrue);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
[false],
[1],
[1],
@@ -79,7 +80,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
[1],
[2],
[3],
@@ -101,7 +102,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue);
- expect(result.getValue()).toBe(false);
+ expect(getObjectValue(result)).toBe(false);
});
it('ValueIfFalse is array', () => {
@@ -121,7 +122,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
[1],
[2],
[3],
@@ -159,7 +160,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
[1],
[false],
[3],
@@ -200,7 +201,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
['yes'],
[2],
['yes'],
@@ -242,7 +243,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
[1],
[2],
[3],
@@ -299,7 +300,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
[1],
[7],
[3],
@@ -347,7 +348,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
['no1', 'yes2', '#N/A', '#N/A'],
['yes1', 'yes2', '#N/A', '#N/A'],
['no1', 'yes2', '#N/A', '#N/A'],
@@ -397,7 +398,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
['no1', 'no2', 'no3', '#N/A'],
['yes2', 'yes3', 'yes4', 'yes5'],
['#N/A', '#N/A', '#N/A', '#N/A'],
@@ -447,7 +448,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
['no1', 'yes2', '#N/A', '#N/A'],
['no2', 'yes3', '#N/A', '#N/A'],
['no3', 'yes4', '#N/A', '#N/A'],
@@ -494,7 +495,7 @@ describe('Test if function', () => {
column: 0,
});
const result = testFunction.calculate(logicTest, valueIfTrue, valueIfFalse);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ expect(getObjectValue(result)).toStrictEqual([
['no1', 'no2', 'no3', '#N/A'],
['yes1', 'yes2', 'yes3', 'yes4'],
['no1', 'no2', 'no3', '#N/A'],
diff --git a/packages/engine-formula/src/functions/logical/if/index.ts b/packages/engine-formula/src/functions/logical/if/index.ts
index 4acf14ef16..cc0d921cd1 100644
--- a/packages/engine-formula/src/functions/logical/if/index.ts
+++ b/packages/engine-formula/src/functions/logical/if/index.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
import { ErrorType } from '../../../basics/error-type';
import { expandArrayValueObject } from '../../../engine/utils/array-object';
-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BooleanValueObject, NullValueObject } from '../../../engine/value-object/primitive-object';
import { BaseFunction } from '../../base-function';
@@ -31,10 +31,6 @@ export class If extends BaseFunction {
return logicalTest;
}
- if (valueIfTrue.isError()) {
- return valueIfTrue;
- }
-
// get single value object
const _logicalTest = this._getSingleValueObject(logicalTest);
diff --git a/packages/sheets-formula-ui/src/locale/function-list/database/en-US.ts b/packages/sheets-formula-ui/src/locale/function-list/database/en-US.ts
index 2354a47012..d9244e62e4 100644
--- a/packages/sheets-formula-ui/src/locale/function-list/database/en-US.ts
+++ b/packages/sheets-formula-ui/src/locale/function-list/database/en-US.ts
@@ -25,8 +25,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DCOUNT: {
@@ -39,8 +40,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DCOUNTA: {
@@ -53,8 +55,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DGET: {
@@ -67,8 +70,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DMAX: {
@@ -81,8 +85,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DMIN: {
@@ -95,8 +100,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DPRODUCT: {
@@ -109,8 +115,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DSTDEV: {
@@ -123,8 +130,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DSTDEVP: {
@@ -137,8 +145,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DSUM: {
@@ -151,8 +160,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DVAR: {
@@ -165,8 +175,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
DVARP: {
@@ -179,8 +190,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'database', detail: 'The range of cells that makes up the list or database.' },
+ field: { name: 'field', detail: 'Indicates which column is used in the function.' },
+ criteria: { name: 'criteria', detail: 'The range of cells that contains the conditions you specify.' },
},
},
};
diff --git a/packages/sheets-formula-ui/src/locale/function-list/database/ja-JP.ts b/packages/sheets-formula-ui/src/locale/function-list/database/ja-JP.ts
index 39c488b996..f9422cdfc0 100644
--- a/packages/sheets-formula-ui/src/locale/function-list/database/ja-JP.ts
+++ b/packages/sheets-formula-ui/src/locale/function-list/database/ja-JP.ts
@@ -25,8 +25,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DCOUNT: {
@@ -39,8 +40,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DCOUNTA: {
@@ -53,8 +55,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DGET: {
@@ -67,8 +70,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DMAX: {
@@ -81,8 +85,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DMIN: {
@@ -95,8 +100,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DPRODUCT: {
@@ -109,8 +115,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DSTDEV: {
@@ -123,8 +130,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DSTDEVP: {
@@ -137,8 +145,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DSUM: {
@@ -151,8 +160,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DVAR: {
@@ -165,8 +175,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
DVARP: {
@@ -179,8 +190,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: 'データベース', detail: 'リストまたはデータベースを構成するセル範囲を指定します。' },
+ field: { name: 'フィールド', detail: '関数の中で使用する列を指定します。' },
+ criteria: { name: '検索条件', detail: '指定した条件が設定されているセル範囲を指定します。' },
},
},
};
diff --git a/packages/sheets-formula-ui/src/locale/function-list/database/ru-RU.ts b/packages/sheets-formula-ui/src/locale/function-list/database/ru-RU.ts
index 5b0b86b2ec..cbbb2678ef 100644
--- a/packages/sheets-formula-ui/src/locale/function-list/database/ru-RU.ts
+++ b/packages/sheets-formula-ui/src/locale/function-list/database/ru-RU.ts
@@ -25,8 +25,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DCOUNT: {
@@ -39,8 +40,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DCOUNTA: {
@@ -53,8 +55,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DGET: {
@@ -67,8 +70,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DMAX: {
@@ -81,8 +85,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DMIN: {
@@ -95,8 +100,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DPRODUCT: {
@@ -109,8 +115,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DSTDEV: {
@@ -123,8 +130,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DSTDEVP: {
@@ -137,8 +145,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DSUM: {
@@ -151,8 +160,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DVAR: {
@@ -165,8 +175,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
DVARP: {
@@ -179,8 +190,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'первый' },
- number2: { name: 'number2', detail: 'второй' },
+ database: { name: 'База данных', detail: 'интервал ячеек, образующих список или базу данных.' },
+ field: { name: 'поле', detail: 'столбец, используемый функцией.' },
+ criteria: { name: 'условия', detail: 'диапазон ячеек, который содержит задаваемые условия.' },
},
},
};
diff --git a/packages/sheets-formula-ui/src/locale/function-list/database/vi-VN.ts b/packages/sheets-formula-ui/src/locale/function-list/database/vi-VN.ts
index 05ef2467da..1cdcfb8098 100644
--- a/packages/sheets-formula-ui/src/locale/function-list/database/vi-VN.ts
+++ b/packages/sheets-formula-ui/src/locale/function-list/database/vi-VN.ts
@@ -25,8 +25,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DCOUNT: {
@@ -39,8 +40,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DCOUNTA: {
@@ -53,8 +55,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DGET: {
@@ -67,8 +70,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DMAX: {
@@ -81,8 +85,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DMIN: {
@@ -95,8 +100,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DPRODUCT: {
@@ -109,8 +115,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DSTDEV: {
@@ -123,8 +130,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DSTDEVP: {
@@ -137,8 +145,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DSUM: {
@@ -151,8 +160,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DVAR: {
@@ -165,8 +175,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
DVARP: {
@@ -179,8 +190,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'Tham số thứ nhất' },
- number2: { name: 'number2', detail: 'Tham số thứ hai' },
+ database: { name: 'cơ sở dữ liệu', detail: 'là phạm vi ô tạo thành danh sách hoặc cơ sở dữ liệu.' },
+ field: { name: 'cánh đồng', detail: 'chỉ rõ cột nào được dùng trong hàm.' },
+ criteria: { name: 'tiêu chuẩn', detail: 'là phạm vi ô chứa các điều kiện mà bạn chỉ rõ.' },
},
},
};
diff --git a/packages/sheets-formula-ui/src/locale/function-list/database/zh-CN.ts b/packages/sheets-formula-ui/src/locale/function-list/database/zh-CN.ts
index da91abd582..6743c607d8 100644
--- a/packages/sheets-formula-ui/src/locale/function-list/database/zh-CN.ts
+++ b/packages/sheets-formula-ui/src/locale/function-list/database/zh-CN.ts
@@ -25,8 +25,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DCOUNT: {
@@ -39,8 +40,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DCOUNTA: {
@@ -53,8 +55,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DGET: {
@@ -67,8 +70,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DMAX: {
@@ -81,8 +85,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DMIN: {
@@ -95,8 +100,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DPRODUCT: {
@@ -109,8 +115,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DSTDEV: {
@@ -123,8 +130,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DSTDEVP: {
@@ -137,8 +145,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DSUM: {
@@ -151,8 +160,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DVAR: {
@@ -165,8 +175,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
DVARP: {
@@ -179,8 +190,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '数据库', detail: '构成列表或数据库的单元格区域。' },
+ field: { name: '字段', detail: '指定函数所使用的列。' },
+ criteria: { name: '条件', detail: '包含指定条件的单元格区域。' },
},
},
};
diff --git a/packages/sheets-formula-ui/src/locale/function-list/database/zh-TW.ts b/packages/sheets-formula-ui/src/locale/function-list/database/zh-TW.ts
index 35fd89b344..d37e2b6fc4 100644
--- a/packages/sheets-formula-ui/src/locale/function-list/database/zh-TW.ts
+++ b/packages/sheets-formula-ui/src/locale/function-list/database/zh-TW.ts
@@ -25,8 +25,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DCOUNT: {
@@ -39,8 +40,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DCOUNTA: {
@@ -53,8 +55,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DGET: {
@@ -67,8 +70,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DMAX: {
@@ -81,8 +85,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DMIN: {
@@ -95,8 +100,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DPRODUCT: {
@@ -109,8 +115,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DSTDEV: {
@@ -123,8 +130,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DSTDEVP: {
@@ -137,8 +145,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DSUM: {
@@ -151,8 +160,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DVAR: {
@@ -165,8 +175,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
DVARP: {
@@ -179,8 +190,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ database: { name: '資料庫', detail: '組成清單或資料庫的儲存格範圍。' },
+ field: { name: '欄位', detail: '指出函數中所使用的欄。' },
+ criteria: { name: '條件', detail: '含有指定條件的儲存格範圍。' },
},
},
};
diff --git a/packages/sheets-formula/src/services/function-list/database.ts b/packages/sheets-formula/src/services/function-list/database.ts
index 7369084d4c..aeab487208 100644
--- a/packages/sheets-formula/src/services/function-list/database.ts
+++ b/packages/sheets-formula/src/services/function-list/database.ts
@@ -24,16 +24,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DAVERAGE.abstract',
functionParameter: [
{
- name: 'formula.functionList.DAVERAGE.functionParameter.number1.name',
- detail: 'formula.functionList.DAVERAGE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DAVERAGE.functionParameter.database.name',
+ detail: 'formula.functionList.DAVERAGE.functionParameter.database.detail',
+ example: 'A4:E10',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DAVERAGE.functionParameter.number2.name',
- detail: 'formula.functionList.DAVERAGE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DAVERAGE.functionParameter.field.name',
+ detail: 'formula.functionList.DAVERAGE.functionParameter.field.detail',
+ example: 'D4',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DAVERAGE.functionParameter.criteria.name',
+ detail: 'formula.functionList.DAVERAGE.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -46,16 +53,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DCOUNT.abstract',
functionParameter: [
{
- name: 'formula.functionList.DCOUNT.functionParameter.number1.name',
- detail: 'formula.functionList.DCOUNT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DCOUNT.functionParameter.database.name',
+ detail: 'formula.functionList.DCOUNT.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DCOUNT.functionParameter.field.name',
+ detail: 'formula.functionList.DCOUNT.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DCOUNT.functionParameter.number2.name',
- detail: 'formula.functionList.DCOUNT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DCOUNT.functionParameter.criteria.name',
+ detail: 'formula.functionList.DCOUNT.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -68,16 +82,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DCOUNTA.abstract',
functionParameter: [
{
- name: 'formula.functionList.DCOUNTA.functionParameter.number1.name',
- detail: 'formula.functionList.DCOUNTA.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DCOUNTA.functionParameter.database.name',
+ detail: 'formula.functionList.DCOUNTA.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DCOUNTA.functionParameter.field.name',
+ detail: 'formula.functionList.DCOUNTA.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DCOUNTA.functionParameter.number2.name',
- detail: 'formula.functionList.DCOUNTA.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DCOUNTA.functionParameter.criteria.name',
+ detail: 'formula.functionList.DCOUNTA.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -90,16 +111,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DGET.abstract',
functionParameter: [
{
- name: 'formula.functionList.DGET.functionParameter.number1.name',
- detail: 'formula.functionList.DGET.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DGET.functionParameter.database.name',
+ detail: 'formula.functionList.DGET.functionParameter.database.detail',
+ example: 'A4:E10',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DGET.functionParameter.number2.name',
- detail: 'formula.functionList.DGET.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DGET.functionParameter.field.name',
+ detail: 'formula.functionList.DGET.functionParameter.field.detail',
+ example: 'D4',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DGET.functionParameter.criteria.name',
+ detail: 'formula.functionList.DGET.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -112,16 +140,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DMAX.abstract',
functionParameter: [
{
- name: 'formula.functionList.DMAX.functionParameter.number1.name',
- detail: 'formula.functionList.DMAX.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DMAX.functionParameter.database.name',
+ detail: 'formula.functionList.DMAX.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DMAX.functionParameter.field.name',
+ detail: 'formula.functionList.DMAX.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DMAX.functionParameter.number2.name',
- detail: 'formula.functionList.DMAX.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DMAX.functionParameter.criteria.name',
+ detail: 'formula.functionList.DMAX.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -134,16 +169,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DMIN.abstract',
functionParameter: [
{
- name: 'formula.functionList.DMIN.functionParameter.number1.name',
- detail: 'formula.functionList.DMIN.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DMIN.functionParameter.database.name',
+ detail: 'formula.functionList.DMIN.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DMIN.functionParameter.field.name',
+ detail: 'formula.functionList.DMIN.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DMIN.functionParameter.number2.name',
- detail: 'formula.functionList.DMIN.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DMIN.functionParameter.criteria.name',
+ detail: 'formula.functionList.DMIN.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -156,16 +198,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DPRODUCT.abstract',
functionParameter: [
{
- name: 'formula.functionList.DPRODUCT.functionParameter.number1.name',
- detail: 'formula.functionList.DPRODUCT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DPRODUCT.functionParameter.database.name',
+ detail: 'formula.functionList.DPRODUCT.functionParameter.database.detail',
+ example: 'A4:E10',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DPRODUCT.functionParameter.number2.name',
- detail: 'formula.functionList.DPRODUCT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DPRODUCT.functionParameter.field.name',
+ detail: 'formula.functionList.DPRODUCT.functionParameter.field.detail',
+ example: 'D4',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DPRODUCT.functionParameter.criteria.name',
+ detail: 'formula.functionList.DPRODUCT.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -178,16 +227,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DSTDEV.abstract',
functionParameter: [
{
- name: 'formula.functionList.DSTDEV.functionParameter.number1.name',
- detail: 'formula.functionList.DSTDEV.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DSTDEV.functionParameter.database.name',
+ detail: 'formula.functionList.DSTDEV.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DSTDEV.functionParameter.field.name',
+ detail: 'formula.functionList.DSTDEV.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DSTDEV.functionParameter.number2.name',
- detail: 'formula.functionList.DSTDEV.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DSTDEV.functionParameter.criteria.name',
+ detail: 'formula.functionList.DSTDEV.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -200,16 +256,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DSTDEVP.abstract',
functionParameter: [
{
- name: 'formula.functionList.DSTDEVP.functionParameter.number1.name',
- detail: 'formula.functionList.DSTDEVP.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DSTDEVP.functionParameter.database.name',
+ detail: 'formula.functionList.DSTDEVP.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DSTDEVP.functionParameter.field.name',
+ detail: 'formula.functionList.DSTDEVP.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DSTDEVP.functionParameter.number2.name',
- detail: 'formula.functionList.DSTDEVP.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DSTDEVP.functionParameter.criteria.name',
+ detail: 'formula.functionList.DSTDEVP.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -222,16 +285,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DSUM.abstract',
functionParameter: [
{
- name: 'formula.functionList.DSUM.functionParameter.number1.name',
- detail: 'formula.functionList.DSUM.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DSUM.functionParameter.database.name',
+ detail: 'formula.functionList.DSUM.functionParameter.database.detail',
+ example: 'A4:E10',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DSUM.functionParameter.number2.name',
- detail: 'formula.functionList.DSUM.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DSUM.functionParameter.field.name',
+ detail: 'formula.functionList.DSUM.functionParameter.field.detail',
+ example: 'D4',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DSUM.functionParameter.criteria.name',
+ detail: 'formula.functionList.DSUM.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -244,16 +314,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DVAR.abstract',
functionParameter: [
{
- name: 'formula.functionList.DVAR.functionParameter.number1.name',
- detail: 'formula.functionList.DVAR.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DVAR.functionParameter.database.name',
+ detail: 'formula.functionList.DVAR.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DVAR.functionParameter.field.name',
+ detail: 'formula.functionList.DVAR.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DVAR.functionParameter.number2.name',
- detail: 'formula.functionList.DVAR.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DVAR.functionParameter.criteria.name',
+ detail: 'formula.functionList.DVAR.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},
@@ -266,16 +343,23 @@ export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [
abstract: 'formula.functionList.DVARP.abstract',
functionParameter: [
{
- name: 'formula.functionList.DVARP.functionParameter.number1.name',
- detail: 'formula.functionList.DVARP.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DVARP.functionParameter.database.name',
+ detail: 'formula.functionList.DVARP.functionParameter.database.detail',
+ example: 'A4:E10',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.DVARP.functionParameter.field.name',
+ detail: 'formula.functionList.DVARP.functionParameter.field.detail',
+ example: 'D4',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.DVARP.functionParameter.number2.name',
- detail: 'formula.functionList.DVARP.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.DVARP.functionParameter.criteria.name',
+ detail: 'formula.functionList.DVARP.functionParameter.criteria.detail',
+ example: 'A1:B2',
require: 1,
repeat: 0,
},