@tapdb/tapdb-data-analysis 0.1.28 → 0.1.29
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/package.json
CHANGED
|
@@ -11,7 +11,7 @@ description: >
|
|
|
11
11
|
|
|
12
12
|
# TapDB 数据分析
|
|
13
13
|
|
|
14
|
-
> Skill 版本:v0.1.
|
|
14
|
+
> Skill 版本:v0.1.29
|
|
15
15
|
|
|
16
16
|
通过 Python 脚本调用 TapDB 运营数据查询接口,获取游戏指标数据并分析。
|
|
17
17
|
|
|
@@ -172,7 +172,7 @@ python3 <SKILL_DIR>/scripts/tapdb_query.py raw /op/active '{"project_id":2588,"s
|
|
|
172
172
|
|
|
173
173
|
## 数据截断规则
|
|
174
174
|
|
|
175
|
-
脚本**默认自动截断**,`_truncation`
|
|
175
|
+
脚本**默认自动截断**,`_truncation` 字段包含总行数与省略行数。TapDB API 会在结果末尾附带**汇总行**(分组字段为 `null`),脚本截断时会保留该汇总行。
|
|
176
176
|
|
|
177
177
|
| 场景 | 阈值 | 方式 |
|
|
178
178
|
|------|------|------|
|
|
@@ -182,7 +182,7 @@ python3 <SKILL_DIR>/scripts/tapdb_query.py raw /op/active '{"project_id":2588,"s
|
|
|
182
182
|
|
|
183
183
|
- 不加 `--all-retention` 通常仅返回 `DR1-DR30 + DR60/90/120/150/180`;加上后会额外补齐 `DR31-DR59`(及对应 `_newDevice/_rate` 列)。
|
|
184
184
|
|
|
185
|
-
-
|
|
185
|
+
- 汇总数据以 API 返回的汇总行为准(分组字段为 `null`),不要在本地再计算汇总
|
|
186
186
|
- 多次查询:每次先提取关键数值再下一个查询,不累积原始数据
|
|
187
187
|
- 版本分布:一次性查询,不按天拆分(除非用户要求"按日趋势")
|
|
188
188
|
- 需完整数据加 `--no-truncate`
|
|
@@ -192,6 +192,7 @@ python3 <SKILL_DIR>/scripts/tapdb_query.py raw /op/active '{"project_id":2588,"s
|
|
|
192
192
|
- **货币转换**:默认将金额转为人民币(CNY)。通过 `--exchange-to-currency` 可切换目标货币(如 USD/JPY/EUR),传 `none` 禁用转换返回原始金额。影响 income/source/user_value/life_cycle/ad_monet 等含金额字段的接口
|
|
193
193
|
- `filters` 即使无条件也必须传 `[]`,否则 500
|
|
194
194
|
- `group` 必传。retention/source 不传 `-g` 时自动用 `activation_time`,其他默认 `time`
|
|
195
|
+
- `life_cycle` 在 `-g activation_os` 时仅支持 `--quota payment_cvs_rate`(其他 quota 会 500)
|
|
195
196
|
- filters 格式: `{"col_name":"...", "data_type":"string|number|bool|date", "calculate_symbol":"include|un_include", "ftv":[...]}`
|
|
196
197
|
- 各接口维度不同,不支持的维度返回 500。**先 `describe` 确认**
|
|
197
198
|
|
|
@@ -83,21 +83,7 @@ _HEAD = 15
|
|
|
83
83
|
_TAIL = 15
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
def
|
|
87
|
-
"""Compute min/max/avg for first N numeric columns."""
|
|
88
|
-
if not rows:
|
|
89
|
-
return {}
|
|
90
|
-
keys = [k for k, v in rows[0].items() if isinstance(v, (int, float))][:limit]
|
|
91
|
-
out = {}
|
|
92
|
-
for k in keys:
|
|
93
|
-
vals = [r[k] for r in rows if isinstance(r.get(k), (int, float))]
|
|
94
|
-
if vals:
|
|
95
|
-
out[k] = {"min": min(vals), "max": max(vals),
|
|
96
|
-
"avg": round(sum(vals) / len(vals), 2)}
|
|
97
|
-
return out
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def _slim_rows(rows, cmd_type):
|
|
86
|
+
def _slim_rows(rows, cmd_type, group_alias=None):
|
|
101
87
|
"""Truncate row count; time-series keeps head+tail, others keep head."""
|
|
102
88
|
if not rows:
|
|
103
89
|
return rows, None
|
|
@@ -110,7 +96,24 @@ def _slim_rows(rows, cmd_type):
|
|
|
110
96
|
rows = rows[:cap] + [f"... 省略 {omit} 条 ..."]
|
|
111
97
|
return rows, {"total_rows": total, "omitted": omit}
|
|
112
98
|
|
|
113
|
-
|
|
99
|
+
total = len(rows)
|
|
100
|
+
|
|
101
|
+
# TapDB API often appends a summary row at the end (group field is null).
|
|
102
|
+
# Keep that row (API-provided) when truncating.
|
|
103
|
+
summary_row = None
|
|
104
|
+
group_key = group_alias
|
|
105
|
+
if group_key and isinstance(rows[-1], dict) and group_key in rows[-1] and rows[-1].get(group_key) is None:
|
|
106
|
+
summary_row = rows[-1]
|
|
107
|
+
rows = rows[:-1]
|
|
108
|
+
else:
|
|
109
|
+
# Best-effort fallback when caller didn't provide group_alias.
|
|
110
|
+
for time_key in _TIME_FIELDS:
|
|
111
|
+
if time_key in rows[-1] and rows[-1].get(time_key) is None:
|
|
112
|
+
summary_row = rows[-1]
|
|
113
|
+
rows = rows[:-1]
|
|
114
|
+
break
|
|
115
|
+
|
|
116
|
+
has_time = bool(rows and (_TIME_FIELDS & set(rows[0].keys())))
|
|
114
117
|
if cmd_type == "whale_user":
|
|
115
118
|
cap = _MAX_WHALE_ROWS
|
|
116
119
|
elif has_time:
|
|
@@ -118,17 +121,19 @@ def _slim_rows(rows, cmd_type):
|
|
|
118
121
|
else:
|
|
119
122
|
cap = _MAX_GROUP_ROWS
|
|
120
123
|
if len(rows) <= cap:
|
|
124
|
+
if summary_row is not None:
|
|
125
|
+
return rows + [summary_row], None
|
|
121
126
|
return rows, None
|
|
122
127
|
|
|
123
|
-
total = len(rows)
|
|
124
|
-
summary = _numeric_summary(rows)
|
|
125
128
|
if has_time:
|
|
126
|
-
omit =
|
|
129
|
+
omit = len(rows) - _HEAD - _TAIL
|
|
127
130
|
rows = rows[:_HEAD] + [{"_": f"... 省略 {omit} 行 ..."}] + rows[-_TAIL:]
|
|
128
131
|
else:
|
|
129
|
-
omit =
|
|
132
|
+
omit = len(rows) - cap
|
|
130
133
|
rows = rows[:cap] + [{"_": f"... 省略 {omit} 行 ..."}]
|
|
131
|
-
|
|
134
|
+
if summary_row is not None:
|
|
135
|
+
rows.append(summary_row)
|
|
136
|
+
return rows, {"total_rows": total, "omitted": omit}
|
|
132
137
|
|
|
133
138
|
|
|
134
139
|
def _list_of_lists_to_dicts(lol):
|
|
@@ -177,7 +182,7 @@ def _rebuild(resp, path, rows, info):
|
|
|
177
182
|
return result
|
|
178
183
|
|
|
179
184
|
|
|
180
|
-
def truncate_response(resp, cmd_type=None):
|
|
185
|
+
def truncate_response(resp, cmd_type=None, group_alias=None):
|
|
181
186
|
"""Truncate API response to save context window tokens."""
|
|
182
187
|
if not resp or (isinstance(resp, dict) and resp.get("error")):
|
|
183
188
|
return resp
|
|
@@ -186,7 +191,7 @@ def truncate_response(resp, cmd_type=None):
|
|
|
186
191
|
return resp
|
|
187
192
|
|
|
188
193
|
info = {}
|
|
189
|
-
rows, row_info = _slim_rows(rows, cmd_type)
|
|
194
|
+
rows, row_info = _slim_rows(rows, cmd_type, group_alias=group_alias)
|
|
190
195
|
if row_info:
|
|
191
196
|
info.update(row_info)
|
|
192
197
|
if not info:
|
|
@@ -466,7 +471,7 @@ ENDPOINT_CAPS = {
|
|
|
466
471
|
"lang_system": "过滤值会自动翻译,可直接用展示名",
|
|
467
472
|
},
|
|
468
473
|
"group_notes": {
|
|
469
|
-
"activation_os": "
|
|
474
|
+
"activation_os": "仅当 quota=payment_cvs_rate 时支持;(建议改用 time/activation_time)",
|
|
470
475
|
},
|
|
471
476
|
"unsupported_note": "分组仅支持 time/activation_time/activation_os;过滤不支持 activation_app_version/first_server/current_server/utmsrc/login_type/payment_source",
|
|
472
477
|
},
|
|
@@ -572,7 +577,10 @@ def do_query(args, endpoint_path, extra=None, cmd_type=None):
|
|
|
572
577
|
url = f"{base_url}/mcp/op/{endpoint_path}"
|
|
573
578
|
result = http_request("POST", url, {"MCP-KEY": key}, body)
|
|
574
579
|
if not getattr(args, "no_truncate", False):
|
|
575
|
-
|
|
580
|
+
group_alias = None
|
|
581
|
+
if isinstance(body.get("group"), dict):
|
|
582
|
+
group_alias = body["group"].get("col_alias")
|
|
583
|
+
result = truncate_response(result, cmd_type or endpoint_path, group_alias=group_alias)
|
|
576
584
|
output(result)
|
|
577
585
|
|
|
578
586
|
|
|
@@ -633,6 +641,13 @@ def cmd_whale_user(args):
|
|
|
633
641
|
|
|
634
642
|
|
|
635
643
|
def cmd_life_cycle(args):
|
|
644
|
+
if getattr(args, "group_by", None) == "activation_os" and getattr(args, "quota", None) != "payment_cvs_rate":
|
|
645
|
+
output({
|
|
646
|
+
"error": True,
|
|
647
|
+
"message": "life_cycle 接口在 -g activation_os 时仅支持 --quota payment_cvs_rate(其他 quota 会 500)",
|
|
648
|
+
"hint": "请改用 --quota payment_cvs_rate 或改用 -g time / -g activation_time",
|
|
649
|
+
})
|
|
650
|
+
return
|
|
636
651
|
do_query(args, "life_cycle", {"quota": args.quota})
|
|
637
652
|
|
|
638
653
|
|