From bf0af3c9463f5a9a38cae5c5766dd391c3bf14df Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Apr 2023 17:12:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Ascore=E8=AE=B0?= =?UTF-8?q?=E5=88=86=E5=8A=A0=E5=85=A5=E4=BB=A3=E7=A0=81=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 5 +++-- app/views/api/v1/projects/contributors/stat.json.jbuilder | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3f74df9f4..ba8afffa4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -877,11 +877,11 @@ class User < Owner end end - def self.develop_score(commit_count, user_id=User.current.id) + def self.develop_score(commit_count, code_line, user_id=User.current.id) user_date_statistic_key = "v2-user-statistic:#{user_id}" follow_count = $redis_cache.hget(user_date_statistic_key, "follow-count") || 0 pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count").to_i || 0 - issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 0 + issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count").to_i || 0 project_count = $redis_cache.hget(user_date_statistic_key, "project-count") || 0 fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0 project_watchers_count = $redis_cache.hget(user_date_statistic_key, "project-watcher-count") || 0 @@ -889,6 +889,7 @@ class User < Owner project_language = $redis_cache.hget(user_date_statistic_key, "project-language") project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length pullrequest_count += commit_count + issues_count += code_line influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i contribution = (60.0 + pullrequest_count.to_i / (pullrequest_count.to_i + 20.0) * 40.0).to_i activity = (60.0 + issues_count.to_i / (issues_count.to_i + 80.0) * 40.0).to_i diff --git a/app/views/api/v1/projects/contributors/stat.json.jbuilder b/app/views/api/v1/projects/contributors/stat.json.jbuilder index f0e91225a..456c37bce 100644 --- a/app/views/api/v1/projects/contributors/stat.json.jbuilder +++ b/app/views/api/v1/projects/contributors/stat.json.jbuilder @@ -1,10 +1,10 @@ json.total_count @result_object[:total_data].to_i result_arr = @result_object[:data] -result_arr = result_arr.sort_by!{|c| User.develop_score(c["commits"])}.reverse +result_arr = result_arr.sort_by!{|c| User.develop_score(c["commits"],c["additions"]+c["deletions"])}.reverse json.contributors result_arr.each do |contributor| user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") if user.blank? - json.score User.develop_score(contributor["commits"]) + json.score User.develop_score(contributor["commits"],contributor["additions"]+contributor["deletions"] )-300 json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"] @@ -15,7 +15,7 @@ json.contributors result_arr.each do |contributor| json.name contributor["name"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) else - json.score User.develop_score(contributor["commits"]) + json.score User.develop_score(contributor["commits"],contributor["additions"]+contributor["deletions"])-300 json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"]