修改了contribution_perc函数,添加了对区块链确权项目的支持

This commit is contained in:
zhangxunhui 2023-02-02 14:00:13 +08:00
parent c5314f7439
commit ada6afa500
1 changed files with 101 additions and 90 deletions

View File

@ -86,6 +86,19 @@ class UsersController < ApplicationController
@project = Project.find(project_id)
user_id = params[:id]
@user = User.find(user_id)
def cal_perc(count_user, count_all)
(count_user * 1.0 / (count_all + 0.000000001)).round(5)
end
if @project.use_blockchain == true or @project.use_blockchain == 1
balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id})[:balance]
balance_all = Blockchain::RepoBasicInfo.call({"project_id": project_id})["cur_supply"]
scores = {
"final" => cal_perc(balance_user, balance_all),
"blockchain" => true
}
else
# 获取所有行为对应的项目内记录总数和个人记录数
features = {
"requirement" => {},
@ -93,10 +106,6 @@ class UsersController < ApplicationController
"review" => {}
}
def cal_perc(count_user, count_all)
(count_user * 1.0 / (count_all + 0.000000001)).round(5)
end
# 1. issue创建
issues = Issue.where(project_id: project_id, issue_classify: 'issue')
issue_all = issues.count
@ -106,7 +115,7 @@ class UsersController < ApplicationController
milestones = Version.where(project_id: project_id)
milestone_all = milestones.count
milestone_user = milestones.where(user_id: user_id).count
features["requirement"] = features["requirement"].merge({"milestone" => {"all" => milestone_all, "perc" => milestone_user * 1.0 / milestone_all}})
features["requirement"] = features["requirement"].merge({"milestone" => {"all" => milestone_all, "perc" => cal_perc(milestone_user, milestone_all)}})
# 3. issue评论
issue_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{project_id} and journalized_type='Issue' and issues.issue_classify='issue'")
issue_comment_all = issue_comments.count
@ -116,7 +125,7 @@ class UsersController < ApplicationController
prs = PullRequest.where(project_id: project_id)
pr_all = prs.count
pr_user = prs.where(user_id: user_id).count
features["development"] = features["development"].merge({"pr" => {"all" => pr_all, "perc" => pr_user * 1.0 / pr_all}})
features["development"] = features["development"].merge({"pr" => {"all" => pr_all, "perc" => cal_perc(pr_user, pr_all)}})
# 5. pr评论
pr_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{project_id} and journalized_type='Issue' and issues.issue_classify='pull_request'")
pr_comment_all = pr_comments.count
@ -165,12 +174,12 @@ class UsersController < ApplicationController
count_all += count_1
counts[category] = count_1
features[category].each do |key, value|
weight = value["all"] * 1.0 / count_1
weight = cal_perc(value["all"], count_1)
weights[category] = weights[category].merge({key => weight})
end
end
categories.each do |category|
weight = counts[category] * 1.0 / count_all
weight = cal_perc(counts[category], count_all)
weights[category] = weights[category].merge({"category_weight" => weight})
end
return weights
@ -178,7 +187,8 @@ class UsersController < ApplicationController
weights_categories = cal_weight(features)
scores = {
"final" => 0.0
"final" => 0.0,
"blockchain" => false
}
features.each do |category, value_1|
category_score = 0.0
@ -188,6 +198,7 @@ class UsersController < ApplicationController
scores["final"] += weights_categories[category]["category_weight"] * category_score.round(4)
scores = scores.merge({category => category_score.round(4)})
end
end
render json: { scores: scores }
end