You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
62 lines
2.0 KiB
THR_DIR_BOTH = "both"
|
|
THR_DIR_UP = "upper"
|
|
THR_DIR_LO = "lower"
|
|
THR_DIR_AUTO = "auto"
|
|
HIGH_THRESHOLD_ZSCORE_MULTIPLIER = 1.2
|
|
CRITICAL_THRESHOLD_ZSCORE_MULTIPLIER = 1.4
|
|
|
|
NO_RECOMMEND_NOT_ENOUGH_DATA = "NO_RECOMMEND_NOT_ENOUGH_DATA"
|
|
|
|
def cascade_thresholds(threshold):
|
|
"""
|
|
Simple cascading thresholds for the initial release
|
|
"""
|
|
medium = threshold
|
|
high = medium * HIGH_THRESHOLD_ZSCORE_MULTIPLIER
|
|
critical = medium * CRITICAL_THRESHOLD_ZSCORE_MULTIPLIER
|
|
|
|
return (critical, high, medium)
|
|
|
|
|
|
def output_thresholds_dict(
|
|
threshold, threshold_rounding, threshold_direction, static_params=None
|
|
):
|
|
def transform(value):
|
|
if static_params:
|
|
return round(value * stdev + mean, threshold_rounding)
|
|
else:
|
|
return round(value, threshold_rounding)
|
|
|
|
critical, high, medium = cascade_thresholds(threshold)
|
|
if static_params:
|
|
mean = static_params[0]
|
|
stdev = static_params[1]
|
|
|
|
if threshold_direction == THR_DIR_BOTH:
|
|
critical_final = transform(critical)
|
|
high_final = [transform(high), transform(-critical)]
|
|
medium_final = [transform(medium), transform(-high)]
|
|
normal_final = transform(-1 * medium)
|
|
return f"{{'critical': {critical_final}, 'high': {high_final}, 'medium': {medium_final}, 'normal': {normal_final}}}"
|
|
elif threshold_direction == THR_DIR_UP:
|
|
critical_final = transform(critical)
|
|
high_final = transform(high)
|
|
medium_final = transform(medium)
|
|
return f"{{'critical': {critical_final}, 'high': {high_final}, 'medium': {medium_final}}}"
|
|
else:
|
|
critical_final = transform(-critical)
|
|
high_final = transform(-high)
|
|
medium_final = transform(-medium)
|
|
return f"{{'high': {critical_final}, 'medium': {high_final}, 'normal': {medium_final}}}"
|
|
|
|
|
|
def confidence_description(score):
|
|
if score > 0.6:
|
|
return "High"
|
|
elif score > 0.4:
|
|
return "Medium"
|
|
elif score > 0.1:
|
|
return "Low"
|
|
else:
|
|
return "No Pattern"
|