Improve handling of mm² and AWG gauges
This commit is contained in:
parent
3eaabc3b53
commit
19f0a82544
@ -10,7 +10,7 @@ connectors:
|
|||||||
|
|
||||||
cables:
|
cables:
|
||||||
W1:
|
W1:
|
||||||
mm2: 0.25
|
gauge: 0.25 mm2
|
||||||
length: 0.2
|
length: 0.2
|
||||||
color_code: DIN
|
color_code: DIN
|
||||||
wirecount: 3
|
wirecount: 3
|
||||||
|
|||||||
@ -5,7 +5,7 @@ templates: # defining templates to be used later on
|
|||||||
- &con_i2c
|
- &con_i2c
|
||||||
pinout: [GND, +5V, SCL, SDA]
|
pinout: [GND, +5V, SCL, SDA]
|
||||||
- &wire_i2c
|
- &wire_i2c
|
||||||
mm2: 0.14
|
gauge: 0.14 mm2
|
||||||
length: 0.2
|
length: 0.2
|
||||||
colors: [BK, RD, YE, GN]
|
colors: [BK, RD, YE, GN]
|
||||||
|
|
||||||
@ -37,13 +37,13 @@ cables:
|
|||||||
type: bundle
|
type: bundle
|
||||||
show_equiv: true
|
show_equiv: true
|
||||||
W3:
|
W3:
|
||||||
mm2: 0.14
|
gauge: 0.14 mm2
|
||||||
length: 0.2
|
length: 0.2
|
||||||
colors: [BK, BU, OG, VT]
|
colors: [BK, BU, OG, VT]
|
||||||
type: bundle
|
type: bundle
|
||||||
show_equiv: true
|
show_equiv: true
|
||||||
W4:
|
W4:
|
||||||
mm2: 0.5
|
gauge: 0.5 mm2
|
||||||
length: 0.35
|
length: 0.35
|
||||||
colors: [BK, RD]
|
colors: [BK, RD]
|
||||||
type: bundle
|
type: bundle
|
||||||
|
|||||||
@ -12,7 +12,7 @@ cables:
|
|||||||
W1:
|
W1:
|
||||||
color_code: IEC # auto-color wires based on a standard
|
color_code: IEC # auto-color wires based on a standard
|
||||||
wirecount: 4 # need to specify number of wires explicitly when using a color code
|
wirecount: 4 # need to specify number of wires explicitly when using a color code
|
||||||
mm2: 0.25 # metric gauge, in mm^2
|
gauge: 0.25 mm2 # also accepts AWG as unit
|
||||||
show_equiv: true # auto-calculate AWG equivalent from metric gauge
|
show_equiv: true # auto-calculate AWG equivalent from metric gauge
|
||||||
length: 0.2 # length in m
|
length: 0.2 # length in m
|
||||||
shield: true
|
shield: true
|
||||||
|
|||||||
@ -15,7 +15,7 @@ connectors:
|
|||||||
cables:
|
cables:
|
||||||
W1: &wire_power # define template
|
W1: &wire_power # define template
|
||||||
colors: [BK, RD] # number of wires implicit in color list
|
colors: [BK, RD] # number of wires implicit in color list
|
||||||
mm2: 0.25
|
gauge: 0.25 # assume mm2 if no gauge unit is specified
|
||||||
show_equiv: true
|
show_equiv: true
|
||||||
length: 0.2
|
length: 0.2
|
||||||
W2:
|
W2:
|
||||||
|
|||||||
@ -17,7 +17,7 @@ cables:
|
|||||||
type: bundle # bundles are routed together, but more loosely than normal cables
|
type: bundle # bundles are routed together, but more loosely than normal cables
|
||||||
wirecount: 6
|
wirecount: 6
|
||||||
colors: [BK, RD] # if number of items in color list is less than wirecount, loop colors
|
colors: [BK, RD] # if number of items in color list is less than wirecount, loop colors
|
||||||
mm2: 0.25
|
gauge: 0.25 mm2
|
||||||
show_equiv: true
|
show_equiv: true
|
||||||
length: 0.2
|
length: 0.2
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
cables:
|
cables:
|
||||||
W1:
|
W1:
|
||||||
mm2: 0.25
|
gauge: 0.25 mm2
|
||||||
show_equiv: true
|
show_equiv: true
|
||||||
length: 0.2
|
length: 0.2
|
||||||
color_code: IEC
|
color_code: IEC
|
||||||
|
|||||||
@ -5,7 +5,7 @@ templates:
|
|||||||
gender: female
|
gender: female
|
||||||
pinout: [GND, VCC, SCL, SDA]
|
pinout: [GND, VCC, SCL, SDA]
|
||||||
- &template_wire
|
- &template_wire
|
||||||
mm2: 0.25
|
gauge: 0.25 mm2
|
||||||
length: 0.2
|
length: 0.2
|
||||||
colors: [PK, TQ, YE, VT]
|
colors: [PK, TQ, YE, VT]
|
||||||
type: bundle
|
type: bundle
|
||||||
|
|||||||
@ -5,7 +5,7 @@ templates:
|
|||||||
gender: female
|
gender: female
|
||||||
pinout: [GND, VCC, SCL, SDA]
|
pinout: [GND, VCC, SCL, SDA]
|
||||||
- &template_wire
|
- &template_wire
|
||||||
mm2: 0.25
|
gauge: 0.25 mm2
|
||||||
length: 0.2
|
length: 0.2
|
||||||
colors: [PK, TQ, YE, VT]
|
colors: [PK, TQ, YE, VT]
|
||||||
type: bundle
|
type: bundle
|
||||||
|
|||||||
@ -159,8 +159,7 @@ class Harness:
|
|||||||
for k, c in self.cables.items():
|
for k, c in self.cables.items():
|
||||||
# a = attributes
|
# a = attributes
|
||||||
a = ['{}x'.format(len(c.colors)) if c.show_wirecount else '',
|
a = ['{}x'.format(len(c.colors)) if c.show_wirecount else '',
|
||||||
'{} mm\u00B2{}'.format(c.mm2, ' ({} AWG)'.format(awg_equiv(c.mm2)) if c.show_equiv else '') if c.mm2 is not None 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
|
||||||
'{} AWG'.format(c.awg) if c.awg else '',
|
|
||||||
'+ S' if c.shield else '',
|
'+ S' if c.shield else '',
|
||||||
'{} m'.format(c.length) if c.length > 0 else '']
|
'{} m'.format(c.length) if c.length > 0 else '']
|
||||||
# print(a)
|
# print(a)
|
||||||
@ -277,24 +276,31 @@ class Harness:
|
|||||||
for pincount in pincounts.keys():
|
for pincount in pincounts.keys():
|
||||||
# print(' ', type, gender, pincount, 'pins :', pincounts[pincount])
|
# print(' ', type, gender, pincount, 'pins :', pincounts[pincount])
|
||||||
designators = [k for k,v in self.connectors.items() if v.type == type and v.gender == gender and v.pincount == pincount]
|
designators = [k for k,v in self.connectors.items() if v.type == type and v.gender == gender and v.pincount == pincount]
|
||||||
bom = bom + '{type}\t{gender}\t{pincount}\t{qty}\t{designators}\n'.format(type=type, gender=gender, pincount=pincount, qty=pincounts[pincount], designators=', '.join(designators))
|
bom = bom + '{type}\t{gender}\t{pincount}\t{qty}\t{designators}\n'.format(type=type,
|
||||||
|
gender=gender,
|
||||||
|
pincount=pincount,
|
||||||
|
qty=pincounts[pincount],
|
||||||
|
designators=', '.join(designators))
|
||||||
|
|
||||||
bom = bom + '\n'
|
bom = bom + '\n'
|
||||||
# list cables
|
# list cables
|
||||||
bom = bom + 'mm2\tWirecount\tTotal length\tQty\tDesignators\n'
|
bom = bom + 'Gauge\tUnit\tWirecount\tTotal length\tQty\tDesignators\n'
|
||||||
bom = bom + '---\t---\t---\t---\t---\n'
|
bom = bom + '---\t---\t---\t---\t---\t---\n'
|
||||||
# TODO: make it work with AWG as well
|
gauges = Counter([v.gauge_and_unit for v in self.cables.values()])
|
||||||
mm2s = Counter([v.mm2 for v in self.cables.values()])
|
for gauge in gauges.keys():
|
||||||
for mm2 in mm2s.keys():
|
wirecounts = Counter([v.wirecount for v in self.cables.values() if v.gauge_and_unit == gauge])
|
||||||
# print(mm2, 'mm2', '({})'.format(mm2s[mm2]))
|
|
||||||
wirecounts = Counter([v.wirecount for v in self.cables.values() if v.mm2 == mm2])
|
|
||||||
for wirecount in wirecounts.keys():
|
for wirecount in wirecounts.keys():
|
||||||
# print(' ', mm2, wirecount, ':', wirecounts[wirecount])
|
# print(' ', gauge, wirecount, ':', wirecounts[wirecount])
|
||||||
lengths = [v.length for v in self.cables.values() if v.mm2 == mm2 and v.wirecount == wirecount]
|
lengths = [v.length for v in self.cables.values() if v.gauge_and_unit == gauge and v.wirecount == wirecount]
|
||||||
designators = [k for k,v in self.cables.items() if v.mm2 == mm2 and v.wirecount == wirecount]
|
designators = [k for k,v in self.cables.items() if v.gauge_and_unit == gauge and v.wirecount == wirecount]
|
||||||
# print(' ', 'Lengths:', lengths)
|
# print(' ', 'Lengths:', lengths)
|
||||||
# print(' ', 'Total lengths:', sum(lengths))
|
# print(' ', 'Total lengths:', sum(lengths))
|
||||||
bom = bom + '{mm2}\t{wirecount}\t{len_total}\t{qty}\t{designators}\n'.format(mm2=mm2, wirecount=wirecount, len_total=round(sum(lengths),3), qty=len(lengths), designators=', '.join(designators))
|
bom = bom + '{gauge}\t{gauge_unit}\t{wirecount}\t{len_total}\t{qty}\t{designators}\n'.format(gauge=gauge[0],
|
||||||
|
gauge_unit=gauge[1],
|
||||||
|
wirecount=wirecount,
|
||||||
|
len_total=round(sum(lengths),3),
|
||||||
|
qty=len(lengths),
|
||||||
|
designators=', '.join(designators))
|
||||||
|
|
||||||
return bom
|
return bom
|
||||||
|
|
||||||
@ -333,8 +339,8 @@ class Connector:
|
|||||||
class Cable:
|
class Cable:
|
||||||
name: str
|
name: str
|
||||||
type: str = None
|
type: str = None
|
||||||
mm2: float = None
|
gauge: float = None
|
||||||
awg: int = None
|
gauge_unit : str = None
|
||||||
show_equiv: bool = False
|
show_equiv: bool = False
|
||||||
length: float = 0
|
length: float = 0
|
||||||
wirecount: int = None
|
wirecount: int = None
|
||||||
@ -347,8 +353,25 @@ class Cable:
|
|||||||
show_wirecount: bool = True
|
show_wirecount: bool = True
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
if self.mm2 and self.awg:
|
|
||||||
raise Exception('You cannot define both mm2 and awg!')
|
if isinstance(self.gauge, str): # gauge and unit specified
|
||||||
|
try:
|
||||||
|
g, u = self.gauge.split(' ')
|
||||||
|
except:
|
||||||
|
raise Exception('Gauge must be a number, or number and unit separated by a space')
|
||||||
|
self.gauge = g
|
||||||
|
self.gauge_unit = u.replace('mm2','mm\u00B2')
|
||||||
|
elif self.gauge is not None: # gauge specified, assume mm2
|
||||||
|
if self.gauge_unit is None:
|
||||||
|
self.gauge_unit = 'mm\u00B2'
|
||||||
|
else:
|
||||||
|
pass # gauge not specified
|
||||||
|
|
||||||
|
self.gauge_and_unit = (self.gauge, self.gauge_unit)
|
||||||
|
|
||||||
|
|
||||||
|
# print('{}\t{}\t{}'.format(self.name, self.gauge, self.gauge_unit))
|
||||||
|
|
||||||
self.connections = []
|
self.connections = []
|
||||||
|
|
||||||
if self.wirecount: # number of wires explicitly defined
|
if self.wirecount: # number of wires explicitly defined
|
||||||
@ -458,7 +481,7 @@ def awg_equiv(mm2):
|
|||||||
if k in awg_equiv_table:
|
if k in awg_equiv_table:
|
||||||
return awg_equiv_table[k]
|
return awg_equiv_table[k]
|
||||||
else:
|
else:
|
||||||
return None
|
return 'unknown'
|
||||||
|
|
||||||
def parse(file_in, file_out=None):
|
def parse(file_in, file_out=None):
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user