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.
This commit is contained in:
Andreas Nordin 2020-06-29 13:11:35 +02:00
parent 7458118f4d
commit c6d32f66aa
2 changed files with 34 additions and 26 deletions

View File

@ -4,7 +4,7 @@
from wireviz.DataClasses import Connector, Cable from wireviz.DataClasses import Connector, Cable
from graphviz import Graph from graphviz import Graph
from wireviz import wv_colors 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 collections import Counter
from typing import List from typing import List
@ -113,9 +113,17 @@ class Harness:
f'{connector.name}:p{loop[1]}{loop_side}:{loop_dir}') f'{connector.name}:p{loop[1]}{loop_side}:{loop_dir}')
for _, cable in self.cables.items(): 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 '', 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 '', '+ S' if cable.shield else '',
f'{cable.length} m' if cable.length > 0 else ''] f'{cable.length} m' if cable.length > 0 else '']
attributes = list(filter(None, attributes)) attributes = list(filter(None, attributes))

View File

@ -3,32 +3,32 @@
from typing import List 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): def awg_equiv(mm2):
awg_equiv_table = { return awg_equiv_table.get(str(mm2), 'Unknown')
'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'
def mm2_equiv(awg):
return mm2_equiv_table.get(str(awg), 'Unknown')
def nested(inp): def nested(inp):
l = [] l = []