Move the cable category filtering before BOM grouping
Simplify the grouping loop slightly, by moving the filtering out.
The category of bundle entries is allways the same and is therefore
not needed for grouping.
The BOM output is unchanged by this change. It is verified using:
python build_examples.py
git diff ../../{examples,tutorial}/*.tsv
This commit is contained in:
parent
dd1372c31d
commit
c9895bd282
@ -271,12 +271,13 @@ class Harness:
|
|||||||
bom_connectors = sorted(bom_connectors, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
bom_connectors = sorted(bom_connectors, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
||||||
bom.extend(bom_connectors)
|
bom.extend(bom_connectors)
|
||||||
# cables
|
# cables
|
||||||
|
# TODO: If category can have other non-empty values than 'bundle', maybe it should be part of item name?
|
||||||
|
# Otherwise, it can be removed from the cable_group because it will allways be empty.
|
||||||
cable_group = lambda c: (c.category, c.gauge, c.gauge_unit, c.wirecount, c.shield)
|
cable_group = lambda c: (c.category, c.gauge, c.gauge_unit, c.wirecount, c.shield)
|
||||||
groups = Counter([cable_group(v) for v in self.cables.values()])
|
groups = Counter([cable_group(v) for v in self.cables.values() if v.category != 'bundle'])
|
||||||
for group in groups:
|
for group in groups:
|
||||||
items = {k: v for k, v in self.cables.items() if cable_group(v) == group}
|
items = {k: v for k, v in self.cables.items() if cable_group(v) == group}
|
||||||
shared = next(iter(items.values()))
|
shared = next(iter(items.values()))
|
||||||
if shared.category != 'bundle':
|
|
||||||
designators = list(items.keys())
|
designators = list(items.keys())
|
||||||
designators.sort()
|
designators.sort()
|
||||||
total_length = sum(i.length for i in items.values())
|
total_length = sum(i.length for i in items.values())
|
||||||
@ -288,13 +289,11 @@ class Harness:
|
|||||||
# bundles (ignores wirecount)
|
# bundles (ignores wirecount)
|
||||||
wirelist = []
|
wirelist = []
|
||||||
# list all cables again, since bundles are represented as wires internally, with the category='bundle' set
|
# list all cables again, since bundles are represented as wires internally, with the category='bundle' set
|
||||||
bundle_group = lambda b: (b.category, b.gauge, b.gauge_unit, b.length)
|
bundle_group = lambda b: (b.gauge, b.gauge_unit, b.length)
|
||||||
groups = Counter([bundle_group(v) for v in self.cables.values()])
|
groups = Counter([bundle_group(v) for v in self.cables.values() if v.category == 'bundle'])
|
||||||
for group in groups:
|
for group in groups:
|
||||||
items = {k: v for k, v in self.cables.items() if bundle_group(v) == group}
|
items = {k: v for k, v in self.cables.items() if bundle_group(v) == group}
|
||||||
shared = next(iter(items.values()))
|
shared = next(iter(items.values()))
|
||||||
# filter out cables that are not bundles
|
|
||||||
if shared.category == 'bundle':
|
|
||||||
for bundle in items.values():
|
for bundle in items.values():
|
||||||
# add each wire from each bundle to the wirelist
|
# add each wire from each bundle to the wirelist
|
||||||
for color in bundle.colors:
|
for color in bundle.colors:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user