diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 32823ab9..d55638df 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -106,7 +106,7 @@ class GraduationTopicsController < ApplicationController def student_select_topic if User.current.student_graduation_topics.where(:course_id => @course.id, :status => [0, 1]).count == 0 @topic.student_graduation_topics << StudentGraduationTopic.new(:course_id => @course.id, :user_id => User.current.id, - :member_id => @course.members.where(:user_id => User.current.id).first.try(:id)) + :member_id => @course.course_members.where(:user_id => current_user.id).first.try(:id)) @topic.update_attributes(:status => 1) end redirect_to graduation_topic_path(@topic) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index a7a7d8c0..84f337d8 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -16,7 +16,7 @@ class HomeworkCommonController < ApplicationController before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment, :start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works, :open_student_works,:add_to_homework_bank,:publish_notice,:end_notice,:publish_homework,:end_homework,:update_explanation, - :cancel_publish, :move_to_category] + :cancel_publish, :move_to_category,:homework_setting] # before_filter :member_of_course, :only => [:index,:setting] @@ -282,93 +282,94 @@ class HomeworkCommonController < ApplicationController end def homework_setting - if @homework.homework_detail_manual.try(:comment_status) == 0 && @course.course_groups.count > 1 - @homework.unified_setting = params[:unified_setting] ? true :false - end + ActiveRecord::Base.transaction do + if @homework.homework_detail_manual.try(:comment_status) == 0 && @course.course_groups.count > 1 + @homework.unified_setting = params[:unified_setting] ? true :false + end - if @homework.unified_setting - params_publish_time = params[:homework_publish_time] - params_end_time = params[:homework_end_time] - # params_archive_time = params[:homework_archive_time] - min_publish_time = params_publish_time - max_end_time = params_end_time - else - # 获取最小发布时间和最大截止时间,赋值给homework - params_publish_time = params[:homework_publish_time_group] - params_end_time = params[:homework_end_time_group] - # params_archive_time = params[:homework_archive_time_group] - min_publish_time = @homework.publish_time ? (format_time @homework.publish_time).to_s : "" - max_end_time = @homework.end_time ? (format_time @homework.end_time).to_s : "" - if params[:homework_end_time_group] - max_end_time = "" - params[:homework_end_time_group].each_with_index do |end_time, index| - if end_time != "" - if max_end_time == "" || end_time > max_end_time - max_end_time = end_time + if @homework.unified_setting + params_publish_time = params[:homework_publish_time] + params_end_time = params[:homework_end_time] + # params_archive_time = params[:homework_archive_time] + min_publish_time = params_publish_time + max_end_time = params_end_time + else + # 获取最小发布时间和最大截止时间,赋值给homework + params_publish_time = params[:homework_publish_time_group] + params_end_time = params[:homework_end_time_group] + # params_archive_time = params[:homework_archive_time_group] + min_publish_time = @homework.publish_time ? (format_time @homework.publish_time).to_s : "" + max_end_time = @homework.end_time ? (format_time @homework.end_time).to_s : "" + if params[:homework_end_time_group] + max_end_time = "" + params[:homework_end_time_group].each_with_index do |end_time, index| + if end_time != "" + if max_end_time == "" || end_time > max_end_time + max_end_time = end_time + end end end end - end - if params[:homework_publish_time_group] - params[:homework_publish_time_group].each_with_index do |publish_time, index| - if publish_time != "" - if min_publish_time == "" || publish_time < min_publish_time - min_publish_time = publish_time + if params[:homework_publish_time_group] + params[:homework_publish_time_group].each_with_index do |publish_time, index| + if publish_time != "" + if min_publish_time == "" || publish_time < min_publish_time + min_publish_time = publish_time + end end end end end - end - # 不统一设置且分班数大于一则更新分组设置 - if !@homework.unified_setting && @course.course_groups.count > 1 - @course.course_groups.each_with_index do |group, index| - homework_group_setting = @homework.homework_group_settings.where(:course_group_id => group.id).first - unless homework_group_setting - homework_group_setting = HomeworkGroupSetting.create(:homework_common_id => @homework.id, :course_group_id => group.id, :course_id => @course.id) + # 不统一设置且分班数大于一则更新分组设置 + if !@homework.unified_setting && @course.course_groups.count > 1 + @course.course_groups.each_with_index do |group, index| + homework_group_setting = @homework.homework_group_settings.where(:course_group_id => group.id).first + unless homework_group_setting + homework_group_setting = HomeworkGroupSetting.create(:homework_common_id => @homework.id, :course_group_id => group.id, :course_id => @course.id) + end end - end - group_id = [] - @homework.homework_group_settings.where("publish_time is null or publish_time > '#{Time.now}'").joins(:course_group).reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each_with_index do |setting, index| - if params[:homework_publish_time_group] && min_publish_time != "" - if params[:homework_publish_time_group][index] && params[:homework_publish_time_group][index] != "" - setting.update_column(:publish_time, params[:homework_publish_time_group][index]) + group_id = [] + @homework.homework_group_settings.where("publish_time is null or publish_time > '#{Time.now}'").joins(:course_group).reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each_with_index do |setting, index| + if params[:homework_publish_time_group] && min_publish_time != "" + if params[:homework_publish_time_group][index] && params[:homework_publish_time_group][index] != "" + setting.update_column(:publish_time, params[:homework_publish_time_group][index]) + end + elsif params[:homework_publish_time_group] && min_publish_time == "" + setting.update_column(:publish_time, Time.now) + group_id << setting.course_group_id end - elsif params[:homework_publish_time_group] && min_publish_time == "" - setting.update_column(:publish_time, Time.now) - group_id << setting.course_group_id end - end - @homework.homework_group_settings.where("end_time is null or end_time > '#{Time.now}'").joins(:course_group).reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each_with_index do |setting, index| - if params[:homework_end_time_group] && max_end_time != "" - if params[:homework_end_time_group][index] && params[:homework_end_time_group][index] != "" - setting.update_column(:end_time, params[:homework_end_time_group][index]) + @homework.homework_group_settings.where("end_time is null or end_time > '#{Time.now}'").joins(:course_group).reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each_with_index do |setting, index| + if params[:homework_end_time_group] && max_end_time != "" + if params[:homework_end_time_group][index] && params[:homework_end_time_group][index] != "" + setting.update_column(:end_time, params[:homework_end_time_group][index]) + end + elsif params[:homework_end_time_group] && max_end_time == "" + setting.update_column(:end_time, Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) end - elsif params[:homework_end_time_group] && max_end_time == "" - setting.update_column(:end_time, Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) end + # 统一设置则删除分组设置 + elsif @homework.unified_setting + @homework.homework_group_settings.destroy_all end - # 统一设置则删除分组设置 - elsif @homework.unified_setting - @homework.homework_group_settings.destroy_all - end - # homework 的记录更新 - # 发布时间不为空 - if params_publish_time && min_publish_time != "" - @homework.publish_time = min_publish_time - @homework.end_time = max_end_time - # @homework.archive_time = params_archive_time if params_archive_time - if @homework.publish_time < Time.now and @homework_detail_manual.comment_status == 0 - @homework_detail_manual.comment_status = 1 - create_homework_user = 1 - - if @homework.course_acts.size == 0 - @homework.course_acts << CourseActivity.new(:user_id => @homework.user_id,:course_id => @homework.course_id) + # homework 的记录更新 + # 发布时间不为空 + if params_publish_time && min_publish_time != "" + @homework.publish_time = min_publish_time + @homework.end_time = max_end_time + # @homework.archive_time = params_archive_time if params_archive_time + if @homework.publish_time < Time.now and @homework_detail_manual.comment_status == 0 + @homework_detail_manual.comment_status = 1 + create_homework_user = 1 + + if @homework.course_acts.size == 0 + @homework.course_acts << CourseActivity.new(:user_id => @homework.user_id,:course_id => @homework.course_id) + end end - end =begin if @homework.archive_time < Time.now && @homework_detail_manual.comment_status < 6 @homework_detail_manual.comment_status = 6 @@ -376,22 +377,22 @@ class HomeworkCommonController < ApplicationController @homework_detail_manual.comment_status = 5 end =end - # 发布时间未设置 则按当前时间立即发布 - elsif params_publish_time && min_publish_time == "" - @homework_detail_manual.comment_status = 1 - @homework.publish_time = Time.now - @homework.unified_setting = 1 - @homework.end_time = Time.at(((1.month.since.to_i)/3600.0).ceil * 3600) - # @homework.archive_time = Time.at(((2.months.since.to_i)/3600.0).ceil * 3600) - - create_homework_user = 1 - if @homework.course_acts.size == 0 - @homework.course_acts << CourseActivity.new(:user_id => @homework.user_id,:course_id => @homework.course_id) - end - # 已发布的作业,只更新截止时间和结束时间 - else - @homework.end_time = max_end_time if params_end_time - # @homework.archive_time = params_archive_time if params_archive_time + # 发布时间未设置 则按当前时间立即发布 + elsif params_publish_time && min_publish_time == "" + @homework_detail_manual.comment_status = 1 + @homework.publish_time = Time.now + @homework.unified_setting = 1 + @homework.end_time = Time.at(((1.month.since.to_i)/3600.0).ceil * 3600) + # @homework.archive_time = Time.at(((2.months.since.to_i)/3600.0).ceil * 3600) + + create_homework_user = 1 + if @homework.course_acts.size == 0 + @homework.course_acts << CourseActivity.new(:user_id => @homework.user_id,:course_id => @homework.course_id) + end + # 已发布的作业,只更新截止时间和结束时间 + else + @homework.end_time = max_end_time if params_end_time + # @homework.archive_time = params_archive_time if params_archive_time =begin if @homework.archive_time < Time.now && @homework_detail_manual.comment_status < 6 @@ -400,189 +401,190 @@ class HomeworkCommonController < ApplicationController @homework_detail_manual.comment_status = 5 end =end - end + end - if params[:homework_allow_late] == '1' - @homework.allow_late = true - if @homework.late_penalty != params[:homework_late_penalty].to_i - @homework.student_works.where(:work_status => 2).each do |work| - work.late_penalty = params[:homework_late_penalty].to_i - work.save + if params[:homework_allow_late] == '1' + @homework.allow_late = true + if @homework.late_penalty != params[:homework_late_penalty].to_i + @homework.student_works.where(:work_status => 2).each do |work| + work.late_penalty = params[:homework_late_penalty].to_i + work.save + end end + @homework.late_penalty = params[:homework_late_penalty].to_i + else + @homework.allow_late = false + @homework.late_penalty = 0 end - @homework.late_penalty = params[:homework_late_penalty].to_i - else - @homework.allow_late = false - @homework.late_penalty = 0 - end - anonymous_comment = @homework.anonymous_comment - absence_penalty = @homework_detail_manual.absence_penalty - appeal_penalty = @homework_detail_manual.appeal_penalty - if @homework_detail_manual.comment_status < 3 - if params[:homework_anonymous_comment] - @homework.anonymous_comment = 0 - @homework_detail_manual.evaluation_start = params[:homework_evaluation_start] if params[:homework_evaluation_start] + anonymous_comment = @homework.anonymous_comment + absence_penalty = @homework_detail_manual.absence_penalty + appeal_penalty = @homework_detail_manual.appeal_penalty + if @homework_detail_manual.comment_status < 3 + if params[:homework_anonymous_comment] + @homework.anonymous_comment = 0 + @homework_detail_manual.evaluation_start = params[:homework_evaluation_start] if params[:homework_evaluation_start] + @homework_detail_manual.evaluation_end = params[:homework_evaluation_end] if params[:homework_evaluation_end] + @homework_detail_manual.evaluation_num = params[:homework_evaluation_num] if params[:homework_evaluation_num] + @homework_detail_manual.absence_penalty = params[:homework_absence_penalty] if params[:homework_absence_penalty] + + else + @homework.anonymous_comment = 1 + @homework_detail_manual.evaluation_start = nil + @homework_detail_manual.evaluation_end = nil + @homework_detail_manual.evaluation_num = 0 + @homework_detail_manual.absence_penalty = 0 + end + else @homework_detail_manual.evaluation_end = params[:homework_evaluation_end] if params[:homework_evaluation_end] @homework_detail_manual.evaluation_num = params[:homework_evaluation_num] if params[:homework_evaluation_num] @homework_detail_manual.absence_penalty = params[:homework_absence_penalty] if params[:homework_absence_penalty] + end + if anonymous_comment != @homework.anonymous_comment + @homework_detail_manual.te_proportion = 1 + @homework_detail_manual.ta_proportion = 0 + @homework_detail_programing.ta_proportion = 0 if @homework_detail_programing + end + if @homework_detail_manual.comment_status < 4 + if @homework.anonymous_comment == 0 && params[:homework_anonymous_appeal] + @homework.anonymous_appeal = 1 + @homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time] + @homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty] + else + @homework.anonymous_appeal = 0 + @homework_detail_manual.appeal_time = nil + @homework_detail_manual.appeal_penalty = 0 + end else - @homework.anonymous_comment = 1 - @homework_detail_manual.evaluation_start = nil - @homework_detail_manual.evaluation_end = nil - @homework_detail_manual.evaluation_num = 0 - @homework_detail_manual.absence_penalty = 0 - end - else - @homework_detail_manual.evaluation_end = params[:homework_evaluation_end] if params[:homework_evaluation_end] - @homework_detail_manual.evaluation_num = params[:homework_evaluation_num] if params[:homework_evaluation_num] - @homework_detail_manual.absence_penalty = params[:homework_absence_penalty] if params[:homework_absence_penalty] - end - if anonymous_comment != @homework.anonymous_comment - @homework_detail_manual.te_proportion = 1 - @homework_detail_manual.ta_proportion = 0 - @homework_detail_programing.ta_proportion = 0 if @homework_detail_programing - end - if @homework_detail_manual.comment_status < 4 - if @homework.anonymous_comment == 0 && params[:homework_anonymous_appeal] - @homework.anonymous_appeal = 1 @homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time] @homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty] - - else - @homework.anonymous_appeal = 0 - @homework_detail_manual.appeal_time = nil - @homework_detail_manual.appeal_penalty = 0 - end - else - @homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time] - @homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty] - end - if absence_penalty != @homework_detail_manual.absence_penalty && @homework_detail_manual.comment_status >= 4 - all_dis_eva = StudentWorksEvaluationDistribution.where(:student_work_id => @homework.student_works.map(&:id)) - has_sw_count = all_dis_eva.select("distinct user_id").count - anon_count = all_dis_eva.count / has_sw_count - @homework.student_works.where("work_status != 0").each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(:student_work_id => @homework.student_works.map(&:id)).count - student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :reviewer_role => 3).count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save end - end - if appeal_penalty != @homework_detail_manual.appeal_penalty && @homework_detail_manual.comment_status >= 4 - @homework.student_works.each do |student_work| - appeal_penalty_count = student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :appeal_status => 3).count - student_work.appeal_penalty = appeal_penalty_count > 0 ? appeal_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save - end - end - - # 助教评分模式有变更 则更新学生分数 - if params[:homework_ta_mode] && @homework_detail_manual.ta_mode.to_i != params[:homework_ta_mode].to_i - @homework_detail_manual.ta_mode = params[:ta_mode].to_i - @homework_detail_manual.save - if @homework_detail_manual.ta_mode == 1 + if absence_penalty != @homework_detail_manual.absence_penalty && @homework_detail_manual.comment_status >= 4 + all_dis_eva = StudentWorksEvaluationDistribution.where(:student_work_id => @homework.student_works.map(&:id)) + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count @homework.student_works.where("work_status != 0").each do |student_work| - ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a") - student_work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(:student_work_id => @homework.student_works.map(&:id)).count - student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :reviewer_role => 3).count + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 student_work.save end - else - @homework.student_works.where("work_status != 0").each do |student_work| - ts_score = StudentWorksScore.where("student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL").order("created_at DESC") - student_work.teaching_asistant_score = ts_score.first.nil? ? nil : ts_score.first.score + end + if appeal_penalty != @homework_detail_manual.appeal_penalty && @homework_detail_manual.comment_status >= 4 + @homework.student_works.each do |student_work| + appeal_penalty_count = student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :appeal_status => 3).count + student_work.appeal_penalty = appeal_penalty_count > 0 ? appeal_penalty_count * @homework_detail_manual.absence_penalty : 0 student_work.save end end - end - # 最终成绩组成 - if params[:homework_final_mode] && params[:homework_final_mode].to_i != @homework_detail_manual.final_mode - @homework_detail_manual.final_mode = params[:homework_final_mode].to_i - if params[:homework_final_mode].to_i == 0 - @homework_detail_manual.te_proportion = params[:te_proportion] - @homework_detail_manual.ta_proportion = params[:ta_proportion] - @homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing - @homework_detail_programing.save if @homework_detail_programing - end - @homework_detail_manual.save if @homework_detail_manual - @homework.save - @homework = HomeworkCommon.find @homework.id - @homework.student_works.where("work_status != 0").each do |student_work| - # set_final_score @homework,student_work - student_work.save + # 助教评分模式有变更 则更新学生分数 + if params[:homework_ta_mode] && @homework_detail_manual.ta_mode.to_i != params[:homework_ta_mode].to_i + @homework_detail_manual.ta_mode = params[:ta_mode].to_i + @homework_detail_manual.save + if @homework_detail_manual.ta_mode == 1 + @homework.student_works.where("work_status != 0").each do |student_work| + ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a") + student_work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f + student_work.save + end + else + @homework.student_works.where("work_status != 0").each do |student_work| + ts_score = StudentWorksScore.where("student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL").order("created_at DESC") + student_work.teaching_asistant_score = ts_score.first.nil? ? nil : ts_score.first.score + student_work.save + end + end end - elsif params[:homework_final_mode] && @homework_detail_manual.final_mode == 0 - if (params[:te_proportion] && params[:te_proportion].to_s != @homework_detail_manual.te_proportion.to_s) || (params[:ta_proportion] && params[:ta_proportion].to_s != @homework_detail_manual.ta_proportion.to_s) || (@homework_detail_programing && @homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s) - @homework_detail_manual.te_proportion = params[:te_proportion] - @homework_detail_manual.ta_proportion = params[:ta_proportion] - @homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing + # 最终成绩组成 + if params[:homework_final_mode] && params[:homework_final_mode].to_i != @homework_detail_manual.final_mode + @homework_detail_manual.final_mode = params[:homework_final_mode].to_i + if params[:homework_final_mode].to_i == 0 + @homework_detail_manual.te_proportion = params[:te_proportion] + @homework_detail_manual.ta_proportion = params[:ta_proportion] + @homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing + @homework_detail_programing.save if @homework_detail_programing + end @homework_detail_manual.save if @homework_detail_manual - @homework_detail_programing.save if @homework_detail_programing @homework.save @homework = HomeworkCommon.find @homework.id @homework.student_works.where("work_status != 0").each do |student_work| # set_final_score @homework,student_work student_work.save end + elsif params[:homework_final_mode] && @homework_detail_manual.final_mode == 0 + if (params[:te_proportion] && params[:te_proportion].to_s != @homework_detail_manual.te_proportion.to_s) || (params[:ta_proportion] && params[:ta_proportion].to_s != @homework_detail_manual.ta_proportion.to_s) || (@homework_detail_programing && @homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s) + @homework_detail_manual.te_proportion = params[:te_proportion] + @homework_detail_manual.ta_proportion = params[:ta_proportion] + @homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing + + @homework_detail_manual.save if @homework_detail_manual + @homework_detail_programing.save if @homework_detail_programing + @homework.save + @homework = HomeworkCommon.find @homework.id + @homework.student_works.where("work_status != 0").each do |student_work| + # set_final_score @homework,student_work + student_work.save + end + end end - end - if @homework.homework_type == 4 - @homework.work_efficiency = params[:work_efficiency] ? 1 : 0 - if params[:eff_score] != @homework.eff_score - @homework.eff_score = params[:eff_score] - score_change = true - end - if @homework_detail_manual.answer_open_evaluation != params[:answer_open_evaluation].to_i - @homework_detail_manual.answer_open_evaluation = params[:answer_open_evaluation].to_i - score_change = true - end - if @homework_detail_manual.shixun_evaluation != params[:shixun_evaluation].to_i - @homework_detail_manual.shixun_evaluation = params[:shixun_evaluation].to_i - score_change = true - end - if params[:challenge] - score_change = true - params[:challenge].each_with_index do |challenge_id, index| - setting = @homework.homework_challenge_settings.where(:challenge_id => challenge_id).first - if setting - setting.update_attributes(:score => params[:score][index]) - else - HomeworkChallengeSetting.create(:homework_common_id => @homework.id, :challenge_id => challenge_id, :shixun_id => @homework.homework_commons_shixuns.shixun_id, :score => params[:score][index]) + if @homework.homework_type == 4 + @homework.work_efficiency = params[:work_efficiency] ? 1 : 0 + if params[:eff_score] != @homework.eff_score + @homework.eff_score = params[:eff_score] + score_change = true + end + if @homework_detail_manual.answer_open_evaluation != params[:answer_open_evaluation].to_i + @homework_detail_manual.answer_open_evaluation = params[:answer_open_evaluation].to_i + score_change = true + end + if @homework_detail_manual.shixun_evaluation != params[:shixun_evaluation].to_i + @homework_detail_manual.shixun_evaluation = params[:shixun_evaluation].to_i + score_change = true + end + if params[:challenge] + score_change = true + params[:challenge].each_with_index do |challenge_id, index| + setting = @homework.homework_challenge_settings.where(:challenge_id => challenge_id).first + if setting + setting.update_attributes(:score => params[:score][index]) + else + HomeworkChallengeSetting.create(:homework_common_id => @homework.id, :challenge_id => challenge_id, :shixun_id => @homework.homework_commons_shixuns.shixun_id, :score => params[:score][index]) + end end + @homework.homework_challenge_settings.where("challenge_id not in (#{params[:challenge].join(',')})").destroy_all end - @homework.homework_challenge_settings.where("challenge_id not in (#{params[:challenge].join(',')})").destroy_all - end - @homework.score_open = params[:homework_score_open] ? 1 : 0 - @homework.save! - if score_change - homework_challenge_settings = HomeworkChallengeSetting.where(:homework_common_id => @homework.id) - @homework.student_works.where("work_status != 0").each do |student_work| - set_shixun_final_score student_work, @homework_detail_manual.answer_open_evaluation, homework_challenge_settings + @homework.score_open = params[:homework_score_open] ? 1 : 0 + @homework.save! + if score_change + homework_challenge_settings = HomeworkChallengeSetting.where(:homework_common_id => @homework.id) + @homework.student_works.where("work_status != 0").each do |student_work| + set_shixun_final_score student_work, @homework_detail_manual.answer_open_evaluation, homework_challenge_settings + end + # 更新所有学生的效率分 + update_student_eff_score HomeworkCommon.where(:id => @homework.id).first end - # 更新所有学生的效率分 - update_student_eff_score HomeworkCommon.where(:id => @homework.id).first + else + @homework.work_public = params[:homework_work_public] ? 1 : 0 + @homework.score_open = params[:homework_score_open] ? 1 : 0 + @homework.answer_public = params[:homework_answer_public] ? 1 : 0 + @homework.comment_public = params[:homework_comment_public] ? 1 : 0 + @homework.save! end - else - @homework.work_public = params[:homework_work_public] ? 1 : 0 - @homework.score_open = params[:homework_score_open] ? 1 : 0 - @homework.answer_public = params[:homework_answer_public] ? 1 : 0 - @homework.comment_public = params[:homework_comment_public] ? 1 : 0 - @homework.save! - end - @homework_detail_manual.save - if create_homework_user.present? - if group_id.present? && group_id.size != 0 - if group_id.size == @course.course_groups.count - create_works_tiding @homework, @course.student + @homework_detail_manual.save + if create_homework_user.present? + if group_id.present? && group_id.size != 0 + if group_id.size == @course.course_groups.count + create_works_tiding @homework, @course.student + else + members = @course.members.where(:course_group_id => group_id) + create_works_tiding @homework, members + end else - members = @course.members.where(:course_group_id => group_id) - create_works_tiding @homework, members + create_works_tiding @homework, @course.student end - else - create_works_tiding @homework, @course.student end end redirect_to student_work_index_path(:homework => @homework.id) @@ -929,60 +931,62 @@ class HomeworkCommonController < ApplicationController end def publish_homework - if @homework.homework_detail_manual.try(:comment_status) == 0 - if params[:group_ids] - if @course.course_groups.where(:id => params[:group_ids].split(",")).count == @course.course_groups.count - @homework.homework_group_settings.destroy_all - @homework.update_attribute("unified_setting", true) - # 发消息 - create_works_tiding @homework, @course.student - else - @homework.update_attribute("unified_setting", false) - @course.course_groups.each do |group| - homework_group_setting = @homework.homework_group_settings.where(:course_group_id => group.id).first - unless homework_group_setting - HomeworkGroupSetting.create(:homework_common_id => @homework.id, :course_group_id => group.id, :course_id => @course.id, :publish_time => @homework.publish_time, :end_time => @homework.end_time) + ActiveRecord::Base.transaction do + if @homework.homework_detail_manual.try(:comment_status) == 0 + if params[:group_ids] + if @course.course_groups.where(:id => params[:group_ids].split(",")).count == @course.course_groups.count + @homework.homework_group_settings.destroy_all + @homework.update_attribute("unified_setting", true) + # 发消息 + create_works_tiding @homework, @course.student + else + @homework.update_attribute("unified_setting", false) + @course.course_groups.each do |group| + homework_group_setting = @homework.homework_group_settings.where(:course_group_id => group.id).first + unless homework_group_setting + HomeworkGroupSetting.create(:homework_common_id => @homework.id, :course_group_id => group.id, :course_id => @course.id, :publish_time => @homework.publish_time, :end_time => @homework.end_time) + end end + @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(",")).update_all(:publish_time => Time.now) + @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(","), :end_time => nil).update_all(:end_time => Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) + # 发消息 + members = @course.members.where(:course_group_id => params[:group_ids].split(",")) + create_works_tiding @homework, members end - @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(",")).update_all(:publish_time => Time.now) - @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(","), :end_time => nil).update_all(:end_time => Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) - # 发消息 - members = @course.members.where(:course_group_id => params[:group_ids].split(",")) - create_works_tiding @homework, members + else + @homework.homework_group_settings.destroy_all + create_works_tiding @homework, @course.student end - else - @homework.homework_group_settings.destroy_all - create_works_tiding @homework, @course.student - end - @homework.update_attribute("publish_time", Time.now) + @homework.update_attribute("publish_time", Time.now) - if @homework.end_time.nil? - @homework.update_attribute("end_time", Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) - elsif HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").count > 0 - @homework.update_attribute("end_time", HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").map(&:end_time).max) - end + if @homework.end_time.nil? + @homework.update_attribute("end_time", Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) + elsif HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").count > 0 + @homework.update_attribute("end_time", HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").map(&:end_time).max) + end =begin if @homework.archive_time.nil? @homework.update_attribute("archive_time", Time.at(((2.months.since.to_i)/3600.0).ceil * 3600)) end =end - @homework.homework_detail_manual.update_attribute('comment_status', 1) + @homework.homework_detail_manual.update_attribute('comment_status', 1) - if @homework.course_acts.size == 0 - @homework.course_acts << CourseActivity.new(:user_id => @homework.user_id,:course_id => @homework.course_id) + if @homework.course_acts.size == 0 + @homework.course_acts << CourseActivity.new(:user_id => @homework.user_id,:course_id => @homework.course_id) + end + else + @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(",")).update_all(:publish_time => Time.now) + @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(","), :end_time => nil).update_all(:end_time => Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) + if HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").count > 0 + @homework.update_attribute("end_time", HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").map(&:end_time).max) + end + # 发消息 + members = @course.members.where(:course_group_id => params[:group_ids].split(",")) + create_works_tiding @homework, members end - else - @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(",")).update_all(:publish_time => Time.now) - @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(","), :end_time => nil).update_all(:end_time => Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)) - if HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").count > 0 - @homework.update_attribute("end_time", HomeworkGroupSetting.where("homework_common_id = #{@homework.id} and end_time is not null").map(&:end_time).max) + if @homework.end_time > Time.now && @homework.homework_detail_manual.try(:comment_status) > 1 + @homework.homework_detail_manual.update_attribute("comment_status", 1) end - # 发消息 - members = @course.members.where(:course_group_id => params[:group_ids].split(",")) - create_works_tiding @homework, members - end - if @homework.end_time > Time.now && @homework.homework_detail_manual.try(:comment_status) > 1 - @homework.homework_detail_manual.update_attribute("comment_status", 1) end redirect_to student_work_index_path(:homework => @homework.id) end @@ -1032,7 +1036,8 @@ class HomeworkCommonController < ApplicationController def end_homework time = Time.now student_works = @homework.student_works.where("0=1") - # if @homework.homework_detail_manual.try(:comment_status) == 1 && @homework.end_time > time + ActiveRecord::Base.transaction do +# if @homework.homework_detail_manual.try(:comment_status) == 1 && @homework.end_time > time if params[:group_ids] # @homework.homework_group_settings.where(:course_group_id => params[:group_id]).where("publish_time > '#{Time.now}' or publish_time is null").update_all(:publish_time => time) @homework.homework_group_settings.where(:course_group_id => params[:group_ids].split(",")).update_all(:end_time => time) @@ -1069,7 +1074,9 @@ class HomeworkCommonController < ApplicationController # 更新所有学生的效率分 update_student_eff_score HomeworkCommon.where(:id => @homework.id).first end - # end +# end + end + redirect_to student_work_index_path(:homework => @homework.id) end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 030f3f10..e0157b67 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -451,15 +451,12 @@ class MyshixunsController < ApplicationController # 只有评测中的game才会创建和更新代码评测中的信息 logger.info("##################game: #{game.status}") logger.info("##################retry_status: #{game.retry_status}") - if game.status == 1 || game.status == 2 && game.retry_status == 1 + if game.status == 1 || game.status == 2 if msg.blank? RunCodeMessage.create!(:game_id => game_id, :status => 1, :message => message) else msg.update_attributes(:status => (msg.status + 1), :message => message) end - else - # 评测完成,初始化评测信息的状态 - msg.update_attributes(:status => 0, :message => nil) if msg.present? end render :json => {:data => "success"} end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index a1e7299a..c6fa78d9 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -28,6 +28,156 @@ class WelcomeController < ApplicationController skip_before_filter :check_authentication, :only => [:index] require 'simple_xlsx_reader' + + DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) + def shixun_to_local + identifiers = params[:identifiers].split(",") + shixuns = Shixun.where(identifier: identifiers) + # 不重复导入 + ActiveRecord::Base.transaction do + begin + shixuns.each do |shixun| + if LocalShixun.where(shixun_id: shixun.id).blank? + + local_shixun = LocalShixun.create!(name: shixun.name, description: shixun.description, user_id: User.current.id, status: 0, + trainee: shixun.trainee, webssh: shixun.webssh, multi_webssh: shixun.multi_webssh, + can_copy: shixun.can_copy, identifier: generate_identifier, shixun_id: shixun.id, + use_scope: shixun.use_scope, visits: 1, evaluate_script: shixun.evaluate_script) + + # 同步镜像 + if shixun.mirror_repositories.present? + shixun.mirror_repositories.each do |mirror| + LocalMirrorRepository.create!(:local_shixun_id => local_shixun.id, :mirror_repository_id => mirror.id) + end + end + + # 同步技术标签 + shixun.shixun_tag_repertoires.each do |str| + LocalShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :local_shixun_id => local_shixun.id) + end + + # 不需要同步版本库,版本库应该是从本地导入到线上的时候由线上版本创建的 + + # 同步复制关卡 + if shixun.challenges.present? + shixun.challenges.each do |challenge| + new_challenge = LocalChallenge.new + new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id") + new_challenge.local_shixun_id = local_shixun.id + new_challenge.save! + # 评测题,选择题暂时不考虑 + # 同步测试集 + if challenge.test_sets.present? + challenge.test_sets.each do |test_set| + new_test_set = LocalTestSet.new + new_test_set.attributes = test_set.attributes.dup.except("id","challenge_id") + new_test_set.local_challenge_id = new_challenge.id + new_test_set.save! + end + end + # 同步关卡标签 + challenge_tags = ChallengeTag.where("challenge_id =? and challenge_choose_id is null", challenge.id) + if challenge_tags.present? + challenge_tags.each do |challenge_tag| + LocalChallengeTag.create!(:local_challenge_id => new_challenge.id, :name => challenge_tag.try(:name)) + end + end + end + end + end + end + render :json => {status: 0, message: "同步成功"} + rescue Exception => e + logger.error("shixun_local_in ##{e.message}") + render :json => {status: -1, message: "同步失败,#{e.message}"} + raise ActiveRecord::Rollback + end + + end + end + + def local_to_shixun + ActiveRecord::Base.transaction do + LocalShixun.find_each do |local_shixun| + identifier = generate_identifier + shixun = Shixun.create!(name: local_shixun.name, description: local_shixun.description, user_id: User.current.id, + trainee: local_shixun.trainee, webssh: local_shixun.webssh, multi_webssh: local_shixun.multi_webssh, + can_copy: local_shixun.can_copy, identifier: identifier, reset_time: Time.now, + modify_time: Time.now, use_scope: local_shixun.use_scope, visits: 1, evaluate_script: local_shixun.evaluate_script) + m = ShixunMember.new(:user_id => User.current.id, :role => 1) + shixun.shixun_members << m + + # 同步镜像 + local_mirrors = LocalMirrorRepository.where(local_shixun_id: local_shixun.id) + if local_mirrors.present? + local_mirrors.each do |local_mirror| + ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => local_mirror.mirror_repository_id) + end + end + + # 同步技术标签 + local_shixun_tags = LocalShixunTagRepertoire.where(local_shixun_id: local_shixun.id) + if local_shixun_tags.present? + local_shixun_tags.each do |str| + ShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :shixun_id => shixun.id) + end + end + + # 创建版本库 + repository = Repository.new + repository.shixun = shixun + repository.type = 'Repository::Gitlab' + repository.identifier = shixun.identifier.downcase + repository.project_id = -1 + repository.save! + s = Trustie::Gitlab::Sync.new + s.create_shixun(shixun, repository) + raise "版本库创建失败" if shixun.gpid.blank? # 若和gitlab没同步成功,则抛出异常 + g = Gitlab.client + shixun.update_column(:git_url, g.project(shixun.gpid).path_with_namespace) + + # 同步关卡信息 + local_challenges = LocalChallenge.where(local_shixun_id: local_shixun.id) + if local_challenges.present? + local_challenges.each do |local_challenge| + new_challenge = Challenge.new + new_challenge.attributes = local_challenge.attributes.dup.except("id","local_shixun_id","user_id") + new_challenge.user_id = User.current.id + new_challenge.shixun_id = shixun.id + new_challenge.save! + + # 同步测试集 + local_test_sets = LocalTestSet.where(local_challenge_id: local_challenge.id) + if local_test_sets.present? + local_test_sets.each do |local_test_set| + new_test_set = TestSet.new + new_test_set.attributes = local_test_set.attributes.dup.except("id","challenge_id") + new_test_set.challenge_id = new_challenge.id + new_test_set.save! + end + end + + # 同步关卡标签 + local_challenge_tags = LocalChallengeTag.where(local_challenge_id: local_challenge.id) + if local_challenge_tags.present? + local_challenge_tags.each do |local_challenge_tag| + ChallengeTag.create!(:challenge_id => new_challenge.id, :name => local_challenge_tag.try(:name)) + end + end + end + end + render :json => {status: 0, message: "success", identifier: shixun.identifier} + end + end + end + + + # 生成表示码 + def generate_identifier + code = DCODES.sample(8).join + return generate_identifier if Shixun.where(identifier: code).present? + code + end def index images = PortalImage.where(status: true).order("position asc") diff --git a/app/models/local_challenge.rb b/app/models/local_challenge.rb new file mode 100644 index 00000000..10cf4586 --- /dev/null +++ b/app/models/local_challenge.rb @@ -0,0 +1,3 @@ +class LocalChallenge < ActiveRecord::Base + +end diff --git a/app/models/local_challenge_tag.rb b/app/models/local_challenge_tag.rb new file mode 100644 index 00000000..9768ef30 --- /dev/null +++ b/app/models/local_challenge_tag.rb @@ -0,0 +1,3 @@ +class LocalChallengeTag < ActiveRecord::Base + +end diff --git a/app/models/local_mirror_repository.rb b/app/models/local_mirror_repository.rb new file mode 100644 index 00000000..d402a2df --- /dev/null +++ b/app/models/local_mirror_repository.rb @@ -0,0 +1,3 @@ +class LocalMirrorRepository < ActiveRecord::Base + +end diff --git a/app/models/local_shixun.rb b/app/models/local_shixun.rb new file mode 100644 index 00000000..b8480236 --- /dev/null +++ b/app/models/local_shixun.rb @@ -0,0 +1,3 @@ +class LocalShixun < ActiveRecord::Base + +end diff --git a/app/models/local_shixun_tag_repertoire.rb b/app/models/local_shixun_tag_repertoire.rb new file mode 100644 index 00000000..b3d2721b --- /dev/null +++ b/app/models/local_shixun_tag_repertoire.rb @@ -0,0 +1,2 @@ +class LocalShixunTagRepertoire < ActiveRecord::Base +end diff --git a/app/models/local_test_set.rb b/app/models/local_test_set.rb new file mode 100644 index 00000000..f4320b58 --- /dev/null +++ b/app/models/local_test_set.rb @@ -0,0 +1,3 @@ +class LocalTestSet < ActiveRecord::Base + +end diff --git a/app/models/shixun_tag_repertoire.rb b/app/models/shixun_tag_repertoire.rb index 83a52ee6..8164c98d 100644 --- a/app/models/shixun_tag_repertoire.rb +++ b/app/models/shixun_tag_repertoire.rb @@ -1,4 +1,4 @@ -class ShixunTagRepertoire < ActiveRecord::Base + class ShixunTagRepertoire < ActiveRecord::Base # attr_accessible :title, :body belongs_to :shixun belongs_to :tag_repertoire diff --git a/app/views/challenges/_edit_evaluating_page.html.erb b/app/views/challenges/_edit_evaluating_page.html.erb index 9701635b..6a04a07b 100644 --- a/app/views/challenges/_edit_evaluating_page.html.erb +++ b/app/views/challenges/_edit_evaluating_page.html.erb @@ -297,6 +297,7 @@ $("#test_file_name").show(); }else{ $("#challenge_shixun_update").submit(); + // location.reload(); } } \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f72d1a56..ea70b6a2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -281,6 +281,9 @@ RedmineApp::Application.routes.draw do ## oauth相关 end get 'welcome/ccf' => 'welcome#ccf' + get 'welcome/shixun_to_local' => 'welcome#shixun_to_local' + get 'welcome/local_to_shixun' => 'welcome#local_to_shixun' + # get 'competitions/home' => 'competitions#home' # get 'competitions/hn' => 'competitions#index' # get 'competitions/db' => 'competitions#db' diff --git a/db/migrate/20190329070441_migrate_homework_common_end_times.rb b/db/migrate/20190329070441_migrate_homework_common_end_times.rb index 0fa7b6cb..ac6bb087 100644 --- a/db/migrate/20190329070441_migrate_homework_common_end_times.rb +++ b/db/migrate/20190329070441_migrate_homework_common_end_times.rb @@ -1,12 +1,12 @@ class MigrateHomeworkCommonEndTimes < ActiveRecord::Migration def up - homework_commons = HomeworkCommon.where("id < 21549") - homework_commons.find_each do |homework| - sql = "update homework_commons set end_time = (select max(end_time) from - homework_seconds where id = #{homework.id}) where id = #{homework.id}" - - ActiveRecord::Base.connection.execute(sql) - end + # homework_commons = HomeworkCommon.where("id < 21549") + # homework_commons.find_each do |homework| + # sql = "update homework_commons set end_time = (select max(end_time) from + # homework_seconds where id = #{homework.id}) where id = #{homework.id}" + # + # ActiveRecord::Base.connection.execute(sql) + # end end def down diff --git a/db/migrate/20190329080718_migrate_homework_common_end_time2.rb b/db/migrate/20190329080718_migrate_homework_common_end_time2.rb index 65d4670a..19f048fe 100644 --- a/db/migrate/20190329080718_migrate_homework_common_end_time2.rb +++ b/db/migrate/20190329080718_migrate_homework_common_end_time2.rb @@ -1,11 +1,11 @@ class MigrateHomeworkCommonEndTime2 < ActiveRecord::Migration def up - homework_commons = HomeworkCommon.where("id >= 21549") - homework_commons.each do |homework| - if homework.publish_time.nil? - homework.update_column('end_time', nil) - end - end + # homework_commons = HomeworkCommon.where("id >= 21549") + # homework_commons.each do |homework| + # if homework.publish_time.nil? + # homework.update_column('end_time', nil) + # end + # end end def down diff --git a/db/migrate/20190412012134_create_local_shixuns.rb b/db/migrate/20190412012134_create_local_shixuns.rb new file mode 100644 index 00000000..39d5adae --- /dev/null +++ b/db/migrate/20190412012134_create_local_shixuns.rb @@ -0,0 +1,47 @@ +class CreateLocalShixuns < ActiveRecord::Migration + def change + create_table :local_shixuns do |t| + t.string :name + t.text :description + t.integer :user_id + t.integer :gpid + t.integer :visits + t.integer :status + t.string :language + t.text :authentication + t.string :identifier + t.text :propaedeutics + t.integer :trainee + t.integer :major_id + t.integer :webssh + t.boolean :homepage_show + t.boolean :hidden + t.integer :fork_from + t.boolean :can_copy + t.datetime :modifiy_tim + t.datetime :reset_time + t.integer :closer_id + t.datetime :end_time + t.string :git_url + t.boolean :vnc + t.integer :myshixuns_count + t.integer :challenges_count + t.integer :use_scope + t.text :evaluate_script + t.integer :mirror_script_id + t.string :image_text + t.boolean :code_hidden + t.boolean :task_pass + t.integer :exec_time + t.string :test_set_permission + t.boolean :sigle_training + t.boolean :hide_code + t.boolean :multi_webssh + t.integer :excute_time + t.integer :averge_star + t.integer :forbid_copy + + t.timestamps + end + end +end diff --git a/db/migrate/20190412025818_create_local_mirror_repositories.rb b/db/migrate/20190412025818_create_local_mirror_repositories.rb new file mode 100644 index 00000000..a47bff50 --- /dev/null +++ b/db/migrate/20190412025818_create_local_mirror_repositories.rb @@ -0,0 +1,10 @@ +class CreateLocalMirrorRepositories < ActiveRecord::Migration + def change + create_table :local_mirror_repositories do |t| + t.integer :local_shixun_id + t.integer :mirror_repository_id + + t.timestamps + end + end +end diff --git a/db/migrate/20190412033547_create_local_shixun_tag_repertoires.rb b/db/migrate/20190412033547_create_local_shixun_tag_repertoires.rb new file mode 100644 index 00000000..d870316a --- /dev/null +++ b/db/migrate/20190412033547_create_local_shixun_tag_repertoires.rb @@ -0,0 +1,10 @@ +class CreateLocalShixunTagRepertoires < ActiveRecord::Migration + def change + create_table :local_shixun_tag_repertoires do |t| + t.integer :tag_repertoire_id + t.integer :local_shixun_id + + t.timestamps + end + end +end diff --git a/db/migrate/20190412062718_create_local_challenges.rb b/db/migrate/20190412062718_create_local_challenges.rb new file mode 100644 index 00000000..156e2a4b --- /dev/null +++ b/db/migrate/20190412062718_create_local_challenges.rb @@ -0,0 +1,29 @@ +class CreateLocalChallenges < ActiveRecord::Migration + def change + create_table :local_challenges do |t| + t.integer :local_shixun_id + t.string :subject + t.integer :status + t.integer :position + t.text :task_pass + t.text :answer + t.integer :score + t.integer :visits + t.string :path + t.integer :evaluation_way + t.integer :difficulty + t.string :exec_path + t.integer :code_line + t.integer :st + t.text :web_route + t.text :picture_path + t.text :expect_picture_path + t.integer :challenge_tags_count + t.datetime :modify_time + t.string :original_picture_path + t.integer :show_type + + t.timestamps + end + end +end diff --git a/db/migrate/20190412062923_create_local_test_sets.rb b/db/migrate/20190412062923_create_local_test_sets.rb new file mode 100644 index 00000000..1ec6e0af --- /dev/null +++ b/db/migrate/20190412062923_create_local_test_sets.rb @@ -0,0 +1,14 @@ +class CreateLocalTestSets < ActiveRecord::Migration + def change + create_table :local_test_sets do |t| + t.text :input + t.text :output + t.integer :local_challenge_id + t.integer :is_public + t.integer :result + t.integer :position + + t.timestamps + end + end +end diff --git a/db/migrate/20190412063622_create_local_challenge_tags.rb b/db/migrate/20190412063622_create_local_challenge_tags.rb new file mode 100644 index 00000000..0b35a12e --- /dev/null +++ b/db/migrate/20190412063622_create_local_challenge_tags.rb @@ -0,0 +1,10 @@ +class CreateLocalChallengeTags < ActiveRecord::Migration + def change + create_table :local_challenge_tags do |t| + t.string :name + t.integer :local_challenge_id + + t.timestamps + end + end +end diff --git a/db/migrate/20190412073015_add_test_set_score_to_local_challenge.rb b/db/migrate/20190412073015_add_test_set_score_to_local_challenge.rb new file mode 100644 index 00000000..49661522 --- /dev/null +++ b/db/migrate/20190412073015_add_test_set_score_to_local_challenge.rb @@ -0,0 +1,5 @@ +class AddTestSetScoreToLocalChallenge < ActiveRecord::Migration + def change + add_column :local_challenges, :test_set_score, :integer + end +end diff --git a/db/migrate/20190412074140_add_shixun_id_to_local_shixun.rb b/db/migrate/20190412074140_add_shixun_id_to_local_shixun.rb new file mode 100644 index 00000000..15d9853c --- /dev/null +++ b/db/migrate/20190412074140_add_shixun_id_to_local_shixun.rb @@ -0,0 +1,5 @@ +class AddShixunIdToLocalShixun < ActiveRecord::Migration + def change + add_column :local_shixuns, :shixun_id, :integer + end +end diff --git a/db/migrate/20190412080258_add_score_to_local_test_sets.rb b/db/migrate/20190412080258_add_score_to_local_test_sets.rb new file mode 100644 index 00000000..8015badd --- /dev/null +++ b/db/migrate/20190412080258_add_score_to_local_test_sets.rb @@ -0,0 +1,5 @@ +class AddScoreToLocalTestSets < ActiveRecord::Migration + def change + add_column :local_test_sets, :score, :integer + end +end diff --git a/lib/tasks/shixun_local.rake b/lib/tasks/shixun_local.rake new file mode 100644 index 00000000..e69de29b diff --git a/spec/factories/local_challenge_tags.rb b/spec/factories/local_challenge_tags.rb new file mode 100644 index 00000000..033d487b --- /dev/null +++ b/spec/factories/local_challenge_tags.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :local_challenge_tag do + name "MyString" + local_challenge_id 1 + end +end diff --git a/spec/factories/local_challenges.rb b/spec/factories/local_challenges.rb new file mode 100644 index 00000000..f8094a5c --- /dev/null +++ b/spec/factories/local_challenges.rb @@ -0,0 +1,25 @@ +FactoryGirl.define do + factory :local_challenge do + local_shixun_id 1 + subject "MyString" + status 1 + position 1 + task_pass "" + answer "" + score 1 + visits 1 + path "MyString" + evaluation_way 1 + difficulty 1 + exec_path "MyString" + code_line 1 + st 1 + web_route "MyText" + picture_path "MyText" + expect_picture_path "MyText" + challenge_tags_count 1 + modify_time "2019-04-12 14:27:18" + original_picture_path "MyString" + show_type 1 + end +end diff --git a/spec/factories/local_mirror_repositories.rb b/spec/factories/local_mirror_repositories.rb new file mode 100644 index 00000000..c56d4106 --- /dev/null +++ b/spec/factories/local_mirror_repositories.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :local_mirror_repository do + local_shixun_id 1 + mirror_repository_id 1 + end +end diff --git a/spec/factories/local_shixun_tag_repertoires.rb b/spec/factories/local_shixun_tag_repertoires.rb new file mode 100644 index 00000000..c0368634 --- /dev/null +++ b/spec/factories/local_shixun_tag_repertoires.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :local_shixun_tag_repertoire do + tag_repertoire_id 1 + local_shixun_id 1 + end +end diff --git a/spec/factories/local_shixuns.rb b/spec/factories/local_shixuns.rb new file mode 100644 index 00000000..c0e0b736 --- /dev/null +++ b/spec/factories/local_shixuns.rb @@ -0,0 +1,37 @@ +FactoryGirl.define do + factory :local_shixun do + name "MyString" + description "MyText" + user_id 1 + gpid 1 + visits 1 + status 1 + language "MyString" + authentication false + identifier "MyString" + propaedeutics "MyText" + trainee 1 + major_id 1 + webssh 1 + homepage_show false + hidden false + fork_from 1 + can_copy false + modifiy_tim "2019-04-12 09:21:34" + reset_time "" + closer_id 1 + end_time "2019-04-12 09:21:34" + git_url "MyString" + vnc false + myshixuns_count 1 + challenges_count 1 + use_scope 1 + evaluate_script "" + mirror_script_id 1 + image_text "MyString" + code_hidden false + task_pass false + exec_time 1 + test_set "MyString" + end +end diff --git a/spec/factories/local_test_sets.rb b/spec/factories/local_test_sets.rb new file mode 100644 index 00000000..792da326 --- /dev/null +++ b/spec/factories/local_test_sets.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :local_test_set do + input "" + output "" + local_challenge_id 1 + is_public 1 + result 1 + position 1 + end +end diff --git a/spec/models/local_challenge_spec.rb b/spec/models/local_challenge_spec.rb new file mode 100644 index 00000000..b123e68c --- /dev/null +++ b/spec/models/local_challenge_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LocalChallenge, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/local_challenge_tag_spec.rb b/spec/models/local_challenge_tag_spec.rb new file mode 100644 index 00000000..7aac14ed --- /dev/null +++ b/spec/models/local_challenge_tag_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LocalChallengeTag, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/local_mirror_repository_spec.rb b/spec/models/local_mirror_repository_spec.rb new file mode 100644 index 00000000..d88aab72 --- /dev/null +++ b/spec/models/local_mirror_repository_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LocalMirrorRepository, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/local_shixun_spec.rb b/spec/models/local_shixun_spec.rb new file mode 100644 index 00000000..deff5715 --- /dev/null +++ b/spec/models/local_shixun_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LocalShixun, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/local_shixun_tag_repertoire_spec.rb b/spec/models/local_shixun_tag_repertoire_spec.rb new file mode 100644 index 00000000..f3d780b0 --- /dev/null +++ b/spec/models/local_shixun_tag_repertoire_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LocalShixunTagRepertoire, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/local_test_set_spec.rb b/spec/models/local_test_set_spec.rb new file mode 100644 index 00000000..117ff963 --- /dev/null +++ b/spec/models/local_test_set_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LocalTestSet, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end