From 4afe81e15bded27a294027b8a0d8b6ea91349b4d Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Wed, 15 Dec 2021 17:36:03 +0000 Subject: [PATCH] updated bundles process --- app/lib/irt/item_response_function.py | 4 ++-- app/models/solver_run.py | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/lib/irt/item_response_function.py b/app/lib/irt/item_response_function.py index df66a0e..3d64df9 100644 --- a/app/lib/irt/item_response_function.py +++ b/app/lib/irt/item_response_function.py @@ -1,4 +1,5 @@ from lib.irt.models.three_parameter_logistic import ThreeParameterLogistic +from lib.errors.item_generation_error import ItemGenerationError class ItemResponseFunction(): def __init__(self, irt_model): @@ -8,5 +9,4 @@ class ItemResponseFunction(): if self.model_data.model == '3PL': return ThreeParameterLogistic(self.model_data, kwargs).result() else: - # potentially error out - return None + raise ItemGenerationError("irt model not supported or provided") diff --git a/app/models/solver_run.py b/app/models/solver_run.py index b030548..7d030a6 100644 --- a/app/models/solver_run.py +++ b/app/models/solver_run.py @@ -32,12 +32,20 @@ class SolverRun(BaseModel): bundles = [] for item in self.items: - attribute_id = getattr(item, type_attribute)() - bundle_index = next((index for (index, bundle) in enumerate(bundles) if bundle['id'] == attribute_id), None) + # dynamically get the attribute that will be used as an identifier to bundle like items + attribute_id = getattr(item, type_attribute, None)() - if bundle_index == None: - bundles.append({ 'id': item.passage, 'count': 1, 'type': type_attribute }) - else: - bundles[bundle_index]['count'] += 1 + # make sure the item has said attribute + if attribute_id != None: + # get index of the bundle in the bundles list + bundle_index = next((index for (index, bundle) in enumerate(bundles) if bundle['id'] == attribute_id), None) + + # if the bundle index isn't found then the bundle hasn't been created + # and added to the list and needs to be, else increment the count of items + # in the bundle + if bundle_index == None: + bundles.append({ 'id': attribute_id, 'count': 1, 'type': type_attribute }) + else: + bundles[bundle_index]['count'] += 1 return bundles