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

dev_course
cxt 5 years ago
commit 93724af8ce

@ -206,7 +206,7 @@ class ChallengesController < ApplicationController
end end
# 关卡评测执行文件如果被修改,需要修改脚本内容 # 关卡评测执行文件如果被修改,需要修改脚本内容
script = modify_shixun_script @shixun, @shixun.evaluate_script script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.update_column(:evaluate_script, script) @shixun.shixun_info.update_column(:evaluate_script, script)
# TODO: # TODO:
# if path != params[:challenge][:path] # if path != params[:challenge][:path]
# shixun_modify_status_without_publish(@shixun, 1) # shixun_modify_status_without_publish(@shixun, 1)

@ -9,11 +9,13 @@ module GitHelper
# 版本库文件内容,带转码 # 版本库文件内容,带转码
def git_fle_content(repo_path, path) def git_fle_content(repo_path, path)
begin begin
content = GitService.file_content(repo_path: repo_path, path: path)["content"] content = GitService.file_content(repo_path: repo_path, path: path)
logger.info("@@@@@@@@@@@@@@@@@@#{content}")
logger.info("@@@@@@@@@@@@@@@@@@#{content}")
decode_content = nil decode_content = nil
if content.present? if content.present?
content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass
content = Base64.decode64(content) content = Base64.decode64(content)
cd = CharDet.detect(content) cd = CharDet.detect(content)
logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}"
@ -27,6 +29,7 @@ module GitHelper
end end
decode_content decode_content
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
raise Educoder::TipException.new("文档内容获取异常") raise Educoder::TipException.new("文档内容获取异常")

@ -48,6 +48,7 @@ class ExercisesController < ApplicationController
@exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的 elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的
@is_teacher_or = 2 @is_teacher_or = 2
# get_exercise_left_time(@exercise,current_user)
member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id默认为0 member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id默认为0
if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
@ -200,10 +201,12 @@ class ExercisesController < ApplicationController
def common_header def common_header
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@user_left_time = nil
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
@is_teacher_or = 0 @is_teacher_or = 0
@user_exercise_answer = @exercise.check_user_answer_status(current_user) @user_exercise_answer = @exercise.check_user_answer_status(current_user)
@user_commit_counts = 0 @user_commit_counts = 0
@user_left_time = get_exercise_left_time(@exercise,current_user)
else else
@is_teacher_or = 1 @is_teacher_or = 1
@user_exercise_answer = 3 #教师页面 @user_exercise_answer = 3 #教师页面
@ -222,6 +225,8 @@ class ExercisesController < ApplicationController
@exercise_publish_count = 1 #试卷未发布,且课堂没有分班的时候 @exercise_publish_count = 1 #试卷未发布,且课堂没有分班的时候
end end
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("没有权限") tip_exception("没有权限")
@ -1016,19 +1021,27 @@ class ExercisesController < ApplicationController
@exercise_user_current.update_attribute("start_at",Time.now) @exercise_user_current.update_attribute("start_at",Time.now)
end end
end end
if @exercise.time > 0
exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0 # ex_time = @exercise.time
exercise_user_left_time = Time.now.to_i - exercise_user_start # if ex_time > 0
time_mill = @exercise.time * 60 #转为毫秒 # time_mill = ex_time * 60 #转为秒
@user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 # exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0
end # exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0
# if (exercise_user_start + time_mill) > exercise_end_time
# time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
# end
# exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
# @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
# end
@t_user_exercise_status = @exercise.get_exercise_status(current_user.id) @t_user_exercise_status = @exercise.get_exercise_status(current_user.id)
@user_left_time = nil
if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) ||
(@exercise_user_current.present? && @exercise_user_current.commit_status == 1) (@exercise_user_current.present? && @exercise_user_current.commit_status == 1)
@user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑
else else
@user_left_time = get_exercise_left_time(@exercise,current_user)
@user_exercise_status = 0 #可编辑 @user_exercise_status = 0 #可编辑
end end
@ -1783,4 +1796,6 @@ class ExercisesController < ApplicationController
end end
end end
end end

