From 7020e5a040d27db9ed2ad6bbec9aa687d3772cea Mon Sep 17 00:00:00 2001 From: lexiaozhang Date: Thu, 5 Oct 2023 23:42:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Gitea=E4=B8=AD=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E9=A1=B9=E7=9B=AE=E4=B8=8D=E5=8F=82=E4=B8=8E=E8=AF=84?= =?UTF-8?q?=E4=BC=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project_evaluation.rb | 39 +++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/app/models/project_evaluation.rb b/app/models/project_evaluation.rb index 42f655c0b..9ce162756 100644 --- a/app/models/project_evaluation.rb +++ b/app/models/project_evaluation.rb @@ -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