Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
daiao 5 years ago
commit 38c4309928

@ -186,6 +186,7 @@ class HomeworkCommonsController < ApplicationController
@work_count = @student_works.size @work_count = @student_works.size
@work_excel = @student_works @work_excel = @student_works
@students = @course.students
# 分页参数 # 分页参数
page = params[:page] || 1 page = params[:page] || 1
@ -236,94 +237,51 @@ class HomeworkCommonsController < ApplicationController
end end
def update_score def update_score
student_works = @homework.student_works begin
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: @course.students.pluck(:user_id)) if @homework.unified_setting
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id). student_works = @homework.student_works
joins("join course_members on myshixuns.user_id=course_members.user_id").where(course_members: {course_id: @course.id, role: 4}).includes(:games) user_ids = @course.students.pluck(:user_id)
myshixuns.find_each(batch_size: 100) do |myshixun| else
work = student_works.select{|work| work.user_id == myshixun.user_id}.first user_ids = @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
setting_time = @homework.homework_group_setting work.user_id student_works = @homework.student_works.where(user_id: user_ids)
end
if setting_time.end_time.present? && (setting_time.end_time > Time.now || (@homework.allow_late && @homework.late_time && @homework.late_time > Time.now))
#logger.info("#############setting_time: #{setting_time.end_time}")
user_total_score = 0
pass_consume_time = 0
final_score = 0
homework.homework_challenge_settings.each do |setting|
game = myshixun.games.where(:challenge_id => setting.challenge_id, :status => 2).first
unless game.nil?
pass_consume_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i
adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last
final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0))
end
end
if work.work_status == 0
is_complete = myshixun.is_complete? && (myshixun.done_time < setting_time.end_time)
work.work_status = setting_time.end_time > Time.now ? 1 : (is_complete ? 1 : 2)
work.late_penalty = setting_time.end_time > Time.now ? 0 : (is_complete ? 0 : homework.late_penalty)
work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at
work.myshixun_id = myshixun.id
end
games = myshixun.games.where(:challenge_id => homework.homework_challenge_settings.map(&:challenge_id))
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
if myshixun_endtime.present?
min_efficiency_changed = min_efficiency_changed.present? ? min_efficiency_changed : false
work.compelete_status = 1
work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i
efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0))
work.efficiency = format("%.2f", efficiency)
# 如果作业的最大效率值有变更则更新所有作品的效率分 myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
if homework.work_efficiency && homework.max_efficiency < work.efficiency includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)})
homework.update_column("max_efficiency", work.efficiency) challenge_settings = @homework.homework_challenge_settings
end myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
end end
work.update_time = Time.now
work.final_score = final_score
score = work.final_score + work.eff_score - work.late_penalty
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
#logger.info("#############work_score: #{score}")
work.save!
end end
end @homework.update_attribute('calculation_time', Time.now)
@homework.student_works.each do || normal_status("更新成功")
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end end
end end
def update_student_score def update_student_score
work = @homework.students_works.find_by(user_id: current_user.id) work = @homework.student_works.find_by(user_id: current_user.id)
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
if work && myshixun ActiveRecord::Base.transaction do
# 判断作品是否关联过myshixun begin
if work.myshixun_id.nil? if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
work.myshixun_id = myshixun.id challenge_settings = @homework.homework_challenge_settings
work.update_time = myshixun.updated_at games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
setting_time = @homework.homework_group_setting myshixun.user_id HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
games = myshixun.games.where(:challenge_id => @homework.homework_challenge_settings.pluck(:challenge_id)) normal_status("更新成功")
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil else
compelete_status = 0 normal_status("已是最新成绩")
if myshixun_endtime.present? && myshixun_endtime < setting_time.end_time
if myshixun_endtime < setting_time.publish_time
compelete_status = 2
else
compelete_status = 1
end
end
games.each do |game|
unless game.nil?
pass_consume_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i
adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last
final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0))
end
end end
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end end
end end
end end
@ -1036,7 +994,7 @@ class HomeworkCommonsController < ApplicationController
if homework.course_acts.size == 0 if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
end end
# 发消息
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids) HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
else else
create_homework_group_settings(homework) create_homework_group_settings(homework)
@ -1057,6 +1015,7 @@ class HomeworkCommonsController < ApplicationController
homework.save! homework.save!
# 更新学生状态及成绩
HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id) HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
end end
normal_status(0, "发布成功") normal_status(0, "发布成功")