@ -613,13 +613,10 @@ class GamesController < ApplicationController
end end
# 批量插入评测结果 # 批量插入评测结果
uid_logger("choose_build") uid_logger("#------------chooice score: #{score}")
sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str
ActiveRecord::Base.connection.execute sql ActiveRecord::Base.connection.execute sql
had_done = @game.had_done
@myshixun.update_attribute(:status, 1) if had_done == 1
# 没通关或者查看了答案通关的时候经验为0 # 没通关或者查看了答案通关的时候经验为0
# 通关但是查看了答案评测的时候金币显示0避免用户以为重复扣除但是在关卡列表中金币显示负数 # 通关但是查看了答案评测的时候金币显示0避免用户以为重复扣除但是在关卡列表中金币显示负数
experience = 0 experience = 0
@ -629,7 +626,8 @@ class GamesController < ApplicationController
if had_passed && !@game.had_passed? if had_passed && !@game.had_passed?
@game.update_attributes(:status => 2, :end_time => Time.now) @game.update_attributes(:status => 2, :end_time => Time.now)
# TPM实训已发布并且没有查看答案 # TPM实训已发布并且没有查看答案
if @shixun.is_published? && !@game.answer_open if @shixun.is_published? && @game.answer_open == 0
uid_logger("@@@@@@@@@@@@@@@@@chooice score: #{score}")
# 查看答案的时候处理final_scor和扣分记录 # 查看答案的时候处理final_scor和扣分记录
experience = score experience = score
reward_attrs = { container_id: @game.id, container_type: 'Game', score: score } reward_attrs = { container_id: @game.id, container_type: 'Game', score: score }
@ -638,6 +636,8 @@ class GamesController < ApplicationController
final_score = score final_score = score
RewardExperienceService.call(@myshixun.owner, reward_attrs) RewardExperienceService.call(@myshixun.owner, reward_attrs)
end end
had_done = @game.had_done
@myshixun.update_attribute(:status, 1) if had_done == 1
end end
grade = @myshixun.owner.try(:grade) grade = @myshixun.owner.try(:grade)

@ -18,6 +18,7 @@ class GitsController < ApplicationController
input_password = username_password.split(":")[1].strip() input_password = username_password.split(":")[1].strip()
uid_logger("git start auth: input_username is #{input_username}") uid_logger("git start auth: input_username is #{input_username}")
# Git 超级权限用户 # Git 超级权限用户
if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip
result = true result = true
@ -43,12 +44,13 @@ class GitsController < ApplicationController
if system_user.present? && system_user.manager_of_shixun?(shixun) if system_user.present? && system_user.manager_of_shixun?(shixun)
result = true result = true
else else
logger.info("git411 start") uid_logger_error("gituser is not shixun manager")
result = false result = false
end end
else else
render :json => { :status => 404 } uid_logger_error("shixun is not exist")
result = false # result = false
result = true # 为了测试跳出
end end
end end
end end

@ -203,6 +203,7 @@ class HomeworkCommonsController < ApplicationController
if @work_excel.present? if @work_excel.present?
student_work_to_xlsx(@work_excel,@homework) student_work_to_xlsx(@work_excel,@homework)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
{table_columns: @work_head_cells,task_users: @work_cells_column} {table_columns: @work_head_cells,task_users: @work_cells_column}
else else

