prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
<|fim_middle|>
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.name = name
self.values = ValueBuffer(name, 128) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
<|fim_middle|>
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.values.update(value) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
<|fim_middle|>
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
<|fim_middle|>
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
<|fim_middle|>
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
<|fim_middle|>
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
<|fim_middle|>
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.inputs = list(inputs)
self.outputs = list(outputs) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
<|fim_middle|>
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop') |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
<|fim_middle|>
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | return self.outputs |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
<|fim_middle|>
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | for output_dev in self.outputs:
output_dev.enable() |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
<|fim_middle|>
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | for output_dev in self.outputs:
output_dev.disable() |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
<|fim_middle|>
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
<|fim_middle|>
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
<|fim_middle|>
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | super().__init__('dummy')
self.temp = 0 |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
<|fim_middle|>
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | return self.temp |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
<|fim_middle|>
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.temp = value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
<|fim_middle|>
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
<|fim_middle|>
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | super().__init__('dummy')
self.speed = None
self.enabled = False |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
<|fim_middle|>
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | if self.enabled:
self.speed = round(self.values.mean()) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
<|fim_middle|>
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.enabled = True |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
<|fim_middle|>
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.enabled = False |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
<|fim_middle|>
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
<|fim_middle|>
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
<|fim_middle|>
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | return [lerp(val, input_min, input_max, output_min, output_max) for val in seq] |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
<|fim_middle|>
<|fim▁end|> | def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
<|fim_middle|>
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
<|fim_middle|>
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.buffer.append(value) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
<|fim_middle|>
<|fim▁end|> | try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
<|fim_middle|>
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.speed = round(self.values.mean()) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
<|fim_middle|>
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise ValueError('provided sequence MUST be iterable') |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
<|fim_middle|>
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | seq = list(seq) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
<|fim_middle|>
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | return float(seq[0]) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
<|fim_middle|>
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise ValueError('sequence must have at least one value.') |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
<|fim_middle|>
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | return float(output_min) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
<|fim_middle|>
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | return float(output_max) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def <|fim_middle|>(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | run |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def <|fim_middle|>(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | enable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def <|fim_middle|>(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | disable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def <|fim_middle|>(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | valid |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def <|fim_middle|>(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def <|fim_middle|>(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | get_value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def <|fim_middle|>(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def <|fim_middle|>(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | set_value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def <|fim_middle|>(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | apply |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def <|fim_middle|>(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | enable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def <|fim_middle|>(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | disable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def <|fim_middle|>(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def <|fim_middle|>(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | run |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def <|fim_middle|>(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | apply_candidates |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def <|fim_middle|>(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | enable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def <|fim_middle|>(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | disable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def <|fim_middle|>(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | valid |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def <|fim_middle|>(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def <|fim_middle|>(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | get_value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def <|fim_middle|>(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | set_value |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def <|fim_middle|>(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def <|fim_middle|>(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | apply |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def <|fim_middle|>(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | enable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def <|fim_middle|>(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | disable |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def <|fim_middle|>(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | mean |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def <|fim_middle|>(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | lerp |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def <|fim_middle|>(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | lerp_range |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def <|fim_middle|>(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def <|fim_middle|>(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | update |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def <|fim_middle|>(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | mean |
<|file_name|>test_bleuscore.py<|end_file_name|><|fim▁begin|># ----------------------------------------------------------------------------
# Copyright 2015-2016 Nervana Systems Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------
'''<|fim▁hole|>'''
from neon.transforms.cost import BLEUScore
def test_bleuscore():
# dataset with two sentences
sentences = ["a quick brown fox jumped",
"the rain in spain falls mainly on the plains"]
references = [["a fast brown fox jumped",
"a quick brown fox vaulted",
"a rapid fox of brown color jumped",
"the dog is running on the grass"],
["the precipitation in spain falls on the plains",
"spanish rain falls for the most part on the plains",
"the rain in spain falls in the plains most of the time",
"it is raining today"]]
# reference scores for the given set of reference sentences
bleu_score_references = [92.9, 88.0, 81.5, 67.1] # bleu1, bleu2, bleu3, bleu4
# compute scores
bleu_metric = BLEUScore()
bleu_metric(sentences, references)
# check against references
for score, reference in zip(bleu_metric.bleu_n, bleu_score_references):
assert round(score, 1) == reference
if __name__ == '__main__':
test_bleuscore()<|fim▁end|> | Test BLEUScore metric against reference |
<|file_name|>test_bleuscore.py<|end_file_name|><|fim▁begin|># ----------------------------------------------------------------------------
# Copyright 2015-2016 Nervana Systems Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------
'''
Test BLEUScore metric against reference
'''
from neon.transforms.cost import BLEUScore
def test_bleuscore():
# dataset with two sentences
<|fim_middle|>
if __name__ == '__main__':
test_bleuscore()
<|fim▁end|> | sentences = ["a quick brown fox jumped",
"the rain in spain falls mainly on the plains"]
references = [["a fast brown fox jumped",
"a quick brown fox vaulted",
"a rapid fox of brown color jumped",
"the dog is running on the grass"],
["the precipitation in spain falls on the plains",
"spanish rain falls for the most part on the plains",
"the rain in spain falls in the plains most of the time",
"it is raining today"]]
# reference scores for the given set of reference sentences
bleu_score_references = [92.9, 88.0, 81.5, 67.1] # bleu1, bleu2, bleu3, bleu4
# compute scores
bleu_metric = BLEUScore()
bleu_metric(sentences, references)
# check against references
for score, reference in zip(bleu_metric.bleu_n, bleu_score_references):
assert round(score, 1) == reference |
<|file_name|>test_bleuscore.py<|end_file_name|><|fim▁begin|># ----------------------------------------------------------------------------
# Copyright 2015-2016 Nervana Systems Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------
'''
Test BLEUScore metric against reference
'''
from neon.transforms.cost import BLEUScore
def test_bleuscore():
# dataset with two sentences
sentences = ["a quick brown fox jumped",
"the rain in spain falls mainly on the plains"]
references = [["a fast brown fox jumped",
"a quick brown fox vaulted",
"a rapid fox of brown color jumped",
"the dog is running on the grass"],
["the precipitation in spain falls on the plains",
"spanish rain falls for the most part on the plains",
"the rain in spain falls in the plains most of the time",
"it is raining today"]]
# reference scores for the given set of reference sentences
bleu_score_references = [92.9, 88.0, 81.5, 67.1] # bleu1, bleu2, bleu3, bleu4
# compute scores
bleu_metric = BLEUScore()
bleu_metric(sentences, references)
# check against references
for score, reference in zip(bleu_metric.bleu_n, bleu_score_references):
assert round(score, 1) == reference
if __name__ == '__main__':
<|fim_middle|>
<|fim▁end|> | test_bleuscore() |
<|file_name|>test_bleuscore.py<|end_file_name|><|fim▁begin|># ----------------------------------------------------------------------------
# Copyright 2015-2016 Nervana Systems Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------
'''
Test BLEUScore metric against reference
'''
from neon.transforms.cost import BLEUScore
def <|fim_middle|>():
# dataset with two sentences
sentences = ["a quick brown fox jumped",
"the rain in spain falls mainly on the plains"]
references = [["a fast brown fox jumped",
"a quick brown fox vaulted",
"a rapid fox of brown color jumped",
"the dog is running on the grass"],
["the precipitation in spain falls on the plains",
"spanish rain falls for the most part on the plains",
"the rain in spain falls in the plains most of the time",
"it is raining today"]]
# reference scores for the given set of reference sentences
bleu_score_references = [92.9, 88.0, 81.5, 67.1] # bleu1, bleu2, bleu3, bleu4
# compute scores
bleu_metric = BLEUScore()
bleu_metric(sentences, references)
# check against references
for score, reference in zip(bleu_metric.bleu_n, bleu_score_references):
assert round(score, 1) == reference
if __name__ == '__main__':
test_bleuscore()
<|fim▁end|> | test_bleuscore |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent<|fim▁hole|> # create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features<|fim▁end|> | self._window = window
self._application = self._parent._application
|
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
<|fim_middle|>
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | SYSTEM_WIDE = 0 |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
<|fim_middle|>
<|fim▁end|> | """Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
<|fim_middle|>
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0) |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
<|fim_middle|>
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | """Returns boolean denoting if specified URI can be handled by this extension"""
return False |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
<|fim_middle|>
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | """Return container widget"""
return self._container |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
<|fim_middle|>
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | """Returns information about extension"""
icon = None
name = None
return icon, name |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
<|fim_middle|>
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | """Method called by the mount manager for unmounting the selected URI"""
pass |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
<|fim_middle|>
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | """Method called by the mount manager for focusing main object"""
pass |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
<|fim_middle|>
<|fim▁end|> | """Returns set of features supported by extension"""
return cls.features |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def <|fim_middle|>(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | __init__ |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def <|fim_middle|>(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | can_handle |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def <|fim_middle|>(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | get_container |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def <|fim_middle|>(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | get_information |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def <|fim_middle|>(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | unmount |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def <|fim_middle|>(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def get_features(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | focus_object |
<|file_name|>mount_manager_extension.py<|end_file_name|><|fim▁begin|>import gtk
class ExtensionFeatures:
SYSTEM_WIDE = 0
class MountManagerExtension:
"""Base class for mount manager extensions.
Mount manager has only one instance and is created on program startup.
Methods defined in this class are called automatically by the mount manager
so you need to implement them.
"""
# features extension supports
features = ()
def __init__(self, parent, window):
self._parent = parent
self._window = window
self._application = self._parent._application
# create user interface
self._container = gtk.VBox(False, 5)
self._controls = gtk.HBox(False, 5)
separator = gtk.HSeparator()
# pack interface
self._container.pack_end(separator, False, False, 0)
self._container.pack_end(self._controls, False, False, 0)
def can_handle(self, uri):
"""Returns boolean denoting if specified URI can be handled by this extension"""
return False
def get_container(self):
"""Return container widget"""
return self._container
def get_information(self):
"""Returns information about extension"""
icon = None
name = None
return icon, name
def unmount(self, uri):
"""Method called by the mount manager for unmounting the selected URI"""
pass
def focus_object(self):
"""Method called by the mount manager for focusing main object"""
pass
@classmethod
def <|fim_middle|>(cls):
"""Returns set of features supported by extension"""
return cls.features
<|fim▁end|> | get_features |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
<|fim▁hole|> md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()<|fim▁end|> | |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
<|fim_middle|>
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | """ SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed' |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
<|fim_middle|>
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | """ APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed' |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
<|fim_middle|>
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | """ APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed' |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
<|fim_middle|>
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | """ APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed' |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
<|fim_middle|>
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | """ Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)] |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
<|fim_middle|>
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | """ Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block]) |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
<|fim_middle|>
<|fim▁end|> | unittest.main() |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def <|fim_middle|>(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | testFIPS180_1_Appendix_A |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def <|fim_middle|>(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | testFIPS180_1_Appendix_B |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def <|fim_middle|>(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | testFIPS180_1_Appendix_C |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def <|fim_middle|>(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def _toBString(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | _toBlock |
<|file_name|>sha1Hash_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
""" sha1Hash_test.py
Unit tests for sha1.py
"""
from crypto.hash.sha1Hash import SHA1
import unittest
import struct
assert struct.calcsize('!IIIII') == 20, '5 integers should be 20 bytes'
class SHA1_FIPS180_TestCases(unittest.TestCase):
""" SHA-1 tests from FIPS180-1 Appendix A, B and C """
def testFIPS180_1_Appendix_A(self):
""" APPENDIX A. A SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abc'
message_digest = 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix A test Failed'
def testFIPS180_1_Appendix_B(self):
""" APPENDIX B. A SECOND SAMPLE MESSAGE AND ITS MESSAGE DIGEST """
hashAlg = SHA1()
message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
message_digest = 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix B test Failed'
def testFIPS180_1_Appendix_C(self):
""" APPENDIX C. A THIRD SAMPLE MESSAGE AND ITS MESSAGE DIGEST
Let the message be the binary-coded form of the ASCII string which consists
of 1,000,000 repetitions of "a". """
hashAlg = SHA1()
message = 1000000*'a'
message_digest = 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL
md_string = _toBString(message_digest)
assert( hashAlg(message) == md_string ), 'FIPS180 Appendix C test Failed'
def _toBlock(binaryString):
""" Convert binary string to blocks of 5 words of uint32() """
return [uint32(word) for word in struct.unpack('!IIIII', binaryString)]
def <|fim_middle|>(block):
""" Convert block (5 words of 32 bits to binary string """
return ''.join([struct.pack('!I',word) for word in block])
if __name__ == '__main__':
# Run the tests from the command line
unittest.main()
<|fim▁end|> | _toBString |
<|file_name|>testing.py<|end_file_name|><|fim▁begin|>"""
.15925 Editor
Copyright 2014 TechInvestLab.ru [email protected]<|fim▁hole|>.15925 Editor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
.15925 Editor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with .15925 Editor.
"""
from iso15926.tools.environment import EnvironmentContext
from PySide.QtCore import *
from PySide.QtGui import *
import os
from framework.dialogs import Choice
class TestWindow(QDialog):
vis_label = tm.main.tests_title
tests_dir = 'tests'
def __init__(self):
QDialog.__init__(self, appdata.topwindow, Qt.WindowSystemMenuHint | Qt.WindowTitleHint)
self.setWindowTitle(self.vis_label)
layout = QVBoxLayout(self)
box = QGroupBox(tm.main.tests_field, self)
self.tests_list = QListWidget(box)
boxlayout = QHBoxLayout(box)
boxlayout.addWidget(self.tests_list)
layout.addWidget(box)
for n in os.listdir(self.tests_dir):
if n.startswith(".") or not n.endswith('.py'):
continue
sp = os.path.splitext(n)
item = QListWidgetItem(sp[0], self.tests_list)
item.setCheckState(Qt.Unchecked)
self.btn_prepare = QPushButton(tm.main.prepare, self)
self.btn_prepare.setToolTip(tm.main.prepare_selected_tests)
self.btn_prepare.clicked.connect(self.OnPrepare)
self.btn_run = QPushButton(tm.main.run, self)
self.btn_run.setToolTip(tm.main.run_selected_tests)
self.btn_run.clicked.connect(self.OnRun)
self.btn_sel_all = QPushButton(tm.main.select_all, self)
self.btn_sel_all.clicked.connect(self.SelectAll)
self.btn_unsel_all = QPushButton(tm.main.unselect_all, self)
self.btn_unsel_all.clicked.connect(self.UnselectAll)
self.btn_cancel = QPushButton(tm.main.cancel, self)
self.btn_cancel.clicked.connect(self.reject)
btnlayout = QHBoxLayout()
btnlayout.addWidget(self.btn_sel_all)
btnlayout.addWidget(self.btn_unsel_all)
btnlayout.addStretch()
btnlayout.addWidget(self.btn_prepare)
btnlayout.addWidget(self.btn_run)
btnlayout.addWidget(self.btn_cancel)
layout.addLayout(btnlayout)
box = QGroupBox(tm.main.tests_result_field, self)
self.report = QPlainTextEdit(self)
boxlayout = QHBoxLayout(box)
boxlayout.addWidget(self.report)
layout.addWidget(box)
self.exec_()
def SelectAll(self):
self.tests_list.SetChecked([x for x in xrange(self.tests_list.Count)])
def UnselectAll(self):
self.tests_list.SetChecked([])
def OnPrepare(self):
if Choice(tm.main.tests_prepare_warning):
for k in self.tests_list.CheckedStrings:
self.report.AppendText(tm.main.tests_preparing.format(k))
locals = {'mode': 'prepare'}
ec = EnvironmentContext(None, locals)
ec.ExecutePythonFile(os.path.join(self.tests_dir, k + '.py'))
self.report.AppendText(tm.main.tests_preparing_done)
def OnRun(self):
all_passed = True
self.report.appendPlainText(tm.main.tests_running)
count = 0
passed = 0
for i in xrange(self.tests_list.count()):
item = self.tests_list.item(i)
name = item.text()
if not item.checkState() == Qt.Checked:
continue
count += 1
locals = {'mode': 'run', 'passed': False}
ec = EnvironmentContext(None, locals)
ec.ExecutePythonFile(os.path.join(self.tests_dir, name + '.py'))
if locals['passed']:
passed += 1
self.report.appendPlainText(tm.main.test_passed.format(name))
else:
self.report.appendPlainText(tm.main.test_failed.format(name))
self.report.appendPlainText(tm.main.tests_result)
self.report.appendPlainText(tm.main.tests_result_info.format(passed, count))
if os.path.exists(TestWindow.tests_dir):
@public('workbench.menu.help')
class xTestMenu:
vis_label = tm.main.menu_tests
@classmethod
def Do(cls):
TestWindow()<|fim▁end|> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.