@ -3,14 +3,67 @@ class StudentWorkController < ApplicationController
include StudentWorkHelper
require 'bigdecimal'
require " base64 "
before_filter :find_homework , :only = > [ :new , :index , :create , :student_work_absence_penalty , :absence_penalty_list , :evaluation_list ]
before_filter :find_homework , :only = > [ :new , :index , :create , :student_work_absence_penalty , :absence_penalty_list , :evaluation_list , :program_test , :set_score_rule ]
before_filter :find_work , :only = > [ :edit , :update , :show , :destroy , :add_score , :praise_student_work ]
before_filter :member_of_course , :only = > [ :index , :new , :create , :show , :add_score , :praise_student_work ]
before_filter :author_of_work , :only = > [ :edit , :update , :destroy ]
before_filter :teacher_of_course , :only = > [ :student_work_absence_penalty , :absence_penalty_list , :evaluation_list ]
protect_from_forgery :except = > :set_program_score
before_filter :teacher_of_course , :only = > [ :student_work_absence_penalty , :absence_penalty_list , :evaluation_list , :set_score_rule ]
###
def program_test
is_test = params [ :is_test ] == 'true'
resultObj = { status : 0 , results : [ ] , error_msg : '' , time : Time . now . strftime ( '%Y-%m-%d %T' ) }
student_work = find_or_save_student_work ( is_test )
unless student_work
resultObj [ :status ] = 100
else
if @homework . homework_type == 2 && @homework . homework_detail_programing
result = test_realtime ( student_work , params [ :src ] )
logger . debug result
resultObj [ :status ] = result [ " status " ]
resultObj [ :results ] = result [ " results " ]
resultObj [ :error_msg ] = result [ " error_msg " ]
results = result [ " results " ]
if result [ " status " ] . to_i == - 2 #编译错误
results = [ result [ " error_msg " ] ]
end
student_work_test = student_work . student_work_tests . build ( status : result [ " status " ] , results : results ,
src : params [ :src ] )
unless student_work . save
resultObj [ :status ] = 200
else
resultObj [ :status ] = result [ " status " ] . to_i
resultObj [ :time ] = student_work_test . created_at . to_s ( :db )
resultObj [ :index ] = student_work . student_work_tests . count
end
end
end
render :json = > resultObj
end
def index
# 作业消息状态更新
@homework . course_messages . each do | homework_message |
if User . current . id == homework_message . user_id && homework_message . viewed == 0
homework_message . update_attributes ( :viewed = > true ) if homework_message . viewed == 0
end
end
# 作品打分消息状态更新
studentworks_scores = CourseMessage . where ( " user_id =? and course_id =? and course_message_type =? and viewed =? " , User . current . id , @homework . course , " StudentWorksScore " , 0 )
studentworks_scores . each do | studentworks_score |
studentworks_score . update_attributes ( :viewed = > true ) if studentworks_score . viewed == 0
end
# 作品评论消息状态更新
journals_for_teacher = CourseMessage . where ( " user_id =? and course_id =? and course_message_type =? and viewed =? " , User . current . id , @homework . course , " JournalsForMessage " , 0 )
journals_for_teacher . each do | journal_for_teacher |
journal_for_teacher . update_attributes ( :viewed = > true )
end
# 作品留言
# 消息end
#设置作业对应的forge_messages表的viewed字段
query_student_work = @homework . course_messages
query_student_work . each do | query |
@ -18,80 +71,33 @@ class StudentWorkController < ApplicationController
query . update_attributes ( :viewed = > true )
end
end
##################################################################################################################
@order , @b_sort , @name , @group = params [ :order ] || " score " , params [ :sort ] || " desc " , params [ :name ] || " " , params [ :group ]
@is_teacher = User . current . allowed_to? ( :as_teacher , @course )
course_group = CourseGroup . find_by_id ( @group ) if @group
if course_group
group_students = course_group . users
if group_students . empty?
student_in_group = '(0)'
@homework_commons = @course . homework_commons . order ( " created_at desc " )
@is_teacher = User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
@is_evaluation = @homework . homework_detail_manual . comment_status == 2 && ! @is_teacher #是不是匿评
@show_all = false
if @is_teacher #老师 || 超级管理员 显示所有列表
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . order ( " #{ @order } #{ @b_sort } " ) , @name
@show_all = true
elsif @homework . homework_detail_manual . comment_status == 1 #学生 && 未开启匿评 只看到自己的
@stundet_works = @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . where ( :user_id = > User . current . id )
elsif @homework . homework_detail_manual . comment_status == 2 #学生 && 开启匿评 看到匿评列表
my_work = @homework . student_works . where ( :user_id = > User . current . id )
@stundet_works = my_work + User . current . student_works_evaluation_distributions . map ( & :student_work ) . select { | work | work . homework_common_id == @homework . id }
elsif @homework . homework_detail_manual . comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
my_work = @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . where ( :user_id = > User . current . id )
if my_work . empty?
@stundet_works = [ ]
else
student_in_group = '(' + group_students . map { | user | user . id } . join ( ',' ) + ')'
end
#老师 || 非匿评作业 || 匿评结束 显示所有的作品
@show_all = @is_teacher || @homework . homework_type != 1 || @homework . homework_detail_manual . comment_status == 3 || User . current . admin?
if @show_all
if @homework . homework_type == 1 || @is_teacher || User . current . admin? #超级管理员 || 老师 || 匿评结束 显示所有的作品
if @order == " name "
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . joins ( :user ) . where ( " users.id in #{ student_in_group } " ) . order ( " users.lastname #{ @b_sort } , users.firstname #{ @b_sort } " ) , @name
else
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . joins ( :user ) . where ( " users.id in #{ student_in_group } " ) . order ( " #{ @order } #{ @b_sort } " ) , @name
end
else #剩余情况: 学生 && 非匿评作业 如果未提交作品,只能看到自己的,提交了作品,能看到所有作品
my_work = @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . where ( :user_id = > User . current . id )
if my_work . empty?
@stundet_works = [ ]
else
if @order == " name "
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . joins ( :user ) . where ( " users.id in #{ student_in_group } " ) . order ( " users.lastname #{ @b_sort } , users.firstname #{ @b_sort } " ) , @name
else
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . joins ( :user ) . where ( " users.id in #{ student_in_group } " ) . order ( " #{ @order } #{ @b_sort } " ) , @name
end
end
end
else #学生
if @homework . homework_detail_manual . comment_status == 1 #未开启匿评,只显示我的作品
@stundet_works = @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . where ( :user_id = > User . current . id )
elsif @homework . homework_detail_manual . comment_status == 2 #匿评列表,显示匿评作品和我的作品
@is_evaluation = true
my_work = @homework . student_works . where ( :user_id = > User . current . id )
@stundet_works = my_work + User . current . student_works_evaluation_distributions . map ( & :student_work ) . select { | work | work . homework_common_id == @homework . id }
end
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . order ( " #{ @order } #{ @b_sort } " ) , @name
@show_all = true
end
else
#老师 || 非匿评作业 || 匿评结束 显示所有的作品
@show_all = @is_teacher || @homework . homework_type != 1 || @homework . homework_detail_manual . comment_status == 3 || User . current . admin?
if @show_all
if @homework . homework_type == 1 || @is_teacher || User . current . admin? #超级管理员 || 老师 || 匿评结束 显示所有的作品
if @order == " name "
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . joins ( :user ) . order ( " users.lastname #{ @b_sort } , users.firstname #{ @b_sort } " ) , @name
else
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . order ( " #{ @order } #{ @b_sort } " ) , @name
end
else #剩余情况: 学生 && 非匿评作业 如果未提交作品,只能看到自己的,提交了作品,能看到所有作品
my_work = @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . where ( :user_id = > User . current . id )
if my_work . empty?
@stundet_works = [ ]
else
if @order == " name "
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . joins ( :user ) . order ( " users.lastname #{ @b_sort } , users.firstname #{ @b_sort } " ) , @name
else
@stundet_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . order ( " #{ @order } #{ @b_sort } " ) , @name
end
end
end
else #学生
if @homework . homework_detail_manual . comment_status == 1 #未开启匿评,只显示我的作品
@stundet_works = @homework . student_works . select ( " student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score " ) . where ( :user_id = > User . current . id )
elsif @homework . homework_detail_manual . comment_status == 2 #匿评列表,显示匿评作品和我的作品
@is_evaluation = true
my_work = @homework . student_works . where ( :user_id = > User . current . id )
@stundet_works = my_work + User . current . student_works_evaluation_distributions . map ( & :student_work ) . select { | work | work . homework_common_id == @homework . id }
end
end
@stundet_works = [ ]
end
@homework_commons = @course . homework_commons . order ( " created_at desc " )
@score = @b_sort == " desc " ? " asc " : " desc "
respond_to do | format |
format . html
format . xls {
@ -102,50 +108,39 @@ class StudentWorkController < ApplicationController
end
def new
student_work = @homework . student_works . where ( " user_id = ? " , User . current . id ) . first
if student_work . nil?
@stundet_work = StudentWork . new
respond_to do | format |
format . html
end
else
render_403
if @homework . homework_type == 2
redirect_to new_user_commit_homework_users_path ( homework_id : @homework . id )
return
end
@user = User . current
@student_work = @homework . student_works . where ( " user_id = ? " , User . current . id ) . first
if @student_work . nil?
@student_work = StudentWork . new
end
respond_to do | format |
format . html { render :layout = > " new_base_user " }
end
end
def create
if params [ :student_work ]
stundet_work = StudentWork . new
stundet_work . name = params [ :student_work ] [ :name ]
stundet_work . description = params [ :student_work ] [ :description ]
stundet_work . project_id = params [ :student_work ] [ :project_id ]
stundet_work . homework_common_id = @homework . id
stundet_work . user_id = User . current . id
stundet_work . save_attachments ( params [ :attachments ] )
student_work = StudentWork . find ( params [ :student_work_id ] ) if params [ :student_work_id ]
student_work || = StudentWork . new
student_work . name = params [ :student_work ] [ :name ]
student_work . description = params [ :student_work ] [ :description ]
student_work . project_id = params [ :student_work ] [ :project_id ]
student_work . homework_common_id = @homework . id
student_work . user_id = User . current . id
student_work . save_attachments ( params [ :attachments ] )
render_attachment_warning_if_needed ( student_work )
#提交作品时,计算是否迟交
if Time . parse ( @homework . end_time . to_s ) . strftime ( " %Y-%m-%d " ) < Time . parse ( Time . now . to_s ) . strftime ( " %Y-%m-%d " )
stundet_work . late_penalty = @homework . late_penalty
else
stu n det_work. late_penalty = 0
stu den t_work. late_penalty = @homework . late_penalty
else
stu den t_work. late_penalty = 0
end
render_attachment_warning_if_needed ( stundet_work )
if stundet_work . save
if @homework . homework_type == 2 && @homework . homework_detail_programing #编程作业,学生提交作品后计算系统得分
url = " http://192.168.80.21:8080/api/questions/ #{ @homework . homework_detail_programing . question_id } /solutions.json "
solutions = {
student_work_id : stundet_work . id ,
src : Base64 . encode64 ( stundet_work . description ) ,
language : @homework . homework_detail_programing . language
}
uri = URI ( url )
body = solutions . to_json
res = Net :: HTTP . new ( uri . host , uri . port ) . start do | client |
request = Net :: HTTP :: Post . new ( uri . path )
request . body = body
request [ " Content-Type " ] = " application/json "
client . request ( request )
end
end
if student_work . save
respond_to do | format |
format . html {
flash [ :notice ] = l ( :notice_successful_create )
@ -164,11 +159,12 @@ class StudentWorkController < ApplicationController
end
def edit
@user = User . current
if ! User . current . admin? && @homework . homework_type == 2 #编程作业不能修改作业
render_403
else
respond_to do | format |
format . html
format . html { render :layout = > " new_base_user " }
end
end
end
@ -197,16 +193,15 @@ class StudentWorkController < ApplicationController
def show
@score = student_work_score @work , User . current
@is_teacher = User . current . allowed_to? ( :as_teacher , @course )
@is_teacher = User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
@student_work_scores = @work . student_works_scores . order ( " updated_at desc " )
respond_to do | format |
format . js
end
end
def destroy
if @homework . homework_type == 2 #编程作业,作品提交后不可以删除
render_403
elsif @work . destroy
if @work . destroy
respond_to do | format |
format . html {
redirect_to student_work_index_url ( :homework = > @homework . id )
@ -217,10 +212,11 @@ class StudentWorkController < ApplicationController
#添加评分,已评分则为修改评分
def add_score
@is_last = params [ :is_last ] == " true "
render_403 and return if User . current == @work . user #不可以匿评自己的作品
@is_teacher = User . current . allowed_to? ( :as_teacher , @course )
@is_teacher = User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
#老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分
render_403 and return unless @is_teacher || ( @homework . homework_type == 1 && @homework . homework_detail_manual . comment_status == 2 )
render_403 and return unless @is_teacher || @homework . homework_detail_manual . comment_status == 2
@score = student_work_score @work , User . current
if @score
@score . comment = params [ :new_form ] [ :user_message ] if params [ :new_form ] && params [ :new_form ] [ :user_message ] && params [ :new_form ] [ :user_message ] != " "
@ -254,35 +250,11 @@ class StudentWorkController < ApplicationController
case @score . reviewer_role
when 1 #教师评分:最后一个教师评分为最终评分
@work . teacher_score = @score . score
@work . final_score = @score . score
when 2 #教辅评分 教辅评分显示平均分
@work . teaching_asistant_score = @work . student_works_scores . where ( :reviewer_role = > 2 ) . average ( :score ) . try ( :round , 2 ) . to_f
if @work . teacher_score . nil?
if @work . student_score . nil?
@work . final_score = @work . teaching_asistant_score
else
ta_proportion = @homework . homework_detail_manual . ta_proportion if @homework . homework_detail_manual
ta_proportion = @homework . homework_detail_programing . ta_proportion if @homework . homework_detail_programing
final_ta_score = BigDecimal . new ( " #{ @work . teaching_asistant_score } " ) * BigDecimal . new ( " #{ ta_proportion } " )
final_s_score = BigDecimal . new ( " #{ @work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ ta_proportion } " ) )
final_score = final_ta_score + final_s_score
@work . final_score = format ( " %.2f " , final_score . to_f )
end
end
when 3 #学生评分 学生评分显示平均分
@work . student_score = @work . student_works_scores . where ( :reviewer_role = > 3 ) . average ( :score ) . try ( :round , 2 ) . to_f
if @work . teacher_score . nil?
if @work . teaching_asistant_score . nil?
@work . final_score = @work . student_score
else
final_ta_score = BigDecimal . new ( " #{ @work . teaching_asistant_score } " ) * BigDecimal . new ( " #{ @homework . homework_detail_manual . ta_proportion } " )
final_s_score = BigDecimal . new ( " #{ @work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ @homework . homework_detail_manual . ta_proportion } " ) )
final_score = final_ta_score + final_s_score
@work . final_score = format ( " %.2f " , final_score . to_f )
end
end
end
if @work . save
respond_to do | format |
format . js
@ -294,6 +266,7 @@ class StudentWorkController < ApplicationController
#添加评分的回复
def add_score_reply
@score = StudentWorksScore . find params [ :score_id ]
@is_last = params [ :is_last ] == " true "
@jour = @score . journals_for_messages . new ( :user_id = > User . current . id , :notes = > params [ :message ] , :reply_id = > 0 )
if @jour . save
@status = 1
@ -386,44 +359,53 @@ class StudentWorkController < ApplicationController
end
end
#设置编程作业得分
def set_program_score
stundet_work = StudentWork . find_by_id params [ :student_work_id ]
@course = stundet_work . homework_common . course
student_score_count = 0
if stundet_work && params [ :results ] && params [ :results ] . class . to_s == " Array "
homework_common = stundet_work . homework_common
params [ :results ] . each do | result |
homework_tests = homework_common . homework_tests . where ( " input = ' #{ result [ :input ] } ' AND output = ' #{ result [ :output ] } ' " )
homework_tests . each do | homework_test |
student_work_test = StudentWorkTest . new
student_work_test . student_work = stundet_work
student_work_test . homework_test = homework_test
student_work_test . result = result [ :status ]
if student_work_test . result == 0
student_score_count += 1
end
student_work_test . error_msg = params [ :compile_error_msg ]
student_work_test . save!
end
#设置评分规则
def set_score_rule
homework_detail_manual = @homework . homework_detail_manual
homework_detail_programing = @homework . homework_detail_programing
unless @homework . late_penalty . to_s == params [ :late_penalty ] . to_s
@homework . late_penalty = params [ :late_penalty ]
@homework . student_works . where ( " created_at > ' #{ @homework . end_time } 23:59:59' " ) . each do | student_work |
student_work . late_penalty = @homework . late_penalty
student_work . save
end
unless homework_common . homework_tests . empty?
stundet_work . student_score = student_score_count * 100 . 0 / homework_common . homework_tests . count
if stundet_work . teacher_score . nil?
if stundet_work . teaching_asistant_score . nil?
stundet_work . final_score = stundet_work . student_score
else
final_ta_score = BigDecimal . new ( " #{ stundet_work . teaching_asistant_score } " ) * BigDecimal . new ( " #{ homework_common . homework_detail_programing . ta_proportion } " )
final_s_score = BigDecimal . new ( " #{ stundet_work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ homework_common . homework_detail_programing . ta_proportion } " ) )
final_score = final_ta_score + final_s_score
stundet_work . final_score = format ( " %.1f " , final_score . to_f )
end
@homework . save
end
unless homework_detail_manual . absence_penalty . to_s == params [ :absence_penalty ] . to_s
homework_detail_manual . absence_penalty = params [ :absence_penalty ]
if homework_detail_manual . comment_status == 3 #当前作业处于匿评结束状态,修改缺评扣分才会修改每个作品应扣分的值
work_ids = " ( " + @homework . student_works . map ( & :id ) . join ( " , " ) + " ) "
@homework . student_works . each do | student_work |
absence_penalty_count = student_work . user . student_works_evaluation_distributions . where ( " student_work_id IN #{ work_ids } " ) . count - student_work . user . student_works_scores . where ( " student_work_id IN #{ work_ids } " ) . count
student_work . absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual . absence_penalty : 0
student_work . save
end
end
homework_detail_manual . save if homework_detail_manual
end
teacher_priority = params [ :teacher_priority ] ? 1 : 0
if homework_detail_manual . ta_proportion . to_s != params [ :ta_proportion ] . to_s || @homework . teacher_priority . to_s != teacher_priority . to_s || ( homework_detail_programing && homework_detail_programing . ta_proportion . to_s != params [ :sy_proportion ] . to_s )
homework_detail_manual . ta_proportion = params [ :ta_proportion ]
homework_detail_programing . ta_proportion = params [ :sy_proportion ] if homework_detail_programing
@homework . teacher_priority = teacher_priority
stundet_work . save!
@homework . save
homework_detail_manual . save if homework_detail_manual
homework_detail_programing . save if homework_detail_programing
@homework . student_works . each do | student_work |
set_final_score @homework , student_work
student_work . save
end
end
respond_to do | format |
format . html { redirect_to student_work_index_url ( :homework = > @homework . id ) }
end
end
private
@ -456,15 +438,19 @@ class StudentWorkController < ApplicationController
end
def teacher_of_course
render_403 unless User . current . allowed_to? ( :as_teacher , @course )
render_403 unless User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
end
#根据条件过滤作业结果
def search_homework_member homeworks , name
name = name . downcase
select_homework = homeworks . select { | homework |
homework . user [ :login ] . to_s . downcase . include? ( name ) || homework . user . user_extensions [ :student_id ] . to_s . downcase . include? ( name ) || ( homework . user [ :lastname ] . to_s . downcase + homework . user [ :firstname ] . to_s . downcase ) . include? ( name )
}
if name == " "
select_homework = homeworks
else
name = name . downcase
select_homework = homeworks . select { | homework |
homework . user [ :login ] . to_s . downcase . include? ( name ) || homework . user . user_extensions [ :student_id ] . to_s . downcase . include? ( name ) || ( homework . user [ :lastname ] . to_s . downcase + homework . user [ :firstname ] . to_s . downcase ) . include? ( name )
}
end
select_homework
end
@ -475,25 +461,7 @@ class StudentWorkController < ApplicationController
sheet1 = book . create_worksheet :name = > " homework "
blue = Spreadsheet :: Format . new :color = > :blue , :weight = > :bold , :size = > 10
sheet1 . row ( 0 ) . default_format = blue
if @homework . homework_type == 0 #普通作业
sheet1 . row ( 0 ) . concat ( [ l ( :excel_user_id ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_mail ) , l ( :excel_homework_name ) ,
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
count_row = 1
items . each do | homework |
sheet1 [ count_row , 0 ] = homework . user . id
sheet1 [ count_row , 1 ] = homework . user . lastname . to_s + homework . user . firstname . to_s
sheet1 [ count_row , 2 ] = homework . user . login
sheet1 [ count_row , 3 ] = homework . user . user_extensions . student_id
sheet1 [ count_row , 4 ] = homework . user . mail
sheet1 [ count_row , 5 ] = homework . name
sheet1 [ count_row , 6 ] = homework . teacher_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . teacher_score )
sheet1 [ count_row , 7 ] = homework . teaching_asistant_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . teaching_asistant_score )
# sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
sheet1 [ count_row , 8 ] = homework . respond_to? ( " score " ) ? homework . score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . score ) : l ( :label_without_score )
sheet1 [ count_row , 9 ] = format_time ( homework . created_at )
count_row += 1
end
elsif @homework . homework_type == 1 #匿评作业
if @homework . homework_type == 1 #匿评作业
sheet1 . row ( 0 ) . concat ( [ l ( :excel_user_id ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_mail ) , l ( :excel_homework_name ) ,
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_n_score ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
count_row = 1
@ -513,7 +481,7 @@ class StudentWorkController < ApplicationController
end
elsif @homework . homework_type == 2 #编程作业
sheet1 . row ( 0 ) . concat ( [ l ( :excel_user_id ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_mail ) , l ( :excel_homework_name ) ,
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_s_score ) , l ( :excel_ f_score) , l ( :excel_commit_time ) ] )
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_s_score ) , l ( :excel_ n_score) , l ( :excel_ f_score) , l ( :excel_commit_time ) ] )
count_row = 1
items . each do | homework |
sheet1 [ count_row , 0 ] = homework . user . id
@ -524,9 +492,10 @@ class StudentWorkController < ApplicationController
sheet1 [ count_row , 5 ] = homework . name
sheet1 [ count_row , 6 ] = homework . teacher_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . teacher_score )
sheet1 [ count_row , 7 ] = homework . teaching_asistant_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . teaching_asistant_score )
sheet1 [ count_row , 8 ] = homework . student_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . student_score )
sheet1 [ count_row , 9 ] = homework . respond_to? ( " score " ) ? homework . score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . score ) : l ( :label_without_score )
sheet1 [ count_row , 10 ] = format_time ( homework . created_at )
sheet1 [ count_row , 8 ] = homework . system_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . system_score )
sheet1 [ count_row , 9 ] = homework . student_score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . student_score )
sheet1 [ count_row , 10 ] = homework . respond_to? ( " score " ) ? homework . score . nil? ? l ( :label_without_score ) : format ( " %.2f " , homework . score ) : l ( :label_without_score )
sheet1 [ count_row , 11 ] = format_time ( homework . created_at )
count_row += 1
end
end
@ -584,4 +553,145 @@ class StudentWorkController < ApplicationController
book . write xls_report
xls_report . string
end
def find_or_save_student_work ( is_test )
student_work = StudentWork . where ( homework_common_id : @homework . id , user_id : User . current . id ) . first
if student_work . nil?
@homework . student_works . build (
name : params [ :title ] ,
description : params [ :src ] ,
user_id : User . current . id ,
is_test : is_test
)
unless @homework . save
logger . debug @homework . errors . full_messages
else
student_work = StudentWork . where ( homework_common_id : @homework . id , user_id : User . current . id ) . first
end
end
student_work
end
def test_realtime ( student_work , src )
url = " #{ Redmine :: Configuration [ 'judge_server' ] } api/realtime_test.json "
factor = [ ]
@homework . homework_tests . each do | test |
factor << { input : test . input , output : test . output }
end
solutions = {
src : src ,
language : @homework . homework_detail_programing . language ,
factor : factor
}
uri = URI ( url )
body = solutions . to_json
res = Net :: HTTP . new ( uri . host , uri . port ) . start do | client |
request = Net :: HTTP :: Post . new ( uri . path )
request . body = body
request [ " Content-Type " ] = " application/json "
client . request ( request )
end
JSON . parse ( res . body )
end
#成绩计算
def set_final_score homework , student_work
if homework && homework . homework_detail_manual
if homework . homework_type == 1 #匿评作业
if homework . teacher_priority == 1 #教师优先
if student_work . teacher_score
student_work . final_score = student_work . teacher_score
else
if student_work . teaching_asistant_score . nil?
student_work . final_score = student_work . student_score
elsif student_work . student_score . nil?
student_work . final_score = student_work . teaching_asistant_score
else
ta_proportion = homework . homework_detail_manual . ta_proportion
final_ta_score = BigDecimal . new ( " #{ student_work . teaching_asistant_score } " ) * BigDecimal . new ( " #{ ta_proportion } " )
final_s_score = BigDecimal . new ( " #{ student_work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ ta_proportion } " ) )
final_score = final_ta_score + final_s_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
end
else #不考虑教师评分
if student_work . teaching_asistant_score . nil?
student_work . final_score = student_work . student_score
elsif student_work . student_score . nil?
student_work . final_score = student_work . teaching_asistant_score
else
ta_proportion = homework . homework_detail_manual . ta_proportion
final_ta_score = BigDecimal . new ( " #{ student_work . teaching_asistant_score } " ) * BigDecimal . new ( " #{ ta_proportion } " )
final_s_score = BigDecimal . new ( " #{ student_work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ ta_proportion } " ) )
final_score = final_ta_score + final_s_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
end
elsif homework . homework_type == 2 && homework . homework_detail_programing #编程作业-----设定:系统评分必定不为空
if homework . teacher_priority == 1 #教师优先
if student_work . teacher_score
student_work . final_score = student_work . teacher_score
else
if student_work . teaching_asistant_score . nil? #教辅未评分
if student_work . student_score . nil?
student_work . final_score = student_work . system_score
else
ta_proportion = homework . homework_detail_programing . ta_proportion + homework . homework_detail_manual . ta_proportion / 2
final_sy_score = BigDecimal . new ( " #{ student_work . system_score || 0 } " ) * BigDecimal . new ( " #{ ta_proportion } " )
final_st_score = BigDecimal . new ( " #{ student_work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ ta_proportion } " ) )
final_score = final_sy_score + final_st_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
elsif student_work . student_score . nil? #学生未评分
if student_work . teaching_asistant_score . nil?
student_work . final_score = student_work . system_score
else
ta_proportion = homework . homework_detail_programing . ta_proportion + ( 1 . 0 - homework . homework_detail_manual . ta_proportion - homework . homework_detail_programing . ta_proportion ) / 2
final_sy_score = BigDecimal . new ( " #{ student_work . system_score || 0 } " ) * BigDecimal . new ( " #{ ta_proportion } " )
final_ts_score = BigDecimal . new ( " #{ student_work . teaching_asistant_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ ta_proportion } " ) )
final_score = final_sy_score + final_ts_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
else
final_sy_score = BigDecimal . new ( " #{ student_work . system_score || 0 } " ) * BigDecimal . new ( " #{ homework . homework_detail_programing . ta_proportion } " )
final_ts_score = BigDecimal . new ( " #{ student_work . teaching_asistant_score } " ) * BigDecimal . new ( " #{ homework . homework_detail_manual . ta_proportion } " )
final_st_score = BigDecimal . new ( " #{ student_work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ homework . homework_detail_programing . ta_proportion } " ) - BigDecimal . new ( " #{ homework . homework_detail_manual . ta_proportion } " ) )
final_score = final_sy_score + final_ts_score + final_st_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
end
else #不考虑教师评分
if student_work . teaching_asistant_score . nil? #教辅未评分
if student_work . student_score . nil?
student_work . final_score = student_work . system_score
else
ta_proportion = homework . homework_detail_programing . ta_proportion + homework . homework_detail_manual . ta_proportion / 2
final_sy_score = BigDecimal . new ( " #{ student_work . system_score || 0 } " ) * BigDecimal . new ( " #{ ta_proportion } " )
final_st_score = BigDecimal . new ( " #{ student_work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ ta_proportion } " ) )
final_score = final_sy_score + final_st_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
elsif student_work . student_score . nil? #学生未评分
if student_work . teaching_asistant_score . nil?
student_work . final_score = student_work . system_score
else
ta_proportion = homework . homework_detail_programing . ta_proportion + ( 1 . 0 - homework . homework_detail_manual . ta_proportion - homework . homework_detail_programing . ta_proportion ) / 2
final_sy_score = BigDecimal . new ( " #{ student_work . system_score || 0 } " ) * BigDecimal . new ( " #{ ta_proportion } " )
final_ts_score = BigDecimal . new ( " #{ student_work . teaching_asistant_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ ta_proportion } " ) )
final_score = final_sy_score + final_ts_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
else
final_sy_score = BigDecimal . new ( " #{ student_work . system_score || 0 } " ) * BigDecimal . new ( " #{ homework . homework_detail_programing . ta_proportion } " )
final_ts_score = BigDecimal . new ( " #{ student_work . teaching_asistant_score } " ) * BigDecimal . new ( " #{ homework . homework_detail_manual . ta_proportion } " )
final_st_score = BigDecimal . new ( " #{ student_work . student_score } " ) * ( BigDecimal . new ( '1.0' ) - BigDecimal . new ( " #{ homework . homework_detail_programing . ta_proportion } " ) - BigDecimal . new ( " #{ homework . homework_detail_manual . ta_proportion } " ) )
final_score = final_sy_score + final_ts_score + final_st_score
student_work . final_score = format ( " %.2f " , final_score . to_f )
end
end
end
end
end
end