@ -335,6 +335,8 @@ module ApplicationHelper
end end
def to_markdown(text) def to_markdown(text)
request_url = request.base_url
return nil if text.blank? return nil if text.blank?
options = { options = {
:autolink => true, :autolink => true,
@ -345,9 +347,11 @@ module ApplicationHelper
:superscript => true, :superscript => true,
:tables => true :tables => true
} }
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options)
markdown.render(text).html_safe m_t = markdown.render(text)
ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t
Rails.logger.info("############_____________ss________________##################{ss}")
ss
end end
end end

@ -272,4 +272,67 @@ class HomeworksService
end end
end end
end end
# 计算实训作品成绩
def update_myshixun_work_score work, myshixun, games, homework, challenge_settings
user_total_score = 0
pass_consume_time = 0
final_score = 0
setting_time = homework.homework_group_setting myshixun.user_id
homework_end_or_late_time = homework.allow_late ? homework.late_time : setting_time.end_time
games.each do |game|
# 在截止时间前通关的关卡才考虑得分
if game.status == 2 && game.end_time <= homework_end_or_late_time
challenge_setting = challenge_settings.select{|setting| setting.challenge_id == game.challenge_id}.first
pass_consume_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i
adjust_score = work.challenge_work_scores.where(:challenge_id => game.challenge_id).last
final_score += if adjust_score.present?
adjust_score.score
elsif homework.homework_detail_manual.answer_open_evaluation
challenge_setting.score
elsif game.final_score > 0
game.real_score(challenge_setting.score)
else
0
end
end
end
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
if myshixun_endtime.present?
work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i
efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0))
work.efficiency = format("%.2f", efficiency)
if myshixun_endtime <= homework_end_or_late_time
work.compelete_status = myshixun_endtime < setting_time.publish_time ? 2 : 1
# 如果作业的最大效率值有变更则更新所有作品的效率分
homework.update_column("max_efficiency", work.efficiency) if homework.work_efficiency && homework.max_efficiency < work.efficiency
end
end
if work.work_status == 0
is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time)
if is_complete || (!homework.allow_late && myshixun.created_at < setting_time.end_time)
work.work_status = 1
elsif homework.allow_late && myshixun.created_at < homework.late_time
work.work_status = 2
end
work.late_penalty = work.work_status == 2 ? homework.late_penalty : 0
work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at
work.myshixun_id = myshixun.id
end
work.update_time = myshixun.updated_at
work.final_score = final_score
score = work.final_score + work.eff_score - work.late_penalty
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
#logger.info("#############work_score: #{score}")
work.calculation_time = Time.now
work.save!
end
end end

@ -68,17 +68,17 @@
<span class="text-gray mlr5">(<%= q&.question_score %>分)</span> <span class="text-gray mlr5">(<%= q&.question_score %>分)</span>
</div> </div>
<div class="pbt5"> <div class="pbt5">
<img src="http://47.96.87.25:48080/api/attachments/368984" alt="电脑的电路图" title="电脑的电路图">
<img class="myavatar avatar-48" alt="udasker_picture" src="http://images.udask.cn/uploaders/user/picture/2/2_udasker.jpg?v=1556452947">
<% q_markdown = to_markdown(q.question_title) %> <% q_markdown = to_markdown(q.question_title) %>
<% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %>
<% if q.question_type == 5 %> <% if q.question_type == 5 %>
<% q_markdown_name = to_markdown(q.shixun_name) %> <% q_markdown_name = to_markdown(q.shixun_name) %>
<% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> <span class="ques-title" ><%= q_markdown_name %></span>
<span class="ques-title" id="ques_marked_<%= index %>"><%= q_name %></span>
<div class="mt8 text-gray"> <div class="mt8 text-gray">
<span id="ques_title_<%= index %>"><%= q_title %></span> <span><%= q_markdown %></span>
</div> </div>
<% else %> <% else %>
<span class="ques-title" id="ques_title_<%= index %>"><%= q_title %></span> <span class="ques-title"><%= q_markdown %></span>
<% end %> <% end %>
</div> </div>
<div class="pbt5"> <div class="pbt5">
@ -86,14 +86,16 @@
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each_with_index do |s,index| %>
<p class="pbt5"> <p class="pbt5">
<span class="choose-radio"></span> <span class="choose-radio"></span>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%> <span class="mr15"><%= convert_to_char((index+1).to_s)%></span>
<span class="inline-block"><%= to_markdown(s.choice_text) %></span>
</p> </p>
<% end %> <% end %>
<% elsif q.question_type == 1 %> <% elsif q.question_type == 1 %>
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each_with_index do |s,index| %>
<p class="pbt5"> <p class="pbt5">
<span class="choose-checkbox"></span> <span class="choose-checkbox"></span>
<span class="mr20"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%> <span class="mr20"><%= convert_to_char((index+1).to_s)%></span>
<span class="inline-block"><%= to_markdown(s.choice_text) %></span>
</p> </p>
<% end %> <% end %>
<% elsif q.question_type == 2 %> <% elsif q.question_type == 2 %>
@ -101,7 +103,7 @@
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each_with_index do |s,index| %>
<span class="mr15"> <span class="mr15">
<span class="choose-radio"></span> <span class="choose-radio"></span>
<span class="mlr5"><%= s.choice_text %></span> <span class="mlr5 inline-block"><%= to_markdown(s.choice_text) %></span>
</span> </span>
<% end %> <% end %>
</p> </p>

