Skip to content

Commit

Permalink
filtragem de cpus com gpu integrada quando orçamento for baixo. #52
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyvitor11000 committed Mar 28, 2023
1 parent 925200e commit 6675b5b
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 33 deletions.
7 changes: 6 additions & 1 deletion src/Scraper/application/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,19 @@ 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,
)

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


Expand Down
1 change: 1 addition & 0 deletions src/Scraper/domain/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ class GetVolatileDataByCostInterval(Command):
component_type: EComponentType
min_cost: float
max_cost: float
need_rank: bool = False
21 changes: 21 additions & 0 deletions src/SearchEngine/domain/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 12 additions & 8 deletions src/Suggester/application/suggester.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]]:
Expand All @@ -64,6 +70,7 @@ def _get_components_by_cost_interval(
component_type,
self.budget * priority[0],
self.budget * priority[1],
True,
)
)

Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/framework/domain/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down
18 changes: 13 additions & 5 deletions src/framework/domain/components_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
38 changes: 33 additions & 5 deletions src/framework/infrastructure/db_filling/store_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
]

Expand Down
16 changes: 9 additions & 7 deletions src/framework/infrastructure/db_management/db_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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",
Expand All @@ -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))
Expand Down

0 comments on commit 6675b5b

Please sign in to comment.