Skip to content

Commit

Permalink
feat: add time_distribution of activities endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tidb-cloud-data-service[bot] authored Nov 25, 2023
1 parent 36b9be2 commit 01f449d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
52 changes: 52 additions & 0 deletions configs/public_api/http_endpoints/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,56 @@
[
{
"name": "/users/activities/time_dist",
"description": "Retrieve a weekly and hourly distribution of a GitHub user's activities (pull requests, issues, issue comments, reviews, review comments, pushes) in the specified time range. (If `from` and `to` are not specified, the default period is the past year.)",
"method": "GET",
"endpoint": "/users/activities/time_distribution",
"data_source": {
"cluster_id": 1379661944642684098
},
"params": [
{
"name": "username",
"type": "string",
"required": 1,
"default": "",
"description": ""
},
{
"name": "type",
"type": "string",
"required": 0,
"default": "all",
"description": "",
"enum": "all,issues,issue_comments,pull_requests,reviews,review_comments,pushes"
},
{
"name": "from",
"type": "string",
"required": 0,
"default": "",
"description": ""
},
{
"name": "to",
"type": "string",
"required": 0,
"default": "2099-12-31",
"description": ""
}
],
"settings": {
"timeout": 30000,
"row_limit": 1000,
"cache_enabled": 0,
"cache_ttl": 0,
"enable_pagination": 0
},
"tag": "Default",
"batch_operation": 0,
"sql_file": "sql/GET-users-activities-time_distribution.sql",
"type": "sql_endpoint",
"return_type": "json"
},
{
"name": "/users/pull_requests/language",
"description": "Retrieve the count and percentage of a GitHub user's opened pull requests in different programming languages. (If `from` and `to` are not specified, the default period is the past year.)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
USE gharchive_dev;

SELECT
DAYOFWEEK(created_at) - 1 AS dayofweek,
HOUR(created_at) AS hour,
COUNT(*) AS activities
FROM github_events ge
WHERE
actor_id = (SELECT id FROM github_users WHERE login = ${username} LIMIT 1)
AND CASE
WHEN ${type} = 'pull_requests' THEN (type = 'PullRequestEvent' AND action = 'opened')
WHEN ${type} = 'issues' THEN (type = 'IssuesEvent' AND action = 'opened')
WHEN ${type} = 'issue_comments' THEN (type = 'IssueCommentEvent' AND action = 'created')
WHEN ${type} = 'reviews' THEN (type = 'PullRequestReviewEvent' AND action = 'created')
WHEN ${type} = 'review_comments' THEN (type = 'PullRequestReviewCommentEvent' AND action = 'created')
WHEN ${type} = 'pushes' THEN (type = 'PushEvent' AND action = '')
ELSE true
END
AND
CASE WHEN ${from} = '' THEN (ge.created_at BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW())
ELSE (ge.created_at >= ${from} AND ge.created_at <= ${to})
END
GROUP BY dayofweek, hour, type
ORDER BY dayofweek, hour, type

0 comments on commit 01f449d

Please sign in to comment.