Source code for gensbi.utils.misc

import math


# ANSI Escape Codes
[docs] RED = "\033[91m"
[docs] YELLOW = "\033[93m"
[docs] GREEN = "\033[92m"
[docs] RESET = "\033[0m"
[docs] def get_colored_value(val, thresholds=(1.1, 1.2)): """Returns the value wrapped in color codes based on thresholds. Parameters ---------- val : float The value to color. thresholds : tuple of float Thresholds for coloring (red/yellow, yellow/green). Defaults to (1.1, 1.2). Returns ------- str The colored string representation of the value. """ if val < thresholds[0]: color = GREEN elif val < thresholds[1]: color = YELLOW else: color = RED return f"{color}{val:.4f}{RESET}"