@ -47,7 +47,7 @@ class ShixunsController < ApplicationController
where("challenge_tags.name like '%#{keyword}%' where("challenge_tags.name like '%#{keyword}%'
or challenges.subject like '%#{keyword}%' or challenges.subject like '%#{keyword}%'
or concat(lastname, firstname) like '%#{keyword}%' or concat(lastname, firstname) like '%#{keyword}%'
or shixuns.name like '%#{keyword.split(" ").join("%")}%'") or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct
end end
## 筛选 状态 ## 筛选 状态
@ -115,8 +115,8 @@ class ShixunsController < ApplicationController
def show_right def show_right
owner = @shixun.owner owner = @shixun.owner
#@fans_count = owner.followers.count #@fans_count = owner.fan_count
#@followed_count = owner.followed_users.count #@followed_count = owner.follow_count
@user_own_shixuns = owner.shixuns.published.count @user_own_shixuns = owner.shixuns.published.count
end end
@ -484,16 +484,15 @@ class ShixunsController < ApplicationController
# 中间需要一个过渡动画 # 中间需要一个过渡动画
# TODO: 第一次开启实训都会去判断是否是纯选择题类型,感觉做成在创建关卡的时候就判断该实训是否是纯选择题更加合适 # TODO: 第一次开启实训都会去判断是否是纯选择题类型,感觉做成在创建关卡的时候就判断该实训是否是纯选择题更加合适
def shixun_exec def shixun_exec
current_myshixun = @shixun.current_myshixun(current_user.id)
if @shixun.opening_time.present? && @shixun.opening_time > Time.now && current_user.shixun_identity(@shixun) > User::EDU_SHIXUN_MEMBER if @shixun.opening_time.present? && @shixun.opening_time > Time.now && current_user.shixun_identity(@shixun) > User::EDU_SHIXUN_MEMBER
tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}")
end end
current_myshixun = @shixun.current_myshixun(current_user.id)
if current_myshixun if current_myshixun
# 如果TPM和TPI的管卡数不相等或者关卡顺序错了说明实训被极大的改动需要重置 # 如果TPM和TPI的管卡数不相等或者关卡顺序错了说明实训被极大的改动需要重置
uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") if current_myshixun.games.count != @shixun.challenges_count ||
if current_myshixun.games.count != @shixun.challenges_count || current_myshixun.games.map(&:challenge_id).sort != Challenge.where(shixun_id: @shixun.id).pluck(:id).sort current_myshixun.games.reorder(:challenge_id).pluck(:challenge_id) != @shixun.challenges.reorder(:id).pluck(:id)
uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}")
# 这里页面弹框要收到 当前用户myshixun的identifier. # 这里页面弹框要收到 当前用户myshixun的identifier.
tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game")
end end
@ -517,7 +516,7 @@ class ShixunsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
cloud_bridge = edu_setting('cloud_bridge') #cloud_bridge = edu_setting('cloud_bridge')
myshixun_identifier = generate_identifier Myshixun, 10 myshixun_identifier = generate_identifier Myshixun, 10
myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier,
modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time,
@ -529,12 +528,12 @@ class ShixunsController < ApplicationController
# fork仓库 # fork仓库
project_fork(myshixun, @repo_path, current_user.login) project_fork(myshixun, @repo_path, current_user.login)
rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) #rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path )
uid_logger("start openGameInstance") #uid_logger("start openGameInstance")
uri = "#{cloud_bridge}/bridge/game/openGameInstance" #uri = "#{cloud_bridge}/bridge/game/openGameInstance"
logger.info("end openGameInstance") #logger.info("end openGameInstance")
params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} #params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last}
uid_logger("openGameInstance params is #{params}") #uid_logger("openGameInstance params is #{params}")
# res = interface_post uri, params, 83, "实训云平台繁忙繁忙等级83" # res = interface_post uri, params, 83, "实训云平台繁忙繁忙等级83"
end end
# 其它创建关卡等操作 # 其它创建关卡等操作
@ -548,6 +547,7 @@ class ShixunsController < ApplicationController
end end
# REDO:开启实训时更新关联作品的状态 # REDO:开启实训时更新关联作品的状态
# TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做
HomeworksService.new.update_myshixun_work_status myshixun HomeworksService.new.update_myshixun_work_status myshixun
@current_task = myshixun.current_task @current_task = myshixun.current_task

