2019-06-19 11:35:26 +00:00
|
|
|
import math
|
2020-08-17 14:45:18 +00:00
|
|
|
from typing import Iterable
|
2019-06-19 11:35:26 +00:00
|
|
|
|
2018-10-13 12:53:46 +00:00
|
|
|
from ereuse_devicehub.resources.device.models import Device
|
|
|
|
|
|
|
|
|
|
|
|
class BaseRate:
|
2019-06-19 11:35:26 +00:00
|
|
|
"""Growing exponential from this value."""
|
2018-10-13 12:53:46 +00:00
|
|
|
CEXP = 0
|
2019-06-19 11:35:26 +00:00
|
|
|
"""Growing lineal starting on this value."""
|
2018-10-13 12:53:46 +00:00
|
|
|
CLIN = 242
|
2019-06-19 11:35:26 +00:00
|
|
|
"""Growing logarithmic starting on this value."""
|
2018-10-13 12:53:46 +00:00
|
|
|
CLOG = 0.5
|
|
|
|
|
2019-06-19 11:35:26 +00:00
|
|
|
"""Processor has 50% of weight over total score, used in harmonic mean."""
|
2018-10-13 12:53:46 +00:00
|
|
|
PROCESSOR_WEIGHT = 0.5
|
2019-06-19 11:35:26 +00:00
|
|
|
"""Storage has 20% of weight over total score, used in harmonic mean."""
|
2018-10-13 12:53:46 +00:00
|
|
|
DATA_STORAGE_WEIGHT = 0.2
|
2019-06-19 11:35:26 +00:00
|
|
|
"""Ram has 30% of weight over total score, used in harmonic mean."""
|
2018-10-13 12:53:46 +00:00
|
|
|
RAM_WEIGHT = 0.3
|
|
|
|
|
2019-04-11 16:29:51 +00:00
|
|
|
def compute(self, device: Device):
|
2018-10-13 12:53:46 +00:00
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def norm(x, x_min, x_max):
|
|
|
|
return (x - x_min) / (x_max - x_min)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def rate_log(x):
|
|
|
|
return math.log10(2 * x) + 3.57 # todo magic number!
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def rate_lin(x):
|
|
|
|
return 7 * x + 0.06 # todo magic number!
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def rate_exp(x):
|
|
|
|
return math.exp(x) / (2 - math.exp(x))
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def harmonic_mean(weights: Iterable[float], rates: Iterable[float]):
|
|
|
|
return sum(weights) / sum(char / rate for char, rate in zip(weights, rates))
|
|
|
|
|
|
|
|
def harmonic_mean_rates(self, rate_processor, rate_storage, rate_ram):
|
2019-06-19 11:35:26 +00:00
|
|
|
"""Merging components using harmonic formula."""
|
2018-10-13 12:53:46 +00:00
|
|
|
total_weights = self.PROCESSOR_WEIGHT + self.DATA_STORAGE_WEIGHT + self.RAM_WEIGHT
|
|
|
|
total_rate = self.PROCESSOR_WEIGHT / rate_processor \
|
|
|
|
+ self.DATA_STORAGE_WEIGHT / rate_storage \
|
|
|
|
+ self.RAM_WEIGHT / rate_ram
|
|
|
|
return total_weights / total_rate
|