新增:贡献占比优化

This commit is contained in:
yystopf 2023-03-24 23:05:01 +08:00
parent 51f460a6b6
commit 29217ff345
2 changed files with 13 additions and 8 deletions

View File

@ -31,7 +31,7 @@ module Watchable
following.size
end
def mindspore_contribution_perc(project)
def simple_contribution_perc(project)
@project = project
@user = self
@ -39,14 +39,16 @@ module Watchable
(count_user * 1.0 / (count_all + 0.000000001)).round(5)
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_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"]
score = cal_perc(balance_user, balance_all)
else
commits_all = Project.mindspore_contributors.map{|i| i['contributions']}.sum
commit_user = Project.mindspore_contributors.select{|i| i['login'] == @user.login}.map{|i| i['contributions']}.sum
score = cal_perc(commit_user, commits_all)
contributors = []
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier,{q_name: self.login, q_email: self.mail})
user_contribution = result[:body][0]
commits_all = result[:total_contributions]
score = cal_perc(user_contribution["contributions"], commits_all)
end
end

View File

@ -1,11 +1,13 @@
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)
@owner = owner
@repo_name = repo_name
@page = params[:page] || 1
@limit = params[:limit] || 20
@q_name = params[:q_name] || ""
@q_email = params[:q_email] || ""
end
def call
@ -15,7 +17,7 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService
private
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
def url
@ -29,7 +31,8 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService
headers = response.headers.to_hash
body = JSON.parse(response.body)
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
nil
# {status: -1, message: "#{body['message']}"}