@ -12,50 +12,6 @@ module UserDecorator
logged_user? ? real_name : full_name logged_user? ? real_name : full_name
end end
# 关注数
def follow_count
Watcher.where(user_id: id, watchable_type: %w(Principal User)).count
# User.watched_by(id).count
end
# 粉丝数
def fan_count
Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count
# watchers.count
end
# 是否绑定邮箱
def email_binded?
mail.present?
end
# 学院的url标识
def college_identifier
Department.find_by_id(department_members.pluck(:department_id).first)&.identifier
end
# 是否能申请试用
def can_apply_trial?
return false if certification == 1
apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization')
apply.present? && !apply.status.zero?
end
# 是否已经签到
def attendance_signed?
attendance = Attendance.find_by(user_id: id)
attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero?
end
# 明日签到金币
def tomorrow_attendance_gold
Attendance.find_by(user_id: id)&.next_gold || 50
end
# ----------- 账号管理 ------------- # ----------- 账号管理 -------------
def authentication_status def authentication_status
if authentication? if authentication?
@ -76,16 +32,4 @@ module UserDecorator
'uncertified' 'uncertified'
end end
end end
def base_info_completed?
user_columns = %i[nickname lastname]
user_extension_columns = %i[gender location location_city identity school_id department]
user_columns.all? { |column| public_send(column).present? } &&
user_extension_columns.all? { |column| user_extension.send(column).present? }
end
def all_certified?
authentication? && professional_certification?
end
end end

@ -32,7 +32,7 @@ module ExerciseQuestionsHelper
def shixun_game_scores(challenge,ex_answerer,shixun_type,question_id) def shixun_game_scores(challenge,ex_answerer,shixun_type,question_id)
game_score = challenge.question_score game_score = challenge.question_score
game_answers = challenge.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer.id).search_shixun_answers("exercise_question_id",question_id) game_answers = challenge.exercise_shixun_answers.where(user_id:ex_answerer.id,exercise_question_id:question_id)
if shixun_type == 2 && game_answers.present? #试卷已截止,用户才可以查看答案 if shixun_type == 2 && game_answers.present? #试卷已截止,用户才可以查看答案
s_score = game_answers.first.score s_score = game_answers.first.score
else else

