> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/workflows/ko/tutorials/integrate-with-ignition/historical-data.md).

# 이력 데이터

Roboflow 디바이스의 Event Store에 저장된 검사 이벤트와 이미지를 Ignition에 표시하고, 기록용 데이터베이스에 복사합니다.

Roboflow 엣지 디바이스는 Workflow가 기록하는 모든 이벤트와 해당 이미지 및 데이터를 [Event Store](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/services/event-store)에 보관합니다. Ignition은 HTTP를 통해 Event Store를 읽으므로 운영자는 각 검사 결과와 모델이 판정한 이미지를 확인할 수 있습니다.

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-d1b94701b8ac10dd6493371ce0c9802ba3ec293e%2Fignition-events-table.png?alt=media" alt="A Perspective view with a table of recent inspections from the Roboflow Event Store and the image of the selected event"><figcaption><p>Event Store의 최근 검사 내역과 선택한 이벤트의 이미지입니다.</p></figcaption></figure>

이 페이지에서는 이벤트를 사용하는 두 가지 방법을 다룹니다.

* 디바이스에서 바로 Perspective 테이블에 이벤트를 표시합니다. 최신 이벤트나 현재 교대 근무 시간과 같은 기간의 이벤트를 볼 수 있습니다. Ignition에는 아무것도 저장되지 않으므로 데이터베이스가 필요하지 않습니다.
* 게이트웨이 스크립트를 사용해 모든 이벤트를 데이터베이스에 복사하면 보고서를 작성하고 디바이스에 더 이상 보관되지 않는 내역을 유지할 수 있습니다.

