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

dev_forum
cxt 6 years ago
commit 14300893f6

1
.gitignore vendored

@ -44,6 +44,7 @@
/config/secrets.yml
/config/redis.yml
/config/elasticsearch.yml
public/upload.html
/config/configuration.yml

@ -90,4 +90,4 @@ gem 'sinatra'
gem 'bulk_insert'
# elasticsearch
# gem 'searchkick'
gem 'searchkick'

@ -90,6 +90,14 @@ GEM
connection_pool (2.2.2)
crass (1.0.4)
diff-lcs (1.3)
elasticsearch (7.2.0)
elasticsearch-api (= 7.2.0)
elasticsearch-transport (= 7.2.0)
elasticsearch-api (7.2.0)
multi_json
elasticsearch-transport (7.2.0)
faraday
multi_json
erubi (1.7.1)
execjs (2.7.0)
faraday (0.15.4)
@ -100,6 +108,7 @@ GEM
grape-entity (0.7.1)
activesupport (>= 4.0)
multi_json (>= 1.3.2)
hashie (3.6.0)
htmlentities (4.3.4)
httparty (0.16.2)
multi_xml (>= 0.5.2)
@ -255,6 +264,10 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
searchkick (3.1.3)
activemodel (>= 4.2)
elasticsearch (>= 5)
hashie
selenium-webdriver (3.14.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
@ -344,6 +357,7 @@ DEPENDENCIES
ruby-ole
rubyzip
sass-rails (~> 5.0)
searchkick
selenium-webdriver
sidekiq
simple_xlsx_reader

@ -501,8 +501,8 @@ class ShixunsController < ApplicationController
# TODO: 目前实训只做软删除.
def destroy
# apply_records = ApplyAction.where(container_id: @shixun.id, container_type: "ApplyShixun")
# apply_records.delete_all if apply_records
apply_records = ApplyAction.where(container_id: @shixun.id, container_type: "ApplyShixun")
apply_records.delete_all if apply_records
# HomeworkCommonShixuns.where(shixun_id: @shixun).delete_all
# @shixun.destroy
@shixun.update_column(:status, -1)

@ -113,17 +113,22 @@ module ExercisesHelper
if ex.question_type <= Exercise::JUDGMENT #选择题和判断题
standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置
right_users_count = 0 #该问题的回答正确的人数
#计算每个问题的答案人数
# commit_users.transaction do
#
# end
user_ids.each do |user_id|
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq
if answer_choice_array.sort == standard_answer
right_users_count += 1
if ex.question_type == Exercise::MULTIPLE #多选题
user_ids.each do |user_id|
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq
if answer_choice_array.sort == standard_answer
right_users_count += 1
end
end
else #单选题和判断题
user_ids.each do |user_id|
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position
if [answer_choice_array] == standard_answer
right_users_count += 1
end
end
end
percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0
ex.exercise_choices.each do |c|
right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置

@ -1,6 +1,5 @@
class ChallengeTag < ApplicationRecord
# TODO: ES feature
# include Searchable::Dependents::ChallengeTag
include Searchable::Dependents::ChallengeTag
belongs_to :challenge, counter_cache: true
belongs_to :challenge_choose, optional: true

@ -1,6 +1,5 @@
class Course < ApplicationRecord
# TODO: ES feature
# include Searchable::Course
include Searchable::Course
has_many :boards, dependent: :destroy

@ -1,6 +1,5 @@
class Memo < ApplicationRecord
# TODO: ES feature
# include Searchable::Memo
include Searchable::Memo
has_many :memo_tag_repertoires, :dependent => :destroy
has_many :tag_repertoires, :through => :memo_tag_repertoires

@ -26,6 +26,7 @@ module Searchable::Memo
{
descendants_contents: Util.map_or_pluck(descendants, :content)
.map { |content| Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH] }
.join('<br/>')
}
end

@ -31,7 +31,7 @@ module Searchable::Shixun
.each_with_index.map { |subject, index| "#{index + 1}#{subject}" }
{
challenge_names: challenge_names,
challenge_names: challenge_names.join(' '),
challenge_tag_names: Util.map_or_pluck(challenge_tags, :name).uniq.join(' ')
}
end

@ -31,15 +31,9 @@ module Searchable::Subject
end
def searchable_stages_data
subject_stages =
stages.map do |stage|
{
name: stage.name,
description: Util.extract_content(stage.description)[0..Searchable::MAXIMUM_LENGTH]
}
end
{ subject_stages: subject_stages}
subject_stages = stages.map { |stage| "#{stage.name} #{Util.extract_content(stage.description)}"[0..Searchable::MAXIMUM_LENGTH] }
{ subject_stages: subject_stages.join('<br/>') }
end
def to_searchable_json

@ -1,6 +1,5 @@
class Shixun < ApplicationRecord
# TODO: ES feature
# include Searchable::Shixun
include Searchable::Shixun
# status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除
# hide_code 隐藏代码窗口

@ -1,6 +1,5 @@
class Stage < ApplicationRecord
# TODO: ES feature
# include Searchable::Dependents::Stage
include Searchable::Dependents::Stage
belongs_to :subject, counter_cache: true

@ -2,8 +2,7 @@
# 可以在初始创建的时候
class Subject < ApplicationRecord
# TODO: ES feature
# include Searchable::Subject
include Searchable::Subject
#status :0 编辑中 1 审核中 2 发布
belongs_to :repertoire

@ -1,7 +1,6 @@
class User < ApplicationRecord
include Watchable
# TODO: ES feature
# include Searchable::Dependents::User
include Searchable::Dependents::User
# Account statuses
STATUS_ANONYMOUS = 0

@ -0,0 +1,13 @@
defaults: &defaults
url: http://localhost:9200
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
url: 'http://elastic:Elas+ucloud123@106.75.27.125:59200/'
# url: 'http://elastic:TEST_elastickibana321@es-cn-0pp174wsj000iubdx.public.elasticsearch.aliyuncs.com'

@ -0,0 +1,2 @@
redis_config = Rails.application.config_for(:elasticsearch)
ENV['ELASTICSEARCH_URL'] = redis_config['url']

@ -26,5 +26,10 @@ class ModifyMdAttachmentUrlForMdCotents < ActiveRecord::Migration[5.2]
subjects.find_each do |s|
s.update_column(:description, s.description.gsub("![](/attachments/download", "![](/api/attachments")) if s.description.present?
end
plats = PlatformSample.where(samples_type: ['introduction', 'knowledge'])
plats.find_each do |p|
p.update_column(:contents, p.contents.gsub("![](/attachments/download", "![](/api/attachments")) if p.contents.present?
end
end
end

Loading…
Cancel
Save