@ -413,43 +413,41 @@ module ExercisesHelper
score2 += 0.0 score2 += 0.0
end end
elsif q.question_type == 5 #实训题时,主观题这里不评分 elsif q.question_type == 5 #实训题时,主观题这里不评分
if answers_content.present? q.exercise_shixun_challenges.each do |exercise_cha|
q.exercise_shixun_challenges.each do |exercise_cha| game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡 if game.present?
if game.present? exercise_cha_score = 0.0
exercise_cha_score = 0.0 answer_status = 0
answer_status = 0 if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1
end
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
cha_path = challenge_path exercise_cha.challenge.path cha_path = challenge_path exercise_cha.challenge.path
if game.status == 2 && game.final_score >= 0 game_challenge = game.game_codes.search_challenge_path(cha_path).first
exercise_cha_score = exercise_cha.question_score #每一关卡的得分 if game_challenge.present?
answer_status = 1 game_code = game_challenge
end code = game_code.try(:new_code)
ex_shixun_answer_content = answers_content.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
game_challenge = game.game_codes.search_challenge_path(cha_path).first
if game_challenge.present?
game_code = game_challenge
code = game_code.try(:new_code)
else
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
end
sx_option = {
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
else else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score) code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
end end
score5 += exercise_cha_score sx_option = {
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
end end
score5 += exercise_cha_score
else
score5 += 0.0
end end
else
score5 += 0.0
end end
end end
user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0
@ -681,6 +679,23 @@ module ExercisesHelper
result result
end end
def get_exercise_left_time(exercise,user)
ex_time = exercise.time
user_left_time = nil
if ex_time > 0
exercise_user = exercise.exercise_users.find_by(user_id:user.id)
time_mill = ex_time * 60 #转为秒
exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0
exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0
if (exercise_user_start + time_mill) > exercise_end_time
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
end
exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
end
user_left_time
end
#实训题学生代码的行数 #实训题学生代码的行数
def content_line(content) def content_line(content)
content.split(/\r?\n/).length content.split(/\r?\n/).length

@ -35,7 +35,7 @@ module ExportHelper
else else
head_cells_add = [] head_cells_add = []
end end
normal_head_b_cells = %w(最终成绩 提交时间 更新时间) normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语)
@work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?) @work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?)
works.each_with_index do |w, index| works.each_with_index do |w, index|
w_user = w.user w_user = w.user
@ -85,8 +85,21 @@ module ExportHelper
w_15 = w.work_score.nil? ? "未评分" : w.work_score.round(1) w_15 = w.work_score.nil? ? "未评分" : w.work_score.round(1)
w_16 = w.commit_time ? format_time(w.commit_time) : "--" w_16 = w.commit_time ? format_time(w.commit_time) : "--"
w_17 = w.update_time ? format_time(w.update_time) : "--" w_17 = w.update_time ? format_time(w.update_time) : "--"
teacher_comments = w.student_works_scores
if teacher_comments.present?
w_18 = ""
teacher_comments.each do |t|
user_name = t.user.real_name
user_time = format_time(t.updated_at)
user_score = t.score
user_comment = t.comment
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n")
end
else
w_18 = "--"
end
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17] row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18]
row_cells_column = row_cells_column.reject(&:blank?) row_cells_column = row_cells_column.reject(&:blank?)
@work_cells_column.push(row_cells_column) @work_cells_column.push(row_cells_column)
end end
@ -102,7 +115,7 @@ module ExportHelper
if allow_late_boolean #允许迟交 if allow_late_boolean #允许迟交
eff_score_cell.push("迟交扣分") eff_score_cell.push("迟交扣分")
end end
shixun_time_cells = %w(最终成绩 更新时间 提交耗时) shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语)
@work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?)
works.each_with_index do |w, index| works.each_with_index do |w, index|
myshixun = w.try(:myshixun) myshixun = w.try(:myshixun)
@ -143,7 +156,20 @@ module ExportHelper
w_15 = w.work_score.nil? ? "--" : w.work_score.round(1) w_15 = w.work_score.nil? ? "--" : w.work_score.round(1)
w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间" w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间"
w_17 = w.cost_time w_17 = w.cost_time
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17] teacher_comments = w.student_works_scores
if teacher_comments.present?
w_18 = ""
teacher_comments.each do |t|
user_name = t.user.real_name
user_time = format_time(t.updated_at)
user_score = t.score
user_comment = t.comment
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n")
end
else
w_18 = "--"
end
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18]
row_cells_column = row_cells_column.reject(&:blank?) row_cells_column = row_cells_column.reject(&:blank?)
@work_cells_column.push(row_cells_column) @work_cells_column.push(row_cells_column)
end end

@ -28,4 +28,9 @@ module Util
end end
end end
end end
def logger_error(exception)
Rails.logger.error(exception.message)
exception.backtrace.each { |message| Rails.logger.error(message) }
end
end end

@ -56,20 +56,13 @@ class Myshixun < ApplicationRecord
# status:0 可以测评的,正在测评的 # status:0 可以测评的,正在测评的
# 如果都完成,则当前任务为最后一个任务 # 如果都完成,则当前任务为最后一个任务
def current_task def current_task
games = self.games
current_game = self.games.select{|game| game.status == 1 || game.status == 0}.first current_game = games.select{|game| game.status == 1 || game.status == 0}.first
if current_game.blank? if current_game.blank?
if self.status == 1 current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id}
logger.info("@3333333333344444444#{self.id}") and g.challenge_id = c.id and g.status = 2 order by c.position desc").first
current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} and
g.challenge_id = c.id and g.status = 2 order by c.position desc").first
else
# 如果没开启过的status都为3所以应该进入第一关
current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} and
g.challenge_id = c.id and g.status = 3 order by c.position asc").first
end
end end
return current_game current_game
end end

@ -1,6 +1,8 @@
# TODO: 已废弃
class Relationship < ApplicationRecord class Relationship < ApplicationRecord
belongs_to :follower, class_name: "User" belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User" belongs_to :followed, class_name: "User"
validates :follower_id, presence: true validates :follower_id, presence: true
validates :followed_id, presence: true validates :followed_id, presence: true
end end

