modified for new base

This commit is contained in:
Josh Burman 2021-12-18 07:27:16 +00:00
commit b3bf662c2f
2 changed files with 25 additions and 25 deletions

View File

@ -13,24 +13,26 @@ def items_csv_to_dict(items_csv_reader):
else:
item = { 'attributes': [] }
for key, col in enumerate(headers):
if key == 0:
item[col] = row[key]
if key == 2:
# make sure id exists
if row[key]:
item['passage_id'] = row[key]
# b param - temp fix! use irt model b param for proper reference
elif key == (1 - len(headers)):
item['b_param'] = row[key]
elif key > 2:
item['attributes'].append({
'id': col,
'value': row[key],
'type': 'metadata'
})
# ensure that the b param is formatted correctly
if len(re.findall(".", row[len(headers) - 1])) >= 3:
for key, col in enumerate(headers):
if key == 0:
item[col] = row[key]
if key == 2:
# make sure passage id exists
if row[key]:
item['passage_id'] = row[key]
# b param - tmep fix! use irt model b param for proper reference
elif key == len(headers) - 1:
item['b_param'] = row[key]
elif key > 2 and key < len(headers) - 1:
item['attributes'].append({
'id': col,
'value': row[key],
'type': 'metadata'
})
items.append(item)
items.append(item)
return items

View File

@ -67,7 +67,11 @@ class LoftService(Base):
# create problem
problem = LpProblem("ata-form-generate", LpMinimize)
# form item count constraint
# dummy objective function, because it just makes things easier™
problem += lpSum([items[item.id]
for item in self.solver_run.items])
# constraints
problem += lpSum([items[item.id]
for item in self.solver_run.items]) == self.solver_run.total_form_items, 'Total form items'
@ -76,21 +80,15 @@ class LoftService(Base):
# multi-objective functions and constraints
for target in self.solver_run.objective_function.tif_targets:
tif = lpSum([item.iif(self.solver_run, target.theta)*items[item.id]
for item in self.solver_run.items])
problem += lpSum([item.iif(self.solver_run, target.theta)*items[item.id]
for item in self.solver_run.items]) <= target.value, f'min tif theta ({target.theta}) target value {target.value}'
problem_objection_functions.append(tif)
for target in self.solver_run.objective_function.tcc_targets:
tcc = lpSum([item.irf(self.solver_run, target.theta)*items[item.id]
for item in self.solver_run.items])
problem += lpSum([item.irf(self.solver_run, target.theta)*items[item.id]
for item in self.solver_run.items]) <= target.value, f'min tcc theta ({target.theta}) target value {target.value}'
problem_objection_functions.append(tcc)
# solve problem
problem.sequentialSolve(problem_objection_functions)
problem.solve()
# add return items and create as a form
form_items = service_helper.solution_items(problem.variables(), self.solver_run)