@dazitech/cli 3.0.7 → 3.0.8
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 +1 -1
- package/dist/clis/dazi-flow.js +1 -1
- package/dist/clis/dazi-onto.js +73 -22
- package/dist/clis/dazi.js +266 -171
- package/dist/docs/flow/flow-project-guide.md +1 -1
- package/dist/docs/guides/quickstart.md +18 -4
- package/dist/docs/guides/troubleshooting.md +1 -1
- package/dist/docs/guides/workspace-v3.md +43 -23
- package/dist/docs/index.json +9 -3
- package/dist/docs/onto/action-guide.md +3 -3
- package/dist/docs/onto/dazi_script_sdk_reference.md +178 -174
- package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
- package/dist/docs/onto/function-guide.md +37 -10
- package/dist/docs/onto/space-management.md +3 -1
- 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 +138 -34
- package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +73 -31
- package/dist/docs/onto//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 +497 -0
- package/dist/docs/onto//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 +597 -541
- package/dist/examples/index.json +202 -22
- package/dist/examples/onto/README.md +43 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +99 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +116 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +85 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +76 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +86 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +103 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +86 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +27 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +10 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.budget_vs_actual.json +10 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.cost_center_profit.json +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +11 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +9 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +521 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +213 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +25 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +86 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +123 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +81 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +90 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +85 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +101 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +90 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +25 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +10 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +10 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +8 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +5 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +403 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +124 -0
- package/dist/prompts/index.json +2 -2
- package/dist/prompts/onto/action-design.md +4 -1
- package/dist/prompts/onto/function-design.md +9 -2
- package/dist/prompts/onto/rule-seed.md +5 -1
- package/dist/prompts/onto/script-publish-run.md +72 -24
- package/package.json +1 -1
- package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
- package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
- package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
- package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
- package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
"""Profit Analysis Ontology Initialization Script for space__profit0520
|
|
2
|
-
|
|
3
|
-
初始化内容:
|
|
4
|
-
1. 创建物理表(3张)
|
|
5
|
-
2. 注册Cube(4个)
|
|
6
|
-
3. 定义对象类型(4种)
|
|
7
|
-
4. 绑定数据源
|
|
8
|
-
5. 定义属性(25个)
|
|
9
|
-
6. 定义链接类型(6种)
|
|
10
|
-
7. 同步指标引用
|
|
11
|
-
|
|
12
|
-
参考示例:资源/examples/onto/setup/profit_ontology_init.py(开发请复制到 项目/onto_<名>/脚本/)
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
import json
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def main():
|
|
19
|
-
space_id = "space__profit0520"
|
|
20
|
-
s = space.get(space_id)
|
|
21
|
-
|
|
22
|
-
output.print("=== Start Profit Analysis Ontology Initialization ===")
|
|
23
|
-
output.print(f"Space: {space_id}")
|
|
24
|
-
|
|
25
|
-
# 1. 创建物理表
|
|
26
|
-
output.print("\n[1/7] Creating physical tables...")
|
|
27
|
-
|
|
28
|
-
# 1.1 利润分析事实表
|
|
29
|
-
s.sql.execute("""
|
|
30
|
-
CREATE TABLE IF NOT EXISTS profit_analysis_fact (
|
|
31
|
-
order_id String,
|
|
32
|
-
product_id String,
|
|
33
|
-
customer_id String,
|
|
34
|
-
order_date Date,
|
|
35
|
-
product_category String,
|
|
36
|
-
customer_region String,
|
|
37
|
-
customer_type String,
|
|
38
|
-
quantity Int32,
|
|
39
|
-
unit_price Float64,
|
|
40
|
-
revenue Float64,
|
|
41
|
-
cost Float64
|
|
42
|
-
) ENGINE = MergeTree()
|
|
43
|
-
ORDER BY (order_date, order_id)
|
|
44
|
-
""")
|
|
45
|
-
output.print("OK profit_analysis_fact")
|
|
46
|
-
|
|
47
|
-
# 1.2 产品维度表
|
|
48
|
-
s.sql.execute("""
|
|
49
|
-
CREATE TABLE IF NOT EXISTS product_dimension (
|
|
50
|
-
product_id String,
|
|
51
|
-
product_name String,
|
|
52
|
-
product_category String,
|
|
53
|
-
cost_price Float64,
|
|
54
|
-
margin_ratio Float64,
|
|
55
|
-
created_at DateTime DEFAULT now()
|
|
56
|
-
) ENGINE = MergeTree()
|
|
57
|
-
ORDER BY (product_id)
|
|
58
|
-
""")
|
|
59
|
-
output.print("OK product_dimension")
|
|
60
|
-
|
|
61
|
-
# 1.3 客户维度表
|
|
62
|
-
s.sql.execute("""
|
|
63
|
-
CREATE TABLE IF NOT EXISTS customer_dimension (
|
|
64
|
-
customer_id String,
|
|
65
|
-
customer_name String,
|
|
66
|
-
customer_region String,
|
|
67
|
-
customer_type String,
|
|
68
|
-
credit_level String,
|
|
69
|
-
created_at DateTime DEFAULT now()
|
|
70
|
-
) ENGINE = MergeTree()
|
|
71
|
-
ORDER BY (customer_id)
|
|
72
|
-
""")
|
|
73
|
-
output.print("OK customer_dimension")
|
|
74
|
-
|
|
75
|
-
# 2. 注册表到空间
|
|
76
|
-
output.print("\n[2/7] Registering tables to space...")
|
|
77
|
-
|
|
78
|
-
s.tables.register("profit_analysis_fact", label="利润分析事实表")
|
|
79
|
-
s.tables.sync_columns("profit_analysis_fact")
|
|
80
|
-
output.print("OK profit_analysis_fact registered")
|
|
81
|
-
|
|
82
|
-
s.tables.register("product_dimension", label="产品维度表")
|
|
83
|
-
s.tables.sync_columns("product_dimension")
|
|
84
|
-
output.print("OK product_dimension registered")
|
|
85
|
-
|
|
86
|
-
s.tables.register("customer_dimension", label="客户维度表")
|
|
87
|
-
s.tables.sync_columns("customer_dimension")
|
|
88
|
-
output.print("OK customer_dimension registered")
|
|
89
|
-
|
|
90
|
-
# 3. 注册Cube
|
|
91
|
-
output.print("\n[3/7] Registering Cubes...")
|
|
92
|
-
|
|
93
|
-
# 3.1 ProfitCube
|
|
94
|
-
s.register_cube(
|
|
95
|
-
name="ProfitCube",
|
|
96
|
-
table="profit_analysis_fact",
|
|
97
|
-
title="利润分析主Cube",
|
|
98
|
-
measures=[
|
|
99
|
-
{"name": "quantity", "col": "quantity", "agg": "sum", "title": "销售数量"},
|
|
100
|
-
{"name": "revenue", "col": "revenue", "agg": "sum", "title": "收入"},
|
|
101
|
-
{"name": "cost", "col": "cost", "agg": "sum", "title": "成本"},
|
|
102
|
-
{"name": "order_count", "col": "order_id", "agg": "uniq", "title": "订单数量"},
|
|
103
|
-
],
|
|
104
|
-
dimensions=[
|
|
105
|
-
{"name": "order_id", "col": "order_id", "type": "string", "title": "订单ID"},
|
|
106
|
-
{"name": "order_date", "col": "order_date", "type": "date", "title": "订单日期"},
|
|
107
|
-
{"name": "product_id", "col": "product_id", "type": "string", "title": "产品ID"},
|
|
108
|
-
{"name": "product_category", "col": "product_category", "type": "string", "title": "产品类别"},
|
|
109
|
-
{"name": "customer_id", "col": "customer_id", "type": "string", "title": "客户ID"},
|
|
110
|
-
{"name": "customer_region", "col": "customer_region", "type": "string", "title": "客户区域"},
|
|
111
|
-
{"name": "customer_type", "col": "customer_type", "type": "string", "title": "客户类型"},
|
|
112
|
-
],
|
|
113
|
-
)
|
|
114
|
-
output.print("OK ProfitCube registered")
|
|
115
|
-
|
|
116
|
-
# 3.2 ProductCube
|
|
117
|
-
s.register_cube(
|
|
118
|
-
name="ProductCube",
|
|
119
|
-
table="profit_analysis_fact",
|
|
120
|
-
title="产品分析Cube",
|
|
121
|
-
measures=[
|
|
122
|
-
{"name": "revenue", "col": "revenue", "agg": "sum", "title": "收入"},
|
|
123
|
-
{"name": "cost", "col": "cost", "agg": "sum", "title": "成本"},
|
|
124
|
-
{"name": "order_count", "col": "order_id", "agg": "uniq", "title": "订单数量"},
|
|
125
|
-
],
|
|
126
|
-
dimensions=[
|
|
127
|
-
{"name": "product_id", "col": "product_id", "type": "string", "title": "产品ID"},
|
|
128
|
-
{"name": "product_category", "col": "product_category", "type": "string", "title": "产品类别"},
|
|
129
|
-
],
|
|
130
|
-
)
|
|
131
|
-
output.print("OK ProductCube registered")
|
|
132
|
-
|
|
133
|
-
# 3.3 CustomerCube
|
|
134
|
-
s.register_cube(
|
|
135
|
-
name="CustomerCube",
|
|
136
|
-
table="profit_analysis_fact",
|
|
137
|
-
title="客户分析Cube",
|
|
138
|
-
measures=[
|
|
139
|
-
{"name": "revenue", "col": "revenue", "agg": "sum", "title": "收入"},
|
|
140
|
-
{"name": "cost", "col": "cost", "agg": "sum", "title": "成本"},
|
|
141
|
-
{"name": "order_count", "col": "order_id", "agg": "uniq", "title": "订单数量"},
|
|
142
|
-
],
|
|
143
|
-
dimensions=[
|
|
144
|
-
{"name": "customer_id", "col": "customer_id", "type": "string", "title": "客户ID"},
|
|
145
|
-
{"name": "customer_region", "col": "customer_region", "type": "string", "title": "客户区域"},
|
|
146
|
-
{"name": "customer_type", "col": "customer_type", "type": "string", "title": "客户类型"},
|
|
147
|
-
],
|
|
148
|
-
)
|
|
149
|
-
output.print("OK CustomerCube registered")
|
|
150
|
-
|
|
151
|
-
# 3.4 TimeCube
|
|
152
|
-
s.register_cube(
|
|
153
|
-
name="TimeCube",
|
|
154
|
-
table="profit_analysis_fact",
|
|
155
|
-
title="时间维度Cube",
|
|
156
|
-
measures=[
|
|
157
|
-
{"name": "revenue", "col": "revenue", "agg": "sum", "title": "收入"},
|
|
158
|
-
{"name": "cost", "col": "cost", "agg": "sum", "title": "成本"},
|
|
159
|
-
],
|
|
160
|
-
dimensions=[
|
|
161
|
-
{"name": "year", "col": "order_date", "type": "date", "title": "年份"},
|
|
162
|
-
{"name": "year_month", "col": "order_date", "type": "string", "title": "年月"},
|
|
163
|
-
{"name": "quarter", "col": "order_date", "type": "string", "title": "季度"},
|
|
164
|
-
],
|
|
165
|
-
)
|
|
166
|
-
output.print("OK TimeCube registered")
|
|
167
|
-
|
|
168
|
-
# 4. 添加派生度量
|
|
169
|
-
output.print("\n[4/7] Adding derived measures...")
|
|
170
|
-
|
|
171
|
-
# ProfitCube派生度量
|
|
172
|
-
s.upsert_derived_measures(
|
|
173
|
-
"ProfitCube",
|
|
174
|
-
[
|
|
175
|
-
{
|
|
176
|
-
"name": "profit",
|
|
177
|
-
"title": "利润",
|
|
178
|
-
"expression": "ProfitCube.revenue - ProfitCube.cost",
|
|
179
|
-
"description": "利润(收入-成本)"
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
"name": "profit_margin",
|
|
183
|
-
"title": "利润率",
|
|
184
|
-
"expression": "if(ProfitCube.revenue > 0, ProfitCube.profit / ProfitCube.revenue, 0)",
|
|
185
|
-
"description": "利润率"
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
)
|
|
189
|
-
output.print("OK ProfitCube derived measures")
|
|
190
|
-
|
|
191
|
-
# ProductCube派生度量
|
|
192
|
-
s.upsert_derived_measures(
|
|
193
|
-
"ProductCube",
|
|
194
|
-
[
|
|
195
|
-
{
|
|
196
|
-
"name": "profit",
|
|
197
|
-
"title": "利润",
|
|
198
|
-
"expression": "ProductCube.revenue - ProductCube.cost",
|
|
199
|
-
"description": "利润(收入-成本)"
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
"name": "profit_margin",
|
|
203
|
-
"title": "利润率",
|
|
204
|
-
"expression": "if(ProductCube.revenue > 0, ProductCube.profit / ProductCube.revenue, 0)",
|
|
205
|
-
"description": "利润率"
|
|
206
|
-
}
|
|
207
|
-
]
|
|
208
|
-
)
|
|
209
|
-
output.print("OK ProductCube derived measures")
|
|
210
|
-
|
|
211
|
-
# CustomerCube派生度量
|
|
212
|
-
s.upsert_derived_measures(
|
|
213
|
-
"CustomerCube",
|
|
214
|
-
[
|
|
215
|
-
{
|
|
216
|
-
"name": "profit",
|
|
217
|
-
"title": "利润",
|
|
218
|
-
"expression": "CustomerCube.revenue - CustomerCube.cost",
|
|
219
|
-
"description": "利润(收入-成本)"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
"name": "profit_margin",
|
|
223
|
-
"title": "利润率",
|
|
224
|
-
"expression": "if(CustomerCube.revenue > 0, CustomerCube.profit / CustomerCube.revenue, 0)",
|
|
225
|
-
"description": "利润率"
|
|
226
|
-
}
|
|
227
|
-
]
|
|
228
|
-
)
|
|
229
|
-
output.print("OK CustomerCube derived measures")
|
|
230
|
-
|
|
231
|
-
# TimeCube派生度量
|
|
232
|
-
s.upsert_derived_measures(
|
|
233
|
-
"TimeCube",
|
|
234
|
-
[
|
|
235
|
-
{
|
|
236
|
-
"name": "profit",
|
|
237
|
-
"title": "利润",
|
|
238
|
-
"expression": "TimeCube.revenue - TimeCube.cost",
|
|
239
|
-
"description": "利润(收入-成本)"
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
"name": "profit_margin",
|
|
243
|
-
"title": "利润率",
|
|
244
|
-
"expression": "if(TimeCube.revenue > 0, TimeCube.profit / TimeCube.revenue, 0)",
|
|
245
|
-
"description": "利润率"
|
|
246
|
-
}
|
|
247
|
-
]
|
|
248
|
-
)
|
|
249
|
-
output.print("OK TimeCube derived measures")
|
|
250
|
-
|
|
251
|
-
# 5. 定义对象类型
|
|
252
|
-
output.print("\n[5/7] Defining object types...")
|
|
253
|
-
|
|
254
|
-
object_types = [
|
|
255
|
-
("Order", "订单", "订单业务对象"),
|
|
256
|
-
("Product", "产品", "产品业务对象"),
|
|
257
|
-
("Customer", "客户", "客户业务对象"),
|
|
258
|
-
("ProfitAnalysis", "利润分析", "利润聚合对象"),
|
|
259
|
-
]
|
|
260
|
-
|
|
261
|
-
for code, name, desc in object_types:
|
|
262
|
-
s.onto.define_object_type(code, name, description=desc)
|
|
263
|
-
output.print(f"OK {code}")
|
|
264
|
-
|
|
265
|
-
# 6. 绑定数据源
|
|
266
|
-
output.print("\n[6/7] Binding data sources...")
|
|
267
|
-
|
|
268
|
-
s.onto.bind_source("Order", "dazi_cube", config={"cube": "ProfitCube"})
|
|
269
|
-
output.print("OK Order -> ProfitCube")
|
|
270
|
-
|
|
271
|
-
s.onto.bind_source("Product", "dazi_cube", config={"cube": "ProductCube"})
|
|
272
|
-
output.print("OK Product -> ProductCube")
|
|
273
|
-
|
|
274
|
-
s.onto.bind_source("Customer", "dazi_cube", config={"cube": "CustomerCube"})
|
|
275
|
-
output.print("OK Customer -> CustomerCube")
|
|
276
|
-
|
|
277
|
-
s.onto.bind_source("ProfitAnalysis", "dazi_cube", config={"cube": "ProfitCube"})
|
|
278
|
-
output.print("OK ProfitAnalysis -> ProfitCube")
|
|
279
|
-
|
|
280
|
-
# 7. 定义属性
|
|
281
|
-
output.print("\n[7/7] Defining properties...")
|
|
282
|
-
|
|
283
|
-
# Order属性
|
|
284
|
-
order_props = [
|
|
285
|
-
("id", "订单ID", "dimension", "ProfitCube.order_id"),
|
|
286
|
-
("date", "订单日期", "dimension", "ProfitCube.order_date"),
|
|
287
|
-
("quantity", "销售数量", "measure", "ProfitCube.quantity"),
|
|
288
|
-
("revenue", "收入", "measure", "ProfitCube.revenue"),
|
|
289
|
-
("cost", "成本", "measure", "ProfitCube.cost"),
|
|
290
|
-
("profit", "利润", "measure", "ProfitCube.profit"),
|
|
291
|
-
("profit_margin", "利润率", "measure", "ProfitCube.profit_margin"),
|
|
292
|
-
]
|
|
293
|
-
for code, name, role, qn in order_props:
|
|
294
|
-
s.onto.define_property("Order", code, name, semantic_role=role, qualified_name=qn)
|
|
295
|
-
output.print("OK Order properties (7)")
|
|
296
|
-
|
|
297
|
-
# Product属性
|
|
298
|
-
product_props = [
|
|
299
|
-
("id", "产品ID", "dimension", "ProductCube.product_id"),
|
|
300
|
-
("category", "产品类别", "dimension", "ProductCube.product_category"),
|
|
301
|
-
("revenue", "累计收入", "measure", "ProductCube.revenue"),
|
|
302
|
-
("cost", "累计成本", "measure", "ProductCube.cost"),
|
|
303
|
-
("profit", "累计利润", "measure", "ProductCube.profit"),
|
|
304
|
-
("profit_margin", "利润率", "measure", "ProductCube.profit_margin"),
|
|
305
|
-
("order_count", "订单数", "measure", "ProductCube.order_count"),
|
|
306
|
-
]
|
|
307
|
-
for code, name, role, qn in product_props:
|
|
308
|
-
s.onto.define_property("Product", code, name, semantic_role=role, qualified_name=qn)
|
|
309
|
-
output.print("OK Product properties (7)")
|
|
310
|
-
|
|
311
|
-
# Customer属性
|
|
312
|
-
customer_props = [
|
|
313
|
-
("id", "客户ID", "dimension", "CustomerCube.customer_id"),
|
|
314
|
-
("region", "客户区域", "dimension", "CustomerCube.customer_region"),
|
|
315
|
-
("type", "客户类型", "dimension", "CustomerCube.customer_type"),
|
|
316
|
-
("revenue", "累计收入", "measure", "CustomerCube.revenue"),
|
|
317
|
-
("cost", "累计成本", "measure", "CustomerCube.cost"),
|
|
318
|
-
("profit", "累计利润", "measure", "CustomerCube.profit"),
|
|
319
|
-
("profit_margin", "利润率", "measure", "CustomerCube.profit_margin"),
|
|
320
|
-
("order_count", "订单数", "measure", "CustomerCube.order_count"),
|
|
321
|
-
]
|
|
322
|
-
for code, name, role, qn in customer_props:
|
|
323
|
-
s.onto.define_property("Customer", code, name, semantic_role=role, qualified_name=qn)
|
|
324
|
-
output.print("OK Customer properties (8)")
|
|
325
|
-
|
|
326
|
-
# ProfitAnalysis属性
|
|
327
|
-
profit_props = [
|
|
328
|
-
("date", "日期", "dimension", "ProfitCube.order_date"),
|
|
329
|
-
("product_category", "产品类别", "dimension", "ProfitCube.product_category"),
|
|
330
|
-
("customer_region", "客户区域", "dimension", "ProfitCube.customer_region"),
|
|
331
|
-
("customer_type", "客户类型", "dimension", "ProfitCube.customer_type"),
|
|
332
|
-
("revenue", "收入", "measure", "ProfitCube.revenue"),
|
|
333
|
-
("cost", "成本", "measure", "ProfitCube.cost"),
|
|
334
|
-
("profit", "利润", "measure", "ProfitCube.profit"),
|
|
335
|
-
("profit_margin", "利润率", "measure", "ProfitCube.profit_margin"),
|
|
336
|
-
]
|
|
337
|
-
for code, name, role, qn in profit_props:
|
|
338
|
-
s.onto.define_property("ProfitAnalysis", code, name, semantic_role=role, qualified_name=qn)
|
|
339
|
-
output.print("OK ProfitAnalysis properties (8)")
|
|
340
|
-
|
|
341
|
-
# 8. 定义链接类型
|
|
342
|
-
output.print("\n[8/7] Defining link types...")
|
|
343
|
-
|
|
344
|
-
link_types = [
|
|
345
|
-
("order_to_product", "订单关联产品", "Order", "Product", "订单包含的产品"),
|
|
346
|
-
("order_to_customer", "订单关联客户", "Order", "Customer", "订单归属客户"),
|
|
347
|
-
("profit_to_product", "利润关联产品", "ProfitAnalysis", "Product", "利润归因到产品"),
|
|
348
|
-
("profit_to_customer", "利润关联客户", "ProfitAnalysis", "Customer", "利润归因到客户"),
|
|
349
|
-
("product_to_profit", "产品归属利润", "Product", "ProfitAnalysis", "产品利润聚合"),
|
|
350
|
-
("customer_to_profit", "客户归属利润", "Customer", "ProfitAnalysis", "客户利润聚合"),
|
|
351
|
-
]
|
|
352
|
-
|
|
353
|
-
for code, name, from_obj, to_obj, desc in link_types:
|
|
354
|
-
s.onto.define_link_type(
|
|
355
|
-
code=code,
|
|
356
|
-
name=name,
|
|
357
|
-
from_object_type_code=from_obj,
|
|
358
|
-
to_object_type_code=to_obj,
|
|
359
|
-
description=desc
|
|
360
|
-
)
|
|
361
|
-
output.print(f"OK {code}")
|
|
362
|
-
|
|
363
|
-
# 9. 同步指标引用
|
|
364
|
-
output.print("\n[9/7] Syncing metric references...")
|
|
365
|
-
s.sync_metric_refs()
|
|
366
|
-
output.print("OK sync_metric_refs")
|
|
367
|
-
|
|
368
|
-
# 总结
|
|
369
|
-
summary = {
|
|
370
|
-
"ok": True,
|
|
371
|
-
"space_id": space_id,
|
|
372
|
-
"tables": 3,
|
|
373
|
-
"cubes": 4,
|
|
374
|
-
"derived_measures": 8,
|
|
375
|
-
"object_types": 4,
|
|
376
|
-
"properties": 30,
|
|
377
|
-
"link_types": 6,
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
output.print("\n=== Profit Analysis Ontology Initialization Completed ===")
|
|
381
|
-
output.print(f"Tables: {summary['tables']}")
|
|
382
|
-
output.print(f"Cubes: {summary['cubes']}")
|
|
383
|
-
output.print(f"Derived Measures: {summary['derived_measures']}")
|
|
384
|
-
output.print(f"Object Types: {summary['object_types']}")
|
|
385
|
-
output.print(f"Properties: {summary['properties']}")
|
|
386
|
-
output.print(f"Link Types: {summary['link_types']}")
|
|
387
|
-
output.success("Initialization completed successfully")
|
|
388
|
-
output.print("__JSON_SUMMARY__" + json.dumps(summary, ensure_ascii=True, default=str))
|