read_history_events
서버 측에서 이벤트 이력(HistoryRead Events)을 기록하면, 클라이언트 측에서 시간 범위를 지정하여 과거 이벤트를 불러올 수 있습니다.
세트
- 실시간 이벤트 구독을 원하시면 다음을 이용하십시오 이벤트 구독.
- 과거 변수 데이터는 다음을 사용해 주십시오. read_history (Raw) / read_history_processed.
서명
def read_history_events(self,
node_id: str,
start_utc: datetime,
end_utc: datetime,
max_events: int = 0) -> List[HistoryEventArgs]: ...
node_id 일반적으로 i=2253 (서버 노드) 또는 사용자 정의 EventNotifier 노드입니다.max_events=0 개수 제한 없음; node_id 빈 문자열은 예외를 발생시킵니다 ValueError.
HistoryEventArgs
@dataclass
class HistoryEventArgs:
severity: int = 0
message: Optional[str] = None
source_name: Optional[str] = None
time: Optional[datetime] = None
event_type: Optional[str] = None
필드 의미가 동일함 EventArrivedEventArgs, 하지만 수명 주기는 반환된 목록의 유효 기간과 동일합니다(매니지드이므로 dispose가 필요하지 않습니다).
내장된 4가지 표준 SelectClauses: Severity / Message / SourceName / Time.
사용법
import datetime as dt
now = dt.datetime.now(dt.timezone.utc)
events = ua.read_history_events(
"i=2253",
start_utc=now - dt.timedelta(days=1),
end_utc=now)
for e in events:
print(f"[{e.severity}] {e.source_name}: {e.message} @ {e.time}")
사용자 정의 EventFilter
read_history_events 수락하지 않음사용자 정의 SelectClauses / EventFilter 매개변수, 기본적으로 내장된 4개 필드만 사용 가능; EventType / Severity 기준으로 필터링하려면 결과를 받은 후 직접 선별해야 합니다.
사용자 정의의 EventFilter 진입점은 EventSubscription.subscribe(node_id, event_filter=...) (고급 사용법, 참조: 이벤트 구독), 실시간 이벤트 구독에만 적용되며, 과거 데이터 읽기에는 적용되지 않습니다.
서버 측 요구 사항
- Events HistoryRead (서버 측 ServerCapabilities 플래그)를 반드시 지원해야 합니다.
- 이벤트 소스 노드에는 EventNotifier 속성(12)의 1번 비트(HistoryRead)가 설정되어 있어야 합니다.
실시간 이벤트 구독과의 관계
| API | 무엇으로 |
|---|---|
| subscribe_events(...) | 실시간 이벤트 (구독 기간 중 발생한) |
| read_history_events(...) | 이력 이벤트 (서버에 보관된) |
일반적인 조합: 시작 시 24시간 동안 read_history_events 적용한 다음, subscribe_events 실시간으로 전환합니다.