-
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 monthly sizes of prs endpoint
- Loading branch information
1 parent
5f64430
commit 4b29802
Showing
3 changed files
with
80 additions
and
3 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
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-sizes.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,33 @@ | ||
USE gharchive_dev; | ||
|
||
SELECT | ||
t_month AS event_month, xs, s, m, l, xl, xxl, all_size | ||
FROM ( | ||
SELECT | ||
t_month, | ||
SUM(IF(changes < 10, 1, 0)) OVER(PARTITION BY t_month) AS xs, | ||
SUM(IF(changes >= 10 AND changes < 30, 1, 0)) OVER(PARTITION BY t_month) AS s, | ||
SUM(IF(changes >= 30 AND changes < 100, 1, 0)) OVER(PARTITION BY t_month) AS m, | ||
SUM(IF(changes >= 100 AND changes < 500, 1, 0)) OVER(PARTITION BY t_month) AS l, | ||
SUM(IF(changes >= 500 AND changes < 1000, 1, 0)) OVER(PARTITION BY t_month) AS xl, | ||
SUM(IF(changes >= 1000, 1, 0)) OVER (PARTITION BY t_month) AS xxl, | ||
COUNT(*) OVER (PARTITION BY t_month) AS all_size, | ||
ROW_NUMBER() OVER (PARTITION BY t_month) AS row_num | ||
FROM ( | ||
SELECT | ||
DATE_FORMAT(created_at, '%Y-%m-01') AS t_month, | ||
additions + deletions AS changes | ||
FROM github_events ge | ||
WHERE | ||
creator_user_id = (SELECT id FROM github_users WHERE login = ${username} LIMIT 1) | ||
AND type = 'PullRequestEvent' | ||
AND action = 'closed' | ||
AND pr_merged = true | ||
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 | ||
) sub | ||
) AS sub | ||
WHERE | ||
row_num = 1 |