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_CN"}} · en_US · ja_JP · zh_TW · 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"]})