forked from Trustie/forgeplus
fix: Gitea中不存在项目不参与评估
This commit is contained in:
parent
9f3375806f
commit
7020e5a040
|
@ -120,15 +120,17 @@ class ProjectEvaluation < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.update_raw_scores(project)
|
||||
evaluation = find_or_initialize_by(project_id: project.id)
|
||||
repo = Gitea::Repository::GetService.new(project.owner, project.identifier).call
|
||||
if !repo.nil?
|
||||
evaluation = find_or_initialize_by(project_id: project.id)
|
||||
|
||||
evaluation.influence = calculate_influence(project)
|
||||
evaluation.community = calculate_community(project)
|
||||
evaluation.vitality = calculate_vitality(project)
|
||||
evaluation.health = calculate_health(project)
|
||||
evaluation.trend = calculate_trend(project)
|
||||
|
||||
evaluation.save
|
||||
evaluation.influence = calculate_influence(project)
|
||||
evaluation.community = calculate_community(project)
|
||||
evaluation.vitality = calculate_vitality(project)
|
||||
evaluation.health = calculate_health(project)
|
||||
evaluation.trend = calculate_trend(project)
|
||||
evaluation.save
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_normalized_scores
|
||||
|
@ -166,4 +168,25 @@ class ProjectEvaluation < ApplicationRecord
|
|||
score_column = "#{interval}_score"
|
||||
ProjectEvaluation.where.not(score: nil).update_all("#{score_column} = score")
|
||||
end
|
||||
|
||||
def self.update_all
|
||||
Project.where(is_public: 1, id: Repository.pluck(:project_id)).find_each do |project|
|
||||
ProjectEvaluation.update_raw_scores(project)
|
||||
end
|
||||
ProjectEvaluation.update_normalized_scores
|
||||
|
||||
current_date = Date.today
|
||||
if current_date.wday == 1
|
||||
ProjectEvaluationTop.evaluate_and_update(:weekly)
|
||||
end
|
||||
if current_date.day == 1
|
||||
ProjectEvaluationTop.evaluate_and_update(:monthly)
|
||||
end
|
||||
if current_date.day == 1 && [1, 4, 7, 10].include?(current_date.month)
|
||||
ProjectEvaluationTop.evaluate_and_update(:quarterly)
|
||||
end
|
||||
if current_date.yday == 1
|
||||
evaluate_and_update(:yearly)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue