新增:贡献占比优化
This commit is contained in:
parent
51f460a6b6
commit
29217ff345
|
@ -31,7 +31,7 @@ module Watchable
|
||||||
following.size
|
following.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def mindspore_contribution_perc(project)
|
def simple_contribution_perc(project)
|
||||||
@project = project
|
@project = project
|
||||||
@user = self
|
@user = self
|
||||||
|
|
||||||
|
@ -39,14 +39,16 @@ module Watchable
|
||||||
(count_user * 1.0 / (count_all + 0.000000001)).round(5)
|
(count_user * 1.0 / (count_all + 0.000000001)).round(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @project['use_blockchain'] == true or @project['use_blockchain'] == 1
|
if (@project['use_blockchain'] == true or @project['use_blockchain'] == 1) && @user.id.present?
|
||||||
balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id})
|
balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id})
|
||||||
balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"]
|
balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"]
|
||||||
score = cal_perc(balance_user, balance_all)
|
score = cal_perc(balance_user, balance_all)
|
||||||
else
|
else
|
||||||
commits_all = Project.mindspore_contributors.map{|i| i['contributions']}.sum
|
contributors = []
|
||||||
commit_user = Project.mindspore_contributors.select{|i| i['login'] == @user.login}.map{|i| i['contributions']}.sum
|
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier,{q_name: self.login, q_email: self.mail})
|
||||||
score = cal_perc(commit_user, commits_all)
|
user_contribution = result[:body][0]
|
||||||
|
commits_all = result[:total_contributions]
|
||||||
|
score = cal_perc(user_contribution["contributions"], commits_all)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
class Gitea::Repository::Contributors::GetService < Gitea::ClientService
|
class Gitea::Repository::Contributors::GetService < Gitea::ClientService
|
||||||
attr_reader :owner, :repo_name, :page, :limit
|
attr_reader :owner, :repo_name, :page, :limit, :q_name, :q_email
|
||||||
|
|
||||||
def initialize(owner, repo_name, params)
|
def initialize(owner, repo_name, params)
|
||||||
@owner = owner
|
@owner = owner
|
||||||
@repo_name = repo_name
|
@repo_name = repo_name
|
||||||
@page = params[:page] || 1
|
@page = params[:page] || 1
|
||||||
@limit = params[:limit] || 20
|
@limit = params[:limit] || 20
|
||||||
|
@q_name = params[:q_name] || ""
|
||||||
|
@q_email = params[:q_email] || ""
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
@ -15,7 +17,7 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService
|
||||||
|
|
||||||
private
|
private
|
||||||
def params
|
def params
|
||||||
Hash.new.merge(token: owner.gitea_token, page: page, limit: limit)
|
Hash.new.merge(token: owner.gitea_token, page: page, limit: limit, q_name: q_name, q_email: q_email)
|
||||||
end
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
|
@ -29,7 +31,8 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService
|
||||||
headers = response.headers.to_hash
|
headers = response.headers.to_hash
|
||||||
body = JSON.parse(response.body)
|
body = JSON.parse(response.body)
|
||||||
total_count = headers["x-total"]
|
total_count = headers["x-total"]
|
||||||
result.merge(total_count: total_count.to_i, body: body)
|
total_contributions = headers["x-total-contributions"]
|
||||||
|
result.merge(total_count: total_count.to_i, total_contributions: total_contributions.to_i, body: body)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
# {status: -1, message: "#{body['message']}"}
|
# {status: -1, message: "#{body['message']}"}
|
||||||
|
|
Loading…
Reference in New Issue