diff --git a/src/Scraper/application/handlers.py b/src/Scraper/application/handlers.py index bd80f9a..b52bdc9 100644 --- a/src/Scraper/application/handlers.py +++ b/src/Scraper/application/handlers.py @@ -123,7 +123,7 @@ def __call__(self, cmd: GetVolatileDataByCostInterval): filters_gt = {"cost": cmd.min_cost} filters_eq = {"component_type": cmd.component_type} - volatile_data = self.uow.repository.get_lower_costs( + volatile_data: list = self.uow.repository.get_lower_costs( filters_eq=filters_eq, filters_lt=filters_lt, filters_gt=filters_gt, @@ -131,6 +131,11 @@ def __call__(self, cmd: GetVolatileDataByCostInterval): components = _get_components_from_volatile_data(volatile_data) + for i, component in enumerate(components): + if component.rank is None: + del volatile_data[i] + del components[i] + return components, volatile_data diff --git a/src/Scraper/domain/commands.py b/src/Scraper/domain/commands.py index f215aef..c787c67 100644 --- a/src/Scraper/domain/commands.py +++ b/src/Scraper/domain/commands.py @@ -71,3 +71,4 @@ class GetVolatileDataByCostInterval(Command): component_type: EComponentType min_cost: float max_cost: float + need_rank: bool = False diff --git a/src/SearchEngine/domain/repositories.py b/src/SearchEngine/domain/repositories.py index 96b185c..f71c291 100644 --- a/src/SearchEngine/domain/repositories.py +++ b/src/SearchEngine/domain/repositories.py @@ -81,3 +81,24 @@ def _get(self, **kwargs): def __repr__(self): raise NotImplemented + + +class ISQLAlchemyRepository(AbstractRepository, metaclass=ABCMeta): + @abstractmethod + def __init__(self, session): + raise NotImplemented + + @abstractmethod + def _add(self, component: Component): + raise NotImplemented + + @abstractmethod + def _get_by_uid(self, ref: UUID): + raise NotImplemented + + @abstractmethod + def _get(self, **kwargs): + raise NotImplemented + + def __repr__(self): + raise NotImplemented diff --git a/src/Suggester/application/suggester.py b/src/Suggester/application/suggester.py index 08ca4ae..33c399d 100644 --- a/src/Suggester/application/suggester.py +++ b/src/Suggester/application/suggester.py @@ -1,5 +1,6 @@ from enum import Enum +import pygad from framework.domain.components import Component, EComponentType, CPUComponent from Scraper.domain.aggragate import VolatileData from framework.infrastructure.connection_util import get_message_bus @@ -54,6 +55,11 @@ def __init__(self, budget: float, purpose: EComputerPurposes): SE_EVENT_HANDLER_MAPPER, SE_COMMAND_HANDLER_MAPPER, SQLAlchemyUnitOfWork ) + # def fitness_func(solution, solution_idx): + # output = numpy.sum(solution*function_inputs) + # fitness = 1.0 / numpy.abs(output - desired_output) + # return fitness + def _get_components_by_cost_interval( self, priorities: dict[EComponentType, tuple], component_type: EComponentType ) -> tuple[list[Component], list[VolatileData]]: @@ -64,6 +70,7 @@ def _get_components_by_cost_interval( component_type, self.budget * priority[0], self.budget * priority[1], + True, ) ) @@ -91,15 +98,12 @@ def generate_computer(self) -> list[Component]: component_priorities, EComponentType.PSU ) - for cpu, cpu_vd in zip(cpus, cpus_vd): - print(cpu) - print(cpu_vd, "\n") - - # if self.budget < _gpu_price_thresh: - # a = [cpu for cpu in cpus if cpu.integrated_gpu] - # input(a) + for i, cpu in enumerate(cpus): + if isinstance(cpu, CPUComponent): + if cpu.integrated_gpu is None or len(cpu.integrated_gpu) == 0: + del cpus[i] + del cpus_vd[i] - # TODO calcula sua 'pontuação' com base na prioridade de suas especificações. # TODO Executa problema da mochila, restringindo com base na compatibilidade. # TODO somar consumo total e definir fonte com o orçamento estabelecido. # TODO caso o orçamento não seja totalmente preenchido, aumentar o orçamento do item prioritário, mantendo as compatibilidades anteriores diff --git a/src/framework/domain/components.py b/src/framework/domain/components.py index 8e8adc7..2b17b79 100644 --- a/src/framework/domain/components.py +++ b/src/framework/domain/components.py @@ -48,9 +48,9 @@ def get_attrs(cls, ctype: EComponentType) -> List[str]: "chipset", "board_size", "n_ram_slots", - "consumption", - "n_usb2", - "n_usb3x", + "memory_type", + "sata", + "n_usb", "n_vga", "n_hdmi", "n_display_port", @@ -67,10 +67,12 @@ class MotherboardComponent(Component): chipset: str board_size: EBoardSize n_ram_slots: int - consumption: int - n_usb2: int - n_usb3x: int + memory_type: ERAMGeneration + + sata: int + + n_usb: int n_vga: int n_hdmi: int @@ -137,7 +139,7 @@ class PersistenceComponent(Component): type: EComponentType = EComponentType.PERSISTENCE storage: int io: EPersistenceIOType - is_HDD: bool + is_HDD: bool = False rpm: int = 0 diff --git a/src/framework/domain/components_enums.py b/src/framework/domain/components_enums.py index d26005f..9785ddd 100644 --- a/src/framework/domain/components_enums.py +++ b/src/framework/domain/components_enums.py @@ -46,14 +46,22 @@ class ERAMGeneration(IntEnum): DDR3L = auto() DDR4 = auto() DDR5 = auto() + SODIMM = auto() class EBoardSize(IntEnum): - PICO_ITX = auto() - NANO_ITX = auto() - MINI_ITX = auto() - MICRO_ATX = auto() - STANDARD = auto() + ATX = auto() + Micro_ATX = auto() + Mini_ITX = auto() + ITX = auto() + E_ATX = auto() + Mini_STX = auto() + Thin_Mini_ITX = auto() + CEB = auto() + Mini_DTX = auto() + SSI = auto() + XL_ATX = auto() + EEB = auto() class EPSUModularity(IntEnum): diff --git a/src/framework/infrastructure/db_filling/store_components.py b/src/framework/infrastructure/db_filling/store_components.py index cb09f71..19a28d6 100644 --- a/src/framework/infrastructure/db_filling/store_components.py +++ b/src/framework/infrastructure/db_filling/store_components.py @@ -23,18 +23,26 @@ "io": EPersistenceIOType, "rate": EPSURate, "modularity": EPSUModularity, + "memory_type": ERAMGeneration, } -def store_components_from_json(json_dir: str, component_cls: Type[Component], **kwargs): +def store_components_from_json( + json_dir: str, component_cls: Type[Component], save_dataframe=False, **kwargs +): component_message_bus = get_message_bus( SE_EVENT_HANDLER_MAPPER, SE_COMMAND_HANDLER_MAPPER, SQLAlchemyUnitOfWork ) + save_path = json_dir.replace("raw", "run") + data_frame = [] + with open(json_dir, "r") as json_file: json_objects = json.load(json_file) for json_object in json_objects: + print(json_object) + json_filtered = { k: v for k, v in json_object.items() if k not in _enumerators } @@ -46,23 +54,43 @@ def store_components_from_json(json_dir: str, component_cls: Type[Component], ** component = component_cls( _id=Component.next_id(), **json_filtered, **json_modified, **kwargs ) - print(component) + try: component_message_bus.handle(AddComponent(component)) + + if save_dataframe: + json_object["uid"] = component.uid.hex + data_frame.append(json_object) + except EntityCollisionException: pass + if save_dataframe: + with open(save_path, "w") as f: + json.dump(data_frame, f, indent=4) + def main(): + hdd_dir = r"..\res\data\raw\hdd.json" + store_components_from_json( + hdd_dir, + PersistenceComponent, + save_dataframe=True, + is_HDD=True, + io=EPersistenceIOType.SATA, + ) + json_dirs = { - GPUComponent: r"..\res\data\raw\gpu.json", + MotherboardComponent: r"..\res\data\raw\motherboard.json", CPUComponent: r"..\res\data\raw\cpu.json", + GPUComponent: r"..\res\data\raw\gpu.json", RAMComponent: r"..\res\data\raw\ram.json", - # PSUComponent: r"..\res\data\raw\psu.json", + PSUComponent: r"..\res\data\raw\psu.json", + PersistenceComponent: r"..\res\data\raw\ssd.json", } [ - store_components_from_json(json_dir, component_cls) + store_components_from_json(json_dir, component_cls, save_dataframe=True) for component_cls, json_dir in json_dirs.items() ] diff --git a/src/framework/infrastructure/db_management/db_structure.py b/src/framework/infrastructure/db_management/db_structure.py index 64c9255..e272b03 100644 --- a/src/framework/infrastructure/db_management/db_structure.py +++ b/src/framework/infrastructure/db_management/db_structure.py @@ -50,7 +50,7 @@ class ComponentInstance(base): uid = Column(BinaryUUID, primary_key=True) component_uid = None type = Column(ENUM(EComponentType)) - manufacturer = Column(VARCHAR(20)) + manufacturer = Column(VARCHAR(50)) model = Column(VARCHAR(100)) rank = Column(INTEGER(4)) @@ -92,9 +92,9 @@ class LowerCostsInstance(base): "chipset", "board_size", "n_ram_slots", - "consumption", - "n_usb2", - "n_usb3x", + "memory_type", + "sata", + "n_usb", "n_vga", "n_hdmi", "n_display_port", @@ -110,13 +110,15 @@ class MotherboardInstance(ComponentInstance): component_uid = Column( BinaryUUID, ForeignKey(ComponentInstance.uid), primary_key=True ) - consumption = Column(INTEGER(5)) chipset = Column(VARCHAR(10)) board_size = Column(ENUM(EBoardSize)) n_ram_slots = Column(INTEGER(1)) - n_usb2 = Column(INTEGER(1)) - n_usb3x = Column(INTEGER(1)) + n_usb = Column(INTEGER(1)) + + memory_type = Column(ENUM(ERAMGeneration)) + + sata = Column(INTEGER(2)) n_vga = Column(INTEGER(1)) n_hdmi = Column(INTEGER(1))