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:
parent
653597a0e9
commit
6c055374a7
@ -13,7 +13,7 @@ if __name__== '__main__':
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from wireviz import wv_colors
|
||||
from wireviz.wv_helper import nested, int2tuple, awg_equiv, flatten2d, tuplelist2tsv
|
||||
from wireviz.wv_helper import nested, int2tuple, mm2_equiv, awg_equiv, flatten2d, tuplelist2tsv
|
||||
|
||||
class Harness:
|
||||
|
||||
@ -117,8 +117,16 @@ class Harness:
|
||||
|
||||
for k, c in self.cables.items():
|
||||
# a = attributes
|
||||
if c.show_equiv:
|
||||
if c.gauge_unit == 'mm\u00B2':
|
||||
gauge_equiv = ' ({} AWG)'.format(awg_equiv(c.gauge))
|
||||
else:
|
||||
gauge_equiv = ' ({} mm\u00B2)'.format(mm2_equiv(c.gauge))
|
||||
else:
|
||||
gauge_equiv = ''
|
||||
|
||||
a = ['{}x'.format(len(c.colors)) if c.show_wirecount else '',
|
||||
'{} {}{}'.format(c.gauge, c.gauge_unit, ' ({} AWG)'.format(awg_equiv(c.gauge)) if c.gauge_unit == 'mm\u00B2' and c.show_equiv else '') if c.gauge else '', # TODO: show equiv
|
||||
'{} {}{}'.format(c.gauge, c.gauge_unit, gauge_equiv) if c.gauge else '',
|
||||
'+ S' if c.shield else '',
|
||||
'{} m'.format(c.length) if c.length > 0 else '']
|
||||
a = list(filter(None, a))
|
||||
|
||||
@ -1,27 +1,28 @@
|
||||
from typing import Any, 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',
|
||||
}
|
||||
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,
|
||||
}
|
||||
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(input):
|
||||
l = []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user