pass rate workbench test v1

This commit is contained in:
nad 2019-04-16 17:47:28 +02:00
parent 0c5fa197d7
commit 75e1817e9c
7 changed files with 108 additions and 182 deletions

View File

@ -10,7 +10,7 @@ from teal.utils import import_resource
from ereuse_devicehub.resources import agent, event, inventory, lot, tag, user
from ereuse_devicehub.resources.device import definitions
from ereuse_devicehub.resources.documents import documents
from ereuse_devicehub.resources.enums import PriceSoftware, RatingSoftware
from ereuse_devicehub.resources.enums import PriceSoftware
class DevicehubConfig(Config):
@ -39,9 +39,7 @@ class DevicehubConfig(Config):
}
API_DOC_CLASS_DISCRIMINATOR = 'type'
WORKBENCH_RATE_SOFTWARE = RatingSoftware.ECost
WORKBENCH_RATE_VERSION = StrictVersion('1.0')
PHOTOBOX_RATE_SOFTWARE = RatingSoftware.ECost
PHOTOBOX_RATE_VERSION = StrictVersion('1.0')
"""
Official versions for WorkbenchRate and PhotoboxRate

View File

@ -54,24 +54,47 @@ class StepRandomDef(StepDef):
SCHEMA = schemas.StepRandom
class BenchmarkDef(EventDef):
VIEW = None
SCHEMA = schemas.Benchmark
class BenchmarkDataStorageDef(BenchmarkDef):
VIEW = None
SCHEMA = schemas.BenchmarkDataStorage
class BenchmarkWithRateDef(BenchmarkDef):
VIEW = None
SCHEMA = schemas.BenchmarkWithRate
class BenchmarkProcessorDef(BenchmarkWithRateDef):
VIEW = None
SCHEMA = schemas.BenchmarkProcessor
class BenchmarkProcessorSysbenchDef(BenchmarkProcessorDef):
VIEW = None
SCHEMA = schemas.BenchmarkProcessorSysbench
class BenchmarkRamSysbenchDef(BenchmarkWithRateDef):
VIEW = None
SCHEMA = schemas.BenchmarkRamSysbench
# TODO add test defs
class RateDef(EventDef):
VIEW = None
SCHEMA = schemas.Rate
class AggregateRateDef(RateDef):
class RateComputerDef(RateDef):
VIEW = None
SCHEMA = schemas.AggregateRate
class WorkbenchRateDef(RateDef):
VIEW = None
SCHEMA = schemas.WorkbenchRate
class ManualRateDef(RateDef):
VIEW = None
SCHEMA = schemas.ManualRate
SCHEMA = schemas.RateComputer
class PriceDef(EventDef):
@ -118,36 +141,6 @@ class StressTestDef(TestDef):
SCHEMA = schemas.StressTest
class BenchmarkDef(EventDef):
VIEW = None
SCHEMA = schemas.Benchmark
class BenchmarkDataStorageDef(BenchmarkDef):
VIEW = None
SCHEMA = schemas.BenchmarkDataStorage
class BenchmarkWithRateDef(BenchmarkDef):
VIEW = None
SCHEMA = schemas.BenchmarkWithRate
class BenchmarkProcessorDef(BenchmarkWithRateDef):
VIEW = None
SCHEMA = schemas.BenchmarkProcessor
class BenchmarkProcessorSysbenchDef(BenchmarkProcessorDef):
VIEW = None
SCHEMA = schemas.BenchmarkProcessorSysbench
class BenchmarkRamSysbenchDef(BenchmarkWithRateDef):
VIEW = None
SCHEMA = schemas.BenchmarkRamSysbench
class ToRepairDef(EventDef):
VIEW = None
SCHEMA = schemas.ToRepair

View File

@ -780,11 +780,11 @@ class TestBiosDifficulty:
"""
Test to determinate a grade to reflect some possibles difficult to access or modify setting in the BIOS, like password protection..
"""
bios_access_range = Column(BDEnum(BiosAccessRange))
bios_access_range = Column(DBEnum(BiosAccessRange))
bios_access_range.comment = 'Range of difficult to access BIOS'
class TestVisual(ManualRate):
class TestVisual(Test):
"""
Manual rate test its are represented with grade and focuses mainly on
the aesthetic or cosmetic defects of important parts of a device.
@ -912,7 +912,7 @@ class Price(JoinedWithOneDeviceMixin, EventWithOneDevice):
"""
version = Column(StrictVersionType)
version.comment = """The version of the software, or None."""
rating_id = Column(UUID(as_uuid=True), ForeignKey(RateComputer.id))
rating_id = Column(UUID(as_uuid=True), ForeignKey(Rate.id))
rating_id.comment = """The AggregateRate used to auto-compute
this price, if it has not been set manually."""
rating = relationship(Rate,
@ -920,7 +920,7 @@ class Price(JoinedWithOneDeviceMixin, EventWithOneDevice):
lazy=True,
cascade=CASCADE_OWN,
uselist=False),
primaryjoin=RateComputer.id == rating_id)
primaryjoin=Rate.id == rating_id)
def __init__(self, *args, **kwargs) -> None:
if 'price' in kwargs:

View File

@ -71,9 +71,11 @@ class RateAlgorithm(BaseRate):
if result:
setattr(rate, field, result)
test_visual = next(e for e in device.events if isinstance(e, TestVisual))
rate_components = self.harmonic_mean_rates(rate.processor, rate.data_storage, rate.ram)
rate.appearance = self.Appearance.from_devicehub(TestVisual.appearance_range).value
rate.functionality = self.Functionality.from_devicehub(TestVisual.functionality_range).value
rate.appearance = self.Appearance.from_devicehub(test_visual.appearance_range).value
rate.functionality = self.Functionality.from_devicehub(test_visual.functionality_range).value
rate.rating = round(max(rate_components + rate.functionality + rate.appearance, 0), 2)
rate.appearance = round(rate.appearance, 2)

View File

@ -12,9 +12,9 @@ from ereuse_devicehub.marshmallow import NestedOn
from ereuse_devicehub.resources import enums
from ereuse_devicehub.resources.agent import schemas as s_agent
from ereuse_devicehub.resources.device import schemas as s_device
from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \
PhysicalErasureMethod, PriceSoftware, RATE_POSITIVE, RatingRange, RatingSoftware, ReceiverRole, \
Severity, SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength, FunctionalityRange
from ereuse_devicehub.resources.enums import AppearanceRange, BiosAccessRange, FunctionalityRange, \
PhysicalErasureMethod, PriceSoftware, RATE_POSITIVE, RatingRange, ReceiverRole, \
Severity, SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength
from ereuse_devicehub.resources.event import models as m
from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE
from ereuse_devicehub.resources.schemas import Thing
@ -167,7 +167,7 @@ class StressTest(Test):
class TestAudio(Test):
__doc__ = m.TestAudio.__doc__
loudspeaker = BDEnum(LoudspeakerRange)
loudspeaker = Boolean()
microphone = Boolean()
@ -185,12 +185,13 @@ class TestBios:
class TestBiosDifficulty:
__doc__ = m.TestBiosDifficulty.__doc__
bios_access_range = EnumField(BiosAccessRange, dump_only=True, data_key='biosAccessRange')
class TestVisual(ManualRate):
class TestVisual():
__doc__ = m.TestVisual.__doc__
appearance_range = DBEnum(AppearanceRange)
appearance_range = EnumField(AppearanceRange, dump_only=True, data_key='appearanceRange')
functionality_range = EnumField(FunctionalityRange, dump_only=True, data_key='functionalityRange')
class Rate(EventWithOneDevice):
@ -198,9 +199,6 @@ class Rate(EventWithOneDevice):
rating = Integer(validate=Range(*RATE_POSITIVE),
dump_only=True,
description=m.Rate.rating.comment)
software = EnumField(RatingSoftware,
dump_only=True,
description=m.Rate.software.comment)
version = Version(dump_only=True,
description=m.Rate.version.comment)
appearance = Integer(validate=Range(-3, 5), dump_only=True)
@ -208,92 +206,13 @@ class Rate(EventWithOneDevice):
rating_range = EnumField(RatingRange, dump_only=True, data_key='ratingRange')
class IndividualRate(Rate):
__doc__ = m.IndividualRate.__doc__
class ManualRate(IndividualRate):
__doc__ = m.ManualRate.__doc__
appearance_range = EnumField(AppearanceRange,
required=True,
data_key='appearanceRange',
description=m.ManualRate.appearance_range.comment)
functionality_range = EnumField(FunctionalityRange,
required=True,
data_key='functionalityRange',
description=m.ManualRate.functionality_range.comment)
labelling = Boolean(description=m.ManualRate.labelling.comment)
class RateComputer(ManualRate):
__doc__ = m.WorkbenchRate.__doc__
class RateComputer(Rate):
__doc__ = m.RateComputer.__doc__
processor = Float()
ram = Float()
data_storage = Float()
graphic_card = Float()
bios = Float()
bios_range = EnumField(Bios,
description=m.WorkbenchRate.bios_range.comment,
data_key='biosRange')
data_storage_range = EnumField(RatingRange, dump_only=True, data_key='dataStorageRange')
ram_range = EnumField(RatingRange, dump_only=True, data_key='ramRange')
processor_range = EnumField(RatingRange, dump_only=True, data_key='processorRange')
graphic_card_range = EnumField(RatingRange, dump_only=True, data_key='graphicCardRange')
class RateMobile(ManualRate):
pass
class QualityRate(Rate):
__doc__ = m.QualityRate.__doc__
ram = Float(dump_only=True, description=m.QualityRate.ram.comment)
processor = Float(dump_only=True, description=m.QualityRate.processor.comment)
data_storage = Float(dump_only=True, description=m.QualityRate.data_storage.comment)
graphic_card = Float(dump_only=True, description=m.QualityRate.processor.comment)
network_adapter = Float(dump_only=True, description=m.QualityRate.network_adapter.comment)
display = Float(dump_only=True, description=m.QualityRate.display.comment)
battery = Float(dump_only=True, description=m.QualityRate.batter.comment)
camera = Float(dump_only=True, description=m.QualityRate.camera.comment)
bios = EnumField(Bios, dump_only=True)
bios_range = EnumField(Bios,
description=m.WorkbenchRate.bios_range.comment,
data_key='biosRange')
class FunctionalityRate(Rate):
__doc__ = m.FunctionalityRate.__doc__
functionality = EnumField(dump_only=True, description=m.FunctionalityRate.functionality.comment)
functionality_range = EnumField(dump_only=True, description=m.FunctionalityRate.functionality_range.comment)
# TODO Finish input rates (internal and external sources) - Whats really interesting to save in BD?? Whichs aspects?
class FinalRate(Rate):
__doc__ = m.FinalRate.__doc__
quality = NestedOn(QualityRate, dump_only=True,
description=m.QualityRate.quality_id.comment)
functionality = NestedOn(FunctionalityRate, dump_only=True,
description=m.FunctionalityRange.functionality_id.comment)
appearance = NestedOn(TestVisual, dump_only=True)
workbench_computer = NestedOn(WorkbenchComputer, dump_only=True,
description=m.ResultRate.workbench_computer_id.comment)
workbench_mobile = NestedOn(WorkbenchMobile, dump_only=True,
description=m.ResultRate.workbench_mobile_id.comment)
appearance_range = EnumField(AppearanceRangev2,
required=True,
data_key='appearanceRangev2',
description=m.ManualRate.appearance_range.comment)
functionality_range = EnumField(FunctionalityRange,
required=True,
data_key='functionalityRangev2',
description=m.ManualRate.functionality_range.comment)
labelling = Boolean(description=m.ManualRate.labelling.comment)
data_storage_range = EnumField(RatingRange, dump_only=True, data_key='dataStorageRange')
ram_range = EnumField(RatingRange, dump_only=True, data_key='ramRange')
processor_range = EnumField(RatingRange, dump_only=True, data_key='processorRange')
@ -307,9 +226,8 @@ class Price(EventWithOneDevice):
rounding=m.Price.ROUND,
required=True,
description=m.Price.price.comment)
software = EnumField(PriceSoftware, dump_only=True, description=m.Price.software.comment)
version = Version(dump_only=True, description=m.Price.version.comment)
rating = NestedOn(AggregateRate, dump_only=True, description=m.Price.rating_id.comment)
rating = NestedOn(Rate, dump_only=True, description=m.Price.rating_id.comment)
class EreusePrice(Price):

View File

@ -10,7 +10,7 @@ from teal.resource import View
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.device.models import Component, Computer
from ereuse_devicehub.resources.enums import SnapshotSoftware
from ereuse_devicehub.resources.event.models import Event, Snapshot, WorkbenchRate
from ereuse_devicehub.resources.event.models import Event, Snapshot, Rate
SUPPORTED_WORKBENCH = StrictVersion('11.0')
@ -81,7 +81,7 @@ class EventView(View):
snapshot.events |= events
# Compute ratings
for rate in (e for e in events_device if isinstance(e, WorkbenchRate)):
for rate in (e for e in events_device if isinstance(e, Rate)):
rates = rate.ratings()
snapshot.events |= rates

View File

@ -18,9 +18,9 @@ import pytest
from ereuse_devicehub.resources.device.models import Desktop, HardDrive, Processor, RamModule
from ereuse_devicehub.resources.enums import AppearanceRange, ComputerChassis, FunctionalityRange
from ereuse_devicehub.resources.event.models import BenchmarkDataStorage, BenchmarkProcessor, \
WorkbenchRate
RateComputer, TestVisual
from ereuse_devicehub.resources.event.rate.workbench.v1_0 import DataStorageRate, ProcessorRate, \
RamRate, Rate
RamRate, RateAlgorithm
def test_rate_data_storage_rate():
@ -32,7 +32,7 @@ def test_rate_data_storage_rate():
hdd_1969 = HardDrive(size=476940)
hdd_1969.events_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8))
data_storage_rate = DataStorageRate().compute([hdd_1969], WorkbenchRate())
data_storage_rate = DataStorageRate().compute([hdd_1969], RateComputer())
assert math.isclose(data_storage_rate, 4.02, rel_tol=0.001), 'DataStorageRate returns incorrect value(rate)'
@ -40,21 +40,21 @@ def test_rate_data_storage_rate():
hdd_3054.events_one.add(BenchmarkDataStorage(read_speed=158, write_speed=34.7))
# calculate DataStorage Rate
data_storage_rate = DataStorageRate().compute([hdd_3054], WorkbenchRate())
data_storage_rate = DataStorageRate().compute([hdd_3054], RateComputer())
assert math.isclose(data_storage_rate, 4.07, rel_tol=0.001), 'DataStorageRate returns incorrect value(rate)'
hdd_81 = HardDrive(size=76319)
hdd_81.events_one.add(BenchmarkDataStorage(read_speed=72.2, write_speed=24.3))
data_storage_rate = DataStorageRate().compute([hdd_81], WorkbenchRate())
data_storage_rate = DataStorageRate().compute([hdd_81], RateComputer())
assert math.isclose(data_storage_rate, 2.61, rel_tol=0.001), 'DataStorageRate returns incorrect value(rate)'
hdd_1556 = HardDrive(size=152587)
hdd_1556.events_one.add(BenchmarkDataStorage(read_speed=78.1, write_speed=24.4))
data_storage_rate = DataStorageRate().compute([hdd_1556], WorkbenchRate())
data_storage_rate = DataStorageRate().compute([hdd_1556], RateComputer())
assert math.isclose(data_storage_rate, 3.70, rel_tol=0.001), 'DataStorageRate returns incorrect value(rate)'
@ -69,7 +69,7 @@ def test_rate_data_storage_size_is_null():
hdd_null = HardDrive(size=None)
hdd_null.events_one.add(BenchmarkDataStorage(read_speed=0, write_speed=0))
data_storage_rate = DataStorageRate().compute([hdd_null], WorkbenchRate())
data_storage_rate = DataStorageRate().compute([hdd_null], RateComputer())
assert data_storage_rate is None
@ -79,7 +79,7 @@ def test_rate_no_data_storage():
"""
hdd_null = HardDrive()
hdd_null.events_one.add(BenchmarkDataStorage(read_speed=0, write_speed=0))
data_storage_rate = DataStorageRate().compute([hdd_null], WorkbenchRate())
data_storage_rate = DataStorageRate().compute([hdd_null], RateComputer())
assert data_storage_rate is None
@ -94,7 +94,7 @@ def test_rate_ram_rate():
ram1 = RamModule(size=2048, speed=1333)
ram_rate = RamRate().compute([ram1], WorkbenchRate())
ram_rate = RamRate().compute([ram1], RateComputer())
# todo rel_tol >= 0.002
assert math.isclose(ram_rate, 2.02, rel_tol=0.002), 'RamRate returns incorrect value(rate)'
@ -109,7 +109,7 @@ def test_rate_ram_rate_2modules():
ram1 = RamModule(size=4096, speed=1600)
ram2 = RamModule(size=2048, speed=1067)
ram_rate = RamRate().compute([ram1, ram2], WorkbenchRate())
ram_rate = RamRate().compute([ram1, ram2], RateComputer())
assert math.isclose(ram_rate, 3.79, rel_tol=0.001), 'RamRate returns incorrect value(rate)'
@ -125,7 +125,7 @@ def test_rate_ram_rate_4modules():
ram3 = RamModule(size=512, speed=667)
ram4 = RamModule(size=512, speed=533)
ram_rate = RamRate().compute([ram1, ram2, ram3, ram4], WorkbenchRate())
ram_rate = RamRate().compute([ram1, ram2, ram3, ram4], RateComputer())
# todo rel_tol >= 0.002
assert math.isclose(ram_rate, 1.993, rel_tol=0.001), 'RamRate returns incorrect value(rate)'
@ -138,7 +138,7 @@ def test_rate_ram_module_size_is_0():
ram0 = RamModule(size=0, speed=888)
ram_rate = RamRate().compute([ram0], WorkbenchRate())
ram_rate = RamRate().compute([ram0], RateComputer())
assert ram_rate is None
@ -150,13 +150,13 @@ def test_rate_ram_speed_is_null():
ram0 = RamModule(size=2048, speed=None)
ram_rate = RamRate().compute([ram0], WorkbenchRate())
ram_rate = RamRate().compute([ram0], RateComputer())
assert math.isclose(ram_rate, 1.85, rel_tol=0.002), 'RamRate returns incorrect value(rate)'
ram0 = RamModule(size=1024, speed=None)
ram_rate = RamRate().compute([ram0], WorkbenchRate())
ram_rate = RamRate().compute([ram0], RateComputer())
# todo rel_tol >= 0.004
assert math.isclose(ram_rate, 1.25, rel_tol=0.004), 'RamRate returns incorrect value(rate)'
@ -168,7 +168,7 @@ def test_rate_no_ram_module():
"""
ram0 = RamModule()
ram_rate = RamRate().compute([ram0], WorkbenchRate())
ram_rate = RamRate().compute([ram0], RateComputer())
assert ram_rate is None
@ -184,7 +184,7 @@ def test_rate_processor_rate():
# add score processor benchmark
cpu.events_one.add(BenchmarkProcessor(rate=3192.34))
processor_rate = ProcessorRate().compute(cpu, WorkbenchRate())
processor_rate = ProcessorRate().compute(cpu, RateComputer())
assert math.isclose(processor_rate, 1, rel_tol=0.001), 'ProcessorRate returns incorrect value(rate)'
@ -199,14 +199,14 @@ def test_rate_processor_rate_2cores():
# add score processor benchmark
cpu.events_one.add(BenchmarkProcessor(rate=27136.44))
processor_rate = ProcessorRate().compute(cpu, WorkbenchRate())
processor_rate = ProcessorRate().compute(cpu, RateComputer())
assert math.isclose(processor_rate, 3.95, rel_tol=0.001), 'ProcessorRate returns incorrect value(rate)'
cpu = Processor(cores=2, speed=3.3)
cpu.events_one.add(BenchmarkProcessor(rate=26339.48))
processor_rate = ProcessorRate().compute(cpu, WorkbenchRate())
processor_rate = ProcessorRate().compute(cpu, RateComputer())
# todo rel_tol >= 0.002
assert math.isclose(processor_rate, 3.93, rel_tol=0.002), 'ProcessorRate returns incorrect value(rate)'
@ -220,7 +220,7 @@ def test_rate_processor_with_null_cores():
# todo try without BenchmarkProcessor, StopIteration problem
cpu.events_one.add(BenchmarkProcessor())
processor_rate = ProcessorRate().compute(cpu, WorkbenchRate())
processor_rate = ProcessorRate().compute(cpu, RateComputer())
# todo rel_tol >= 0.003
assert math.isclose(processor_rate, 1.38, rel_tol=0.003), 'ProcessorRate returns incorrect value(rate)'
@ -233,7 +233,7 @@ def test_rate_processor_with_null_speed():
cpu = Processor(cores=1, speed=None)
cpu.events_one.add(BenchmarkProcessor(rate=0))
processor_rate = ProcessorRate().compute(cpu, WorkbenchRate())
processor_rate = ProcessorRate().compute(cpu, RateComputer())
assert math.isclose(processor_rate, 1.06, rel_tol=0.001), 'ProcessorRate returns incorrect value(rate)'
@ -323,11 +323,15 @@ def test_rate_computer_rate():
RamModule(size=2048, speed=1067),
cpu
}
# add functionality and appearance range
rate_pc = WorkbenchRate(appearance_range=AppearanceRange.A,
functionality_range=FunctionalityRange.A)
# Add test visual with functionality and appearance range
visual_test = TestVisual()
visual_test.appearance_range = AppearanceRange.A
visual_test.functionality_range = FunctionalityRange.A
pc_test.events_one.add(visual_test)
# Compute all components rates and general rating
Rate().compute(pc_test, rate_pc)
rate_pc = RateAlgorithm().compute(pc_test)
assert math.isclose(rate_pc.ram, 3.79, rel_tol=0.001)
@ -348,11 +352,14 @@ def test_rate_computer_rate():
RamModule(size=2048, speed=1333),
cpu
}
# add functionality and appearance range
rate_pc = WorkbenchRate(appearance_range=AppearanceRange.B,
functionality_range=FunctionalityRange.A)
# Add test visual with functionality and appearance range
visual_test = TestVisual()
visual_test.appearance_range = AppearanceRange.B
visual_test.functionality_range = FunctionalityRange.A
pc_test.events_one.add(visual_test)
# Compute all components rates and general rating
Rate().compute(pc_test, rate_pc)
rate_pc = RateAlgorithm().compute(pc_test)
assert math.isclose(rate_pc.ram, 2.02, rel_tol=0.001)
@ -376,11 +383,15 @@ def test_rate_computer_rate():
RamModule(size=512, speed=533),
cpu
}
# add functionality and appearance range
rate_pc = WorkbenchRate(appearance_range=AppearanceRange.C,
functionality_range=FunctionalityRange.A)
# Add test visual with functionality and appearance range
visual_test = TestVisual()
visual_test.appearance_range = AppearanceRange.C
visual_test.functionality_range = FunctionalityRange.A
pc_test.events_one.add(visual_test)
# Compute all components rates and general rating
Rate().compute(pc_test, rate_pc)
rate_pc = RateAlgorithm().compute(pc_test)
assert math.isclose(rate_pc.ram, 1.99, rel_tol=0.001)
@ -401,11 +412,15 @@ def test_rate_computer_rate():
RamModule(size=0, speed=None),
cpu
}
# add functionality and appearance range
rate_pc = WorkbenchRate(appearance_range=AppearanceRange.B,
functionality_range=FunctionalityRange.A)
# Add test visual with functionality and appearance range
visual_test = TestVisual()
visual_test.appearance_range = AppearanceRange.B
visual_test.functionality_range = FunctionalityRange.A
pc_test.events_one.add(visual_test)
# Compute all components rates and general rating
Rate().compute(pc_test, rate_pc)
rate_pc = RateAlgorithm().compute(pc_test)
assert math.isclose(rate_pc.ram, 1, rel_tol=0.001)