basic funcionality improvements, as well as bundle refactor prep

This commit is contained in:
spushy 2022-02-08 20:34:14 -05:00
parent 872397e825
commit 744abbb7b8
4 changed files with 19 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import csv
import io
import re
from tokenize import String
def items_csv_to_dict(items_csv_reader, solver_run):
items = []
@ -14,10 +15,11 @@ def items_csv_to_dict(items_csv_reader, solver_run):
item = { 'attributes': [] }
# ensure that the b param is formatted correctly
if len(re.findall(".", row[len(headers) - 1])) >= 3:
if row[len(headers) - 1] != '' and is_float(row[len(headers) - 1]):
for key, col in enumerate(headers):
if solver_run.irt_model.formatted_b_param() == col:
item['b_param'] = row[key]
value = float(row[key])
item['b_param'] = value
elif solver_run.get_constraint(col) and solver_run.get_constraint(col).reference_attribute.type == 'bundle':
if row[key]:
item[solver_run.get_constraint(col).reference_attribute.id] = row[key]
@ -81,10 +83,18 @@ def solution_items(variables, solver_run):
form_items = []
for v in variables:
if v.varValue is not None and v.varValue > 0:
if v.varValue > 0 and 'Item_' in v.name:
item_id = v.name.replace('Item_', '')
item = solver_run.get_item(item_id)
# add item to list and then remove from master item list
form_items.append(item)
return form_items
# probably a better place for this...
def is_float(element: String) -> bool:
try:
float(element)
return True
except ValueError:
return False

View File

@ -4,7 +4,7 @@ import logging
from lib.errors.item_generation_error import ItemGenerationError
def build_constraints(solver_run, problem, items):
def build_constraints(solver_run, problem, items, bundles):
try:
total_form_items = solver_run.total_form_items
constraints = solver_run.constraints

View File

@ -19,7 +19,7 @@ class ServiceListener(SqsListener):
logging.info('Process complete for %s', service.file_name)
def main():
logging.info('Starting Solver Service (v1.1.1)...')
logging.info('Starting Solver Service (v1.1.2)...')
listener = ServiceListener(
os.environ['SQS_QUEUE'],
region_name=os.environ['AWS_REGION'],

View File

@ -68,6 +68,9 @@ class LoftService(Base):
# setup vars
items = LpVariable.dicts(
"Item", [item.id for item in self.solver_run.items], lowBound=1, upBound=1, cat='Binary')
bundles = LpVariable.dicts(
"Bundle", [bundle.id for bundle in self.solver_run.bundles], lowBound=1, upBound=1, cat='Binary')
problem_objection_functions = []
# create problem
@ -82,7 +85,7 @@ class LoftService(Base):
for item in self.solver_run.items]) == self.solver_run.total_form_items, 'Total form items'
# dynamic constraints
problem = solver_helper.build_constraints(self.solver_run, problem, items)
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
# multi-objective constraints
for target in self.solver_run.objective_function.tif_targets: