Skip to content

Commit

Permalink
Merge pull request #258 from Boavizta/dev
Browse files Browse the repository at this point in the history
Internal code refactoring and easier process for adding a cloud instance
  • Loading branch information
da-ekchajzer authored Jan 16, 2024
2 parents 14a705e + d0683cb commit 005e975
Show file tree
Hide file tree
Showing 70 changed files with 10,017 additions and 8,338 deletions.
1,934 changes: 967 additions & 967 deletions boaviztapi/data/archetypes/cloud/aws.csv

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion boaviztapi/data/archetypes/cloud/gcp.csv

This file was deleted.

4 changes: 2 additions & 2 deletions boaviztapi/data/archetypes/components/cpu.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id,name,units,model_range,manufacturer,family,core_units,tdp,die_size_per_core,USAGE.time_workload,USAGE.use_time_ratio,USAGE.hours_life_time,CONSUMPTION_PROFILE.params
DEFAULT,,"1;1;1",,,,24;1;64,,,50;0;100,1,26280,"{'a': 171.2, 'b': 0.0354, 'c': 36.89, 'd': -10.13}"
id,name,units,model_range,manufacturer,family,core_units,tdp,threads,die_size_per_core,USAGE.time_workload,USAGE.use_time_ratio,USAGE.hours_life_time,CONSUMPTION_PROFILE.params
DEFAULT,,"1;1;1",,,,24;1;64,,,,50;0;100,1,26280,"{'a': 171.2, 'b': 0.0354, 'c': 36.89, 'd': -10.13}"
153 changes: 138 additions & 15 deletions boaviztapi/data/archetypes/server.csv

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions boaviztapi/data/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ default_case: "rack"
default_assembly: "DEFAULT"
default_motherboard: "DEFAULT"

default_server: "compute_medium"
default_server: "platform_compute_medium"

default_cloud: "a1.4xlarge"
default_cloud_instance: "a1.4xlarge"
default_cloud_provider: "aws"

