tcc and tif drift, compensated for string value casing, csv to dict improved process
This commit is contained in:
@ -2,7 +2,7 @@ import csv
|
||||
import io
|
||||
import re
|
||||
|
||||
def items_csv_to_dict(items_csv_reader):
|
||||
def items_csv_to_dict(items_csv_reader, solver_run):
|
||||
items = []
|
||||
headers = []
|
||||
|
||||
@ -16,21 +16,17 @@ def items_csv_to_dict(items_csv_reader):
|
||||
# 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:
|
||||
if solver_run.irt_model.formatted_b_param() == col:
|
||||
item['b_param'] = row[key]
|
||||
elif key > 2 and key < len(headers) - 1:
|
||||
item['attributes'].append({
|
||||
'id': col,
|
||||
'value': row[key],
|
||||
'type': 'metadata'
|
||||
})
|
||||
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]
|
||||
elif solver_run.get_constraint(col):
|
||||
constraint = solver_run.get_constraint(col)
|
||||
item['attributes'].append(constraint.reference_attribute)
|
||||
else:
|
||||
if row[key]:
|
||||
item[col] = row[key]
|
||||
|
||||
items.append(item)
|
||||
|
||||
|
@ -26,29 +26,29 @@ def build_constraints(solver_run, problem, items):
|
||||
for item in solver_run.items]) <= round(total_form_items * (max / 100)), f'{attribute.id} - {attribute.value} - max'
|
||||
elif attribute.type == 'bundle':
|
||||
# TODO: account for many different bundle types, since the id condition in L33 could yield duplicates
|
||||
total_bundles = randint(constraint.minimum, constraint.maximum)
|
||||
selected_bundles = sample(solver_run.bundles, total_bundles)
|
||||
total_bundle_items = 0
|
||||
if solver_run.bundles != None:
|
||||
total_bundles = randint(constraint.minimum, constraint.maximum)
|
||||
selected_bundles = sample(solver_run.bundles, total_bundles)
|
||||
total_bundle_items = 0
|
||||
|
||||
for bundle in selected_bundles:
|
||||
for bundle in selected_bundles:
|
||||
con = dict(zip([item.id for item in solver_run.items],
|
||||
[(getattr(item, bundle.type, False) == bundle.id)
|
||||
for item in solver_run.items]))
|
||||
problem += lpSum([con[item.id]
|
||||
* items[item.id]
|
||||
for item in solver_run.items]) == bundle.count, f'Bundle constraint for {bundle.type} ({bundle.id})'
|
||||
total_bundle_items += bundle.count
|
||||
|
||||
# make sure all other items added to the form
|
||||
# are not a part of any bundle
|
||||
# currently only supports single bundle constraints, will need refactoring for multiple bundle constraints
|
||||
con = dict(zip([item.id for item in solver_run.items],
|
||||
[(getattr(item, bundle.type, False) == bundle.id)
|
||||
for item in solver_run.items]))
|
||||
[(getattr(item, attribute.id, None) == None)
|
||||
for item in solver_run.items]))
|
||||
problem += lpSum([con[item.id]
|
||||
* items[item.id]
|
||||
for item in solver_run.items]) == bundle.count, f'Bundle constraint for {bundle.type} ({bundle.id})'
|
||||
total_bundle_items += bundle.count
|
||||
|
||||
# make sure all other items added to the form
|
||||
# are not a part of any bundle
|
||||
# currently only supports single bundle constraints, will need refactoring for multiple bundle constraints
|
||||
con = dict(zip([item.id for item in solver_run.items],
|
||||
[(getattr(item, attribute.id, None) == None)
|
||||
for item in solver_run.items]))
|
||||
problem += lpSum([con[item.id]
|
||||
* items[item.id]
|
||||
for item in solver_run.items]) == solver_run.total_form_items - total_bundle_items, f'Remaining items are not of a bundle type'
|
||||
|
||||
for item in solver_run.items]) == solver_run.total_form_items - total_bundle_items, f'Remaining items are not of a bundle type'
|
||||
|
||||
return problem
|
||||
except ValueError as error:
|
||||
|
Reference in New Issue
Block a user