我的目标是随着时间的推移跟踪BigQuery repo的受欢迎程度。
我想使用公开的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 Archive是事件的时间表。我可以尝试将它们全部加起来,但数字与GitHub UI中的数字不匹配。我想因为它不算unstar行动。这是我使用的查询:
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
答案 0 :(得分:4)
#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"
天真伯爵:有些人出演并取消明星,并再次出演。这会创建重复的WatchEvents。
独特的演员ID数:每个人只能出演一次。我们可以统计这些(但我们不知道他们是否未加星标,所以总数将低于此数。)
演员登录的独特之处:某些历史月份缺少'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/01/19。
相关:
https://stackoverflow.com/a/42935592/132438