mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:33:05 +08:00
新增:固定数据清洗及获取
This commit is contained in:
@@ -31,6 +31,25 @@ module Watchable
|
||||
following.size
|
||||
end
|
||||
|
||||
def mindspore_contribution_perc(project)
|
||||
@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
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
def contribution_perc(project)
|
||||
@project = project
|
||||
@user = self
|
||||
|
||||
@@ -438,4 +438,32 @@ class Project < ApplicationRecord
|
||||
def del_project_issue_cache_delete_count
|
||||
$redis_cache.hdel("issue_cache_delete_count", self.id)
|
||||
end
|
||||
|
||||
def self.mindspore_contributors
|
||||
cache_result = $redis_cache.get("ProjectMindsporeContributors")
|
||||
if cache_result.nil?
|
||||
contributors = []
|
||||
file = File.open('public/mindspore_authors', 'r')
|
||||
file.each_line do |l|
|
||||
itemArray = l.gsub("\r\n", "").split("|:|")
|
||||
email = itemArray[0]
|
||||
username = itemArray[1]
|
||||
commits = itemArray[2].to_i
|
||||
if username =~ CustomRegexp::LOGIN && email =~ CustomRegexp::EMAIL
|
||||
user = User.find_by(login: username, mail: email)
|
||||
else
|
||||
user = User.find_by(mail: email) unless username =~ CustomRegexp::LOGIN
|
||||
user = User.find_by(login: username) unless email =~ CustomRegexp::EMAIL
|
||||
end
|
||||
contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys
|
||||
end
|
||||
file.close
|
||||
|
||||
$redis_cache.set("ProjectMindsporeContributors", contributors.to_json)
|
||||
|
||||
return contributors
|
||||
else
|
||||
return JSON.parse(cache_result)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user