add passage attribute to item and bundles generation method for solver run
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from models.attribute import Attribute
|
||||
|
||||
@ -8,6 +8,7 @@ from lib.irt.item_information_function import ItemInformationFunction
|
||||
|
||||
class Item(BaseModel):
|
||||
id: int
|
||||
passage: Optional[int]
|
||||
attributes: List[Attribute]
|
||||
b_param: float = 0.00
|
||||
|
||||
@ -27,4 +28,4 @@ class Item(BaseModel):
|
||||
for attribute in self.attributes:
|
||||
if attribute.id == ref_attribute.id and attribute.value == ref_attribute.value:
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
@ -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