Skip to content

Commit

Permalink
fix: added interunit and category conversion for handling threshold a…
Browse files Browse the repository at this point in the history
…cross different unit types
  • Loading branch information
SagarRajput-7 committed Oct 1, 2024
1 parent 2d9718b commit 029e0e1
Show file tree
Hide file tree
Showing 3 changed files with 392 additions and 3 deletions.
1 change: 1 addition & 0 deletions frontend/src/container/GridTableComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function GridTableComponent({
thresholds,
e.title as string,
Number(textForThreshold),
columnUnits?.[e.title as string],
);

const idx = thresholds.findIndex(
Expand Down
33 changes: 30 additions & 3 deletions frontend/src/container/GridTableComponent/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable sonarjs/cognitive-complexity */
import { ColumnsType, ColumnType } from 'antd/es/table';
import { convertUnit } from 'container/NewWidget/RightContainer/dataFormatCategories';
import { ThresholdProps } from 'container/NewWidget/RightContainer/Threshold/types';
import { QUERY_TABLE_CONFIG } from 'container/QueryTable/config';
import { QueryTableProps } from 'container/QueryTable/QueryTable.intefaces';
Expand Down Expand Up @@ -30,10 +31,29 @@ function evaluateCondition(
}
}

function evaluateThresholdWithConvertedValue(
value: number,
thresholdValue: number,
thresholdOperator?: string,
thresholdUnit?: string,
columnUnits?: string,
): boolean {
const convertedValue = convertUnit(value, columnUnits, thresholdUnit);

if (convertedValue) {
return evaluateCondition(thresholdOperator, convertedValue, thresholdValue);
}

// todo-sagar: what if invalid unit for conversion? - currently it just drop unit from comparison and compare the value

return evaluateCondition(thresholdOperator, value, thresholdValue);
}

export function findMatchingThreshold(
thresholds: ThresholdProps[],
label: string,
value: number,
columnUnits?: string,
): {
threshold: ThresholdProps;
hasMultipleMatches: boolean;
Expand All @@ -45,10 +65,17 @@ export function findMatchingThreshold(
if (
threshold.thresholdValue !== undefined &&
threshold.thresholdTableOptions === label &&
evaluateCondition(
threshold.thresholdOperator,
// evaluateCondition(
// threshold.thresholdOperator,
// value,
// threshold.thresholdValue,
// )
evaluateThresholdWithConvertedValue(
value,
threshold.thresholdValue,
threshold?.thresholdValue,
threshold.thresholdOperator,
threshold.thresholdUnit,
columnUnits,
)
) {
matchingThresholds.push(threshold);
Expand Down
Loading

0 comments on commit 029e0e1

Please sign in to comment.