Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add community openrank metric interface #1505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRepoOpenrank, getRepoActivity, getUserOpenrank, getUserActivity, getAttention } from './indices';
import { getRepoOpenrank, getRepoActivity, getUserOpenrank, getUserActivity, getAttention, getRepoCommunityOpenrank } from './indices';
import {
chaossCodeChangeCommits, chaossBusFactor, chaossIssuesNew, chaossIssuesClosed, chaossChangeRequestsAccepted,
chaossChangeRequestsDeclined, chaossIssueResolutionDuration, chaossCodeChangeLines, chaossTechnicalFork,
Expand All @@ -10,6 +10,7 @@ module.exports = {
// index
getRepoActivity: getRepoActivity,
getRepoOpenrank: getRepoOpenrank,
getRepoCommunityOpenrank: getRepoCommunityOpenrank,
getUserActivity: getUserActivity,
getUserOpenrank: getUserOpenrank,
getAttention: getAttention,
Expand Down
63 changes: 63 additions & 0 deletions src/metrics/indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,69 @@ ${getOutterOrderAndLimit(config, 'openrank')}`;
return processQueryResult(result, ['openrank']);
}

interface RepoCommunityOpenRankConfig {
limit: number;
};
export const getRepoCommunityOpenrank = async (config: QueryConfig<RepoCommunityOpenRankConfig>) => {
config = getMergedConfig(config);
const whereClause: string[] = [];
const repoWhereClause = await getRepoWhereClause(config);
if (repoWhereClause) whereClause.push(repoWhereClause);
const timeRangeClause = getTimeRangeWhereClause(config);
if (timeRangeClause) whereClause.push(timeRangeClause);
const limit = config.options?.limit ?? 30;

const sql = `
SELECT
id,
${getTopLevelPlatform(config)},
argMax(name, time) AS name,
${getGroupArrayInsertAtClause(config, { key: 'openrank', noPrecision: true, defaultValue: '[]' })}
FROM
(
SELECT
${getGroupIdClause(config)},
time,
${limit > 0 ?
`arraySlice(groupArray((actor_login, openrank)), 1, ${limit}) AS openrank` :
`groupArray((actor_login, openrank)) AS openrank`}
FROM
(
SELECT
${getGroupTimeClause(config, 'g.created_at')},
g.platform AS platform,
g.repo_id AS repo_id,
argMax(g.repo_name, time) AS repo_name,
argMax(g.org_id, time) AS org_id,
argMax(g.org_login, time) AS org_login,
c.actor_id AS actor_id,
argMax(c.actor_login, time) AS actor_login,
SUM(c.openrank * g.openrank / r.openrank) AS openrank
FROM
(SELECT * FROM community_openrank WHERE ${whereClause.join(' AND ')}) c,
(SELECT * FROM global_openrank WHERE ${whereClause.join(' AND ')}) g,
(SELECT repo_id, platform, created_at, SUM(openrank) AS openrank FROM community_openrank WHERE actor_id > 0 AND ${whereClause.join(' AND ')} GROUP BY repo_id, platform, created_at) r
WHERE
c.actor_id > 0
AND c.repo_id = g.repo_id
AND c.platform = g.platform
AND c.created_at = g.created_at
AND g.repo_id = r.repo_id
AND g.platform = r.platform
AND g.created_at = r.created_at
GROUP BY
platform, repo_id, actor_id, time
ORDER BY openrank DESC
)
GROUP BY id, platform, time
)
GROUP BY id, platform
${getOutterOrderAndLimit({ ...config, order: undefined }, 'openrank')}
`;
const result = await clickhouse.query(sql);
return processQueryResult(result, ['openrank']);
};

export const basicActivitySqlComponent = `
if(type='PullRequestEvent' AND action='closed' AND pull_merged=1, issue_author_id, actor_id) AS actor_id,
argMax(if(type='PullRequestEvent' AND action='closed' AND pull_merged=1, issue_author_login, actor_login), created_at) AS actor_login,
Expand Down
1 change: 1 addition & 0 deletions src/open_digger.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const openDigger = {
openrank: {
getRepoOpenrank: func.getRepoOpenrank,
getUserOpenrank: func.getUserOpenrank,
getRepoCommunityOpenrank: func.getRepoCommunityOpenrank,
},
attention: {
getAttention: func.getAttention,
Expand Down