我的目标是随着时间的推移跟踪我的 BigQuery 存储库的受欢迎程度。
我想使用公开可用的 BigQuery 数据集,例如 GitHub Archive或 the GitHub dataset
GitHub 数据集 sample_repos
不包含星数的快照:
SELECT
watch_count
FROM
[bigquery-public-data:github_repos.sample_repos]
WHERE
repo_name == 'angular/angular'
返回 5318。
GitHub 存档是事件的时间轴。我可以尝试将它们全部相加,但数字与 GitHub UI 中的数字不匹配。我猜是因为它不算非明星行为。这是我使用的查询:
SELECT
COUNT(*)
FROM
[githubarchive:year.2011],
[githubarchive:year.2012],
[githubarchive:year.2013],
[githubarchive:year.2014],
[githubarchive:year.2015],
[githubarchive:year.2016],
TABLE_DATE_RANGE([githubarchive:day.], TIMESTAMP('2017-01-01'), TIMESTAMP('2017-03-30') )
WHERE
repo.name == 'angular/angular'
AND type = "WatchEvent"
返回 24144
实际值为21,921
最佳答案
#standardSQL
SELECT
COUNT(*) naive_count,
COUNT(DISTINCT actor.id) unique_by_actor_id,
COUNT(DISTINCT actor.login) unique_by_actor_login
FROM `githubarchive.month.*`
WHERE repo.name = 'angular/angular'
AND type = "WatchEvent"
天真的计数:有些人加注星标和取消加注星标,然后又加注星标。这会创建重复的 WatchEvent。
按 Actor ID 计数唯一:每个人只能出演一次。我们可以计算这些(但我们不知道他们是否未加星标,因此总数会低于此)。
Actor 登录唯一:一些历史月份缺少“actor.id”字段。我们可以改为查看“actor.login”字段(但有些人更改了他们的登录名)。
或者,感谢 GHTorrent 项目:
#standardSQL
SELECT COUNT(*) stars
FROM `ghtorrent-bq.ght_2017_01_19.watchers` a
JOIN `ghtorrent-bq.ght_2017_01_19.projects` b
ON a.repo_id=b.id
WHERE url = 'https://api.github.com/repos/angular/angular'
LIMIT 10
20567,截至 2017 年 1 月 19 日。
相关:
- 当项目更改名称时会发生什么?
https://stackoverflow.com/a/42935592/132438
- 如何在 GHtorrent 更新之前获取更新的数据?
关于github - 如何获取 BigQuery 中给定 repo 的 GitHub 星总数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42918135/