竞赛排行榜规则调整

dev_sync_trustie
cxt 5 years ago
parent 803d9d5d7d
commit 96376620d7

@ -84,8 +84,8 @@ class Competitions::CompetitionsController < Competitions::BaseController
def chart_rules def chart_rules
@competition = current_competition @competition = current_competition
@stages = @competition.competition_stages com_module = @competition.competition_modules.find_by(module_type: "chart")
@rule_contents = @competition.chart_rules @rule_contents = com_module&.competition_module_md_contents
end end
def update_chart_rules def update_chart_rules

@ -37,7 +37,7 @@ module CompetitionsHelper
def chart_stages competition def chart_stages competition
stages = [] stages = []
statistic_stages = competition.competition_stages.where("rate > 0") statistic_stages = competition.competition_stages.where("score_rate > 0")
if competition.end_time && competition.end_time < Time.now && statistic_stages.size > 1 if competition.end_time && competition.end_time < Time.now && statistic_stages.size > 1
stages << {id: nil, name: "总排行榜", rate: 1.0, start_time: competition.start_time, end_time: competition.end_time} stages << {id: nil, name: "总排行榜", rate: 1.0, start_time: competition.start_time, end_time: competition.end_time}
end end

@ -7,8 +7,6 @@ class CompetitionModule < ApplicationRecord
def module_url def module_url
result_url = url.present? ? url : case module_type result_url = url.present? ? url : case module_type
when "home"
"/competitions/#{competition.identifier}.json"
when "chart" when "chart"
"/competitions/#{competition.identifier}/charts.json" "/competitions/#{competition.identifier}/charts.json"
when "enroll" when "enroll"

@ -3,6 +3,6 @@ class CompetitionModuleMdContent < ApplicationRecord
has_many :attachments, as: :container, dependent: :destroy has_many :attachments, as: :container, dependent: :destroy
validates :name, presence: true # validates :name, presence: true
validates :content, presence: true validates :content, presence: true
end end

@ -0,0 +1,14 @@
class MigrateCompetitionChartRules < ActiveRecord::Migration[5.2]
def change
add_column :competition_module_md_contents, :competition_stage_id, :integer, default: 0
ChartRule.all.each do |rule|
if rule.competition
com_module = rule.competition.competition_modules.find_by(module_type: "chart")
if com_module
CompetitionModuleMdContent.create!(content: rule.content, competition_module_id: com_module.id, competition_stage_id: rule.competition_stage_id ? rule.competition_stage_id : 0)
end
end
end
end
end
Loading…
Cancel
Save