2026-06-02 21:08:48 +08:00
|
|
|
import enum
|
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
from typing import Iterator
|
|
|
|
|
from ..common import DeviceKind, Circuit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResultPriority(enum.Enum):
|
|
|
|
|
"""
|
|
|
|
|
The priority of the result.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
LESS_DEVICES = enum.auto()
|
|
|
|
|
"""Less devices is the first priority."""
|
|
|
|
|
MORE_ACCURACY = enum.auto()
|
|
|
|
|
"""More accuracy is the first priority."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class ResolverRequest:
|
|
|
|
|
"""
|
2026-06-15 15:58:04 +08:00
|
|
|
All request infomation for the resolver.
|
2026-06-02 21:08:48 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
device_kind: DeviceKind
|
|
|
|
|
"""The kind of device to resolve."""
|
|
|
|
|
target_value: float
|
|
|
|
|
"""The target value of the device."""
|
|
|
|
|
tolerance: float
|
2026-06-15 15:58:04 +08:00
|
|
|
"""The tolerance of the device in absolute value."""
|
2026-06-02 21:08:48 +08:00
|
|
|
result_priority: ResultPriority
|
|
|
|
|
"""The priority of the result."""
|
|
|
|
|
count_limit: int
|
2026-06-15 15:58:04 +08:00
|
|
|
"""The limited count of results."""
|
2026-06-02 21:08:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Resolver(ABC):
|
|
|
|
|
"""
|
|
|
|
|
Abstract base class for all resolvers.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2026-06-15 15:58:04 +08:00
|
|
|
def resolve(self, request: ResolverRequest) -> Iterator[Circuit]:
|
2026-06-02 21:08:48 +08:00
|
|
|
pass
|