This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/resources/event/rate/main.py

26 lines
767 B
Python
Raw Normal View History

from ereuse_devicehub.resources.device.models import Device
2019-04-11 16:29:51 +00:00
from ereuse_devicehub.resources.event.models import RateComputer
from ereuse_devicehub.resources.event.rate.workbench import v1_0
RATE_TYPES = {
2019-04-11 16:29:51 +00:00
RateComputer: {
'1.0': v1_0.Rate()
}
}
2019-04-11 16:29:51 +00:00
def rate(device: Device, version):
"""
Rates the passed-in ``rate`` using values from the rate itself
and the ``device``.
This method mutates ``rate``.
:param device: The device to use as a model.
:param rate: A half-filled rate.
"""
assert cls in RATE_TYPES, 'Rate type {} not supported.'.format(cls)
2019-04-11 16:29:51 +00:00
assert str(rate.version) in RATE_TYPES[cls], \
'Rate version {} not supported.'.format(rate.version)
2019-04-11 16:29:51 +00:00
RATE_TYPES[cls][str(rate.version)].compute(device)