{"version":3,"file":"aggregateUtils.mjs","names":["SeverityTypeEnums","NumberOperatorEnums","getThresholdStatus","aggThreshold","aggregateValue","thresholdTypes","type","Success","threshold","successThreshold","Error","errorThreshold","Warning","warningThreshold","Info","infoThreshold","thresholdStatus","evaluateThreshold","JSON","parse","console","error","operator","value1","value2","thresholdMet","Equals","parseFloat","Does_Not_Equal","Greater_Than","Less_Than","Greater_Than_Or_Equal_To","Less_Than_Or_Equal_To","Between"],"sources":["../../../../src/UI/utilityDisplay/utilities/aggregateUtils.js"],"sourcesContent":["import { SeverityTypeEnums } from '../../../enums/unitySystemEnums';\nimport { NumberOperatorEnums } from '../../../models/NumberOperator';\n\nexport const getThresholdStatus = (aggThreshold, aggregateValue) => {\n  if (!aggThreshold || !aggregateValue) return null;\n  // Order of this array matters\n  const thresholdTypes = [\n    {\n      type: SeverityTypeEnums.Success,\n      threshold: aggThreshold.successThreshold\n    },\n    { type: SeverityTypeEnums.Error, threshold: aggThreshold.errorThreshold },\n    {\n      type: SeverityTypeEnums.Warning,\n      threshold: aggThreshold.warningThreshold\n    },\n    { type: SeverityTypeEnums.Info, threshold: aggThreshold.infoThreshold }\n  ];\n\n  let thresholdStatus = '';\n  for (const { type, threshold } of thresholdTypes) {\n    if (threshold && evaluateThreshold(threshold, aggregateValue)) {\n      thresholdStatus = type;\n      break;\n    }\n  }\n\n  return thresholdStatus;\n};\n\nconst evaluateThreshold = (threshold = {}, aggregateValue) => {\n  if (typeof threshold === 'string') {\n    try {\n      threshold = JSON.parse(threshold);\n    } catch {\n      console.error(`Could not parse: ${threshold}`);\n      return false;\n    }\n  }\n  const { operator, value1, value2 } = threshold;\n  let thresholdMet = false;\n\n  switch (operator) {\n    case NumberOperatorEnums.Equals:\n      thresholdMet = aggregateValue === parseFloat(value1);\n      break;\n    case NumberOperatorEnums.Does_Not_Equal:\n      thresholdMet = aggregateValue !== parseFloat(value1);\n      break;\n    case NumberOperatorEnums.Greater_Than:\n      thresholdMet = aggregateValue > parseFloat(value1);\n      break;\n    case NumberOperatorEnums.Less_Than:\n      thresholdMet = aggregateValue < parseFloat(value1);\n      break;\n    case NumberOperatorEnums.Greater_Than_Or_Equal_To:\n      thresholdMet = aggregateValue >= parseFloat(value1);\n      break;\n    case NumberOperatorEnums.Less_Than_Or_Equal_To:\n      thresholdMet = aggregateValue <= parseFloat(value1);\n      break;\n    case NumberOperatorEnums.Between:\n      thresholdMet =\n        aggregateValue >= parseFloat(value1) &&\n        aggregateValue <= parseFloat(value2);\n      break;\n    default:\n      break;\n  }\n\n  return thresholdMet;\n};\n"],"mappings":";;;AAGA,MAAaE,sBAAsBC,cAAcC,mBAAmB;AAClE,KAAI,CAACD,gBAAgB,CAACC,eAAgB,QAAO;CAE7C,MAAMC,iBAAiB;EACrB;GACEC,MAAMN,kBAAkBO;GACxBC,WAAWL,aAAaM;GACzB;EACD;GAAEH,MAAMN,kBAAkBU;GAAOF,WAAWL,aAAaQ;GAAgB;EACzE;GACEL,MAAMN,kBAAkBY;GACxBJ,WAAWL,aAAaU;GACzB;EACD;GAAEP,MAAMN,kBAAkBc;GAAMN,WAAWL,aAAaY;GAAe;EACxE;CAED,IAAIC,kBAAkB;AACtB,MAAK,MAAM,EAAEV,MAAME,eAAeH,eAChC,KAAIG,aAAaS,kBAAkBT,WAAWJ,eAAe,EAAE;AAC7DY,oBAAkBV;AAClB;;AAIJ,QAAOU;;AAGT,MAAMC,qBAAqBT,YAAY,EAAE,EAAEJ,mBAAmB;AAC5D,KAAI,OAAOI,cAAc,SACvB,KAAI;AACFA,cAAYU,KAAKC,MAAMX,UAAU;SAC3B;AACNY,UAAQC,MAAM,oBAAoBb,YAAY;AAC9C,SAAO;;CAGX,MAAM,EAAEc,UAAUC,QAAQC,WAAWhB;CACrC,IAAIiB,eAAe;AAEnB,SAAQH,UAAR;EACE,KAAKrB,oBAAoByB;AACvBD,kBAAerB,mBAAmBuB,WAAWJ,OAAO;AACpD;EACF,KAAKtB,oBAAoB2B;AACvBH,kBAAerB,mBA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