Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOM From Multiple Cables #267

Open
leoheck opened this issue Jan 15, 2022 · 3 comments
Open

BOM From Multiple Cables #267

leoheck opened this issue Jan 15, 2022 · 3 comments

Comments

@leoheck
Copy link

leoheck commented Jan 15, 2022

I have a project where I have some cables and wires described with wireviz.

I am looking for a way to have a unified BOM that I can use to buy parts.

For instance

  • cable_a.yml
  • cable_b.yml
  • cable_c.yml

Cables A and B use the same wires to make the cables.
B and C have a connector in common.

I would like to have BOM that has all these on the same table so the one buying parts could buy all togueter.
It could be generated like this (if this feature does not exist yet)

wireviz --bom cable_a.yml cable_b.yml cable_c.yml

Do we have such a feature?

@kvid
Copy link
Collaborator

kvid commented Jan 28, 2022

Thank you for this new use case. There is no current feature supporting this, but I have created a simple Python script tsv2yaml.py that might help you:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Convert a set of WireViz BOM TSV output files into WireViz YAML input for a total BOM
# Created by @kvid for issue #267
from pathlib import Path
from sys import argv

print('additional_bom_items:')
for a in argv[1:]:
  prefix = Path(a).with_suffix('').stem.replace(' ', '_')
  print(f'  # From {a}')
  with Path(a).open() as tsv:
    keys = [k.strip().lower().replace('/', '') for k in next(tsv).split('\t')]
    for row in tsv:
      print('  -')
      for k, v in zip(keys, row.split('\t')):
        if k != 'id':
          v = v.strip()
          if k == 'designators':
            v = ', '.join([f'{prefix}:{d}' for d in v.split(', ') if d != ''])
          print(f'    {k}: {v}')

Execute the commands e.g. like this on the WireViz tutorials:

python3 tsv2yaml.py ../../tutorial/*.tsv > _test/tutorials.yaml
python3 wireviz.py _test/tutorials.yaml

I got this result from the commands above:
tutorials-total-bom
Note that I have not verified the correctness of this total BOM. Please try it out on your use case, and tell me if this might do the job good enough.

@kvid
Copy link
Collaborator

kvid commented Jan 29, 2022

A minor variation of my Python script above that format the designator prefix differently, and also include the prefix as designator in entries without any other designator:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Convert a set of WireViz BOM TSV output files into WireViz YAML input for a total BOM
# Created by @kvid for issue #267
from pathlib import Path
from sys import argv

print('additional_bom_items:')
for a in argv[1:]:
  prefix = Path(a).with_suffix('').stem.replace(' ', '_')
  print(f'  # From {a}')
  with Path(a).open() as tsv:
    keys = [k.strip().lower().replace('/', '') for k in next(tsv).split('\t')]
    for row in tsv:
      print('  -')
      for k, v in zip(keys, row.split('\t')):
        if k != 'id':
          v = v.strip()
          if k == 'designators':
            v = f'({prefix})' if v == '' else \
              ', '.join([f'({prefix}){d}' for d in v.split(', ') if d != ''])
          print(f'    {k}: {v}')

Excerpt of the result when running the same commands as in my previous message:
tutorials-total-bom2
Please comment the prefix+designator formatting. What is more readable?

@leoheck
Copy link
Author

leoheck commented Jan 29, 2022

This is awesome. I don't have a computer with me for some days. But I will definitely test thus asap. Thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants