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

Better additional component BOM table #226

Draft
wants to merge 38 commits into
base: dev
Choose a base branch
from
Draft

Conversation

formatc1702
Copy link
Collaborator

@formatc1702 formatc1702 commented Mar 23, 2021

Closes #224.
Based on #197 (still unmerged).
Implements an additional note attribute for additional components as proposed in #222.
Implements additional_parameters (Dict) to be displayed in connector and cable nodes.
Will integrate #214 to allow the user to set show_part_numbers and show_bom_item_numbers from YAML.

Will rebase this branch onto dev once #197 and #214 are merged.

kvid and others added 30 commits December 30, 2020 08:46
- Use the actual BOM as first parameter instead of the whole harness.
- Use a whole AdditionalComponent as second parameter instead of each
  attribute separately.
Move the lambda declaration out of the function scope for common
access from two different functions.
Assign input designators once to a temporary variable for easy reusage.
- Use one common entry loop to consume iterator only once.
- Use same key function for sort() and groupby(),
  except replace None with empty string when sorting.
Seems to be the most popular search alternative:
 https://stackoverflow.com/questions/8653516/python-list-of-dictionaries-search

Raising StopIteration if not found is better than returning None
to detect such an internal error more easily.
Make a list from the group iterator for reusage in sum expressions
and to pick first group entry. The expected group sizes are very small,
so performance loss by creating a temporary list should be neglectable.

Alternativly, itertools.tee(group, 3) could be called to triplicate
the iterator, but it was not chosen for readability reasons.
This type alias describes the possible types of keys and values in
the dict representing a BOM entry.
Build output string in component_table_entry() as the similar strings
in generate_bom(). Repeating a couple of minor if-expressions is small
cost to obtain a more compact and readable main expression.
This way, both BOM and harness.additional_bom_items uses the same
set of keys in their dict entries. This was originally suggested
in a #115 review, but had too many issues to be implemented then.
@formatc1702
Copy link
Collaborator Author

Current state:

bomnumbertest

Source
connectors:
  X1:
    type: Plug
    pincount: 4
    pn: 123
    manufacturer: ACME
    mpn: ABC
    additional_components:
      -
        type: Crimp
        pn: 987
        manufacturer: ACME
        mpn: ZYX
        qty_multiplier: populated
      -
        type: Housing
        pn: 345
        manufacturer: OTHER
      -
        type: Label
        note: '"ABC-123"'

  X2:
    type: Receptacle
    pincount: 4
    pn: 234
    manufacturer: ACME
    mpn: DEF
    additional_components:
      -
        type: Crimp
        pn: 876
        manufacturer: ACME
        mpn: WVU


cables:
  W1:
    wirecount: 4
    gauge: 0.25
    length: 99
    color_code: DIN
    pn: qwerty
    mpn: uiop
    additional_components:
      -
        type: Sleeving
        qty: 5
        unit: m

connections:
  -
    - X1: [1-4]
    - W1: [1-4]
    - X2: [1-4]

The issue of retrieving BOM numbers for the major components is still open.

@formatc1702
Copy link
Collaborator Author

formatc1702 commented Mar 23, 2021

@kvid @Tyler-Ward

I am open for suggestions as to how to extract the assigned BOM ID for cables and connectors (after deduplication etc.) and inserting it into the new bom_item_number attribute of each component, before rendering the graphical output.

@formatc1702
Copy link
Collaborator Author

formatc1702 commented Mar 23, 2021

Using additional_parameters to add user-defined parameters to connectors and cables, as proposed in #222:

bomnumbertest

Source
connectors:
  X1:
    type: KK 254
    subtype: plug
    pincount: 4
    pinlabels: [QWE,RTY,UIO,P__]
    pn: 123
    manufacturer: ACME
    mpn: ABC
    additional_parameters:
      Sleeving removal: 15 mm
      Insulation removal: 2 mm
      Label: A01-5-10
      Tag: ABCDEFG
    additional_components:
      -
        type: Crimp
        pn: 987
        manufacturer: ACME
        mpn: ZYX
        qty_multiplier: populated
      -
        type: Housing
        pn: 345
        manufacturer: OTHER
      -
        type: Label
        note: '"ABC-123"'

  X2:
    type: KPPX
    subtype: Plug
    pincount: 4
    pn: 234
    manufacturer: ACME
    mpn: DEF
    additional_components:
      -
        type: Crimp
        pn: 876
        manufacturer: ACME
        mpn: WVU
        qty_multiplier: populated


cables:
  W1:
    wirecount: 4
    gauge: 0.25
    length: 99
    color_code: DIN
    pn: qwerty
    mpn: uiop
    additional_parameters:
      Twist pairs: (1+2) , (3+4)
      Twist rate: 5/mm
      Twist direction: CCW
    additional_components:
      -
        type: Heat shrink
        qty: 30
        unit: mm
        note: left
      -
        type: Heat shrink
        qty: 20
        unit: mm
        note: right

connections:
  -
    - X1: [1-4]
    - W1: [1-4]
    - X2: [1-4]

Harness.show_bom_item_numbers is set to False for this rendering.

@formatc1702 formatc1702 force-pushed the feature/bom-bubbles branch from 010b5c9 to 9821ca3 Compare March 23, 2021 17:09
@kvid
Copy link
Collaborator

kvid commented Mar 24, 2021

@kvid @Tyler-Ward

I am open for suggestions as to how to extract the assigned BOM ID for cables and connectors (after deduplication etc.) and inserting it into the new bom_item_number attribute of each component, before rendering the graphical output.

Instead of storing the bom_item_number in main components, I suggest storing a new bom_key that is easily computed in generate_bom() by using the same BOMEntry dict that is appended to bom_entries also as input to bom_types_group() and store the returned key into bom_key. Then, after deduplication and BOM ID assignment, this bom_key can be used to search for BOM ID in a slightly simplified get_bom_index() that takes the key as input (called target today). The call to clean_whitespace() could be moved into bom_types_group(). By also storing such a new bom_key in AdditionalComponent the same way, it is easy to call the same get_bom_index() for all components. Create a new type alias for this key: BOMKey = Tuple[str, ...] (above the BOMEntry type alias).

Edit: I suggest defining a new helper function:

def add_bom_entry_get_key(entries: List[BOMEntry], entry: BOMEntry) -> BOMKey:
    entries.append(entry)
    return bom_types_group(entry)

Then call it for each component by only changing one line at each location, like this:

part.bom_key = add_bom_entry_get_key(bom_entries, {
    'description': part.description,
    ...
    **optional_fields(part),
})
...
connector.bom_key = add_bom_entry_get_key(bom_entries, {
    'description': description, ...
    **optional_fields(connector),
})

Edit2: I will add a few changes to #197 to prepare for this.

@kvid kvid mentioned this pull request Mar 26, 2021
@formatc1702 formatc1702 changed the base branch from feature/simplify-BOM-code to dev August 22, 2021 18:48
@formatc1702 formatc1702 mentioned this pull request Oct 25, 2021
5 tasks
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

Successfully merging this pull request may close these issues.

2 participants