From 9aaefd495fb9e5eaeb10749e7d09c22bce50a9fd Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Mon, 24 Jun 2019 12:54:27 +0000 Subject: [PATCH] =?UTF-8?q?Bug=202514=20-=20mettre=20=C3=A0=20jour=20le=20?= =?UTF-8?q?plan=20de=20c=C3=A2blage=20alimentation=20des=20serveurs=20comm?= =?UTF-8?q?uns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit amélioration: désormais le diagramme fait bien ressortir les câblages qui méritent de l'attention : - en rouge les cables en surcharge (dont l'ampérage max peut dépasser la capacité) - en noir les cables qui n'ont pas de charge Pour que le rouge soit réservé aux cables à problème, les conventions de couleurs pour les cables non surchargés ont été modifieés : c'est désormais en teintes de bleu. --- PowerDiagram.py | 57 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/PowerDiagram.py b/PowerDiagram.py index 72b5a31..0dd5ce0 100644 --- a/PowerDiagram.py +++ b/PowerDiagram.py @@ -261,8 +261,49 @@ class PowerConfig(object): s += str(c) + '\n' return s +class CableColorer(object): + + def get_cable_color(self, amperes, capacity): + raise NotImplementedError + +class SimpleColorer(CableColorer): + + def get_cable_color(self, amperes, capacity): + saturation = amperes / capacity + if saturation > 1.0: + color = '/svg/red' + elif saturation > 0.75: + color = '/svg/orange' + elif saturation < 0.001: + color = '/svg/black' # probably an error + else: + color = '/svg/green' + return color + +class RampColorer(CableColorer): + + @staticmethod + def hotness_to_hsv_color(hotness): + """ + :param float hotness: temperature of the wire ratio (0.0 : cold -> 1.0 : hot) + """ + clamped_hotness = max(min(hotness, 1.0), 0.0) + return "%f, 1.0, 0.8" % ((clamped_hotness) * 0.33 + 0.33) + + def get_cable_color(self, amperes, capacity): + saturation = amperes / capacity + # color = RampColorer.hotness_to_hsv_color(pow(saturation, 4.0)) + clamped_saturation = max(min(saturation, 1.0), 0.0) + color = '/ylgnbu9/%d' % (int(clamped_saturation * 5) + 4) + + if saturation < 0.001: + color = '/svg/black' # probably an error + elif saturation > 1.0: + color = '/svg/red' + return color def power_config_to_svg(power_config, svg_file_path): + """ creates a svg diagram representing the input power configuration @@ -280,12 +321,6 @@ def power_config_to_svg(power_config, svg_file_path): graph.edge_attr['fontsize'] = 10 # default : 14 pt graph.edge_attr['len'] = 1.5 # default : 1.0 - def hotness_to_hsv_color(hotness): - """ - :param float hotness: temperature of the wire ratio (0.0 : cold -> 1.0 : hot) - """ - clamped_hotness = max(min(hotness, 1.0), 0.0) - return "%f, 1.0, 0.8" % ((1.0 - clamped_hotness) * 0.33) # graph.add_node('a') # graph.add_node('b') @@ -316,6 +351,8 @@ def power_config_to_svg(power_config, svg_file_path): y += 1.0 x += 1.0 + cable_colorer = RampColorer() + for con in power_config.connections: # print(con.from_plug.machine.name, con.to_plug.machine.name) if not con.is_redundancy_cable(): # don't display redundancy cables, as they might overlap and hide the main one @@ -330,13 +367,7 @@ def power_config_to_svg(power_config, svg_file_path): penwidth = 100.0 * penwidth_scaler # make the problem clearly visible else: max_amp = str(capacity) + 'A' - if amperes / capacity > 1.0: - color = 'red' - elif amperes / capacity > 0.75: - color = 'orange' - else: - color = 'green' - color = hotness_to_hsv_color(pow(amperes / capacity, 4.0)) + color = cable_colorer.get_cable_color(amperes, capacity) penwidth = capacity * penwidth_scaler label = "%.1f/%s" % (amperes, max_amp) # color='//%d' % int(9.0-amperes/capacity*8)