ProEye-X API
วิธีอ่านและเขียนข้อมูลการวิเคราะห์งานในอินสแตนซ์เฉพาะของบริษัท (https://บริษัท.proeye-x.com) จากระบบภายนอก เช่น MES, ERP, BI ทุกการเรียกใช้ JSON-RPC 2.0 ส่งแบบ POST ไปที่ /jsonrpc เพียงที่เดียว
เริ่มต้นใช้งาน
ที่อยู่สำหรับเรียก
ที่อยู่แตกต่างกันในแต่ละอินสแตนซ์ของบริษัท ชื่อฐานข้อมูลตรงกับส่วนหน้าของที่อยู่บริษัท (บริษัท)
POST https://company.proeye-x.com/jsonrpc
สร้าง API key
เข้าสู่ระบบอินสแตนซ์ → เมนูผู้ใช้ (มุมขวาบน) › โปรไฟล์ของฉัน (การตั้งค่า) › ความปลอดภัยของบัญชี › “API key ใหม่” ใช้คีย์แทนรหัสผ่าน และจะแสดงเพียงครั้งเดียว เก็บคีย์ไว้ในโปรแกรมฝั่งเซิร์ฟเวอร์เท่านั้น อย่าใส่ในโค้ดเบราว์เซอร์
ยืนยันตัวตน (รับ uid)
ใช้อีเมลเข้าสู่ระบบและ API key เพื่อรับหมายเลขผู้ใช้ (uid) จากนั้นส่งฐานข้อมูล uid และ API key ไปกับทุกการเรียก
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() นี้
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 {})ภาษา
ระบุ lang ใน context เพื่อรับชื่องานและชื่อองค์ประกอบเป็นภาษานั้น (เมื่อมีคำแปล) ตัวอย่าง: {"context": {"lang": "th_TH"}} · en_US · ja_JP · zh_CN · zh_TW · vi_VN · 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. รายการการวิเคราะห์
ดึงรายการการวิเคราะห์งาน (เซสชัน) พร้อมเวลารอบเฉลี่ย อัตรา VA และจำนวนองค์ประกอบ
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 -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. ดึงองค์ประกอบงาน
ดึงองค์ประกอบงานของการวิเคราะห์หนึ่งรายการตามรอบ: เวลาเริ่ม/สิ้นสุด (วินาที) เวลามาตรฐาน เวลา VA และ NVA cycle_no คือรอบที่องค์ประกอบงานนั้นอยู่ (1, 2, 3 …)
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
ดึงข้อมูลที่กรอกในแท็บ LOSS สำหรับทุกช่วง NVA ขององค์ประกอบงาน (รายการ segment_data ที่ type = nva) เนื้อหา LOSS (loss_data) และรหัสประเภทความสูญเปล่า (loss_type_data) ถูกเก็บเป็นอาร์เรย์ JSON ตามลำดับเดียวกัน จับคู่ตามตัวอย่างด้านล่างเพื่อได้แถว รอบ · องค์ประกอบงาน · เวลาช่วง · ประเภทความสูญเปล่า · เนื้อหา LOSS
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 defects4. สร้างการวิเคราะห์
สร้างการวิเคราะห์งานใหม่ ต้องระบุ O-No (หมายเลขเฉพาะ) และห้ามซ้ำ คืนค่า ID ใหม่
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. เพิ่มองค์ประกอบงาน
เพิ่มองค์ประกอบหลายรายการพร้อมกันตามช่วงเวลาวิดีโอ ผลรวม เช่น เวลารอบและอัตรา VA คำนวณใหม่อัตโนมัติ
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. แก้ไข / ลบองค์ประกอบ
เปลี่ยนชื่อ เวลา หรือประเภทงาน (write) หรือลบ (unlink)
model("wa.element", "write", [[205], {"name": "Pick and place", "video_end_time": 4.6}])
model("wa.element", "unlink", [[206]])true true
7. บันทึก LOSS
เขียนเนื้อหา LOSS และรหัสประเภทความสูญเปล่าของแต่ละช่วง NVA เป็นอาร์เรย์ JSON ตามลำดับเวลา ค่าลำดับที่ n เป็นของช่วง NVA ลำดับที่ n รหัส: w1 ผลิตมากเกิน · w2 รอคอย · w3 ขนย้าย · w4 กระบวนการเกินจำเป็น · w5 สินค้าคงคลัง · w6 การเคลื่อนไหว · w7 ของเสีย
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. ดึงรอบการทำงาน
ดึงรอบที่วัดแล้วพร้อมเวลาเริ่ม สิ้นสุด และเวลารอบ
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. การเปรียบเทียบ (ก่อน / หลัง)
จับคู่การวิเคราะห์สองรายการเป็นการเปรียบเทียบ สร้างแถวเปรียบเทียบ แล้วดึงการลดเวลารอบ การปรับปรุง VA และความต่างรายองค์ประกอบ
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. การจัดสมดุลสายการผลิต
ดึง takt time ประสิทธิภาพสายการผลิต กระบวนการคอขวด และเวลารอบกับภาระของแต่ละกระบวนการ
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
ดึงแผนภูมิคน-เครื่องจักร (MMC) และแผนภูมิหลายกิจกรรม (MAC) พร้อมโครงสร้างเวลาและอัตราการใช้งาน
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"]})