Internal BoM: two other options for the sorting criteria.

This commit is contained in:
Salvador E. Tropea 2021-10-20 13:55:36 -03:00
parent 79a363e49f
commit 20ead17d4a
3 changed files with 16 additions and 3 deletions

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
and it contain at least one space, now we try to use the text before the
space. This helps for cases like "10K 1%".
- Generic filter: options to match if a field is/isn't defined.
- Internal BoM: two other options for the sorting criteria.
### Changed
- Internal BoM: now components with different Tolerance, Voltage, Current

View File

@ -349,7 +349,7 @@ class ComponentGroup(object):
return row
def get_value_sort(comp):
def get_value_sort(comp, fallback_ref=False):
""" Try to better sort R, L and C components """
res = comp.value_sort
if res:
@ -361,6 +361,8 @@ def get_value_sort(comp):
# milli Ohms
value = "{0:15d}".format(int(value * 1000 * mult + 0.1))
return value
if fallback_ref:
return comp.ref_prefix + "{0:15d}".format(_suffix_to_num(comp.ref_suffix))
return comp.value
@ -439,8 +441,16 @@ def group_components(cfg, components):
if cfg.normalize_values:
g.fields[ColumnList.COL_VALUE_L] = normalize_value(g.components[0], decimal_point)
# Sort the groups
# First priority is the Type of component (e.g. R?, U?, L?)
groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, get_value_sort(g.components[0])])
if cfg.sort_style == 'type_value':
# First priority is the Type of component (e.g. R?, U?, L?)
# Second is the value
groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, get_value_sort(g.components[0])])
elif cfg.sort_style == 'type_value_ref':
# First priority is the Type of component (e.g. R?, U?, L?)
# Second is the value, but if we don't have a value we use the reference
groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, get_value_sort(g.components[0], True)])
else: # ref
groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, _suffix_to_num(g.components[0].ref_suffix)])
# Enumerate the groups and compute stats
n_total = 0
n_fitted = 0

View File

@ -330,6 +330,8 @@ class BoMOptions(BaseOptions):
""" [string|list(string)] Include this distributors list. Default is all the available """
self.no_distributors = Optionable
""" [string|list(string)] Exclude this distributors list. They are removed after computing `distributors` """
self.sort_style = 'type_value'
""" [type_value,type_value_ref,ref] Sorting criteria """
self._format_example = 'CSV'
super().__init__()