add passage attribute to item and bundles generation method for solver run
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user