ProEye-X API

從 MES、ERP、BI 等外部系統讀寫企業專屬實例(https://公司.proeye-x.com)中的作業分析資料。所有呼叫皆使用 JSON-RPC 2.0,以 POST 方式傳送至 /jsonrpc。

開始使用

呼叫位址

每個企業實例的位址不同。資料庫名稱與企業位址的前綴(公司)相同。

POST https://company.proeye-x.com/jsonrpc

建立 API 金鑰

登入實例 → 右上角使用者選單 › 我的個人資料(偏好設定)› 帳戶安全 ›「新增 API 金鑰」。金鑰取代密碼使用,僅在建立時顯示一次。請只在伺服器端程式中保存金鑰,不要放入瀏覽器程式碼。

驗證(取得 uid)

以登入電子郵件與 API 金鑰換取使用者編號(uid),之後每次呼叫都一併傳送資料庫、uid 與 API 金鑰。

curl
curl -s https://company.proeye-x.com/jsonrpc \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "call", "params": {
        "service": "common", "method": "authenticate",
        "args": ["company", "you@company.com", "YOUR_API_KEY", {}]}}'

# → {"jsonrpc": "2.0", "id": null, "result": 7}      (7 = uid)

Python 輔助函式

以下範例使用此輔助函式 model()。

Python
import requests

URL = "https://company.proeye-x.com/jsonrpc"
DB, LOGIN, KEY = "company", "you@company.com", "YOUR_API_KEY"

def call(service, method, *args):
    r = requests.post(URL, json={"jsonrpc": "2.0", "method": "call",
                                 "params": {"service": service, "method": method, "args": args}}, timeout=30)
    r.raise_for_status()
    body = r.json()
    if body.get("error"):
        raise RuntimeError(body["error"]["data"]["message"])
    return body.get("result")          # no "result" key when the method returns nothing

UID = call("common", "authenticate", DB, LOGIN, KEY, {})

def model(name, method, args, kw=None):
    return call("object", "execute_kw", DB, UID, KEY, name, method, args, kw or {})

語言

在 context 指定 lang,作業名稱與要素作業名稱會以該語言回傳(若有翻譯)。例:{"context": {"lang": "zh_TW"}} · en_US · ja_JP · zh_CN · vi_VN · th_TH · id_ID · es_ES · de_DE · ko_KR。

錯誤

失敗時回傳 HTTP 200 與 "error" 物件,error.data.message 說明原因(無權限、缺少必填欄位等)。

API 列表

element_type 是作業類型欄位的鍵(va = 1 號、nva = 2 號、wait = 3 號,自訂欄位為 c4 …)。VA/NVA 時間依 segment_data 區間計算。

1. 作業分析列表

模型 · wa.session方法 · search_read

取得作業分析(工作階段)列表及平均 CT、VA 率、要素作業數量。

Python
rows = model("wa.session", "search_read", [[]], {
    "fields": ["o_no", "name", "process_name", "cycle_time_avg", "va_ratio", "element_count"],
    "order": "date desc", "limit": 20,
    "context": {"lang": "en_US"},       # names in English (optional)
})
curl
curl -s https://company.proeye-x.com/jsonrpc -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0", "method": "call", "params": {"service": "object", "method": "execute_kw",
  "args": ["company", 7, "YOUR_API_KEY", "wa.session", "search_read", [[]],
           {"fields": ["o_no", "name", "cycle_time_avg", "va_ratio"], "limit": 20}]}}'
回應範例
[{"id": 6, "o_no": "O-ENG-NOVICE-01", "name": "Engine Assembly - Novice",
  "process_name": "Engine Assembly Work", "cycle_time_avg": 165.33, "va_ratio": 63.7, "element_count": 14}]

2. 查詢要素作業

模型 · wa.element方法 · search_read

依週期取得某個作業分析的要素作業,包含開始/結束時間(秒)、標準時間、VA 與 NVA 時間。 cycle_no 表示該要素作業屬於第幾個週期(1, 2, 3 …)。

Python
elements = model("wa.element", "search_read",
    [[["session_id", "=", 6], ["cycle_no", "=", 1]]],
    {"fields": ["cycle_no", "sequence", "name", "element_type", "video_start_time", "video_end_time",
                "standard_time", "va_time", "nva_time"], "order": "cycle_no, sequence"})
