updated bundles process

This commit is contained in:
Josh Burman
2021-12-15 17:36:03 +00:00
parent a827312ef5
commit 4afe81e15b
2 changed files with 16 additions and 8 deletions

View File

@ -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