@ -47,14 +47,6 @@ class User < ApplicationRecord
has_many :graduation_works, dependent: :destroy has_many :graduation_works, dependent: :destroy
# 关注
has_many :relationships, foreign_key: "follower_id", dependent: :destroy
has_many :followed_users, through: :relationships, source: :followed
# 粉丝
has_many :reverse_relationships, foreign_key: "followed_id",
class_name: "Relationship",
dependent: :destroy
has_many :followers, through: :reverse_relationships, source: :follower
has_many :students_for_courses, foreign_key: :student_id, dependent: :destroy has_many :students_for_courses, foreign_key: :student_id, dependent: :destroy
has_one :onclick_time, :dependent => :destroy has_one :onclick_time, :dependent => :destroy
@ -161,19 +153,16 @@ class User < ApplicationRecord
self.user_extension.try(:student_id) self.user_extension.try(:student_id)
end end
# 关注总数 # 关注数
def following?(other_user) def follow_count
relationships.find_by(followed_id: other_user) Watcher.where(user_id: id, watchable_type: %w(Principal User)).count
end # User.watched_by(id).count
# 关注
def follow!(other_user)
relationships.create!(followed_id: other_user)
end end
# 取消关注 # 粉丝数
def unfollow!(other_user) def fan_count
relationships.find_by(followed_id: other_user.id).destroy Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count
# watchers.count
end end
# 判断当前用户是否为老师 # 判断当前用户是否为老师
@ -545,6 +534,51 @@ class User < ApplicationRecord
Educoder::Utils.random_hex(16) Educoder::Utils.random_hex(16)
end end
# 基本资料是否完善
def base_info_completed?
user_columns = %i[nickname lastname]
user_extension_columns = %i[gender location location_city identity school_id department]
user_columns.all? { |column| public_send(column).present? } &&
user_extension_columns.all? { |column| user_extension.send(column).present? }
end
# 全部已认证
def all_certified?
authentication? && professional_certification?
end
# 是否绑定邮箱
def email_binded?
mail.present?
end
# 学院的url标识
def college_identifier
Department.find_by_id(department_members.pluck(:department_id).first)&.identifier
end
# 是否能申请试用
def can_apply_trial?
return false if certification == 1
apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization')
apply.present? && !apply.status.zero?
end
# 是否已经签到
def attendance_signed?
attendance = Attendance.find_by(user_id: id)
attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero?
end
# 明日签到金币
def tomorrow_attendance_gold
Attendance.find_by(user_id: id)&.next_gold || 60 # 基础50连续签到+10
end
protected protected
def validate_password_length def validate_password_length
# 管理员的初始密码是5位 # 管理员的初始密码是5位

@ -7,7 +7,7 @@ json.stage_list do
json.evaluate_count game.evaluate_count json.evaluate_count game.evaluate_count
json.finished_time finished_time game.end_time json.finished_time finished_time game.end_time
json.time_consuming time_consuming game json.time_consuming time_consuming game
json.myself_experience game.final_score #经验值 json.myself_experience game.final_score < 0 ? 0 : game.final_score #经验值
json.experience game.challenge.all_score #经验值 json.experience game.challenge.all_score #经验值
json.user_score user_score.round(1).to_s #用户获得的分数 json.user_score user_score.round(1).to_s #用户获得的分数
json.game_score game_score.round(1).to_s #该关卡的总分数 json.game_score game_score.round(1).to_s #该关卡的总分数

@ -1,5 +1,7 @@
json.course_is_end @course.is_end # true表示已结束false表示未结束 json.course_is_end @course.is_end # true表示已结束false表示未结束
json.extract! @exercise, :id,:exercise_name,:exercise_description,:show_statistic,:time json.extract! @exercise, :id,:exercise_name,:exercise_description,:show_statistic
json.time @user_left_time
json.exercise_status @ex_status json.exercise_status @ex_status
json.user_permission do json.user_permission do

