add passage attribute to item and bundles generation method for solver run
This commit is contained in:
parent
ae8f303269
commit
a827312ef5
@ -9,14 +9,15 @@ def build_constraints(solver_run, problem, items):
|
||||
min = constraint.minimum
|
||||
max = constraint.maximum
|
||||
|
||||
con = dict(zip([item.id for item in solver_run.items],
|
||||
[item.attribute_exists(attribute)
|
||||
for item in solver_run.items]))
|
||||
problem += lpSum([con[item.id]
|
||||
* items[item.id]
|
||||
for item in solver_run.items]) >= round(total_form_items * (min / 100)), f'{attribute.id} - {attribute.value} - min'
|
||||
problem += lpSum([con[item.id]
|
||||
* items[item.id]
|
||||
for item in solver_run.items]) <= round(total_form_items * (max / 100)), f'{attribute.id} - {attribute.value} - max'
|
||||
if attribute.type == 'metadata':
|
||||
con = dict(zip([item.id for item in solver_run.items],
|
||||
[item.attribute_exists(attribute)
|
||||
for item in solver_run.items]))
|
||||
problem += lpSum([con[item.id]
|
||||
* items[item.id]
|
||||
for item in solver_run.items]) >= round(total_form_items * (min / 100)), f'{attribute.id} - {attribute.value} - min'
|
||||
problem += lpSum([con[item.id]
|
||||
* items[item.id]
|
||||
for item in solver_run.items]) <= round(total_form_items * (max / 100)), f'{attribute.id} - {attribute.value} - max'
|
||||
|
||||
return problem
|
||||
|
@ -19,9 +19,9 @@ class ServiceListener(SqsListener):
|
||||
logging.info('Process complete for %s', service.file_name)
|
||||
|
||||
def main():
|
||||
logging.info('Starting Solver Service (v1.0.1)...')
|
||||
logging.info('Starting Solver Service (v1.1.0)...')
|
||||
listener = ServiceListener(
|
||||
'measure-development-solver-ingest',
|
||||
os.environ['SQS_QUEUE'],
|
||||
region_name=os.environ['AWS_REGION'],
|
||||
aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
|
||||
aws_secret_key=os.environ['AWS_SECRET_ACCESS_KEY'],
|
||||
@ -31,6 +31,6 @@ def main():
|
||||
|
||||
if __name__ == '__main__':
|
||||
myname=os.path.basename(sys.argv[0])
|
||||
pidfile='/tmp/%s' % myname # any name
|
||||
pidfile='/tmp/%s' % myname
|
||||
daemon = Daemonize(app=myname,pid=pidfile, action=main, foreground=True)
|
||||
daemon.start()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user