src: add scaling of shared harness
This commit is contained in:
parent
c31ef661dc
commit
5b41913827
@ -13,6 +13,7 @@ import wireviz.wireviz as wv
|
|||||||
from wireviz import APP_NAME, __version__
|
from wireviz import APP_NAME, __version__
|
||||||
from wireviz.wv_bom import bom_list
|
from wireviz.wv_bom import bom_list
|
||||||
from wireviz.wv_utils import bom2tsv
|
from wireviz.wv_utils import bom2tsv
|
||||||
|
from wireviz.wv_harness_quantity import HarnessQuantity
|
||||||
|
|
||||||
format_codes = {
|
format_codes = {
|
||||||
"c": "csv",
|
"c": "csv",
|
||||||
@ -95,7 +96,21 @@ epilog = (
|
|||||||
default=False,
|
default=False,
|
||||||
help=f"Output {APP_NAME} version and exit.",
|
help=f"Output {APP_NAME} version and exit.",
|
||||||
)
|
)
|
||||||
def cli(files, formats, prepend, output_dir, output_name, version):
|
@click.option(
|
||||||
|
"-u",
|
||||||
|
"--use-qty-multipliers",
|
||||||
|
is_flag=True,
|
||||||
|
type=bool,
|
||||||
|
help="if set, the shared bom counts will be scaled with the qty-multipliers",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"-m",
|
||||||
|
"--multiplier-file-name",
|
||||||
|
default='quantity_multipliers.txt',
|
||||||
|
type=str,
|
||||||
|
help="name of file used to fetch the qty_multipliers",
|
||||||
|
)
|
||||||
|
def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multipliers, multiplier_file_name):
|
||||||
"""
|
"""
|
||||||
Parses the provided FILE and generates the specified outputs.
|
Parses the provided FILE and generates the specified outputs.
|
||||||
"""
|
"""
|
||||||
@ -141,9 +156,19 @@ def cli(files, formats, prepend, output_dir, output_name, version):
|
|||||||
shared_bom = ret["shared_bom"]
|
shared_bom = ret["shared_bom"]
|
||||||
|
|
||||||
if "shared_bom" in output_formats:
|
if "shared_bom" in output_formats:
|
||||||
|
shared_bom_file = (_output_dir / "shared_bom").with_suffix(".tsv")
|
||||||
|
print(f'Generating shared bom at {shared_bom_file}')
|
||||||
|
if use_qty_multipliers:
|
||||||
|
harnesses = HarnessQuantity(files, multiplier_file_name, output_dir=_output_dir)
|
||||||
|
harnesses.fetch_qty_multipliers_from_file()
|
||||||
|
qty_multipliers = harnesses.multipliers
|
||||||
|
for bom_item in shared_bom.values():
|
||||||
|
bom_item.scale_per_harness(qty_multipliers)
|
||||||
|
|
||||||
shared_bomlist = bom_list(shared_bom)
|
shared_bomlist = bom_list(shared_bom)
|
||||||
|
|
||||||
shared_bom_tsv = bom2tsv(shared_bomlist)
|
shared_bom_tsv = bom2tsv(shared_bomlist)
|
||||||
(_output_dir / "shared_bom").with_suffix(".tsv").open("w").write(shared_bom_tsv)
|
shared_bom_file.open("w").write(shared_bom_tsv)
|
||||||
|
|
||||||
print() # blank line after execution
|
print() # blank line after execution
|
||||||
|
|
||||||
|
|||||||
@ -268,6 +268,8 @@ class BomEntry:
|
|||||||
category: Optional[str] = None
|
category: Optional[str] = None
|
||||||
ignore_in_bom: Optional[bool] = False
|
ignore_in_bom: Optional[bool] = False
|
||||||
|
|
||||||
|
scaled_per_harness = False
|
||||||
|
|
||||||
# Used to add all occurence of a BomEntry
|
# Used to add all occurence of a BomEntry
|
||||||
designators: [List] = field(default_factory=list)
|
designators: [List] = field(default_factory=list)
|
||||||
per_harness: [Dict] = field(default_factory=dict)
|
per_harness: [Dict] = field(default_factory=dict)
|
||||||
@ -286,6 +288,9 @@ class BomEntry:
|
|||||||
"per_harness": "Per Harness",
|
"per_harness": "Per Harness",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
f'{id}: {self.partnumbers}, {self.qty}'
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.partnumbers, self.description))
|
return hash((self.partnumbers, self.description))
|
||||||
|
|
||||||
@ -394,6 +399,23 @@ class BomEntry:
|
|||||||
return self.partnumbers.BOM_KEY_TO_COLUMNS[key]
|
return self.partnumbers.BOM_KEY_TO_COLUMNS[key]
|
||||||
raise ValueError(f"key '{key}' not found in bom keys")
|
raise ValueError(f"key '{key}' not found in bom keys")
|
||||||
|
|
||||||
|
def scale_per_harness(self, qty_multipliers):
|
||||||
|
if self.scaled_per_harness:
|
||||||
|
logging.warn('{self}: Already scaled')
|
||||||
|
|
||||||
|
qty = NumberAndUnit(0, self.qty.unit_str)
|
||||||
|
for name, info in self.per_harness.items():
|
||||||
|
multiplier_name = [k for k in qty_multipliers.keys() if name.endswith(k)]
|
||||||
|
if len(multiplier_name) == 0:
|
||||||
|
raise ValueError(f'No multiplier found for harness {name} in {qty_multipliers}')
|
||||||
|
if len(multiplier_name) > 1:
|
||||||
|
raise ValueError(f'Conflicting multipliers found ({multiplier_name}) for harness {name} in {qty_multipliers}')
|
||||||
|
|
||||||
|
info['qty'] *= qty_multipliers[multiplier_name[0]]
|
||||||
|
qty += info['qty']
|
||||||
|
self.qty = qty
|
||||||
|
self.scaled_per_harness = True
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Options:
|
class Options:
|
||||||
|
|||||||
@ -52,7 +52,10 @@ class Harness:
|
|||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
pn = self.metadata.get("pn", "")
|
pn = self.metadata.get("pn", "")
|
||||||
output_name = self.metadata["output_name"]
|
output_name = self.metadata["output_name"]
|
||||||
return pn + output_name
|
if pn:
|
||||||
|
return f"{pn}-{output_name}"
|
||||||
|
else:
|
||||||
|
return output_name
|
||||||
|
|
||||||
def add_connector(self, designator: str, *args, **kwargs) -> None:
|
def add_connector(self, designator: str, *args, **kwargs) -> None:
|
||||||
conn = Connector(designator=designator, *args, **kwargs)
|
conn = Connector(designator=designator, *args, **kwargs)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user