MCPcopy
hub / github.com/deepops-ai/deepops / getThreshold

Function getThreshold

ui/src/components/Threshold/utils.ts:3–26  ·  view source on GitHub ↗
(value:number, thresholds: ThresholdsConfig, max?:number)

Source from the content-addressed store, hash-verified

1import { Threshold, ThresholdsConfig } from "types/threshold";
2
3export const getThreshold = (value:number, thresholds: ThresholdsConfig, max?:number): Threshold => {
4 let t;
5 if (!thresholds) {
6 return t
7 }
8 if (thresholds.mode == 'absolute') {
9 t = thresholds.thresholds.find(s => s.value <= value)
10 } else {
11 if (max == undefined || max == null) {
12 console.error("max is required when thresholds mode is percentage")
13 return null
14 }
15
16 const percentage = value / max * 100
17 t = thresholds.thresholds.find(s => s.value <= percentage)
18 }
19
20 if (!t && thresholds.thresholds.length > 0) {
21 // use base one
22 t = thresholds.thresholds[thresholds.thresholds.length - 1]
23 }
24
25 return t
26}

Callers 5

BarGaugeFunction · 0.90
updateMethod · 0.90
ComplexTable.tsxFile · 0.90
StatGraph.tsxFile · 0.90
PiePanelFunction · 0.90

Calls 1

findMethod · 0.80

Tested by

no test coverage detected