Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
fix: add constant for TSD modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj0047 committed Mar 1, 2023
1 parent fb166a1 commit 9c19b13
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
37 changes: 5 additions & 32 deletions src/expression-modifiers/helper.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
import util from '../utils/util';
import TSD from './time-series-decomposition/constants';

const NO_BREAK_SPACE = ' ';
const IDEOGRAPHIC_SPACE = ' ';
const MARKER1 = `${NO_BREAK_SPACE}(${IDEOGRAPHIC_SPACE}`;
const MARKER2 = `${IDEOGRAPHIC_SPACE})${NO_BREAK_SPACE}`;

const TSD_EXPRESSIONS = {
observed: '',
trend: 'STL_Trend',
seasonal: 'STL_Seasonal',
residual: 'STL_Residual',
};

const TSD_OPTIONS = [
{
value: 'observed',
translation: 'cao.trendDecomposition.parameters.decomposition.observed',
},
{
value: 'trend',
translation: 'cao.trendDecomposition.parameters.decomposition.trend',
},
{
value: 'seasonal',
translation: 'cao.trendDecomposition.parameters.decomposition.seasonal',
},
{
value: 'residual',
translation: 'cao.trendDecomposition.parameters.decomposition.residual',
},
];

function getExpressionWithMarkers(expression) {
return MARKER1 + expression + MARKER2;
}
Expand Down Expand Up @@ -353,15 +328,15 @@ function initModifier(modifier, defaultOptions) {
}

function getTDSExpressionName(modifier) {
const filteredOption = TSD_OPTIONS.find(option => option.value === modifier.decomposition);
return filteredOption ? TSD_EXPRESSIONS[filteredOption.value] : '';
const filteredOption = TSD.OPTIONS.find(option => option.value === modifier.decomposition);
return filteredOption ? TSD.EXPRESSIONS[filteredOption.value] : '';
}

function getDecomposition(measure) {
let decomposition = 'observed';
Object.values(TSD_EXPRESSIONS).find((item) => {
Object.values(TSD.EXPRESSIONS).find((item) => {
const expression = measure.qDef.base.qDef.toLowerCase() || measure.qDef.qDef.toLowerCase();
if (TSD_EXPRESSIONS[item] && expression.includes(TSD_EXPRESSIONS[item].toLowerCase())) {
if (TSD.EXPRESSIONS[item] && expression.includes(TSD.EXPRESSIONS[item].toLowerCase())) {
decomposition = item;
}
return item;
Expand Down Expand Up @@ -455,8 +430,6 @@ export default {

generateTSDExpression,

TSD_OPTIONS,

getDecomposition,

};
27 changes: 27 additions & 0 deletions src/expression-modifiers/time-series-decomposition/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default {
EXPRESSIONS: {
observed: '',
trend: 'STL_Trend',
seasonal: 'STL_Seasonal',
residual: 'STL_Residual',
},

OPTIONS: [
{
value: 'observed',
translation: 'cao.trendDecomposition.parameters.decomposition.observed',
},
{
value: 'trend',
translation: 'cao.trendDecomposition.parameters.decomposition.trend',
},
{
value: 'seasonal',
translation: 'cao.trendDecomposition.parameters.decomposition.seasonal',
},
{
value: 'residual',
translation: 'cao.trendDecomposition.parameters.decomposition.residual',
},
],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import util from '../../utils/util';
import helper from '../helper';
import TSD from './constants';

const MODIFIER_TYPE = 'timeSeriesDecomposition';

Expand Down Expand Up @@ -55,7 +56,7 @@ export default function (rootPath, translationKeys = {}) {
component: 'dropdown',
schemaIgnore: true,
defaultValue: translationKeys.trendDecompositionParametersDecompositionObserved || 'cao.trendDecomposition.parameters.decomposition.observed',
options: helper.TSD_OPTIONS,
options: TSD.OPTIONS,
},
steps: {
refFn: data => `${getRef(data, rootPath)}.steps`,
Expand Down

0 comments on commit 9c19b13

Please sign in to comment.