# every cycle: drop the ["cycle_no", "=", 1] condition — cycle_no tells which cycle each element belongs to
回應範例
[{"id": 70, "cycle_no": 1, "sequence": 1, "name": "Fetch the tools and prepare.", "element_type": "wait",
  "video_start_time": 189.656, "video_end_time": 198.398, "standard_time": 8.742,
  "va_time": 4.104, "nva_time": 4.638}, ...]

3. 查詢 LOSS

模型 · wa.element方法 · search_read (LOSS)

取得在 LOSS 分頁中輸入的內容。要素作業的每個 NVA 區間(segment_data 中 type = nva)對應的 LOSS 內容(loss_data)與浪費類型代碼(loss_type_data)依相同順序存成 JSON 陣列,依下例配對即可得到 週期 · 要素作業 · 區間時間 · 浪費類型 · LOSS 內容 的列。

Python
import json

rows = model("wa.element", "search_read", [[["session_id", "=", session_id]]],
             {"fields": ["cycle_no", "sequence", "name", "segment_data", "loss_data", "loss_type_data"],
              "order": "cycle_no, sequence"})
losses = []
for e in rows:
    nva = [s for s in json.loads(e["segment_data"] or "[]") if s["type"] == "nva"]
    notes = json.loads(e["loss_data"] or "[]")          # LOSS text, one per NVA segment
    types = json.loads(e["loss_type_data"] or "[]")     # waste type code, one per NVA segment
    for i, seg in enumerate(nva):
        losses.append({"cycle_no": e["cycle_no"], "element": e["name"],
                       "start": seg["start"], "end": seg["end"], "dur": seg["dur"],
                       "loss_type": types[i] if i < len(types) else "",
                       "loss": notes[i] if i < len(notes) else ""})
回應範例
# rows (raw)
[{"id": 207, "cycle_no": 1, "sequence": 1, "name": "Fasten bolt",
  "segment_data": "[{\"type\": \"va\", \"start\": 4.2, \"end\": 7.0, \"dur\": 2.8}, {\"type\": \"nva\", \"start\": 7.0, ...}]",
  "loss_data": "[\"Searching for the wrench\", \"Waiting for the jig\"]",
  "loss_type_data": "[\"w6\", \"w2\"]"}]

# losses
[{"cycle_no": 1, "element": "Fasten bolt", "start": 7.0, "end": 9.1, "dur": 2.1, "loss_type": "w6", "loss": "Searching for the wrench"},
 {"cycle_no": 1, "element": "Fasten bolt", "start": 11.0, "end": 12.6, "dur": 1.6, "loss_type": "w2", "loss": "Waiting for the jig"}]

# loss_type: w1 overproduction · w2 waiting · w3 transport · w4 over-processing · w5 inventory · w6 motion · w7 defects

4. 建立作業分析

模型 · wa.session方法 · create

建立新的作業分析。O-No(唯一編號)為必填且不可重複。回傳新的 ID。

Python
session_id = model("wa.session", "create", [{
    "o_no": "O-2026-LINE3-01",          # required, unique
    "name": "Line 3 sub-assembly",
    "process_name": "Sub-assembly",
}])
回應範例
21

5. 新增要素作業

模型 · wa.element方法 · create

依影片時間區間一次新增多個要素作業。CT、VA 率等彙總會自動重新計算。

Python
ids = model("wa.element", "create", [[
    {"session_id": session_id, "cycle_no": 1, "sequence": 1, "name": "Pick part",
     "element_type": "va", "video_start_time": 0.0, "video_end_time": 4.2},
    {"session_id": session_id, "cycle_no": 1, "sequence": 2, "name": "Fasten bolt",
     "element_type": "va", "video_start_time": 4.2, "video_end_time": 9.8},
]])
summary = model("wa.session", "read", [[session_id]],
                {"fields": ["element_count", "cycle_time_avg", "va_ratio"]})
回應範例
[205, 206]
[{"id": 18, "element_count": 2, "cycle_time_avg": 9.8, "va_ratio": 100.0}]

6. 修改 / 刪除要素作業

模型 · wa.element方法 · write / unlink

修改名稱、時間或作業類型(write),或刪除(unlink)。

Python
model("wa.element", "write", [[205], {"name": "Pick and place", "video_end_time": 4.6}])
model("wa.element", "unlink", [[206]])
回應範例
true
true

7. 輸入 LOSS

模型 · wa.element方法 · write (LOSS)

