Files
MediaCrawler/docs/queries/recent-7-days-videos.sql
T
butubb 3b0cdbe5ea
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s
docs(schema): 最近七天视频只留平台报的作品总数,并写明它现在不可信
按用户要求去掉「库内视频数」,只保留 `账号作品数`(平台主页写的总数)。

但这一列**现在是错的**,所以把证据写进注释:`锋哥苏州同城人脉汇` 库里存着它
10-12 / 10-13 / 10-14 / 10-15 四条作品(一天一条),平台却在连续 8 次快照、横跨
22 小时里一直报「作品 2」。全局 dy 的 1559 行快照中,49% 作品数为 0、58% 粉丝数
为 0,NULL 一行都没有 —— `douyin_api._as_int` 的失败分支 `return 0` 把「读不到」
伪装成了 0,而 models.py 的要求恰恰相反。

注释里给了换成库内计数的写法,供和可信口径对照。
2026-10-16 16:55:46 +08:00

57 lines
3.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 最近七天发布的视频(抖音)。换平台把两处 platform='dy' 改成 'xhs'。
--
-- 窗口按 **published_at(作者发布时间)** 算,不经过时区:库里存的是毫秒时间戳,
-- 用 UNIX_TIMESTAMP() 拿当前 epoch 相减,和 MySQL 的 time_zone 设置无关。
--
-- 改成「最近七天我们采到的」就把 n.published_at 换成 n.first_seen_at(两处)。
--
-- **`账号作品数` 这一列现在不可信,用之前先知道这一点。**
--
-- 它取的是平台主页写的总数(`monitor_creator_stat.works_count`,来自抖音资料接口的
-- `aweme_count`)。实测 `锋哥苏州同城人脉汇`:库里存着它 10-12 / 10-13 / 10-14 / 10-15
-- 四条作品(一天一条),而平台在连续 **8 次快照、横跨 22 小时**里一直报「作品 2」。
-- 全局看,dy 的 1559 行快照里有 49% 作品数是 0、58% 粉丝数是 0,而 NULL 一行都没有
-- —— 因为 `douyin_api._as_int` 的失败分支 `return 0`,把「读不到」伪装成了 0
-- (models.py 里那份注释的要求恰恰相反:不要伪造成 0,0 是"掉到零")。
--
-- 所以这一列偏小是常态。要和可信口径对照,把这一行换成按库内作品计数:
-- (SELECT COUNT(DISTINCT n2.note_id) FROM monitor_note n2
-- JOIN monitor_task t5 ON t5.id = n2.task_id
-- WHERE t5.platform='dy' AND n2.creator_hash = n.creator_hash) AS 账号作品数
SELECT
COALESCE(st.nickname, n.creator_name, '') AS 博主昵称,
st.works_count AS 账号作品数,
ca.alias AS 博主备注,
FROM_UNIXTIME(n.published_at / 1000) AS 发布时间,
n.title AS 标题,
n.note_url AS 链接,
m.liked_count AS 点赞,
m.comment_count AS 评论,
m.collected_count AS 收藏,
m.share_count AS 分享,
(SELECT GROUP_CONCAT(t.name ORDER BY t.sort_order SEPARATOR ' / ')
FROM monitor_note_tag nt
JOIN monitor_tag t ON t.id = nt.tag_id
WHERE nt.platform = 'dy' AND nt.note_id = n.note_id) AS 标签,
(SELECT na.alias FROM monitor_note_alias na
WHERE na.platform = 'dy' AND na.note_id = n.note_id LIMIT 1) AS 作品备注,
FROM_UNIXTIME(n.first_seen_at / 1000) AS 首次采到
FROM monitor_note n
JOIN monitor_task t ON t.id = n.task_id
-- 这条作品最近一轮的指标
LEFT JOIN monitor_note_metric m
ON m.id = (SELECT m2.id FROM monitor_note_metric m2
WHERE m2.task_id = n.task_id AND m2.note_id = n.note_id
ORDER BY m2.run_id DESC LIMIT 1)
-- 博主最近一轮的账号级指标(昵称优先取这个,它每轮都从资料接口重写)
LEFT JOIN monitor_creator_stat st
ON st.id = (SELECT s.id FROM monitor_creator_stat s
JOIN monitor_task t2 ON t2.id = s.task_id
WHERE t2.platform = 'dy' AND s.creator_hash = n.creator_hash
ORDER BY s.captured_at DESC, s.id DESC LIMIT 1)
LEFT JOIN monitor_creator_alias ca
ON ca.platform = 'dy' AND ca.creator_hash = n.creator_hash
WHERE t.platform = 'dy'
AND n.published_at >= (UNIX_TIMESTAMP() - 7 * 86400) * 1000
ORDER BY n.published_at DESC;