From c6d32f66aacb3d3a8fa931f0ecc014d04851b4c6 Mon Sep 17 00:00:00 2001 From: Andreas Nordin Date: Mon, 29 Jun 2020 13:11:35 +0200 Subject: [PATCH] Fix AWG<-> mm2 conversions Add an inverted dictionary and a lookup function from awg -> mm2. Also do some minor refactoring. Both sides of the conversion table were converted to strings, since '0000' and '2/0' are perfectly valid AWG values. --- src/wireviz/Harness.py | 14 +++++++++--- src/wireviz/wv_helper.py | 46 ++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index c11ad9a..4ccd42f 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -4,7 +4,7 @@ from wireviz.DataClasses import Connector, Cable from graphviz import Graph from wireviz import wv_colors -from wireviz.wv_helper import awg_equiv, tuplelist2tsv, nested, flatten2d +from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, flatten2d from collections import Counter from typing import List @@ -113,9 +113,17 @@ class Harness: f'{connector.name}:p{loop[1]}{loop_side}:{loop_dir}') for _, cable in self.cables.items(): - awg_fmt = f' ({awg_equiv(cable.gauge)} AWG)' if cable.gauge_unit == 'mm\u00B2' and cable.show_equiv else '' + + if cable.show_equiv: + if cable.gauge_unit =='mm\u00B2': + awg_fmt = f' ({awg_equiv(cable.gauge)} AWG)' + else: + awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' + else: + awg_fmt = '' + attributes = [f'{len(cable.colors)}x' if cable.show_wirecount else '', - f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '', # TODO: show equiv + f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '', '+ S' if cable.shield else '', f'{cable.length} m' if cable.length > 0 else ''] attributes = list(filter(None, attributes)) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 65ccdb3..222fd74 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -3,32 +3,32 @@ from typing import List +awg_equiv_table = { + '0.09': '28', + '0.14': '26', + '0.25': '24', + '0.34': '22', + '0.5': '21', + '0.75': '20', + '1': '18', + '1.5': '16', + '2.5': '14', + '4': '12', + '6': '10', + '10': '8', + '16': '6', + '25': '4', + '35': '2', + '50': '1', +} + +mm2_equiv_table = {v:k for k,v in awg_equiv_table.items()} def awg_equiv(mm2): - awg_equiv_table = { - '0.09': 28, - '0.14': 26, - '0.25': 24, - '0.34': 22, - '0.5': 21, - '0.75': 20, - '1': 18, - '1.5': 16, - '2.5': 14, - '4': 12, - '6': 10, - '10': 8, - '16': 6, - '25': 4, - '35': 2, - '50': 1, - } - k = str(mm2) - if k in awg_equiv_table: - return awg_equiv_table[k] - else: - return 'unknown' + return awg_equiv_table.get(str(mm2), 'Unknown') +def mm2_equiv(awg): + return mm2_equiv_table.get(str(awg), 'Unknown') def nested(inp): l = []