@ -11,4 +11,5 @@ json.homework_id homework.id
json.homework_type homework.homework_type json.homework_type homework.homework_type
if homework.homework_type == "practice" if homework.homework_type == "practice"
json.shixun_identifier homework.shixuns.take.try(:identifier) json.shixun_identifier homework.shixuns.take.try(:identifier)
json.shixun_id homework.shixuns.take.try(:id)
end end

@ -16,6 +16,7 @@ json.work_public @homework.work_public
if @user_course_identity < Course::STUDENT if @user_course_identity < Course::STUDENT
json.calculation_time @homework.calculation_time if @homework.homework_type == "practice"
# 教师身份的评阅、提交状态、分班过滤 # 教师身份的评阅、提交状态、分班过滤
if @homework.homework_type != "practice" if @homework.homework_type != "practice"
json.teacher_comment teacher_comment @homework, @current_user.id json.teacher_comment teacher_comment @homework, @current_user.id
@ -30,7 +31,7 @@ elsif @user_course_identity == Course::STUDENT
if @homework.homework_type == "practice" if @homework.homework_type == "practice"
json.(@work, :id, :work_status, :update_time, :ultimate_score) json.(@work, :id, :work_status, :update_time, :ultimate_score)
json.calculation_time @work.calculation_time
json.late_penalty @work.late_penalty if @homework.allow_late json.late_penalty @work.late_penalty if @homework.allow_late
json.cost_time @work.myshixun.try(:total_cost_time) json.cost_time @work.myshixun.try(:total_cost_time)
json.work_score work_score_format(@work.work_score, true, @score_open) json.work_score work_score_format(@work.work_score, true, @score_open)
@ -94,7 +95,7 @@ if @homework.homework_type == "practice"
json.user_login work.user.try(:login) json.user_login work.user.try(:login)
json.user_name work.user.try(:real_name) json.user_name work.user.try(:real_name)
json.student_id work.user.try(:student_id) json.student_id work.user.try(:student_id)
json.group_name @course.course_student(work.user_id).try(:course_group_name) json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
end end
elsif @homework.homework_type == "group" || @homework.homework_type == "normal" elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.anonymous_comment @homework.anonymous_comment json.anonymous_comment @homework.anonymous_comment
@ -133,7 +134,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
end end
json.student_id work.user.try(:student_id) json.student_id work.user.try(:student_id)
json.group_name @course.course_student(work.user_id).try(:course_group_name) json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
if @homework.homework_type == "group" if @homework.homework_type == "group"
if @homework.homework_detail_group.base_on_project if @homework.homework_detail_group.base_on_project
json.project_info project_info work, @current_user, @user_course_identity json.project_info project_info work, @current_user, @user_course_identity

@ -338,6 +338,8 @@ Rails.application.routes.draw do
get :publish_groups get :publish_groups
get :end_groups get :end_groups
post :alter_name post :alter_name
get :update_score
get :update_student_score
end end
collection do collection do

@ -0,0 +1,6 @@
class AddCalculationTimeToHomework < ActiveRecord::Migration[5.2]
def change
add_column :homework_commons, :calculation_time, :datetime
add_column :student_works, :calculation_time, :datetime
end
end
Loading…
Cancel
Save