diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index 2bbbd6ef..72732a1a 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -17,7 +17,8 @@ class CompetitionTeamsController < ApplicationController @team_user_ids = @team.team_members.pluck(:user_id) - shixuns = Shixun.where(user_id: @team_user_ids, status: 2).where('shixuns.created_at > ?', Time.parse('2018-06-01')) + shixuns = Shixun.where(user_id: @team_user_ids, status: 2) + .where('shixuns.created_at > ? && shixuns.created_at <= ?', Time.parse('2018-06-01'), @competition.end_time) shixuns = shixuns.joins('left join shixuns forked_shixuns on forked_shixuns.fork_from = shixuns.id and forked_shixuns.status = 2') shixuns = shixuns.select('shixuns.id, shixuns.identifier, shixuns.user_id, shixuns.myshixuns_count, shixuns.name, shixuns.fork_from, sum(forked_shixuns.myshixuns_count) forked_myshixun_count') @shixuns = shixuns.group('shixuns.id').order('shixuns.myshixuns_count desc').includes(:creator) @@ -30,18 +31,30 @@ class CompetitionTeamsController < ApplicationController forked_myshixun_count_map = get_valid_myshixun_count(forked_shixun_map.keys) forked_myshixun_count_map.each { |k, v| @myshixun_count_map[forked_shixun_map[k]] += v } - # todo:使用新版course_members + @course_count_map = get_valid_course_count(shixun_ids) + forked_map = get_valid_course_count(forked_shixun_map.keys) + @forked_course_count_map = {} + forked_map.each do |forked_id, course_count| + @forked_course_count_map[forked_shixun_map[forked_id]] ||= 0 + @forked_course_count_map[forked_shixun_map[forked_id]] += course_count + end + + + # 课堂 course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01')) + .where('courses.created_at <= ?', @competition.end_time) .joins('join course_members on course_members.course_id = courses.id and course_members.role in (1,2,3)') .where(course_members: { user_id: @team_user_ids }).pluck(:id) courses = Course.where(id: course_ids).joins(:shixun_homework_commons).where('homework_commons.publish_time < now()') @courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count') .group('courses.id').order('shixun_homework_count desc').having('shixun_homework_count > 0') + course_ids = @courses.map(&:id) @course_myshixun_map = Myshixun.joins(student_works: :homework_common) - .where(homework_commons: { course_id: @courses.map(&:id) }) + .where(homework_commons: { course_id: course_ids }) .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') .group('homework_commons.course_id').count + @course_shixun_count_map = get_valid_shixun_count(course_ids) end def search_teacher @@ -345,6 +358,28 @@ class CompetitionTeamsController < ApplicationController .group('shixun_id').count end + def get_valid_course_count(ids) + percentage_sql = StudentWork.where('homework_common_id = homework_commons.id') + .select('count(compelete_status !=0 ) as finish, count(*) as total') + .having('finish > (total / 2)').to_sql + + Course.joins(shixun_homework_commons: :homework_commons_shixuns) + .where('shixun_id in (?)', ids) + .where("exists (#{percentage_sql})") + .group('shixun_id').count + end + + def get_valid_shixun_count(ids) + percentage_sql = StudentWork.where('homework_common_id = homework_commons.id') + .select('count(compelete_status !=0 ) as finish, count(*) as total') + .having('finish > (total / 2)').to_sql + Shixun.joins(homework_commons_shixuns: :homework_common) + .where(homework_commons: { homework_type: 3 }) + .where('course_id in (?)', ids) + .where("exists (#{percentage_sql})") + .group('course_id').count + end + def record_agent_user_action # 记录是否是引流用户的行为 ip = request.remote_ip diff --git a/app/controllers/libraries_controller.rb b/app/controllers/libraries_controller.rb index ac861841..a1e8a56c 100644 --- a/app/controllers/libraries_controller.rb +++ b/app/controllers/libraries_controller.rb @@ -1,7 +1,9 @@ class LibrariesController < ApplicationController + include ApplicationHelper layout 'base_library' before_filter :require_login, :except => [:index, :show] + before_filter :check_authentication, except: [:index, :show] after_filter :increment_visit_count, only: [:show, :create, :edit, :update] def index diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b1eee18d..bfd4b8be 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3,7 +3,7 @@ class ManagementsController < ApplicationController before_filter :require_business before_filter :require_admin, :only => [:shixun_setting_list, :mirror_repository, :mirror_picture_shixuns, :editmd_template, :editmd_template, :subject_level_system, :subject_setting_list, - :shixun_authorization, :ec_template, :codemirror_template, :update_user, + :shixun_authorization, :ec_template, :codemirror_template, :course_guide_template, :shixun_quality_score, :tech_system, :update_notice, :setting_banner, :training_2018, :create_standard] layout 'base_management' @@ -220,6 +220,9 @@ class ManagementsController < ApplicationController @user.nickname = params[:nickname] @user.lastname = params[:lastname] @user.business = params[:business].to_i + if params[:admin] + @user.admin = params[:admin].to_i + end @user.firstname = "" @user.mail = params[:mail].strip == "" ? nil : params[:mail] @user.phone = params[:phone].strip == "" ? nil : params[:phone] @@ -1661,7 +1664,8 @@ end # 删除单位 def delete_school school = School.where(:id => params[:school]).first - UserExtensions.where(:school_id => params[:school]).update_all(:school_id => nil, :department_id => nil) + UserExtensions.where(:school_id => params[:school]).update_all(school_id: nil, department_id: nil) + User.joins(:user_extension).where(user_extensions: {school_id: params[:school]}).update_all(profile_completed: false) ApplyAddSchools.where(:school_id => params[:school]).destroy_all ApplyAddDepartment.where(:school_id => params[:school]).destroy_all school.destroy @@ -1752,7 +1756,7 @@ end Tiding.create(:user_id => applied_department.user_id, :trigger_user_id => 0, :container_id => applied_department.id, :container_type =>'ApplyAddDepartment', :belong_container_id => applied_department.department.school_id, :belong_container_type=> 'School', :tiding_type => "System", :status => 2, :extra => params[:reason]) # 删除学校的用户 users = UserExtensions.where("department_id = #{applied_department.department_id}") - users.update_all(:department_id => nil) + users.update_all(department_id: nil, profile_completed: false) applied_department.department.destroy # 已审批删除 elsif params[:tip] == "applied" @@ -1866,6 +1870,7 @@ end # 删除学校的用户 users = UserExtensions.where("school_id = #{applied_school.school_id}") + User.where(id: users.map(&:user_id)).update_all(profile_completed: false) # 申请了职业认证的用户撤销申请 apply_user_auth = ApplyUserAuthentication.where(:user_id => users.map(&:user_id), :auth_type => 2, :status => 0) @@ -3692,7 +3697,7 @@ end diskfile1 = disk_filename("UserAuthentication", apply_user.user_id) +"ID" apply_user.update_attributes(:is_delete => true) - File.delete(diskfile1) + File.delete(diskfile1) if File.exist?(diskfile1) =begin begin diff --git a/app/controllers/project_packages_controller.rb b/app/controllers/project_packages_controller.rb index 6721c1c4..7a0990f3 100644 --- a/app/controllers/project_packages_controller.rb +++ b/app/controllers/project_packages_controller.rb @@ -1,10 +1,11 @@ # encoding=utf-8 # For react class ProjectPackagesController < ApplicationController - before_filter :require_login, :except => [:index, :show] - include ApplicationHelper + before_filter :require_login, except: [:index] + before_filter :check_authentication, except: [:index] + def show render_react end diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 1ecd5733..251400d5 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -126,21 +126,26 @@ class SchoolController < ApplicationController chinese << char end end + if pinyin.size > 0 + search_str = "name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'" + else + search_str = "name like '%#{chinese.join("")}%'" + end if params[:no_school_ids] if(condition == '') @school = School.where("id not in #{params[:no_school_ids]}").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) @school_count = School.count else - @school = School.where("id not in #{params[:no_school_ids]} and name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) - @school_count = School.where("id not in #{params[:no_school_ids]} and name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count + @school = School.where("id not in #{params[:no_school_ids]} and #{search_str}").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) + @school_count = School.where("id not in #{params[:no_school_ids]} and #{search_str}").count end else if(condition == '') @school = School.reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) @school_count = School.count else - @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) - @school_count = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count + @school = School.where(search_str).reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) + @school_count = School.where(search_str).count end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 05f04630..251e6de7 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -54,6 +54,12 @@ class WelcomeController < ApplicationController end end + def join_private_courses + @invitation_code = params[:invitation_code] + respond_to do |format| + format.js + end + end def shixun_to_local identifiers = params[:identifiers].split(",") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aac2a843..6a62503e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -628,18 +628,19 @@ module ApplicationHelper return end =end - user_e = UserExtensions.where(:user_id => User.current.id).first - if User.current.lastname.blank? || user_e.school_id.blank? || user_e.identity.blank? || User.current.mail.blank? - redirect_to my_account_path - Rails.logger.info("check_authentication end") - elsif User.current.certification != 1 # 系统没有授权 - day_cer = UserDayCertification.where(:user_id => User.current.id).last - unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 - redirect_to my_account_path - Rails.logger.info("check_authentication end") - return - end - end + + # 暂时不需要试用授权 + # if !User.current.profile_completed? + # redirect_to my_account_path + # Rails.logger.info("check_authentication end") + # elsif User.current.certification != 1 # 系统没有授权 + # day_cer = UserDayCertification.where(:user_id => User.current.id).last + # unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 + # redirect_to my_account_path + # Rails.logger.info("check_authentication end") + # return + # end + # end end def match_specific_symbol(str) diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 1d4eb879..44cfb760 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -26,7 +26,7 @@ module WelcomeHelper def register_info user_agent case user_agent.register_status when 0 - "改IP未登录" + "IP未登录" when 1 "代理之前注册" when 2 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 0d201ed3..35193f2d 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -32,7 +32,7 @@ class Shixun < ActiveRecord::Base has_many :users, :through => :shixun_members has_many :shixun_members, :dependent => :destroy has_one :repository, :dependent => :destroy - has_many :homework_commons_shixunses + has_many :homework_commons_shixuns, class_name: 'HomeworkCommonsShixuns' has_many :homework_challenge_settings, :dependent => :destroy has_many :challenges, :dependent => :destroy has_many :myshixuns, :dependent => :destroy diff --git a/app/views/competition_teams/show.html.erb b/app/views/competition_teams/show.html.erb index 129fa32a..f8e1f1c5 100644 --- a/app/views/competition_teams/show.html.erb +++ b/app/views/competition_teams/show.html.erb @@ -20,11 +20,23 @@ <% total_myshixun_count = 0 total_forked_myshixun_count = 0 + total_shixun_score = 0 %> <% @shixuns.each do |shixun| %> <% total_myshixun_count += shixun.myshixuns_count total_forked_myshixun_count += shixun['forked_myshixun_count'].to_i + + valid_course_count = @course_count_map.fetch(shixun.id, 0) + valid_student_count = @myshixun_count_map.fetch(shixun.id, 0) + score = + if shixun.fork_from.blank? + 500 + 50 * valid_course_count + 10 * valid_student_count + else + 100 + 10 * valid_course_count + 5 * valid_student_count + end + score += @forked_course_count_map.fetch(shixun.id, 0) + total_shixun_score += score %>
<%= stage.name %>
- <% end %> - -- 标注说明:每个小组选择一种编程语言的题目,针对标注任务中指定的标注模块,要求对代码模块、模块中的代码文件, 以及文件中的函数必须进行标注,关键代码块、代码行及关键变量等由参赛者自由选择进行标注。 正式赛第一阶段的比赛在标注阶段就开放查看所有人的标注,请大家根据个人理解,写出自己的风格。我们将综合考虑标注的原创性、准确性、 完整性和多样性等不同的维度对标注质量进行评分。<%= challenge_description_extra[i] %> -
- -<%= row_data[:name] || entry.name %>
-- <% - is_start = Time.now > first_section.start_time - competition_url = User.current.logged? ? "#{entry.url}?eid=#{User.current.id}" : "#{entry.url}" - btn_url = is_start ? "#{competition_url}" : "javascript:void(0);" - %> - <%= entry.name %> -
- - <% if row_data.present? %> -项目简介
-<%= raw row_data[:description] %>
-标注任务
-<%= row_data[:task] %>
-经典算法解读:
- -- 点击进入代标注模块 -
- <% end %> -<%= @competition.sub_title %>
- <% unless User.current.logged? %> + <% if !User.current.logged? %> <%= link_to "创建战队", signin_path, :remote => true, :class => "enroll-in-b enroll-in-b-green fr" %> + <% elsif !User.current.try(:profile_completed?) %> + <%= link_to "创建战队", 'javascript:void(0)', :class => "enroll-in-b enroll-in-b-green fr", onclick: "userProfileModal()" %> <% else %> <% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %> <% if !@can_enroll %> @@ -19,8 +21,10 @@ <% end %> <% end %> - <% unless User.current.logged? %> + <% if !User.current.logged? %> <%= link_to "加入战队", signin_path, :remote => true, :class => "enroll-in-b fr" %> + <% elsif !User.current.try(:profile_completed?) %> + <%= link_to "加入战队", 'javascript:void(0)', :class => "enroll-in-b fr", onclick: "userProfileModal()" %> <% else %> <% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %> <% if !@can_enroll %> @@ -153,6 +157,14 @@ pop_box_new(htmlvalue, 500, 205); } + function userProfileModal() { + var htmlvalue = '
'; + pop_box_new(htmlvalue, 480, 205); + } + function joinSure() { if ($("#codeinput").val().trim() == "") { $("#codeInput-notice").html("请输入邀请码"); diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index c1b5b575..1f463345 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -1,6 +1,10 @@ - 登录 + 登录 - 登录 + 注册 <%#= link_to '注册', user_join_path, :class => "ml5 color-white" %>