feat: support full click gap history generation

This commit is contained in:
SHAREit
2026-10-16 17:30:32 +08:00
parent 6e2baee3de
commit 7cb90022f4
2 changed files with 37 additions and 12 deletions
+7 -3
View File
@@ -15,8 +15,8 @@ clicks_diff_rate REAL, updated_at TEXT NOT NULL
## 输出协议
- `data/YYYYMMDD.json`:直接 JSON 数组;最近 7 天每天生成一个文件,即使当天无数据也生成 `[]`。
- `data/index.json`:包含 `schema_version`、`generated_at` 和最近 7 天的 `data/YYYYMMDD.json` 清单。
- `data/YYYYMMDD.json`:直接 JSON 数组;默认最近 7 天每天生成一个文件,即使当天无数据也生成 `[]`。使用 `--all` 时只为数据库中实际有数据的日期生成文件。
- `data/index.json`:包含 `schema_version`、`generated_at` 和本次实际生成的 `data/YYYYMMDD.json` 清单。
- 每行字段为 `dt`(`YYYYMMDD`)、`attr_platform`、`pkg_name`、`shareit_clicks`、`af_clicks`、`installs_ua`、`clicks_diff`、`clicks_diff_rate`;最后一项可以为 `null`。
默认日期边界为运行日往前 6 天至运行日,首尾包含,共 7 天。手工补数使用 `--start-date` 和 `--end-date`,两者必须同时提供且最多 7 天。
@@ -29,11 +29,15 @@ mac2 推荐始终通过包装脚本运行:
cd /Users/shareit./Library/CloudStorage/OneDrive-个人/ubuntu/Gitea/af-click-gap
scripts/run_pipeline.sh
scripts/run_pipeline.sh --start-date 2026-10-10 --end-date 2026-10-16
# 全量重建数据库中所有实际有数据的日期并 push
scripts/run_pipeline.sh --all
```
包装脚本默认定位项目根目录,并读取 sibling 项目 `../direct-report-dashboard/.env`(mac2 默认路径为 `~/ubuntu/Gitea/af-click-gap` 与 `~/ubuntu/Gitea/direct-report-dashboard`)。也可以用 `PROJECT_ROOT` 和 `ENV_FILE` 覆盖路径。它只解析 `AGENTSTAGE_USER`、`AGENTSTAGE_TOKEN`,不执行整个 `.env`;凭据只进入子进程环境,不写入文件、remote URL、命令行参数或日志。脚本使用临时 `GIT_ASKPASS` 响应 Git 的用户名和密码提示,临时文件权限为仅当前用户可读写,并在退出时清理。
不要直接运行 `python3 scripts/af_click_gap_pipeline.py --push`:该命令可能使用 mac2 Keychain 中没有仓库写权限的旧凭据。包装脚本会执行相同的 SQLite 最近 7 天提取和 `--push`,额外参数会继续传给流水线。需要只检查数据时可直接使用 `python3 scripts/af_click_gap_pipeline.py --dry-run`。
不要直接运行 `python3 scripts/af_click_gap_pipeline.py --push`:该命令可能使用 mac2 Keychain 中没有仓库写权限的旧凭据。包装脚本会执行相同的 SQLite 最近 7 天提取和 `--push`,额外参数会继续传给流水线;因此 `scripts/run_pipeline.sh --all` 最终执行全量 `--all --push`。需要只检查数据时可直接使用 `python3 scripts/af_click_gap_pipeline.py --dry-run` 或 `python3 scripts/af_click_gap_pipeline.py --all --dry-run`。
`--all` 会读取数据库中 `pid='shareit'` 的全部记录并按实际出现的日期生成 JSON;它不能与日期范围参数同时使用。全量运行可能改动并提交大量历史数据,执行前应确认数据库内容和工作区,且仍会经过字段、日期、数值、JSON 和 Git 数据白名单校验。脚本对数据库使用 SQLite 只读连接,不建表、不迁移、不写入数据库。
`--dry-run` 只读取数据库并在仓库外临时目录生成、校验 JSON,不写 `data` 或 Git。正式运行先原子替换 `data/` 输出目录中的数据文件,再执行 Git;数据库查询或校验失败不会发布文件。Git 安全检查只允许本次生成的 `data/*.json`(含 `data/index.json`),工作区存在其它未提交改动时拒绝继续。push 失败会保留本地 commit,不会 force push。