add passage attribute to item and bundles generation method for solver run

This commit is contained in:
Josh Burman
2021-12-14 21:28:38 +00:00
parent ae8f303269
commit a827312ef5
4 changed files with 30 additions and 14 deletions

View File

@ -27,3 +27,17 @@ class SolverRun(BaseModel):
def remove_items(self, items):
self.items = [item for item in self.items if item not in items]
return True
def bundles(self, type_attribute):
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)
if bundle_index == None:
bundles.append({ 'id': item.passage, 'count': 1, 'type': type_attribute })
else:
bundles[bundle_index]['count'] += 1
return bundles