From ba856829b121ae1e7048ac58ffb9a24beed8d6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Nicolet?= Date: Fri, 6 Oct 2023 14:14:39 +0200 Subject: [PATCH] Interpolate test colors between red and green --- server/fishtest/util.py | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/server/fishtest/util.py b/server/fishtest/util.py index dcd7f97a8..dc9d84b39 100644 --- a/server/fishtest/util.py +++ b/server/fishtest/util.py @@ -227,6 +227,53 @@ def format_bounds(elo_model, elo0, elo1): ) +def interpolate_color(c1, c2, t): + # blend two colors c1 and c2 in the format "#44EB44" + # t must be a real 0 <= t <= 1 + + c1 = c1.lstrip('#') + c2 = c2.lstrip('#') + rgb1 = tuple(int(c1[i:i+2], 16) for i in (0, 2, 4)) + rgb2 = tuple(int(c2[i:i+2], 16) for i in (0, 2, 4)) + r = int((1-t) * rgb1[0] + t * rgb2[0]) + g = int((1-t) * rgb1[1] + t * rgb2[1]) + b = int((1-t) * rgb1[2] + t * rgb2[2]) + color = '#{:02x}{:02x}{:02x}'.format(r, g, b) + + return color.upper() + + +def color_run(run, WLD): + color = "" + + if "sprt" in run["args"] : + sprt = run["args"]["sprt"] + llr = float(sprt["llr"]) + low = float(sprt["lower_bound"]) + up = float(sprt["upper_bound"]) + percent = 1.0 * (llr - low) / (up - low) + percent = max(0.0, min(1.0, percent)) + + # rejection color + # yellow (#FFFF00) or red (#FF6A6A) + if WLD[0] > WLD[1] : + color_low = "#FFFF00" + else : + color_low = "#FF6A6A" + + # acceptation color + # blue (#66CCFF) or green (#44EB44) + if (float(sprt["elo0"]) + float(sprt["elo1"])) < 0.0 : + color_up = "#66CCFF" + else : + color_up = "#44EB44" + + # calculate interpolated color + color = interpolate_color(color_low, color_up, percent) + + return color + + def format_results(run_results, run): result = {"style": "", "info": []} @@ -285,6 +332,7 @@ def format_results(run_results, run): + ", ".join(str(run_results["pentanomial"][i]) for i in range(0, 5)) ) + # color the result if state == "rejected": if WLD[0] > WLD[1]: result["style"] = "yellow" @@ -295,6 +343,9 @@ def format_results(run_results, run): result["style"] = "#66CCFF" else: result["style"] = "#44EB44" + else: + result["style"] = color_run(run, WLD) + return result