pre-filter 100% constraint items

This commit is contained in:
Josh Burman 2022-03-23 15:57:47 +00:00
parent e04eead569
commit 09d3fce02d
2 changed files with 11 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import io
import re import re
from tokenize import String from tokenize import String
from models.item import Item
def items_csv_to_dict(items_csv_reader, solver_run): def items_csv_to_dict(items_csv_reader, solver_run):
items = [] items = []
@ -41,7 +42,15 @@ def items_csv_to_dict(items_csv_reader, solver_run):
if row[key]: if row[key]:
item[col] = row[key] item[col] = row[key]
items.append(item) # confirm item is only added if it meets the criteria of 100% constraints as a pre-filter
valid_item = True
item = Item.parse_obj(item)
for constraint in solver_run.constraints:
attribute = item.get_attribute(constraint.reference_attribute)
if attribute and constraint.minimum == 100 and int(attribute.value) == 0:
valid_item = False
if valid_item: items.append(item)
return items return items

View File

@ -53,9 +53,7 @@ class LoftService(Base):
items_csv_reader = csv_helper.file_stream_reader(items_csv) items_csv_reader = csv_helper.file_stream_reader(items_csv)
# add items to solver run # add items to solver run
for item in service_helper.items_csv_to_dict(items_csv_reader, solver_run.items = service_helper.items_csv_to_dict(items_csv_reader, solver_run)
solver_run):
solver_run.items.append(Item.parse_obj(item))
logging.info('Processed Attributes...') logging.info('Processed Attributes...')