reverting to basic cases

This commit is contained in:
Joshua Burman
2022-02-09 16:33:38 -05:00
parent 2232b3342c
commit ab9b5525a4
4 changed files with 72 additions and 157 deletions

View File

@ -1,10 +1,6 @@
from pydantic import BaseModel
from typing import List
from models.item import Item
class Bundle(BaseModel):
id: int
count: int
items: List[Item]
type: str

View File

@ -1,5 +1,3 @@
import logging
from pydantic import BaseModel
from typing import List, Optional
@ -22,19 +20,17 @@ class SolverRun(BaseModel):
advanced_options: Optional[AdvancedOptions]
engine: str
def get_item(self, item_id: int) -> Item or bool:
def get_item(self, item_id):
for item in self.items:
if str(item.id) == item_id:
return item
return False
def remove_items(self, items: list[Item]) -> bool:
def remove_items(self, items):
self.items = [item for item in self.items if item not in items]
return True
def generate_bundles(self):
logging.info('Generating Bundles...')
bundle_constraints = (constraint.reference_attribute for constraint in self.constraints if constraint.reference_attribute.type == 'bundle')
for bundle_constraint in bundle_constraints:
@ -57,24 +53,16 @@ class SolverRun(BaseModel):
self.bundles.append(Bundle(
id=attribute_id,
count=1,
items=[item],
type=type_attribute
))
else:
self.bundles[bundle_index].count += 1
self.bundles[bundle_index].items.append(item)
else:
self.bundles = [Bundle(
id=attribute_id,
count=1,
items=[item],
type=type_attribute
)]
def get_constraint(self, name: str) -> Constraint or None:
def get_constraint(self, name):
return next((constraint for constraint in self.constraints if constraint.reference_attribute.id == name), None)
# temp function until we build out bundles to more than just for cases
# for now it treats "bundle" attributes as a single unique constraint
def get_constraint_by_type(self, type: str) -> Constraint or None:
return next((constraint for constraint in self.constraints if constraint.reference_attribute.type == type), None)