Skip to content

Commit

Permalink
queries: add completion-rate queries (pingcap#1664)
Browse files Browse the repository at this point in the history
* queries: add completion-rate queries

* add self-merged-ratio query
  • Loading branch information
Mini256 authored Oct 23, 2023
1 parent ebad385 commit aa3bf51
Show file tree
Hide file tree
Showing 22 changed files with 357 additions and 145 deletions.
6 changes: 3 additions & 3 deletions configs/queries/orgs/issues/closed-ratio/template.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ WITH repos AS (
SELECT
cpppt.type,
cpppt.issues AS current_period_issues,
ROUND(cpppt.issues / cppt.issues_total * 100, 2) AS current_period_percentage,
ROUND(cpppt.issues / cppt.issues_total, 2) AS current_period_percentage,
ppppt.issues AS past_period_issues,
ROUND(ppppt.issues / pppt.issues_total * 100, 2) AS past_period_percentage,
ROUND((cpppt.issues / cppt.issues_total - ppppt.issues / pppt.issues_total) * 100, 2) AS percentage_change
ROUND(ppppt.issues / pppt.issues_total, 2) AS past_period_percentage,
ROUND((cpppt.issues / cppt.issues_total - ppppt.issues / pppt.issues_total), 2) AS percentage_change
FROM current_period_issues_per_type cpppt
LEFT JOIN past_period_issues_per_type ppppt ON cpppt.type = ppppt.type
LEFT JOIN current_period_issues_total cppt ON 1 = 1
Expand Down
2 changes: 1 addition & 1 deletion configs/queries/orgs/issues/total/template.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ WITH repos AS (
SELECT
IFNULL(cpp.issues, 0) AS current_period_total,
IFNULL(ppp.issues, 0) AS past_period_total,
ROUND((cpp.issues - ppp.issues) / ppp.issues * 100, 2) AS growth_percentage
ROUND((cpp.issues - ppp.issues) / ppp.issues, 2) AS growth_percentage
FROM current_period_issues cpp
LEFT JOIN past_period_issues ppp ON 1 = 1
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
"default": "past_28_days"
},
{
"name": "n",
"type": "integer",
"default": 10
"name": "role",
"type": "string",
"enums": ["all", "pr_creators", "pr_commenters", "pr_reviewers", "issue_creators", "issue_commenters", "commit_authors"],
"default": "all"
},
{
"name": "excludeBots",
"type": "boolean",
"default": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
WITH repos AS (
SELECT
gr.repo_id, gr.repo_name
FROM github_repos gr
WHERE
gr.owner_id = {{ownerId}}
{% if repoIds.size > 0 %}
AND gr.repo_id IN ({{ repoIds | join: ',' }})
{% endif %}
), participants_summary AS (
SELECT
CASE WHEN gu.country_code NOT IN ('', 'N/A', 'UND') THEN 1 ELSE 0 END AS is_filled,
COUNT(DISTINCT actor_login) AS participants
FROM github_events ge
JOIN github_users gu ON ge.actor_login = gu.login
WHERE
ge.repo_id IN (SELECT repo_id FROM repos)

{% case role %}
{% when 'pr_creators' %}
AND ge.type = 'PullRequestEvent' AND ge.action = 'opened'
{% when 'pr_reviewers' %}
AND ge.type = 'PullRequestReviewEvent' AND ge.action = 'created'
{% when 'issue_creators' %}
AND ge.type = 'IssuesEvent' AND ge.action = 'opened'
{% when 'commit_authors' %}
AND ge.type = 'PushEvent' AND ge.action = ''
{% when 'pr_commenters' %}
AND ge.type = 'IssueCommentEvent' AND ge.action = 'created'
AND EXISTS (
SELECT 1
FROM mv_repo_pull_requests mrpr
WHERE mrpr.repo_id = ge.repo_id AND mrpr.number = ge.number
)
{% when 'issue_commenters' %}
AND ge.type = 'IssueCommentEvent' AND ge.action = 'created'
AND EXISTS (
SELECT 1
FROM mv_repo_issues mri
WHERE mri.repo_id = ge.repo_id AND mri.number = ge.number
)
{% else %}
-- Events considered as participation (Exclude `WatchEvent`, which means star a repo).
AND ge.type IN ('IssueCommentEvent', 'DeleteEvent', 'CommitCommentEvent', 'MemberEvent', 'PushEvent', 'PublicEvent', 'ForkEvent', 'ReleaseEvent', 'PullRequestReviewEvent', 'CreateEvent', 'GollumEvent', 'PullRequestEvent', 'IssuesEvent', 'PullRequestReviewCommentEvent')
AND ge.action IN ('added', 'published', 'reopened', 'closed', 'created', 'opened', '')
{% endcase %}

{% if excludeBots %}
-- Exclude bot users.
AND LOWER(ge.actor_login) NOT LIKE '%bot%'
AND ge.actor_login NOT IN (SELECT login FROM blacklist_users LIMIT 255)
{% endif %}

{% case period %}
{% when 'past_7_days' %} AND ge.created_at > (NOW() - INTERVAL 7 DAY)
{% when 'past_28_days' %} AND ge.created_at > (NOW() - INTERVAL 28 DAY)
{% when 'past_90_days' %} AND ge.created_at > (NOW() - INTERVAL 90 DAY)
{% when 'past_12_months' %} AND ge.created_at > (NOW() - INTERVAL 12 MONTH)
{% endcase %}
GROUP BY is_filled
), participants_total AS (
SELECT SUM(participants) AS total FROM participants_summary
)
SELECT
ROUND(ps.participants / pt.total, 2) AS percentage
FROM
participants_summary ps,
participants_total pt
WHERE
is_filled = 1
LIMIT 1

This file was deleted.

2 changes: 1 addition & 1 deletion configs/queries/orgs/participants/locations/template.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ participants_total AS (
SELECT
ppc.country_code,
ppc.participants,
ROUND(ppc.participants / pt.total * 100, 2) AS percentage
ROUND(ppc.participants / pt.total, 2) AS percentage
FROM
participants_per_country ppc,
participants_total pt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"cacheHours": 1,
"engine": "liquid",
"cacheProvider": "NORMAL_TABLE",
"params": [
{
"name": "ownerId",
"replaces": "11855343",
"type": "integer"
},
{
"name": "repoIds",
"replaces": "41986369",
"type": "array",
"default": [],
"itemType": "integer",
"maxArrayLength": 50
},
{
"name": "period",
"type": "string",
"enums": ["past_7_days", "past_28_days", "past_90_days", "past_12_months"],
"default": "past_28_days"
},
{
"name": "role",
"type": "string",
"enums": ["all", "pr_creators", "pr_commenters", "pr_reviewers", "issue_creators", "issue_commenters", "commit_authors"],
"default": "all"
},
{
"name": "excludeBots",
"type": "boolean",
"default": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ WITH repos AS (
{% if repoIds.size > 0 %}
AND gr.repo_id IN ({{ repoIds | join: ',' }})
{% endif %}
), stars_overview AS (
), participants_summary AS (
SELECT
SUM(IF(gu.organization_formatted IS NOT NULL AND LENGTH(gu.organization_formatted) != 0, 1, 0)) AS stars_with_org,
COUNT(*) AS stars_total
IF(gu.organization_formatted IS NOT NULL AND LENGTH(gu.organization_formatted) != 0, 1, 0) AS is_filled,
COUNT(DISTINCT actor_login) AS participants
FROM github_events ge
JOIN github_users gu ON ge.actor_login = gu.login
WHERE
ge.repo_id IN (SELECT repo_id FROM repos)

{% case role %}
{% when 'pr_creators' %}
AND ge.type = 'PullRequestEvent' AND ge.action = 'opened'
Expand All @@ -28,47 +29,42 @@ WITH repos AS (
AND ge.type = 'IssueCommentEvent' AND ge.action = 'created'
AND EXISTS (
SELECT 1
FROM github_events ge2
WHERE
ge2.type = 'PullRequestEvent'
AND ge2.action = 'opened'
AND ge2.created_at < ge.created_at
AND ge2.repo_id = ge.repo_id
AND ge2.number = ge.number
FROM mv_repo_pull_requests mrpr
WHERE mrpr.repo_id = ge.repo_id AND mrpr.number = ge.number
)
{% when 'issue_commenters' %}
AND ge.type = 'IssueCommentEvent' AND ge.action = 'created'
AND EXISTS (
SELECT 1
FROM github_events ge2
WHERE
ge2.type = 'IssuesEvent'
AND ge2.action = 'opened'
AND ge2.created_at < ge.created_at
AND ge2.repo_id = ge.repo_id
AND ge2.number = ge.number
FROM mv_repo_issues mri
WHERE mri.repo_id = ge.repo_id AND mri.number = ge.number
)
{% else %}
-- Events considered as participation (Exclude `WatchEvent`, which means star a repo).
AND ge.type IN ('IssueCommentEvent', 'DeleteEvent', 'CommitCommentEvent', 'MemberEvent', 'PushEvent', 'PublicEvent', 'ForkEvent', 'ReleaseEvent', 'PullRequestReviewEvent', 'CreateEvent', 'GollumEvent', 'PullRequestEvent', 'IssuesEvent', 'PullRequestReviewCommentEvent')
AND ge.action IN ('added', 'published', 'reopened', 'closed', 'created', 'opened', '')
{% endcase %}

{% if excludeBots %}
-- Exclude bot users.
AND ge.actor_login NOT LIKE '%bot%'
{% endif %}

{% case period %}
{% when 'past_7_days' %}
AND ge.created_at > (NOW() - INTERVAL 7 DAY)
{% when 'past_28_days' %}
AND ge.created_at > (NOW() - INTERVAL 28 DAY)
{% when 'past_90_days' %}
AND ge.created_at > (NOW() - INTERVAL 90 DAY)
{% when 'past_12_months' %}
AND ge.created_at > (NOW() - INTERVAL 12 MONTH)
{% when 'past_7_days' %} AND ge.created_at > (NOW() - INTERVAL 7 DAY)
{% when 'past_28_days' %} AND ge.created_at > (NOW() - INTERVAL 28 DAY)
{% when 'past_90_days' %} AND ge.created_at > (NOW() - INTERVAL 90 DAY)
{% when 'past_12_months' %} AND ge.created_at > (NOW() - INTERVAL 12 MONTH)
{% endcase %}
GROUP BY is_filled
), participants_total AS (
SELECT SUM(participants) AS total FROM participants_summary
)
SELECT
ROUND(so.stars_with_org / so.stars_total * 100, 2) AS percentage
ROUND(ps.participants / pt.total, 2) AS percentage
FROM
stars_overview so
participants_summary ps,
participants_total pt
WHERE
is_filled = 1
LIMIT 1
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ participants_total AS (
SELECT
ppo.organization_name,
ppo.participants,
ROUND(ppo.participants / pt.participants_total * 100, 2) AS percentage
ROUND(ppo.participants / pt.participants_total, 2) AS percentage
FROM
participants_per_org ppo,
participants_total pt
Expand Down
Loading

0 comments on commit aa3bf51

Please sign in to comment.