Files
old-krovovi-kalkulator/helix/calculators/bom_helper.py

44 lines
1.3 KiB
Python
Raw Normal View History

2017-11-07 09:23:57 +01:00
from math import ceil
from helix.constants.panel_type import PanelType
2017-11-27 17:04:51 +01:00
from helix.constants.parts import *
2017-11-07 09:23:57 +01:00
2017-11-27 17:04:51 +01:00
# This story askes for this special parts to be showed
# www.pivotaltracker.com/n/projects/1544689/stories/148016595
PARTS_SHOWN_EVEN_WITH_0_ELEMENTS = [
delta_kit_inverter_mount,
delta_kit_inverter_mount_dt
]
2017-11-07 09:23:57 +01:00
def add_parts_to_list(parts_list, parts_to_add, multiplier=1):
for part, quantity in parts_to_add.items():
previous_value = parts_list.get(part) or 0
2017-11-27 17:04:51 +01:00
if quantity != 0 or part in PARTS_SHOWN_EVEN_WITH_0_ELEMENTS:
2017-11-07 09:23:57 +01:00
parts_list[part] = previous_value + quantity * multiplier
def apply_fudge_factors(parts_list, fudge_factors):
for part, quantity in parts_list.items():
fudge_factor = fudge_factors.get(part) or 1.0
parts_list[part] = quantity * fudge_factor
def apply_package_size_rounding(parts_list, package_sizes):
for part, quantity in parts_list.items():
package_size = package_sizes.get(part) or 1
parts_list[part] = package_size * ceil(quantity / package_size)
def get_panel_type_counts(panels):
panel_type_counts = {
PanelType.Corner: 0,
PanelType.NorthSouth: 0,
PanelType.EastWest: 0,
PanelType.Middle: 0,
}
for panel in panels:
panel_type_counts[panel.panel_type] += 1
return panel_type_counts