@ -21,7 +21,11 @@ if @exercises_count > 0
json.exercises do json.exercises do
json.array! @exercises do |exercise| json.array! @exercises do |exercise|
ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_)
json.extract! exercise, :id, :exercise_name,:is_public,:created_at,:time json.extract! exercise, :id, :exercise_name,:is_public,:created_at
if @is_teacher_or == 2
json.time get_exercise_left_time(exercise,@current_user_)
end
json.exercise_status ex_index[:ex_status] json.exercise_status ex_index[:ex_status]
json.lock_status ex_index[:lock_icon] json.lock_status ex_index[:lock_icon]
json.publish_time ex_index[:publish_time] # 试卷的发布时间 json.publish_time ex_index[:publish_time] # 试卷的发布时间

@ -1,5 +1,6 @@
wb = xlsx_package.workbook wb = xlsx_package.workbook
# wb.use_autowidth = false
wb.styles do |s| wb.styles do |s|
sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center}
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center}
@ -8,7 +9,7 @@ wb.styles do |s|
sheet.add_row table_columns, :style => blue_cell sheet.add_row table_columns, :style => blue_cell
if task_users.count > 0 if task_users.count > 0
task_users.each do |user| task_users.each do |user|
sheet.add_row user, :style => sz_all sheet.add_row user, :height => 20,:style => sz_all
end #each_widh_index end #each_widh_index
end end
sheet.column_widths *([20]*sheet.column_info.count) sheet.column_widths *([20]*sheet.column_info.count)

@ -10,7 +10,7 @@ json.array! @members do |member|
json.user do json.user do
json.partial! 'users/user', locals: { user: member.user } json.partial! 'users/user', locals: { user: member.user }
json.user_shixuns_count member.user.shixuns.published.count json.user_shixuns_count member.user.shixuns.published.count
#json.fans_count member.user.followers.count #json.fans_count member.user.fan_count
json.brief_introduction member.user.user_extension.brief_introduction json.brief_introduction member.user.user_extension.brief_introduction
json.identity member.user.identity json.identity member.user.identity
json.school_name member.user.school_name json.school_name member.user.school_name

@ -0,0 +1,6 @@
class AddIndexForEvaluateRecord < ActiveRecord::Migration[5.2]
def change
# 增加evalute_records的索引提高查询效率
add_index :evaluate_records, :game_id
end
end

@ -0,0 +1,51 @@
# 新版Git测试说明
统一:
参考实训http://47.96.87.25:48080/shixuns/ca9fvobr/repository
请求方式POST
参数{repo_path: "educoder/ca9fvobr.git"}
公共方法:
['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file',
'file_content', 'commits']
1、仓库目录接口
测试方法模拟1000个用户同时去访问接口访问方式
http://121.199.19.206:9000/api/file_tree
参数:
{repo_path: "educoder/ca9fvobr.git", path: ''} // 如:{path: 'step1'}
2、创建版本库
访问地址http://121.199.19.206:9000/api/add_repository
参数:
{repo_path: 比如:"Hjqreturn/aaass1.git"}
3、fork版本库
http://121.199.19.206:9000/api/fork_repository
参数:
{repo_path: 'Hjqreturn/aaass1.git', fork_repository_path: 'educoder/ca9fvobr.git'}
说明fork_repository_path是源项目的repo_path, repo_path是新项目的
4、更新文件
测试方法:
1、更新同一个文件并发量可以不用很大可以用同一个用户并发10-100
2、更新不同的文件可以依据创建的版本库去更新
访问地址http://121.199.19.206:9000/api/update_file
参数:
{repo_path: "educoder/ca9fvobr.git",
file_path: 'step1/main.py',
message: 'commit by test',
content: 'afdjadsjfj1111',
author_name: 'guange',
author_email: '8863824@gmil.com'}
5、获取文件内容
访问地址http://121.199.19.206:9000/api/file_content
参数:
{repo_path: "educoder/ca9fvobr.git", file_path: 'step1/main.py',}
6、获取提交记录
访问地址http://121.199.19.206:9000/api/commits
参数:
{repo_path: 比如:"educoder/ca9fvobr.git"}

@ -0,0 +1,16 @@
namespace :git do
desc "检测是否TPM是否需要更新"
task :shixun_check_update => :environment do
end
desc "检测版本库是否有异常"
task :myshixuns_check_update => :environment do
end
task :check => :environment do
end
end
Loading…
Cancel
Save