Moved the BoM stats computation.

Now is in a loop that already operates with this information.
This commit is contained in:
Salvador E. Tropea 2020-08-01 18:39:34 -03:00
parent 5be7254594
commit a9cd9a649b
2 changed files with 14 additions and 7 deletions

View File

@ -365,16 +365,28 @@ def group_components(cfg, components):
# 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])])
# Enumerate the groups
# Enumerate the groups and compute stats
n_total = 0
n_fitted = 0
c = 1
dnf = 1
cfg.n_groups = len(groups)
for g in groups:
if cfg.ignore_dnf and not g.is_fitted():
is_fitted = g.is_fitted()
if cfg.ignore_dnf and not is_fitted:
g.update_field('Row', str(dnf))
dnf += 1
else:
g.update_field('Row', str(c))
c += 1
# Stats
g_l = g.get_count()
n_total += g_l
if is_fitted:
n_fitted += g_l
cfg.n_total = n_total
cfg.n_fitted = n_fitted
cfg.n_build = n_fitted * cfg.number
return groups

View File

@ -32,11 +32,6 @@ def write_bom(filename, ext, groups, headings, cfg):
# Allow renaming the columns
head_names = [h if h.lower() not in cfg.column_rename else cfg.column_rename[h.lower()] for h in headings]
result = False
# Some stats
cfg.n_groups = len(groups)
cfg.n_total = sum([g.get_count() for g in groups])
cfg.n_fitted = sum([g.get_count() for g in groups if g.is_fitted()])
cfg.n_build = cfg.n_fitted * cfg.number
# CSV file writing
if ext in ["csv", "tsv", "txt"]:
result = write_csv(filename, ext, groups, headings, head_names, cfg)