대신 최신 결과를 Ignition 태그로 가져오려면(예: 마지막 결과 또는 불량 개수)  [실시간 데이터](https://docs.roboflow.com/workflows/ko/tutorials/integrate-with-ignition/live-data.md).

## 사전 요구 사항

* 디바이스에서 스트림으로 실행 중인 Workflow와, "Write to Local Event Store"가 켜져 있는  [Roboflow Vision Events](https://docs.roboflow.com/workflows/ko/blocks/blocks/data-storage/roboflow-vision-events.md) 블록이 필요합니다. 이 모드에서 블록은 각 이벤트를 디바이스의 다음 경로에 있는 Event Store에 기록합니다. `http://localhost:8001` Roboflow API 키는 필요하지 않습니다.
* Ignition 게이트웨이는 포트  `8001`.
* 데이터베이스 옵션을 사용하려면 Ignition에 데이터베이스 연결이 필요합니다.

{% hint style="info" %}
이 단계와 스크린샷은 Ignition 8.1(Designer 8.1.55)을 기준으로 합니다. 8.3을 포함한 다른 버전에서는 메뉴 이름, 대화상자 및 속성 이름이 다를 수 있습니다.
{% endhint %}

## 이벤트 확인하기

브라우저에서  `http://<device-ip>:8001/v2/events?limit=5` 를 엽니다. 응답에는 최신 이벤트부터 순서대로 표시됩니다.

```json
{
  "events": [
    {
      "id": "3714e263-8159-4748-83db-ad804dde25cc",
      "stream_id": "bottle-line-1",
      "event_schema": "quality_check",
      "event_data": {"result": "fail", "externalId": "CASE-20437"},
      "custom_metadata": {"bottleCount": 11, "line": "Line 1"},
      "images": [{"file_id": "a1f0c2...", "label": "workflow"}],
      "created_at": "2026-11-13T15:42:10.512Z"
    }
  ],
  "count": 1,
  "next_timestamp": "2026-11-13T15:42:10.512Z"
}
```

`event_data` 에는 블록에서 선택한 이벤트 유형의 필드가 들어 있습니다(예: Quality Check의 "Result" 및 "External ID").  `custom_metadata` 에는 블록의 "Custom Metadata"가 들어 있습니다. 각 이미지는 다음 주소에서 제공됩니다. `http://<device-ip>:8001/images/<file_id>`. 자세한 내용은  [Event Store REST API](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/services/event-store/rest-api).

## Perspective에 최근 이벤트 표시하기

1. Perspective 뷰에 "Table" 구성 요소를 추가합니다.
2. 테이블의  `props.data`  옆에 있는 바인딩 아이콘을 클릭하고 "HTTP"를 선택합니다.
   * URL: `"http://<device-ip>:8001/v2/events?limit=20"` URL은 표현식이므로 따옴표로 묶습니다.
   * 메서드: `GET`.
   * "Polling"을 켜고 다음 값으로 설정합니다. `5` 초.
   * "캐시 및 공유"를 켜면, 하나의 요청으로 해당 뷰를 표시하는 모든 세션에 응답할 수 있습니다.

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-a642b31e56d24007c5f9e72da1b151e9a1c64fcc%2Fignition-designer-http-binding.png?alt=media" alt="The Edit Binding dialog for Events.props.data with an HTTP binding: a URL expression to port 8001, Method GET, Cache and Share and Polling every 5 seconds turned on, and a binding preview of the response"><figcaption><p>HTTP 바인딩입니다. 미리 보기에는 Event Store의 응답과 변환 스크립트가 생성하는 행이 표시됩니다.</p></figcaption></figure>

3. "변환 추가"를 클릭하고 "스크립트"를 선택한 다음, 각 이벤트를 행으로 바꾸는 스크립트를 붙여 넣습니다.

```python
def transform(self, value, quality, timestamp):
    if value is None:
        return []
    return [
        {
            "time": e["created_at"][11:19],
            "case": e["event_data"].get("externalId"),
            "result": e["event_data"].get("result"),
            "bottles": e["custom_metadata"].get("bottleCount"),
            "image_id": e["images"][0]["file_id"] if e["images"] else None,
        }
        for e in value["events"]
    ]
```

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-4899a888613e6b261ba8ebc58f27bb7bec1caed7%2Fignition-designer-http-transform.png?alt=media" alt="The Script transform in the HTTP binding dialog, with the transform function that maps each event to time, case, result, bottles and image_id"><figcaption><p>바인딩 대화상자의 Script 변환입니다.</p></figcaption></figure>

이벤트에 맞게 필드를 변경하세요. `event_data` 에는 이벤트 유형의 필드가 들어 있고, `custom_metadata` 에는 사용자가 직접 정의한 값(예: `bottleCount`). `created_at` 은 UTC 기준입니다.

바인딩은 게이트웨이에서 실행되므로, 테이블에 연결해야 하는 포트에 접근할 수 있어야 하는 것은 게이트웨이뿐입니다. `8001` 자세한 내용은 다음을 참조하세요. [HTTP 바인딩](https://docs.inductiveautomation.com/docs/8.3/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/http-bindings-in-perspective).

### 시간 범위 표시

특정 시점(예: 교대 근무 시작 시점) 이후의 이벤트를 표시하려면 바인딩 URL에 `start_time` 을 추가합니다.

```
"http://<device-ip>:8001/v2/events?limit=1000&start_time="
  + replace(dateFormat(setTime(now(60000), 6, 0, 0), "yyyy-MM-dd'T'HH:mm:ssXXX"), "+", "%2B")
```

`setTime(now(60000), 6, 0, 0)` 는 게이트웨이 시간대의 오늘 오전 6시를 나타내며, 이 표현식은 매분 다시 실행됩니다. 계속 이동하는 시간 범위를 사용하려면 대신 `addHours(now(60000), -8)` 를 사용합니다. 시간 범위의 끝을 지정하려면 같은 방식으로 `end_time` 을 추가합니다.

형식에서 `XXX` 를 유지하세요. 이 부분은 시간대 오프셋(예: `-05:00`)을 추가합니다. 오프셋이 없는 시간은 Event Store에서 장치의 시간대로 해석됩니다. 또한 `replace` 는 양수 오프셋의 `+` 를 인코딩합니다. 그렇지 않으면 URL에서 공백으로 변환됩니다.

각 요청은 최신 이벤트부터 최대 1,000개를 반환합니다. 시간 범위에 이벤트가 이보다 많이 포함되면 범위를 줄이거나 이벤트를 데이터베이스에 복사하세요.

### 이벤트 이미지 표시

운영자가 클릭한 행의 이미지를 표시합니다.

1. 뷰에 다음 이름의 사용자 지정 속성을 추가합니다. `selectedImage`, 값은 빈 문자열로 설정합니다.
2. 테이블을 마우스 오른쪽 버튼으로 클릭하고 "이벤트 구성..."을 선택합니다. "컴포넌트 이벤트"에서 "onRowClick"을 선택하고 "스크립트" 액션을 추가한 다음, 스크립트 본문에 다음 줄을 추가합니다:

```python
self.view.custom.selectedImage = event.value.image_id
```

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-0c018ca1c9d3983aee10fedac27701663ec506b9%2Fignition-designer-onrowclick.png?alt=media" alt="The Event Configuration dialog on the Events table with onRowClick selected and a Script action that sets self.view.custom.selectedImage"><figcaption><p>테이블의 <code>onRowClick</code> 스크립트.</p></figcaption></figure>

3. "이미지" 컴포넌트를 추가하고 `props.source` 를 표현식에 바인딩합니다:

```
if({view.custom.selectedImage} = "", "", "http://<device-ip>:8001/images/" + {view.custom.selectedImage})
```

숨기려면 `image_id` 열을 테이블의 `props.columns` 에 추가하고 `visible` 을 다음과 같이 설정합니다: `false`.

다음 폴링에서 행이 추가될 때 스크립트는 이미지를 제자리에 유지합니다. 테이블의 `props.selection` 새 데이터가 선택 항목을 지우므로 선택 항목을 잃게 됩니다.

이미지는 운영자의 브라우저에서 로드되므로 운영자의 컴퓨터가 포트에 연결할 수 있어야 합니다. `8001`.

## 이벤트를 데이터베이스에 복사하기

실시간 쿼리는 장치에 아직 남아 있는 데이터만 확인하며, 저장 공간이 차면 오래된 이벤트가 삭제됩니다. 기록을 더 오래 보존하거나 여러 장치의 데이터를 통합해 보고하려면 이벤트를 데이터베이스에 복사하세요. 게이트웨이 타이머 스크립트는 세션을 열어 둔 사용자가 있는지와 관계없이 실행됩니다. 이 스크립트를 사용해 새 이벤트를 소유한 테이블에 복사한 다음, 해당 테이블을 기반으로 보고서를 만들 수 있습니다.

### 테이블 만들기

이 예제에서는 PostgreSQL을 사용합니다. 데이터베이스에 맞게 데이터 형식을 조정하세요.

```sql
CREATE TABLE roboflow_events (
  id TEXT PRIMARY KEY,
  created_at TIMESTAMPTZ NOT NULL,
  stream_id TEXT,
  event_schema TEXT,
  event_data TEXT,
  image_id TEXT
);
```

이벤트의  `id` 는 기본 키이므로 스크립트가 같은 이벤트를 두 번 읽어도 한 번만 저장됩니다.

### 커서 태그 만들기

String 유형의 메모리 태그를 만듭니다(예:  `[default]Roboflow/EventCursor`). 스크립트는 복사한 이벤트 중 가장 최근 이벤트의 시간을 이 태그에 저장합니다.

### 타이머 스크립트 추가

1. Designer의 Project Browser에서 "Scripting" > "Gateway Events"를 열고 "Timer"를 선택합니다.
2. 타이머 스크립트를 추가합니다. "Choose Timer Settings"에서 이름을 입력하고 "Delay (ms)"를 다음 값으로 설정합니다. `5000`, "Fixed Delay"는 그대로 둡니다.

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-9f84be3b9062822351af742ae2b4e9a82d271073%2Fignition-designer-timer-settings.png?alt=media" alt="The Choose Timer Settings dialog with the name Copy Roboflow Events, Delay 5,000 ms, Enabled, Fixed Delay and Shared threading"><figcaption><p>타이머 설정입니다.</p></figcaption></figure>

3. 이 스크립트를 붙여 넣고 장치 주소와 데이터베이스 연결 이름을 바꿉니다:

```python
DEVICE = "http://192.168.1.50:8001"
DB = "MyDatabase"
CURSOR_TAG = "[default]Roboflow/EventCursor"

client = system.net.httpClient(timeout=10000, version="HTTP_1_1")
cursor = system.tag.readBlocking([CURSOR_TAG])[0].value or "1970-01-01T00:00:00Z"

response = client.get(DEVICE + "/v2/events", params={
    "start_time": cursor,
    "sort_direction": "asc",
    "limit": 1000,
})

if response.good:
    body = response.json
    for event in body["events"]:
        if system.db.runScalarPrepQuery("SELECT 1 FROM roboflow_events WHERE id = ?", [event["id"]], DB):
            continue
        images = event["images"]
        system.db.runPrepUpdate(
            "INSERT INTO roboflow_events (id, created_at, stream_id, event_schema, event_data, image_id) "
            "VALUES (?, CAST(? AS TIMESTAMPTZ), ?, ?, ?, ?)",
            [event["id"], event["created_at"], event["stream_id"], event["event_schema"],
             system.util.jsonEncode(event["event_data"]), images[0]["file_id"] if images else None],
            DB)
    if body["events"]:
        system.tag.writeBlocking([CURSOR_TAG], [body["next_timestamp"]])
else:
    system.util.getLogger("Roboflow").warn("Event Store returned %s" % response.statusCode)
```

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-bbfd9fb20f6bb1e2bd6bb6ecc30a2118477be1d2%2Fignition-designer-gateway-timer-script.png?alt=media" alt="The Gateway Event Scripts window with the Timer section selected, a timer named Copy Roboflow Events at 5,000 ms, and the script that copies events into the roboflow_events table"><figcaption><p>"Gateway Event Scripts"의 타이머 스크립트입니다.</p></figcaption></figure>

각 실행은 커서 시간부터 가장 오래된 순서로 최대 1,000개의 이벤트를 요청합니다. 새 이벤트를 저장하고 커서를 가장 최신 이벤트로 이동합니다. 1,000개가 넘는 이벤트가 도착한 경우 다음 실행에서 나머지를 복사합니다. 커서 시간에 해당하는 이벤트는 매번 다시 반환되며, `SELECT` 가 이를 건너뜁니다.

일부 이벤트만 복사하려면 다음에 필터를 추가합니다. `params` (예: `"event_schema": "quality_check"` 또는 `"metadata_filter": "line:eq:Line 1"`).

{% hint style="warning" %}
장치의 저장 공간이 가득 차면 오래된 이미지를 제거합니다. 그보다 오래된 행의 데이터는 남아 있지만 이미지는 더 이상 로드되지 않습니다. 이미지를 더 오래 보관하려면 스크립트에서 다음을 사용해 다운로드하고 `client.get(DEVICE + "/images/" + file_id).body` 바이트 데이터를 데이터베이스에 저장합니다.
{% endhint %}

## Event Store에 키가 필요한 경우

서비스에 `API_KEY` 가 설정되어 있지 않으면 Event Store는 키 없이 요청을 받습니다. 키가 설정된 경우 `X-API-Key` 헤더에 키를 전송합니다. 다음을 추가하세요. `headers={"X-API-Key": key}` 를 `client.get(...)`에 추가하거나 HTTP 바인딩에 헤더를 추가합니다. 키는 뷰에 두지 말고, 예를 들어 바인딩이 읽는 태그에 저장하세요.

## 문제 해결

<table data-search="false"><thead><tr><th>문제</th><th>해결 방법</th></tr></thead><tbody><tr><td>상태 <code>401</code></td><td>Event Store에 다음이 설정되어 있습니다: <code>API_KEY</code>. 전송 <code>X-API-Key</code>.</td></tr><tr><td>테이블이 비어 있습니다</td><td>게이트웨이 호스트에서 다음을 실행합니다 <code>curl http://&#x3C;device-ip>:8001/health</code>. 실패하면 게이트웨이에서 장치에 연결할 수 없습니다.</td></tr><tr><td>데이터베이스에 새 행이 추가되지 않습니다</td><td>커서 태그를 확인하세요. 미래 시각이 저장되어 있다면 삭제하세요.</td></tr><tr><td>새 이벤트의 이미지가 로드되지 않습니다</td><td>운영자 컴퓨터에서 포트에 연결할 수 없습니다 <code>8001</code>, 또는 세션에서 HTTPS를 사용합니다. 자세한 내용은 다음을 참조하세요. <a href="https://docs.roboflow.com/workflows/ko/tutorials/integrate-with-ignition/live-video.md#perspective-over-https">HTTPS를 통한 Perspective</a>.</td></tr><tr><td>이전 이벤트의 이미지가 로드되지 않습니다</td><td>장치에서 이미지를 제거했습니다. 데이터베이스로 이벤트 복사 아래의 경고를 참조하세요.</td></tr></tbody></table>

## 관련 항목

* [라이브 비디오](https://docs.roboflow.com/workflows/ko/tutorials/integrate-with-ignition/live-video.md)
* [라이브 데이터](https://docs.roboflow.com/workflows/ko/tutorials/integrate-with-ignition/live-data.md)