default_laptop: "laptop-pro"
Expand Down
3,561 changes: 1,789 additions & 1,772 deletions boaviztapi/data/crowdsourcing/cpu_specs.csv

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions boaviztapi/dto/component/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ def mapper_cpu(cpu_dto: CPU, archetype=get_component_archetype(config["default_c
if cpu_dto.die_size_per_core is not None:
cpu_component.die_size_per_core.set_input(cpu_dto.die_size_per_core)

if cpu_dto.die_size_per_core is not None:
cpu_component.die_size_per_core.set_input(cpu_dto.die_size_per_core)

elif cpu_dto.die_size is not None and cpu_dto.core_units is not None:
die_size_per_core = cpu_dto.die_size / cpu_dto.core_units
cpu_component.die_size_per_core.set_completed(
Expand Down
33 changes: 17 additions & 16 deletions boaviztapi/dto/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from boaviztapi.dto.usage.usage import mapper_usage_server, mapper_usage_cloud
from boaviztapi.model.boattribute import Status, Boattribute
from boaviztapi.model.component import ComponentCase
from boaviztapi.model.device import DeviceServer, DeviceCloudInstance
from boaviztapi.model.device.server import DeviceServer
from boaviztapi.model.services.cloud_instance import ServiceCloudInstance
from boaviztapi.model.usage import ModelUsage
from boaviztapi.service.archetype import get_server_archetype, get_arch_component, get_cloud_instance_archetype


Expand Down Expand Up @@ -44,42 +46,41 @@ def mapper_server(server_dto: Server, archetype=get_server_archetype(config["def
server_model = device_mapper(server_dto, server_model)

server_model.usage = mapper_usage_server(server_dto.usage or UsageServer(), archetype=get_arch_component(server_model.archetype,"USAGE"))
complete_components_usage(server_model)
complete_components_usage(server_model, server_model.usage)

return server_model


def complete_components_usage(server_model: DeviceServer):
complete_component_usage(server_model.cpu.usage, server_model.usage)
complete_component_usage(server_model.case.usage, server_model.usage)
for ram_unit in server_model.ram:
complete_component_usage(ram_unit.usage, server_model.usage)
for disk_unit in server_model.disk:
complete_component_usage(disk_unit.usage, server_model.usage)
def complete_components_usage(model: DeviceServer, usage: ModelUsage):
complete_usage(model.cpu.usage, usage)
complete_usage(model.case.usage, usage)
for ram_unit in model.ram:
complete_usage(ram_unit.usage, usage)
for disk_unit in model.disk:
complete_usage(disk_unit.usage, usage)


def complete_component_usage(usage_component, usage_device):
def complete_usage(usage_component, usage_device):
if usage_device.avg_power.is_set():
return
for attr, val in usage_component.__iter__():
if isinstance(val, Boattribute) and not val.is_set() and usage_device.__getattribute__(attr).is_set():
usage_component.__setattr__(attr, usage_device.__getattribute__(attr))


class Cloud(Server):
provider: Optional[str] = None
instance_type: Optional[str] = None
usage: Optional[UsageCloud] = None

def mapper_cloud_instance(cloud_dto: Cloud, archetype=get_cloud_instance_archetype(config["default_cloud"], config["default_cloud_provider"])) -> DeviceCloudInstance:
model_cloud_instance = DeviceCloudInstance(archetype=archetype)

model_cloud_instance = device_mapper(cloud_dto, model_cloud_instance)
def mapper_cloud_instance(cloud_dto: Cloud, archetype=get_cloud_instance_archetype(config["default_cloud_instance"], config["default_cloud_provider"])) -> ServiceCloudInstance:
model_cloud_instance = ServiceCloudInstance(archetype=archetype)

model_cloud_instance.usage = mapper_usage_cloud(cloud_dto.usage or UsageCloud(), archetype=get_arch_component(model_cloud_instance.archetype, "USAGE"))

complete_component_usage(model_cloud_instance.cpu.usage, model_cloud_instance.usage)
for ram_unit in model_cloud_instance.ram:
complete_component_usage(ram_unit.usage, model_cloud_instance.usage)
complete_components_usage(model_cloud_instance.platform, model_cloud_instance.usage)
complete_usage(model_cloud_instance.platform.usage, model_cloud_instance.usage)

return model_cloud_instance

Expand Down
10 changes: 8 additions & 2 deletions boaviztapi/dto/usage/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from boaviztapi.service.archetype import get_cloud_instance_archetype, get_server_archetype
from boaviztapi.service.factor_provider import get_available_countries


class WorkloadTime(BaseDTO):
time_percentage: float = None
load_percentage: float = None


class ElecFactors(BaseDTO):
gwp: Optional[float] = None
adp: Optional[float] = None
Expand Down Expand Up @@ -93,7 +95,8 @@ def mapper_usage(usage_dto: Usage, archetype=None) -> ModelUsage:
return usage_model


def mapper_usage_server(usage_dto: UsageServer, archetype=get_server_archetype(config["default_server"]).get("USAGE")) -> ModelUsageServer:
def mapper_usage_server(usage_dto: UsageServer,
archetype=get_server_archetype(config["default_server"]).get("USAGE")) -> ModelUsageServer:
usage_model_server = ModelUsageServer(archetype=archetype)

for elec_factor in usage_dto.elec_factors.__dict__.keys():
Expand Down Expand Up @@ -124,7 +127,10 @@ def mapper_usage_server(usage_dto: UsageServer, archetype=get_server_archetype(c
return usage_model_server


def mapper_usage_cloud(usage_dto: UsageCloud, archetype=get_cloud_instance_archetype(config["default_cloud"], config["default_cloud_provider"]).get("USAGE")) -> ModelUsageCloud:
def mapper_usage_cloud(usage_dto: UsageCloud, archetype=get_cloud_instance_archetype(config["default_cloud_instance"],
config[
"default_cloud_provider"]).get(
"USAGE")) -> ModelUsageCloud:
usage_model_cloud = ModelUsageCloud(archetype=archetype)

for elec_factor in usage_dto.elec_factors.__dict__.keys():
Expand Down
17 changes: 0 additions & 17 deletions boaviztapi/model/component/assembly.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
import boaviztapi.utils.roundit as rd
from boaviztapi.model import ComputedImpacts
from boaviztapi.model.component.component import Component
from boaviztapi.model.impact import ImpactFactor
from boaviztapi.service.factor_provider import get_impact_factor


class ComponentAssembly(Component):
NAME = "ASSEMBLY"

def __init__(self, **kwargs):
super().__init__(**kwargs)

def impact_embedded(self, impact_type: str) -> ComputedImpacts:
impact_factor = ImpactFactor(
value=get_impact_factor(item='assembly', impact_type=impact_type)['impact'],
min=get_impact_factor(item='assembly', impact_type=impact_type)['impact'],
max=get_impact_factor(item='assembly', impact_type=impact_type)['impact']
)

return impact_factor.value, impact_factor.min, impact_factor.max, ["End of life is not included in the calculation"]

def impact_use(self, impact_type: str, duration: float) -> ComputedImpacts:
raise NotImplementedError

67 changes: 1 addition & 66 deletions boaviztapi/model/component/case.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from typing import Tuple

from boaviztapi import config
from boaviztapi.model import ComputedImpacts
from boaviztapi.model.boattribute import Boattribute
from boaviztapi.model.component.component import Component
from boaviztapi.model.impact import ImpactFactor
from boaviztapi.service.archetype import get_arch_value, get_component_archetype
from boaviztapi.service.factor_provider import get_impact_factor


class ComponentCase(Component):
Expand All @@ -19,64 +14,4 @@ def __init__(self, archetype=get_component_archetype(config["default_case"], "ca
default=get_arch_value(archetype, 'case_type', 'default'),
min=get_arch_value(archetype, 'case_type', 'min'),
max=get_arch_value(archetype, 'case_type', 'max')
)

def impact_embedded(self, impact_type: str) -> ComputedImpacts:
if self.case_type.value == 'rack':
return self.__impact_manufacture_rack(impact_type)
elif self.case_type.value == 'blade':
return self.__impact_manufacture_blade(impact_type)

def __impact_manufacture_rack(self, impact_type: str) -> ComputedImpacts:
impact_factor = ImpactFactor(
value=get_impact_factor(item='case', impact_type=impact_type)['rack']['impact'],
min=get_impact_factor(item='case', impact_type=impact_type)['rack']['impact'],
max=get_impact_factor(item='case', impact_type=impact_type)['rack']['impact']
)

if self.case_type.is_archetype() and self.case_type.value == 'rack':
blade_impact = self.__impact_manufacture_blade(impact_type)
if blade_impact[0] > impact_factor.value:
return impact_factor.value, impact_factor.min, blade_impact[2], ["End of life is not included in the calculation"]
else:
return impact_factor.value, blade_impact[1], impact_factor.max, ["End of life is not included in the calculation"]
return impact_factor.value, impact_factor.min, impact_factor.max, ["End of life is not included in the calculation"]

def __impact_manufacture_blade(self, impact_type: str) -> ComputedImpacts:
impact_blade_server, impact_blade_16_slots = self.__get_impact_constants_blade(impact_type)

impact = self.__compute_impact_manufacture_blade(impact_blade_server, impact_blade_16_slots)

if self.case_type.is_archetype() and self.case_type.value == 'blade':
rack_impact = self.__impact_manufacture_rack(impact_type)
if rack_impact[0] > impact.value:
return impact.value, impact.min, rack_impact[2], ["End of life is not included in the calculation"]
else:
return impact.value, rack_impact[1], impact.max, ["End of life is not included in the calculation"]

return impact.value, impact.min, impact.max, ["End of life is not included in the calculation"]

def __get_impact_constants_blade(self, impact_type: str) -> Tuple[ImpactFactor, ImpactFactor]:
impact_blade_server = ImpactFactor(
value=get_impact_factor(item='case', impact_type=impact_type)['blade']['impact_blade_server'],
min=get_impact_factor(item='case', impact_type=impact_type)['blade']['impact_blade_server'],
max=get_impact_factor(item='case', impact_type=impact_type)['blade']['impact_blade_server'],
)
impact_blade_16_slots = ImpactFactor(
value=get_impact_factor(item='case', impact_type=impact_type)['blade']['impact_blade_16_slots'],
min=get_impact_factor(item='case', impact_type=impact_type)['blade']['impact_blade_16_slots'],
max=get_impact_factor(item='case', impact_type=impact_type)['blade']['impact_blade_16_slots'],
)

return impact_blade_server, impact_blade_16_slots

@staticmethod
def __compute_impact_manufacture_blade(impact_blade_server: ImpactFactor, impact_blade_16_slots: ImpactFactor) -> ImpactFactor:
return ImpactFactor(
value=(impact_blade_16_slots.value / 16) + impact_blade_server.value,
min=(impact_blade_16_slots.min / 16) + impact_blade_server.min,
max=(impact_blade_16_slots.max / 16) + impact_blade_server.max
)

def impact_use(self, impact_type: str, duration: float) -> ComputedImpacts:
raise NotImplementedError
)
23 changes: 3 additions & 20 deletions boaviztapi/model/component/component.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from abc import abstractmethod

from boaviztapi.model import ComputedImpacts
from boaviztapi.model.boattribute import Boattribute
from boaviztapi.model.impact import Assessable
from boaviztapi.model.usage import ModelUsage
from boaviztapi.service.archetype import get_arch_value, get_arch_component


class Component:
class Component(Assessable):
NAME = "COMPONENT"

def __init__(self, archetype=None, **kwargs):
super().__init__(**kwargs)
self.impact_factor = {}
self.archetype = archetype
self.units = Boattribute(
Expand All @@ -32,19 +31,3 @@ def usage(self) -> ModelUsage:
@usage.setter
def usage(self, value: int) -> None:
self._usage = value

def impact_use(self, impact_type: str, duration: float) -> ComputedImpacts:
if not self.usage.avg_power.is_set():
raise NotImplementedError
impact_factor = self.usage.elec_factors[impact_type]

impacts = impact_factor.value * (self.usage.avg_power.value / 1000) * self.usage.use_time_ratio.value * duration

max_impact = impact_factor.max * (self.usage.avg_power.max / 1000) * self.usage.use_time_ratio.min * duration
min_impact = impact_factor.min * (self.usage.avg_power.min / 1000) * self.usage.use_time_ratio.max * duration

return impacts, min_impact, max_impact, []

@abstractmethod
def impact_embedded(self, impact_type: str) -> ComputedImpacts:
raise NotImplementedError
Loading

0 comments on commit 005e975

Please sign in to comment.