依時間順序以 JSON 陣列寫入每個 NVA 區間的 LOSS 內容與浪費類型代碼,陣列第 n 個值對應第 n 個 NVA 區間。代碼:w1 過量生產 · w2 等待 · w3 搬運 · w4 過度加工 · w5 庫存 · w6 動作 · w7 不良。

Python
import json

# element with NVA segments 7.0–9.1 s and 11.0–12.6 s → one entry per NVA segment, in time order
model("wa.element", "write", [[207], {
    "loss_data": json.dumps(["Searching for the wrench", "Waiting for the jig"]),
    "loss_type_data": json.dumps(["w6", "w2"]),
}])
回應範例
true

8. 查詢週期

模型 · wa.cycle方法 · search_read

取得已量測週期的開始、結束時間與週期時間。

Python
cycles = model("wa.cycle", "search_read", [[["session_id", "=", 4]]],
               {"fields": ["sequence", "video_start", "video_end", "cycle_time"], "order": "sequence"})
回應範例
[{"id": 4, "sequence": 1, "video_start": 0.767, "video_end": 17.15, "cycle_time": 16.383}, ...]

9. 對比分析(改善前 / 後)

模型 · wa.comparison方法 · create · action_build_lines · read

將兩個作業分析組成對比分析並產生對比列,取得 CT 縮短、VA 改善及各要素作業的差異。

Python
cid = model("wa.comparison", "create", [{
    "name": "Line 1 before / after", "session_a_id": 7, "session_b_id": 11}])
model("wa.comparison", "action_build_lines", [[cid]])
result = model("wa.comparison", "read", [[cid]],
               {"fields": ["ct_a", "ct_b", "ct_reduction", "ct_reduction_pct", "va_improvement"]})
lines = model("wa.comparison.line", "search_read", [[["comparison_id", "=", cid]]],
              {"fields": ["sequence", "step_name", "time_a", "time_b", "time_diff"], "order": "sequence"})
回應範例
[{"id": 3, "ct_a": 22.72, "ct_b": 23.39, "ct_reduction": -0.67, "ct_reduction_pct": -2.9, "va_improvement": -6.4}]
[{"id": 49, "sequence": 1, "step_name": "UP", "time_a": 2.85, "time_b": 2.723, "time_diff": -0.127}, ...]

10. 產線平衡

模型 · wa.linebalance · wa.lb.process方法 · search_read

取得節拍時間、產線效率、瓶頸工序及各工序的週期時間與負荷率。

Python
lines = model("wa.linebalance", "search_read", [[]],
              {"fields": ["name", "takt_time", "lb_efficiency", "bottleneck_name", "max_ct"]})
processes = model("wa.lb.process", "search_read", [[["lb_id", "=", lines[0]["id"]]]],
                  {"fields": ["sequence", "process_name", "cycle_time", "load_ratio", "over_takt"],
                   "order": "sequence"})
回應範例
[{"id": 1, "name": "LB_Robot Assembly Line MAC Analysis", "takt_time": 27.74,
  "lb_efficiency": 90.0, "bottleneck_name": "Robot Assembly Line (After Improvement)", "max_ct": 27.74}]
[{"id": 1, "sequence": 10, "process_name": "Robot Assembly Line (After Improvement)",
  "cycle_time": 23.39, "load_ratio": 84.3, "over_takt": false}, ...]

11. MMC · MAC

模型 · wa.mmc · wa.mac方法 · search_read

取得人機分析(MMC)與多作業分析(MAC)的時間構成與稼動率。

Python
mmc = model("wa.mmc", "search_read", [[]],
            {"fields": ["name", "total_time", "machine_time", "walk_time", "wait_time", "load_ratio"]})
mac = model("wa.mac", "search_read", [[]],
            {"fields": ["name", "process_count", "takt_time", "avg_ct", "utilization", "balance_eff"]})
回應範例
[{"id": 1, "name": "Engine Assembly Line", "total_time": 165.33, "machine_time": 0.0,
  "walk_time": 0.0, "wait_time": 0.0, "load_ratio": 100.0}]
[{"id": 1, "name": "Robot Assembly Line MAC Analysis", "process_count": 4, "takt_time": 0.0,
  "avg_ct": 24.97, "utilization": 0.0, "balance_eff": 90.0}]

以 fields_get 查看全部欄位:model("wa.session", "fields_get", [], {"attributes": ["string", "type"]})