@dazitech/cli 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/clis/dazi-app.js +2 -2
- package/dist/clis/dazi-flow.js +2 -2
- package/dist/clis/dazi-onto.js +318 -40
- package/dist/clis/dazi.js +407 -185
- package/dist/docs/flow/flow-project-guide.md +1 -1
- package/dist/docs/guides/cli-reference.md +16 -3
- package/dist/docs/guides/troubleshooting.md +1 -1
- package/dist/docs/index.json +1 -13
- package/dist/docs/onto/dazi_script_sdk_reference.md +1 -1
- package/dist/docs/onto/dazi_script_seed_data_guide.md +1 -1
- package/dist/docs/onto/function-guide.md +6 -6
- package/dist/docs/onto//346/234/254/344/275/223/345/210/206/347/261/273/350/247/204/345/210/222/344/270/216SDK/346/211/251/345/261/225/346/226/271/346/241/210.md +169 -169
- package/dist/docs/onto//346/234/254/344/275/223/345/221/275/345/220/215/350/247/204/350/214/203_/347/211/251/347/220/206/350/241/250Cube/344/270/216/345/257/271/350/261/241.md +3 -2
- package/dist/docs/onto//346/234/254/344/275/223/345/274/200/345/217/221/344/274/230/345/214/226/346/200/273/347/273/223.md +257 -242
- package/dist/docs/onto//346/234/254/344/275/223/350/204/232/346/234/254/347/274/226/345/206/231/346/214/207/345/215/227.md +12 -12
- package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +14 -13
- package/dist/docs/onto//350/204/232/346/234/254/350/277/220/350/241/214/345/270/270/350/247/201/351/224/231/350/257/257/345/244/204/347/220/206.md +70 -15
- package/dist/examples/index.json +222 -6
- package/dist/examples/onto/README.md +34 -36
- package/dist/examples/onto/_templates/onto_preflight.ps1 +84 -0
- package/dist/examples/onto/index.json +53 -0
- package/dist/examples/onto/index.yaml +29 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/README.md +23 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +12 -11
- package/dist/{docs/onto → examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/plans}//350/247/204/345/210/222/347/244/272/344/276/213_/345/210/251/346/266/246/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +4 -4
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_category_mount.py +1 -1
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +1 -1
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/README.md +24 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_availability_analysis.py +84 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_downtime_breakdown.py +119 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_energy_intensity.py +98 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_get_summary.py +125 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_maintenance_compliance.py +77 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_mom_analysis.py +118 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_oee_analysis.py +126 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_plan_vs_actual.py +105 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_top_fault_equipment.py +104 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_unit_comparison.py +120 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_yoy_analysis.py +115 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/save_test_arguments.ps1 +42 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.availability_analysis.json +7 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.downtime_breakdown.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.energy_intensity.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.get_summary.json +7 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.maintenance_compliance.json +7 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.mom_analysis.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.oee_analysis.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.plan_vs_actual.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.top_fault_equipment.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.unit_comparison.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.yoy_analysis.json +8 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/plans//345/214/226/345/267/245/350/256/276/345/244/207/350/277/220/350/220/245/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +735 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/setup/equip_ops_category_mount.py +106 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/setup/equip_ops_ontology_init.py +1077 -0
- package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/setup/equip_ops_seed_data.py +552 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/README.md +23 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +13 -12
- package/dist/{docs/onto → examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/plans}//350/247/204/345/210/222/347/244/272/344/276/213_/344/272/247/345/223/201/351/224/200/345/224/256/346/234/254/344/275/223/350/247/204/345/210/222/346/226/271/346/241/210.md +2 -2
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_category_mount.py +1 -1
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +1 -1
- package/dist/prompts/index.json +1 -1
- package/dist/prompts/onto/planning-design.md +226 -104
- package/dist/prompts/onto/script-publish-run.md +8 -6
- package/package.json +1 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""同比分析 equip_ops.fn.yoy_analysis
|
|
2
|
+
|
|
3
|
+
参数:start_date, end_date, metric=oee|availability|output, plant_id(可选)
|
|
4
|
+
返回:current / previous / yoy 对比
|
|
5
|
+
|
|
6
|
+
发布:
|
|
7
|
+
dazi onto script publish 项目/DAZI_TEST/本体/ontos/设备运营/functions/equip_ops_fn_yoy_analysis.py \
|
|
8
|
+
--space space_cate_test01 --register-function-id equip_ops.fn.yoy_analysis
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from datetime import datetime, timedelta
|
|
12
|
+
|
|
13
|
+
TEST_ARGUMENTS = {
|
|
14
|
+
"v": 1,
|
|
15
|
+
"arguments": {
|
|
16
|
+
"start_date": "2025-01-01",
|
|
17
|
+
"end_date": "2026-06-30",
|
|
18
|
+
"metric": "oee",
|
|
19
|
+
},
|
|
20
|
+
"object_type_code": "EquipmentAnalysis",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _build_ops_where(start_date, end_date, plant_id=None):
|
|
25
|
+
clauses = []
|
|
26
|
+
if start_date and end_date:
|
|
27
|
+
clauses.append(f"calendar_date >= '{start_date}' AND calendar_date <= '{end_date}'")
|
|
28
|
+
if plant_id:
|
|
29
|
+
clauses.append(f"plant_id = '{plant_id}'")
|
|
30
|
+
return ("WHERE " + " AND ".join(clauses)) if clauses else ""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _query_period_metrics(p, start_date, end_date, plant_id):
|
|
34
|
+
where_clause = _build_ops_where(start_date, end_date, plant_id)
|
|
35
|
+
sql = f"""
|
|
36
|
+
SELECT
|
|
37
|
+
sum(runtime_min) AS sum_runtime_min,
|
|
38
|
+
sum(calendar_minutes - planned_downtime_min) AS sum_available_min,
|
|
39
|
+
sum(actual_output_qty) AS sum_actual_output,
|
|
40
|
+
sum(qualified_output_qty) AS sum_qualified_output,
|
|
41
|
+
sumIf(runtime_min * ideal_cycle_rate, runtime_min > 0) AS sum_theoretical_output
|
|
42
|
+
FROM fact_equipment_daily_ops
|
|
43
|
+
{where_clause}
|
|
44
|
+
"""
|
|
45
|
+
rows = p.sql.query(sql)
|
|
46
|
+
row = rows[0] if rows else {}
|
|
47
|
+
sum_runtime = float(row.get("sum_runtime_min") or 0)
|
|
48
|
+
sum_available = float(row.get("sum_available_min") or 0)
|
|
49
|
+
sum_actual = float(row.get("sum_actual_output") or 0)
|
|
50
|
+
sum_qualified = float(row.get("sum_qualified_output") or 0)
|
|
51
|
+
sum_theoretical = float(row.get("sum_theoretical_output") or 0)
|
|
52
|
+
availability = sum_runtime / sum_available if sum_available > 0 else 0.0
|
|
53
|
+
quality = sum_qualified / sum_actual if sum_actual > 0 else 0.0
|
|
54
|
+
performance = sum_actual / sum_theoretical if sum_theoretical > 0 else 0.0
|
|
55
|
+
oee = availability * performance * quality
|
|
56
|
+
return {
|
|
57
|
+
"oee": round(oee, 4),
|
|
58
|
+
"availability": round(availability, 4),
|
|
59
|
+
"output": round(sum_actual, 2),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _calc_yoy(current, previous):
|
|
64
|
+
if previous == 0:
|
|
65
|
+
return 0.0 if current == 0 else None
|
|
66
|
+
return round((current - previous) / previous, 4)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _ontology_fn_body(p):
|
|
70
|
+
params = dict(p.get_params() or {})
|
|
71
|
+
start_date = params.get("start_date") or "2025-01-01"
|
|
72
|
+
end_date = params.get("end_date") or "2026-06-30"
|
|
73
|
+
metric = params.get("metric", "oee")
|
|
74
|
+
plant_id = params.get("plant_id") or None
|
|
75
|
+
|
|
76
|
+
start_dt = datetime.strptime(start_date, "%Y-%m-%d")
|
|
77
|
+
end_dt = datetime.strptime(end_date, "%Y-%m-%d")
|
|
78
|
+
prev_start = (start_dt - timedelta(days=365)).strftime("%Y-%m-%d")
|
|
79
|
+
prev_end = (end_dt - timedelta(days=365)).strftime("%Y-%m-%d")
|
|
80
|
+
|
|
81
|
+
current_metrics = _query_period_metrics(p, start_date, end_date, plant_id)
|
|
82
|
+
previous_metrics = _query_period_metrics(p, prev_start, prev_end, plant_id)
|
|
83
|
+
|
|
84
|
+
current_value = current_metrics.get(metric, 0)
|
|
85
|
+
previous_value = previous_metrics.get(metric, 0)
|
|
86
|
+
yoy = _calc_yoy(current_value, previous_value)
|
|
87
|
+
|
|
88
|
+
result = {
|
|
89
|
+
"metric": metric,
|
|
90
|
+
"period": f"{start_date} ~ {end_date}",
|
|
91
|
+
"previous_period": f"{prev_start} ~ {prev_end}",
|
|
92
|
+
"current": current_value,
|
|
93
|
+
"previous": previous_value,
|
|
94
|
+
"yoy": yoy,
|
|
95
|
+
}
|
|
96
|
+
return p.function_result(
|
|
97
|
+
columns=["metric", "period", "previous_period", "current", "previous", "yoy"],
|
|
98
|
+
data=[result],
|
|
99
|
+
row_count=1,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def main():
|
|
104
|
+
s = space.get(ctx.space_id or "")
|
|
105
|
+
_Ports = type(
|
|
106
|
+
"_Ports",
|
|
107
|
+
(),
|
|
108
|
+
{
|
|
109
|
+
"get_params": lambda self: dict(ctx.params or {}),
|
|
110
|
+
"function_result": lambda self, **kw: onto.function_result(**kw),
|
|
111
|
+
},
|
|
112
|
+
)
|
|
113
|
+
p = _Ports()
|
|
114
|
+
p.sql = s.sql
|
|
115
|
+
return _ontology_fn_body(p)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# 批量保存各函数的 test_arguments
|
|
2
|
+
# 用法:在 dazi-work 根目录执行 .\项目\DAZI_TEST\本体\ontos\设备运营\functions\save_test_arguments.ps1
|
|
3
|
+
|
|
4
|
+
$spaceId = "space_cate_test01"
|
|
5
|
+
|
|
6
|
+
$functions = @(
|
|
7
|
+
@{ fn_id = "equip_ops.fn.get_summary"; file = "equip_ops.fn.get_summary.json" },
|
|
8
|
+
@{ fn_id = "equip_ops.fn.oee_analysis"; file = "equip_ops.fn.oee_analysis.json" },
|
|
9
|
+
@{ fn_id = "equip_ops.fn.availability_analysis"; file = "equip_ops.fn.availability_analysis.json" },
|
|
10
|
+
@{ fn_id = "equip_ops.fn.downtime_breakdown"; file = "equip_ops.fn.downtime_breakdown.json" },
|
|
11
|
+
@{ fn_id = "equip_ops.fn.yoy_analysis"; file = "equip_ops.fn.yoy_analysis.json" },
|
|
12
|
+
@{ fn_id = "equip_ops.fn.mom_analysis"; file = "equip_ops.fn.mom_analysis.json" },
|
|
13
|
+
@{ fn_id = "equip_ops.fn.top_fault_equipment"; file = "equip_ops.fn.top_fault_equipment.json" },
|
|
14
|
+
@{ fn_id = "equip_ops.fn.maintenance_compliance"; file = "equip_ops.fn.maintenance_compliance.json" },
|
|
15
|
+
@{ fn_id = "equip_ops.fn.energy_intensity"; file = "equip_ops.fn.energy_intensity.json" },
|
|
16
|
+
@{ fn_id = "equip_ops.fn.plan_vs_actual"; file = "equip_ops.fn.plan_vs_actual.json" },
|
|
17
|
+
@{ fn_id = "equip_ops.fn.unit_comparison"; file = "equip_ops.fn.unit_comparison.json" }
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
Write-Host "获取函数列表..."
|
|
21
|
+
$raw = (dazi onto function list --space $spaceId 2>&1) -join "`n"
|
|
22
|
+
$idx = $raw.IndexOf('__JSON_SUMMARY__')
|
|
23
|
+
if ($idx -lt 0) {
|
|
24
|
+
Write-Host "无法解析 function list 输出"
|
|
25
|
+
exit 1
|
|
26
|
+
}
|
|
27
|
+
$fnList = ($raw.Substring($idx + 16) | ConvertFrom-Json).data.functions
|
|
28
|
+
|
|
29
|
+
foreach ($fn in $functions) {
|
|
30
|
+
$fnId = $fn.fn_id
|
|
31
|
+
$jsonPath = Join-Path $PSScriptRoot "test_arguments/$($fn.file)"
|
|
32
|
+
$fnInfo = $fnList | Where-Object { $_.function_id -eq $fnId }
|
|
33
|
+
if ($fnInfo) {
|
|
34
|
+
$ofnId = $fnInfo.id
|
|
35
|
+
Write-Host "保存 $fnId (ofnId=$ofnId)..."
|
|
36
|
+
& dazi onto function save-test-arguments $ofnId --space $spaceId --arguments-json-file $jsonPath
|
|
37
|
+
} else {
|
|
38
|
+
Write-Host "函数 $fnId 未找到,请先 publish"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Write-Host "完成"
|