Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
commit
b4967c8a5a
|
@ -128,6 +128,7 @@ class Project < ApplicationRecord
|
||||||
has_many :project_invite_links, dependent: :destroy
|
has_many :project_invite_links, dependent: :destroy
|
||||||
has_many :project_topic_ralates, dependent: :destroy
|
has_many :project_topic_ralates, dependent: :destroy
|
||||||
has_many :project_topics, through: :project_topic_ralates
|
has_many :project_topics, through: :project_topic_ralates
|
||||||
|
has_many :commit_logs, dependent: :destroy
|
||||||
after_create :incre_user_statistic, :incre_platform_statistic
|
after_create :incre_user_statistic, :incre_platform_statistic
|
||||||
after_save :check_project_members
|
after_save :check_project_members
|
||||||
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data
|
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data
|
||||||
|
|
|
@ -877,6 +877,29 @@ class User < Owner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.develop_score(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") || 0
|
||||||
|
issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 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
|
||||||
|
project_praises_count = $redis_cache.hget(user_date_statistic_key, "project-praise-count") || 0
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
experience = 10 * project_count.to_i + 5 * fork_count.to_i + project_watchers_count.to_i + project_praises_count.to_i
|
||||||
|
experience = (60.0 + experience / (experience + 100.0) * 40.0).to_i
|
||||||
|
language = (60.0 + project_languages_count.to_i / (project_languages_count.to_i + 5.0) * 40.0).to_i
|
||||||
|
score = influence+ contribution + activity + experience + language
|
||||||
|
|
||||||
|
score
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def validate_password_length
|
def validate_password_length
|
||||||
|
|
|
@ -2,6 +2,7 @@ json.total_count @result_object[:total_data].to_i
|
||||||
json.contributors @result_object[:data].each do |contributor|
|
json.contributors @result_object[:data].each do |contributor|
|
||||||
user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}")
|
user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}")
|
||||||
if user.blank?
|
if user.blank?
|
||||||
|
json.score 300
|
||||||
json.contributions contributor["commits"]
|
json.contributions contributor["commits"]
|
||||||
json.additions contributor["additions"]
|
json.additions contributor["additions"]
|
||||||
json.deletions contributor["deletions"]
|
json.deletions contributor["deletions"]
|
||||||
|
@ -12,6 +13,7 @@ json.contributors @result_object[:data].each do |contributor|
|
||||||
json.name contributor["name"]
|
json.name contributor["name"]
|
||||||
json.image_url User::Avatar.get_letter_avatar_url(contributor["name"])
|
json.image_url User::Avatar.get_letter_avatar_url(contributor["name"])
|
||||||
else
|
else
|
||||||
|
json.score User.develop_score(user["id"])
|
||||||
json.contributions contributor["commits"]
|
json.contributions contributor["commits"]
|
||||||
json.additions contributor["additions"]
|
json.additions contributor["additions"]
|
||||||
json.deletions contributor["deletions"]
|
json.deletions contributor["deletions"]
|
||||||
|
|
|
@ -7,6 +7,19 @@ json.score item[1]
|
||||||
json.name owner_common["name"]
|
json.name owner_common["name"]
|
||||||
json.type owner_common["type"]
|
json.type owner_common["type"]
|
||||||
json.login owner_common["login"]
|
json.login owner_common["login"]
|
||||||
|
if owner_common["tmp_projects"].nil?
|
||||||
|
normal_projects = Project.members_projects(item[0]).to_sql
|
||||||
|
org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: item[0]}).to_sql
|
||||||
|
issue_project = Project.joins(:issues).where(issues: {author_id: item[0]}).to_sql
|
||||||
|
pull_project = Project.joins(:pull_requests).where(pull_requests: {user_id: item[0]}).to_sql
|
||||||
|
commit_project = Project.joins(:commit_logs).where(commit_logs: {user_id: item[0]}).to_sql
|
||||||
|
project_count = Project.from("( #{normal_projects} UNION #{org_projects} UNION #{issue_project} UNION #{pull_project} UNION #{issue_project} ) AS projects").distinct.size
|
||||||
|
|
||||||
|
$redis_cache.hset("v2-owner-common:#{item[0]}", 'tmp_projects', project_count)
|
||||||
|
json.projects_count project_count
|
||||||
|
else
|
||||||
|
json.projects_count owner_common["tmp_projects"]
|
||||||
|
end
|
||||||
json.avatar_url owner_common["avatar_url"]
|
json.avatar_url owner_common["avatar_url"]
|
||||||
if popular_project.blank?
|
if popular_project.blank?
|
||||||
json.project nil
|
json.project nil
|
||||||
|
|
Loading…
Reference in New Issue