Browse Source

更改:贡献者贡献占比计算

pull/342/head
yystopf 3 years ago
parent
commit
b8869bd0e2
2 changed files with 22 additions and 1 deletions
  1. +20
    -0
      app/models/concerns/watchable.rb
  2. +2
    -1
      app/views/repositories/_contributor.json.jbuilder

+ 20
- 0
app/models/concerns/watchable.rb View File

@@ -31,6 +31,26 @@ module Watchable
following.size
end

def simple_contribution_perc(project, perc=nil)
@project = project
@user = self

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) && @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)
score = (score * 100).round(1).to_s + "%"
else
score = perc
end

score
end

def contribution_perc(project)
@project = project
@user = self


+ 2
- 1
app/views/repositories/_contributor.json.jbuilder View File

@@ -6,6 +6,7 @@ if user.blank?
json.type nil
json.name contributor["login"]
json.image_url User::Avatar.get_letter_avatar_url(contributor["login"])
json.contribution_perc User.new(login: contributor["login"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"])
else
json.contributions contributor["contributions"]
# json.gid contributor["id"]
@@ -14,5 +15,5 @@ else
json.name user["name"]
json.image_url user["avatar_url"]
db_user = User.find_by_id(user["id"])
json.contribution_perc db_user.contribution_perc(project) if db_user.present?
json.contribution_perc db_user.simple_contribution_perc(project) if db_user.present?
end

Loading…
Cancel
Save