From a833b946a6d82cc73031c3c1219973fd66f225e2 Mon Sep 17 00:00:00 2001 From: Milho001 <l.milhomemfrancochristino@uu.nl> Date: Wed, 26 Jul 2023 19:30:43 +0000 Subject: [PATCH] feat(querybuilder): full rework of querybuilder Inner query in JSON format fully reworked. The interface was reworked to use entity attributes as part of query logic. Handle inner logic and types fully reworked for better type-checking and future-proofing. Includes logic in query building, parsing, and execution. Logic pills can be created from the handle drop and from the side panel. Solves #42 and #53 --- apps/web/src/app/panels/Visualization.tsx | 2 +- apps/web/src/components/navbar/navbar.tsx | 2 +- .../model/logic/mathAggregations.tsx | 745 ++++++++++++++++++ .../querybuilder/model/logic/mathFilters.tsx | 93 +++ .../model/logic/mathFunctions.tsx | 67 ++ .../lib/querybuilder/model/logic/utils.ts | 0 libs/shared/node.d.ts | 13 + 7 files changed, 920 insertions(+), 2 deletions(-) create mode 100644 libs/shared/lib/querybuilder/model/logic/mathAggregations.tsx create mode 100644 libs/shared/lib/querybuilder/model/logic/mathFilters.tsx create mode 100644 libs/shared/lib/querybuilder/model/logic/mathFunctions.tsx create mode 100644 libs/shared/lib/querybuilder/model/logic/utils.ts create mode 100644 libs/shared/node.d.ts diff --git a/apps/web/src/app/panels/Visualization.tsx b/apps/web/src/app/panels/Visualization.tsx index bdbe50bad..77f923184 100644 --- a/apps/web/src/app/panels/Visualization.tsx +++ b/apps/web/src/app/panels/Visualization.tsx @@ -54,7 +54,7 @@ export const VisualizationPanel = () => { <SemanticSubstrates /> </div> */} </div> - + {/* <div /> */} </div> ); diff --git a/apps/web/src/components/navbar/navbar.tsx b/apps/web/src/components/navbar/navbar.tsx index 24b69be41..9ecb2378a 100644 --- a/apps/web/src/components/navbar/navbar.tsx +++ b/apps/web/src/components/navbar/navbar.tsx @@ -204,7 +204,7 @@ export const Navbar = (props: NavbarComponentProps) => { <h2>user: {auth.userID}</h2> <h3 className="text-xs">session: {auth.sessionID}</h3> </div> - + </> ) : ( <> diff --git a/libs/shared/lib/querybuilder/model/logic/mathAggregations.tsx b/libs/shared/lib/querybuilder/model/logic/mathAggregations.tsx new file mode 100644 index 000000000..5baebb3b6 --- /dev/null +++ b/libs/shared/lib/querybuilder/model/logic/mathAggregations.tsx @@ -0,0 +1,745 @@ +/** + * This program has been developed by students from the bachelor Computer Science at + * Utrecht University within the Software Project course. + * © Copyright Utrecht University (Department of Information and Computing Sciences) + */ + +import { Position } from 'reactflow'; +import { GeneralDescription, MathAggregationTypes } from './general'; + +export const MathAggregations: Record<MathAggregationTypes, GeneralDescription<MathAggregationTypes>> = { + [MathAggregationTypes.AVG]: { + key: 'mathFunctionAvg', + name: 'Average', + type: MathAggregationTypes.AVG, + description: 'Average of all values', + numInputs: 1, + inputs: [{ name: '1', type: 'float', default: 0 }], + output: { name: 'avg', type: 'float' }, + logic: ['Avg', '@1'], + }, + [MathAggregationTypes.COUNT]: { + key: 'mathFunctionCount', + name: 'Count', + type: MathAggregationTypes.COUNT, + description: 'Count the number of values', + numInputs: 1, + inputs: [{ name: '1', type: 'float', default: 0 }], + + output: { name: 'count', type: 'float' }, + logic: ['Count', '@1'], + }, + [MathAggregationTypes.MAX]: { + key: 'mathFunctionMax', + name: 'Maximum', + type: MathAggregationTypes.MAX, + description: 'Maximum of all values', + numInputs: 1, + inputs: [{ name: '1', type: 'float', default: 0 }], + output: { name: 'max', type: 'float' }, + logic: ['Max', '@1'], + }, + [MathAggregationTypes.MIN]: { + key: 'mathFunctionMin', + name: 'Minimum', + type: MathAggregationTypes.MIN, + description: 'Minimum of all values', + numInputs: 1, + inputs: [{ name: '1', type: 'float', default: 0 }], + output: { name: 'min', type: 'float' }, + logic: ['Min', '@1'], + }, + [MathAggregationTypes.SUM]: { + key: 'mathFunctionSum', + name: 'Sum', + type: MathAggregationTypes.SUM, + description: 'Sum of all values', + numInputs: 1, + inputs: [{ name: '1', type: 'float', default: 0 }], + output: { name: 'sum', type: 'float' }, + logic: ['Sum', '@1'], + }, + // [MathAggregationTypes.STD]: { + // key: 'mathFunctionStd', + // name: 'Standard Deviation', + // type: MathAggregationTypes.STD, + // description: 'Standard deviation of all values', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'std', type: 'float' }, + // logic: ['Std', '@1'], + // }, + // [MathAggregationTypes.ADD]: { + // key: 'mathFunctionAdd', + // name: 'Add', + // type: MathAggregationTypes.ADD, + // description: 'Add two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float', default: 0 }, + // { name: '2', type: 'float', default: 0 }, + // ], + // output: { name: '+', type: 'float' }, + // logic: ['+', '@1', '@2'], + // }, + // [MathAggregationTypes.SUBTRACT]: { + // key: 'mathFunctionSubtract', + // name: 'Subtract', + // type: MathAggregationTypes.SUBTRACT, + // description: 'Subtract two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float' }, + // { name: '2', type: 'float' }, + // ], + // output: { name: '-', type: 'float' }, + // logic: ['-', '@1', '@2'], + // }, + // [MathAggregationTypes.MULTIPLY]: { + // key: 'mathFunctionMultiply', + // name: 'Multiply', + // type: MathAggregationTypes.MULTIPLY, + // description: 'Multiply two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float' }, + // { name: '2', type: 'float' }, + // ], + // output: { name: '*', type: 'float' }, + // logic: ['*', '@1', '@2'], + // }, + // [MathAggregationTypes.DIVIDE]: { + // key: 'mathFunctionDivide', + // name: 'Divide', + // type: MathAggregationTypes.DIVIDE, + // description: 'Divide two values', + + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float' }, + // { name: '2', type: 'float' }, + // ], + // output: { name: '/', type: 'float' }, + // logic: ['/', '@1', '@2'], + // }, + // [MathAggregationTypes.POWER]: { + // key: 'mathFunctionPower', + // name: 'Power', + // type: MathAggregationTypes.POWER, + // description: 'Raise a value to the power of another value', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float' }, + // { name: '2', type: 'float' }, + // ], + // output: { name: '^', type: 'float' }, + // logic: ['^', '@1', '@2'], + // }, + // [MathAggregationTypes.SQRT]: { + // key: 'mathFunctionSqrt', + // name: 'Square Root', + // type: MathAggregationTypes.SQRT, + // description: 'Square root of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'sqrt', type: 'float' }, + // logic: ['Sqrt', '@1'], + // }, + // [MathAggregationTypes.LOG]: { + // key: 'mathFunctionLog', + // name: 'Logarithm', + // type: MathAggregationTypes.LOG, + // description: 'Logarithm of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'log', type: 'float' }, + // logic: ['Log', '@1'], + // }, + // [MathAggregationTypes.EXP]: { + // key: 'mathFunctionExp', + // name: 'Exponential', + // type: MathAggregationTypes.EXP, + // description: 'Exponential of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'exp', type: 'float' }, + // logic: ['Exp', '@1'], + // }, + // [MathAggregationTypes.ABS]: { + // key: 'mathFunctionAbs', + // name: 'Absolute Value', + // type: MathAggregationTypes.ABS, + // description: 'Absolute value of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'abs', type: 'float' }, + // logic: ['Abs', '@1'], + // }, + // [MathAggregationTypes.CEIL]: { + // key: 'mathFunctionCeil', + // name: 'Ceiling', + // type: MathAggregationTypes.CEIL, + // description: 'Ceiling of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'ceil', type: 'float' }, + // logic: ['Ceil', '@1'], + // }, + // [MathAggregationTypes.FLOOR]: { + // key: 'mathFunctionFloor', + // name: 'Floor', + // type: MathAggregationTypes.FLOOR, + // description: 'Floor of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'floor', type: 'float' }, + // logic: ['Floor', '@1'], + // }, + // [MathAggregationTypes.ROUND]: { + // key: 'mathFunctionRound', + // name: 'Round', + // type: MathAggregationTypes.ROUND, + // description: 'Round a value to the nearest integer', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'round', type: 'float' }, + // logic: ['Round', '@1'], + // }, + // [MathAggregationTypes.TRUNC]: { + // key: 'mathFunctionTrunc', + // name: 'Truncate', + // type: MathAggregationTypes.TRUNC, + // description: 'Truncate a value to the nearest integer towards zero', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + + // output: { name: 'trunc', type: 'float' }, + // logic: ['Trunc', '@1'], + // }, + // [MathAggregationTypes.RANDOM]: { + // key: 'mathFunctionRandom', + // name: 'Random', + // type: MathAggregationTypes.RANDOM, + // description: 'Random value between 0 and 1', + // numInputs: 0, + // inputs: [], + // output: { name: 'random', type: 'float' }, + // logic: ['Random'], + // }, + // [MathAggregationTypes.RANDOMINT]: { + // key: 'mathFunctionRandomInt', + // name: 'Random Integer', + // type: MathAggregationTypes.RANDOMINT, + // description: 'Random integer between two values', + // numInputs: 2, + // inputs: [ + // { name: 'min', type: 'float' }, + // { name: 'max', type: 'float' }, + // ], + // output: { name: 'randomInt', type: 'float' }, + // logic: ['RandomInt', '@1', '@2'], + // }, + // [MathAggregationTypes.SIN]: { + // key: 'mathFunctionSin', + // name: 'Sine', + // type: MathAggregationTypes.SIN, + // description: 'Sine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'sin', type: 'float' }, + // logic: ['Sin', '@1'], + // }, + // [MathAggregationTypes.COS]: { + // key: 'mathFunctionCos', + // name: 'Cosine', + // type: MathAggregationTypes.COS, + // description: 'Cosine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'cos', type: 'float' }, + // logic: ['Cos', '@1'], + // }, + // [MathAggregationTypes.TAN]: { + // key: 'mathFunctionTan', + // name: 'Tangent', + // type: MathAggregationTypes.TAN, + // description: 'Tangent of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'tan', type: 'float' }, + // logic: ['Tan', '@1'], + // }, + // [MathAggregationTypes.ASIN]: { + // key: 'mathFunctionAsin', + // name: 'Arcsine', + // type: MathAggregationTypes.ASIN, + // description: 'Arcsine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'asin', type: 'float' }, + // logic: ['Asin', '@1'], + // }, + // [MathAggregationTypes.ACOS]: { + // key: 'mathFunctionAcos', + // name: 'Arccosine', + // type: MathAggregationTypes.ACOS, + // description: 'Arccosine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'acos', type: 'float' }, + // logic: ['Acos', '@1'], + // }, + // [MathAggregationTypes.ATAN]: { + // key: 'mathFunctionAtan', + // name: 'Arctangent', + // type: MathAggregationTypes.ATAN, + // description: 'Arctangent of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'atan', type: 'float' }, + // logic: ['Atan', '@1'], + // }, + // [MathAggregationTypes.SINH]: { + // key: 'mathFunctionSinh', + // name: 'Hyperbolic Sine', + // type: MathAggregationTypes.SINH, + // description: 'Hyperbolic sine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'sinh', type: 'float' }, + // logic: ['Sinh', '@1'], + // }, + // [MathAggregationTypes.COSH]: { + // key: 'mathFunctionCosh', + // name: 'Hyperbolic Cosine', + // type: MathAggregationTypes.COSH, + // description: 'Hyperbolic cosine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'cosh', type: 'float' }, + // logic: ['Cosh', '@1'], + // }, + // [MathAggregationTypes.TANH]: { + // key: 'mathFunctionTanh', + // name: 'Hyperbolic Tangent', + // type: MathAggregationTypes.TANH, + // description: 'Hyperbolic tangent of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'tanh', type: 'float' }, + // logic: ['Tanh', '@1'], + // }, + // [MathAggregationTypes.ASINH]: { + // key: 'mathFunctionAsinh', + // name: 'Hyperbolic Arcsine', + // type: MathAggregationTypes.ASINH, + // description: 'Hyperbolic arcsine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'asinh', type: 'float' }, + // logic: ['Asinh', '@1'], + // }, + // [MathAggregationTypes.ACOSH]: { + // key: 'mathFunctionAcosh', + // name: 'Hyperbolic Arccosine', + // type: MathAggregationTypes.ACOSH, + // description: 'Hyperbolic arccosine of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'acosh', type: 'float' }, + // logic: ['Acosh', '@1'], + // }, + // [MathAggregationTypes.ATANH]: { + // key: 'mathFunctionAtanh', + // name: 'Hyperbolic Arctangent', + // type: MathAggregationTypes.ATANH, + // description: 'Hyperbolic arctangent of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'atanh', type: 'float' }, + // logic: ['Atanh', '@1'], + // }, + // [MathAggregationTypes.DEGREES]: { + // key: 'mathFunctionDegrees', + // name: 'Degrees', + // type: MathAggregationTypes.DEGREES, + // description: 'Convert a value from radians to degrees', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'degrees', type: 'float' }, + // logic: ['Degrees', '@1'], + // }, + // [MathAggregationTypes.RADIANS]: { + // key: 'mathFunctionRadians', + // name: 'Radians', + // type: MathAggregationTypes.RADIANS, + // description: 'Convert a value from degrees to radians', + // numInputs: 1, + + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'radians', type: 'float' }, + // logic: ['Radians', '@1'], + // }, + // [MathAggregationTypes.SIGN]: { + // key: 'mathFunctionSign', + // name: 'Sign', + // type: MathAggregationTypes.SIGN, + // description: 'Sign of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'sign', type: 'float' }, + // logic: ['Sign', '@1'], + // }, + // [MathAggregationTypes.RANDOMNORMAL]: { + // key: 'mathFunctionRandomNormal', + // name: 'Random Normal', + // type: MathAggregationTypes.RANDOMNORMAL, + // description: 'Random value from a normal distribution', + // numInputs: 2, + // inputs: [ + // { name: 'mean', type: 'float' }, + // { name: 'std', type: 'float' }, + // ], + // output: { name: 'randomNormal', type: 'float' }, + // logic: ['RandomNormal', '@1', '@2'], + // }, + // [MathAggregationTypes.RANDOMLOGNORMAL]: { + // key: 'mathFunctionRandomLogNormal', + // name: 'Random Log Normal', + // type: MathAggregationTypes.RANDOMLOGNORMAL, + // description: 'Random value from a log normal distribution', + // numInputs: 2, + // inputs: [ + // { name: 'mean', type: 'float' }, + // { name: 'std', type: 'float' }, + // ], + // output: { name: 'randomLogNormal', type: 'float' }, + // logic: ['RandomLogNormal', '@1', '@2'], + // }, + // [MathAggregationTypes.RANDOMEXPONENTIAL]: { + // key: 'mathFunctionRandomExponential', + // name: 'Random Exponential', + // type: MathAggregationTypes.RANDOMEXPONENTIAL, + // description: 'Random value from an exponential distribution', + // numInputs: 1, + // inputs: [{ name: 'lambda', type: 'float' }], + // output: { name: 'randomExponential', type: 'float' }, + // logic: ['RandomExponential', '@1'], + // }, + // [MathAggregationTypes.RANDOMGAMMA]: { + // key: 'mathFunctionRandomGamma', + // name: 'Random Gamma', + // type: MathAggregationTypes.RANDOMGAMMA, + // description: 'Random value from a gamma distribution', + // numInputs: 2, + // inputs: [ + // { name: 'alpha', type: 'float' }, + // { name: 'beta', type: 'float' }, + // ], + // output: { name: 'randomGamma', type: 'float' }, + // logic: ['RandomGamma', '@1', '@2'], + // }, + // [MathAggregationTypes.RANDOMBETA]: { + // key: 'mathFunctionRandomBeta', + // name: 'Random Beta', + // type: MathAggregationTypes.RANDOMBETA, + // description: 'Random value from a beta distribution', + // numInputs: 2, + // inputs: [ + // { name: 'alpha', type: 'float' }, + // { name: 'beta', type: 'float' }, + // ], + // output: { name: 'randomBeta', type: 'float' }, + // logic: ['RandomBeta', '@1', '@2'], + // }, + // [MathAggregationTypes.RANDOMCHISQUARE]: { + // key: 'mathFunctionRandomChiSquare', + // name: 'Random Chi Square', + // type: MathAggregationTypes.RANDOMCHISQUARE, + // description: 'Random value from a chi square distribution', + // numInputs: 1, + // inputs: [{ name: 'k', type: 'float' }], + // output: { name: 'randomChiSquare', type: 'float' }, + // logic: ['RandomChiSquare', '@1'], + // }, + // [MathAggregationTypes.RANDOMWEIBULL]: { + // key: 'mathFunctionRandomWeibull', + // name: 'Random Weibull', + // type: MathAggregationTypes.RANDOMWEIBULL, + // description: 'Random value from a Weibull distribution', + // numInputs: 2, + // inputs: [ + // { name: 'k', type: 'float' }, + // { name: 'lambda', type: 'float' }, + // ], + // output: { name: 'randomWeibull', type: 'float' }, + // logic: ['RandomWeibull', '@1', '@2'], + // }, + // [MathAggregationTypes.RANDOMCAUCHY]: { + // key: 'mathFunctionRandomCauchy', + // name: 'Random Cauchy', + // type: MathAggregationTypes.RANDOMCAUCHY, + // description: 'Random value from a Cauchy distribution', + // numInputs: 2, + // inputs: [ + // { name: 'x0', type: 'float' }, + // { name: 'gamma', type: 'float' }, + // ], + // output: { name: 'randomCauchy', type: 'float' }, + // logic: ['RandomCauchy', '@1', '@2'], + // }, + // [MathAggregationTypes.RANDOMPOISSON]: { + // key: 'mathFunctionRandomPoisson', + // name: 'Random Poisson', + // type: MathAggregationTypes.RANDOMPOISSON, + // description: 'Random value from a Poisson distribution', + // numInputs: 1, + // inputs: [{ name: 'lambda', type: 'float' }], + // output: { name: 'randomPoisson', type: 'float' }, + // logic: ['RandomPoisson', '@1'], + // }, + // [MathAggregationTypes.RANDOMIRWINHALL]: { + // key: 'mathFunctionRandomIrwinHall', + // name: 'Random Irwin Hall', + // type: MathAggregationTypes.RANDOMIRWINHALL, + // description: 'Random value from an Irwin Hall distribution', + // numInputs: 2, + // inputs: [ + // { name: 'n', type: 'float' }, + // { name: 'scale', type: 'float' }, + // ], + // output: { name: 'randomIrwinHall', type: 'float' }, + // logic: ['RandomIrwinHall', '@1', '@2'], + // }, + // [MathAggregationTypes.CHIQUARETEST]: { + // key: 'mathFunctionChiSquareTest', + // name: 'Chi Square Test', + // type: MathAggregationTypes.CHIQUARETEST, + // description: 'Chi square test', + // numInputs: 2, + // inputs: [ + // { name: 'observed', type: 'float' }, + // { name: 'expected', type: 'float' }, + // ], + // output: { name: 'chiSquareTest', type: 'float' }, + // logic: ['ChiSquareTest', '@1', '@2'], + // }, + // [MathAggregationTypes.CORRELATION]: { + // key: 'mathFunctionCorrelation', + // name: 'Correlation', + // type: MathAggregationTypes.CORRELATION, + // description: 'Correlation between two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float' }, + // { name: '2', type: 'float' }, + // ], + // output: { name: 'correlation', type: 'float' }, + // logic: ['Correlation', '@1', '@2'], + // }, + // [MathAggregationTypes.COVARIANCE]: { + // key: 'mathFunctionCovariance', + // name: 'Covariance', + // type: MathAggregationTypes.COVARIANCE, + // description: 'Covariance between two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float' }, + // { name: '2', type: 'float' }, + // ], + // output: { name: 'covariance', type: 'float' }, + // logic: ['Covariance', '@1', '@2'], + // }, + // [MathAggregationTypes.FREQUENCY]: { + // key: 'mathFunctionFrequency', + // name: 'Frequency', + // type: MathAggregationTypes.FREQUENCY, + // description: 'Frequency of a value in a dataset', + // numInputs: 2, + // inputs: [ + // { name: 'value', type: 'float' }, + // { name: 'dataset', type: 'float' }, + // ], + // output: { name: 'frequency', type: 'float' }, + // logic: ['Frequency', '@1', '@2'], + // }, + // [MathAggregationTypes.MEAN]: { + // key: 'mathFunctionMean', + // name: 'Mean', + // type: MathAggregationTypes.MEAN, + // description: 'Mean of a dataset', + // numInputs: 1, + // inputs: [{ name: 'dataset', type: 'float' }], + // output: { name: 'mean', type: 'float' }, + // logic: ['Mean', '@1'], + // }, + // [MathAggregationTypes.MEDIAN]: { + // key: 'mathFunctionMedian', + // name: 'Median', + // type: MathAggregationTypes.MEDIAN, + // description: 'Median of a dataset', + // numInputs: 1, + // inputs: [{ name: 'dataset', type: 'float' }], + // output: { name: 'median', type: 'float' }, + // logic: ['Median', '@1'], + // }, + // [MathAggregationTypes.MODE]: { + // key: 'mathFunctionMode', + // name: 'Mode', + // type: MathAggregationTypes.MODE, + // description: 'Mode of a dataset', + // numInputs: 1, + // inputs: [{ name: 'dataset', type: 'float' }], + // output: { name: 'mode', type: 'float' }, + // logic: ['Mode', '@1'], + // }, + // [MathAggregationTypes.RANK]: { + // key: 'mathFunctionRank', + // name: 'Rank', + // type: MathAggregationTypes.RANK, + // description: 'Rank of a value in a dataset', + // numInputs: 2, + // inputs: [ + // { name: 'value', type: 'float' }, + // { name: 'dataset', type: 'float' }, + // ], + // output: { name: 'rank', type: 'float' }, + // logic: ['Rank', '@1', '@2'], + // }, + // [MathAggregationTypes.STDEV]: { + // key: 'mathFunctionStdev', + // name: 'Standard Deviation', + // type: MathAggregationTypes.STDEV, + // description: 'Standard deviation of a dataset', + // numInputs: 1, + // inputs: [{ name: 'dataset', type: 'float' }], + // output: { name: 'stdev', type: 'float' }, + // logic: ['Stdev', '@1'], + // }, + // [MathAggregationTypes.VARIANCE]: { + // key: 'mathFunctionVariance', + // name: 'Variance', + // type: MathAggregationTypes.VARIANCE, + // description: 'Variance of a dataset', + // numInputs: 1, + // inputs: [{ name: 'dataset', type: 'float' }], + // output: { name: 'variance', type: 'float' }, + // logic: ['Variance', '@1'], + // }, + // [MathAggregationTypes.ZSCORE]: { + // key: 'mathFunctionZscore', + // name: 'Z-Score', + // type: MathAggregationTypes.ZSCORE, + // description: 'Z-score of a value in a dataset', + // numInputs: 2, + // inputs: [ + // { name: 'value', type: 'float' }, + // { name: 'dataset', type: 'float' }, + // ], + // output: { name: 'zscore', type: 'float' }, + // logic: ['Zscore', '@1', '@2'], + // }, + // [MathAggregationTypes.AND]: { + // key: 'mathFunctionAnd', + // name: 'And', + // type: MathAggregationTypes.AND, + // description: 'Logical AND of two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'boolean' }, + // { name: '2', type: 'boolean' }, + // ], + // output: { name: 'and', type: 'boolean' }, + // logic: ['And', '@1', '@2'], + // }, + // [MathAggregationTypes.OR]: { + // key: 'mathFunctionOr', + // name: 'Or', + // type: MathAggregationTypes.OR, + // description: 'Logical OR of two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'boolean' }, + // { name: '2', type: 'boolean' }, + // ], + // output: { name: 'or', type: 'boolean' }, + // logic: ['Or', '@1', '@2'], + // }, + // [MathAggregationTypes.NOT]: { + // key: 'mathFunctionNot', + // name: 'Not', + // type: MathAggregationTypes.NOT, + // description: 'Logical NOT of a value', + // numInputs: 1, + // inputs: [{ name: '1', type: 'boolean' }], + // output: { name: 'not', type: 'boolean' }, + // logic: ['Not', '@1'], + // }, + + // { + // key: 'mathFunctionCount', + // name: 'Count', + // type: MathAggregationTypes.COUNT, + // description: 'Count the number of values', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'count', type: 'float' }, + // logic: ['Count', '@1'], + // }, + // { + // key: 'mathFunctionMax', + // name: 'Maximum', + // type: MathAggregationTypes.MAX, + // description: 'Maximum of all values', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'max', type: 'float' }, + // logic: ['Max', '@1'], + // }, + // { + // key: 'mathFunctionMin', + // name: 'Minimum', + // type: MathAggregationTypes.MIN, + // description: 'Minimum of all values', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'min', type: 'float' }, + // logic: ['Min', '@1'], + // }, + // { + // key: 'mathFunctionSum', + // name: 'Sum', + // type: MathAggregationTypes.SUM, + // description: 'Sum of all values', + // numInputs: 1, + // inputs: [{ name: '1', type: 'float' }], + // output: { name: 'sum', type: 'float' }, + // logic: ['Sum', '@1'], + // }, + // // { + // // key: 'mathFunctionStd', + // // name: 'Standard Deviation', + // // type: MathAggregationTypes.STD, + // // description: 'Standard deviation of all values', + // // numInputs: 1, + // // inputs: [{ name: '1', type: 'float' }], + // // output: { name: 'std', type: 'float' }, + // // logic: ['Std', '@1'], + // // }, + // { + // key: 'mathFunctionAdd', + // name: 'Add', + // type: MathAggregationTypes.ADD, + // description: 'Add two values', + // numInputs: 2, + // inputs: [ + // { name: '1', type: 'float' }, + // { name: '2', type: 'float' }, + // ], + // output: { name: '+', type: 'float' }, + // logic: ['+', '@1', '@2'], + // }, +}; + +/** All available functions in the function bar. */ +export const MathAggregationArray: Array<GeneralDescription<MathAggregationTypes>> = Object.values(MathAggregations); diff --git a/libs/shared/lib/querybuilder/model/logic/mathFilters.tsx b/libs/shared/lib/querybuilder/model/logic/mathFilters.tsx new file mode 100644 index 000000000..0c235dd78 --- /dev/null +++ b/libs/shared/lib/querybuilder/model/logic/mathFilters.tsx @@ -0,0 +1,93 @@ +/** + * This program has been developed by students from the bachelor Computer Science at + * Utrecht University within the Software Project course. + * © Copyright Utrecht University (Department of Information and Computing Sciences) + */ + +import { Position } from 'reactflow'; +import { GeneralDescription, InputNode, MathFilterTypes } from './general'; + +export const MathFilters: Record<MathFilterTypes, GeneralDescription<MathFilterTypes>> = { + [MathFilterTypes.EQUAL]: { + key: 'mathFilterEqual', + name: 'Equal', + type: MathFilterTypes.EQUAL, + description: 'Equal to another value', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '==', type: 'float' }, + logic: ['==', '@1', '@2'], + }, + [MathFilterTypes.NOT_EQUAL]: { + key: 'mathFilterNotEqual', + name: 'Not Equal', + type: MathFilterTypes.NOT_EQUAL, + description: 'Not equal to another value', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '!=', type: 'float' }, + logic: ['!=', '@1', '@2'], + }, + [MathFilterTypes.LESS_THAN]: { + key: 'mathFilterLessThan', + name: 'Less Than', + type: MathFilterTypes.LESS_THAN, + description: 'Less than another value', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '<', type: 'float' }, + logic: ['<', '@1', '@2'], + }, + [MathFilterTypes.LESS_THAN_EQUAL]: { + key: 'mathFilterLessThanOrEqual', + name: 'Less Than or Equal', + type: MathFilterTypes.LESS_THAN_EQUAL, + description: 'Less than or equal to another value', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '<=', type: 'float' }, + logic: ['<=', '@1', '@2'], + }, + [MathFilterTypes.GREATER_THAN]: { + key: 'mathFilterGreaterThan', + name: 'Greater Than', + type: MathFilterTypes.GREATER_THAN, + description: 'Greater than another value', + + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '>', type: 'float' }, + logic: ['>', '@1', '@2'], + }, + [MathFilterTypes.GREATER_THAN_EQUAL]: { + key: 'mathFilterGreaterThanOrEqual', + name: 'Greater Than or Equal', + type: MathFilterTypes.GREATER_THAN_EQUAL, + description: 'Greater than or equal to another value', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '>=', type: 'float' }, + logic: ['>=', '@1', '@2'], + }, +}; + +/** All available functions in the function bar. */ +export const MathFilterArray: Array<GeneralDescription<MathFilterTypes>> = Object.values(MathFilters); diff --git a/libs/shared/lib/querybuilder/model/logic/mathFunctions.tsx b/libs/shared/lib/querybuilder/model/logic/mathFunctions.tsx new file mode 100644 index 000000000..5375664aa --- /dev/null +++ b/libs/shared/lib/querybuilder/model/logic/mathFunctions.tsx @@ -0,0 +1,67 @@ +/** + * This program has been developed by students from the bachelor Computer Science at + * Utrecht University within the Software Project course. + * © Copyright Utrecht University (Department of Information and Computing Sciences) + */ + +import { Position } from 'reactflow'; +import { GeneralDescription, MathFunctionTypes } from './general'; + +export const MathFunctions: Record<MathFunctionTypes, GeneralDescription<MathFunctionTypes>> = { + [MathFunctionTypes.ADD]: { + key: 'mathFunctionAdd', + name: 'Add', + type: MathFunctionTypes.ADD, + description: 'Add two values', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '+', type: 'float' }, + logic: ['+', '@1', '@2'], + }, + [MathFunctionTypes.SUBTRACT]: { + key: 'mathFunctionSubtract', + name: 'Subtract', + type: MathFunctionTypes.SUBTRACT, + description: 'Subtract two values', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '-', type: 'float' }, + logic: ['-', '@1', '@2'], + }, + [MathFunctionTypes.MULTIPLY]: { + key: 'mathFunctionMultiply', + name: 'Multiply', + type: MathFunctionTypes.MULTIPLY, + description: 'Multiply two values', + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '*', type: 'float' }, + logic: ['*', '@1', '@2'], + }, + [MathFunctionTypes.DIVIDE]: { + key: 'mathFunctionDivide', + name: 'Divide', + type: MathFunctionTypes.DIVIDE, + description: 'Divide two values', + + numInputs: 2, + inputs: [ + { name: '1', type: 'float', default: 0 }, + { name: '2', type: 'float', default: 0 }, + ], + output: { name: '/', type: 'float' }, + logic: ['/', '@1', '@2'], + }, +}; + +/** All available functions in the function bar. */ +export const MathFunctionArray: Array<GeneralDescription<MathFunctionTypes>> = Object.values(MathFunctions); diff --git a/libs/shared/lib/querybuilder/model/logic/utils.ts b/libs/shared/lib/querybuilder/model/logic/utils.ts new file mode 100644 index 000000000..e69de29bb diff --git a/libs/shared/node.d.ts b/libs/shared/node.d.ts new file mode 100644 index 000000000..3d2ced5bc --- /dev/null +++ b/libs/shared/node.d.ts @@ -0,0 +1,13 @@ +interface ImportMeta { + env: { + VITE_BACKEND_URL: string; + VITE_BACKEND_WSS_URL: string; + VITE_BACKEND_USER: string; + VITE_BACKEND_SCHEMA: string; + VITE_BACKEND_QUERY: string; + VITE_STAGING: string; + VITE_KEYCLOAK_URL: string; + VITE_KEYCLOAK_REALM: string; + VITE_KEYCLOAK_CLIENT: string; + }; +} -- GitLab