-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add time_distribution of activities endpoint
- Loading branch information
1 parent
36b9be2
commit 01f449d
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
configs/public_api/http_endpoints/sql/GET-users-activities-time_distribution.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |