forked from Trustie/forgeplus
Compare commits
3 Commits
824767ca30
...
7020e5a040
| Author | SHA1 | Date |
|---|---|---|
|
|
7020e5a040 | |
|
|
9f3375806f | |
|
|
ec0a6be9d4 |
|
|
@ -1,33 +1,6 @@
|
|||
class Admins::ProjectEvaluationController < Admins::BaseController
|
||||
def update
|
||||
Project.where(is_public: 1, id: Repository.pluck(:project_id)).find_each do |project|
|
||||
ProjectEvaluation.update_raw_scores(project)
|
||||
end
|
||||
ProjectEvaluation.update_normalized_scores
|
||||
|
||||
def evaluate_and_update(interval)
|
||||
ProjectEvaluationTop.top_projects_selection(interval)
|
||||
ProjectEvaluation.update_scores_by_interval(interval)
|
||||
end
|
||||
|
||||
current_date = Date.today
|
||||
|
||||
if current_date.wday == 1
|
||||
evaluate_and_update(:weekly)
|
||||
end
|
||||
|
||||
if current_date.day == 1
|
||||
evaluate_and_update(:monthly)
|
||||
end
|
||||
|
||||
if current_date.day == 1 && [1, 4, 7, 10].include?(current_date.month)
|
||||
evaluate_and_update(:quarterly)
|
||||
end
|
||||
|
||||
if current_date.yday == 1
|
||||
evaluate_and_update(:yearly)
|
||||
end
|
||||
|
||||
ProjectEvaluation.update_all
|
||||
render_ok()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -291,38 +291,30 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def score
|
||||
project_evaluation = ProjectEvaluation.find_by(project_id: @project.id)
|
||||
|
||||
response_data = {
|
||||
influence_norm_score: project_evaluation&.norm_influence || 0,
|
||||
community_norm_score: project_evaluation&.norm_community || 0,
|
||||
vitality_norm_score: project_evaluation&.norm_vitality || 0,
|
||||
health_norm_score: project_evaluation&.norm_health || 0,
|
||||
trend_norm_score: project_evaluation&.norm_trend || 0,
|
||||
score: project_evaluation&.score || 0,
|
||||
updated_at: project_evaluation&.updated_at&.strftime("%Y-%m-%d %H:%M")
|
||||
}
|
||||
render json: response_data
|
||||
@project_evaluation = ProjectEvaluation.find_by(project_id: @project.id)
|
||||
if @project_evaluation.nil?
|
||||
render_error("暂无得分数据")
|
||||
end
|
||||
end
|
||||
|
||||
def top
|
||||
period = params[:period]
|
||||
time_interval = params[:time_interval]
|
||||
|
||||
if period.present? && time_interval.present?
|
||||
project_evaluation_ids = ProjectEvaluationTop.where(evaluation_period: period, time_interval: time_interval)
|
||||
.pluck(:project_id)
|
||||
|
||||
projects = Project.where(id: project_evaluation_ids).includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units, :project_topics).project_statics_select
|
||||
render json: projects
|
||||
custom_params = {
|
||||
ids: project_evaluation_ids.join(","),
|
||||
}
|
||||
@total_count = project_evaluation_ids.count
|
||||
scope = Projects::ListQuery.call(custom_params)
|
||||
@projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units, :project_topics))
|
||||
else
|
||||
render_error("参数错误")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
class EvaluateProjectJob < ApplicationJob
|
||||
queue_as :message
|
||||
|
||||
def perform(*args)
|
||||
ProjectEvaluation.update_all
|
||||
end
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -54,4 +54,9 @@ class ProjectEvaluationTop < ApplicationRecord
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
def self.evaluate_and_update(interval)
|
||||
ProjectEvaluationTop.top_projects_selection(interval)
|
||||
ProjectEvaluation.update_scores_by_interval(interval)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
json.influence_norm_score @project_evaluation.norm_influence
|
||||
json.community_norm_score @project_evaluation.norm_community
|
||||
json.vitality_norm_score @project_evaluation.norm_vitality
|
||||
json.health_norm_score @project_evaluation.norm_health
|
||||
json.trend_norm_score @project_evaluation.norm_trend
|
||||
json.score @project_evaluation.score
|
||||
json.updated_at time_from_now(@project_evaluation.updated_at)
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
json.total_count @total_count
|
||||
json.projects @projects do |project|
|
||||
json.id project.id
|
||||
json.repo_id project&.repository&.id
|
||||
json.identifier render_identifier(project)
|
||||
json.name project.name
|
||||
json.description Nokogiri::HTML(project.description).text
|
||||
json.visits project.visits
|
||||
json.praises_count project.praises_count.to_i
|
||||
json.forked_count project.forked_count.to_i
|
||||
json.is_public project.is_public
|
||||
json.mirror_url project.repository&.mirror_url
|
||||
json.type project&.numerical_for_project_type
|
||||
json.last_update_time render_unix_time(project.updated_on)
|
||||
json.time_ago time_from_now(project.updated_on)
|
||||
json.forked_from_project_id project.forked_from_project_id
|
||||
json.open_devops project.open_devops?
|
||||
json.platform project.platform
|
||||
json.author do
|
||||
if project.educoder?
|
||||
project_educoder = project.project_educoder
|
||||
json.name project_educoder&.owner
|
||||
json.login project_educoder&.repo_name.split('/')[0]
|
||||
# json.image_url render_educoder_avatar_url(project.project_educoder)
|
||||
else
|
||||
user = project.owner
|
||||
json.type user.type
|
||||
json.name user.try(:show_real_name)
|
||||
json.login user.login
|
||||
json.image_url url_to_avatar(user)
|
||||
end
|
||||
end
|
||||
|
||||
json.category do
|
||||
if project.project_category.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_category.id
|
||||
json.name project.project_category.name
|
||||
end
|
||||
end
|
||||
json.language do
|
||||
if project.project_language.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_language.id
|
||||
json.name project.project_language.name
|
||||
end
|
||||
end
|
||||
json.topics project.project_topics.each do |topic|
|
||||
json.(topic, :id, :name)
|
||||
end
|
||||
end
|
||||
|
|
@ -7,3 +7,8 @@ delay_expired_issue:
|
|||
cron: "0 0 * * *"
|
||||
class: "DelayExpiredIssueJob"
|
||||
queue: message
|
||||
|
||||
evaluate_project:
|
||||
cron: "0 0 * * *"
|
||||
class: "EvaluateProjectJob"
|
||||
queue: message
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EvaluateProjectJob, type: :job do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Loading…
Reference in New Issue