diff --git a/app/api/mobile/apis/cnmooc.rb b/app/api/mobile/apis/cnmooc.rb index a5540327..21585ea0 100644 --- a/app/api/mobile/apis/cnmooc.rb +++ b/app/api/mobile/apis/cnmooc.rb @@ -3,7 +3,7 @@ module Mobile module Apis class Cnmooc < Grape::API - before {cnmooc_access_key!} + # before {cnmooc_access_key!} content_type :json, 'application/json;charset=UTF-8' resources :cnmoocs do diff --git a/app/models/school_daily_active_user.rb b/app/models/school_daily_active_user.rb new file mode 100644 index 00000000..0edd00fa --- /dev/null +++ b/app/models/school_daily_active_user.rb @@ -0,0 +1,3 @@ +class SchoolDailyActiveUser < ActiveRecord::Base + belongs_to :school_daily_report +end \ No newline at end of file diff --git a/app/models/school_daily_report.rb b/app/models/school_daily_report.rb index 494eacfd..6b24d8be 100644 --- a/app/models/school_daily_report.rb +++ b/app/models/school_daily_report.rb @@ -1,3 +1,5 @@ class SchoolDailyReport < ActiveRecord::Base belongs_to :school + + has_many :school_daily_active_users, dependent: :delete_all end \ No newline at end of file diff --git a/app/services/cnmoocs_service.rb b/app/services/cnmoocs_service.rb index 72318905..bce54650 100644 --- a/app/services/cnmoocs_service.rb +++ b/app/services/cnmoocs_service.rb @@ -3,60 +3,49 @@ class CnmoocsService include GamesHelper def get_resources_data params - page = params[:pageNo].to_i - limit = params[:pageSize] || 16 - offset = page * limit.to_i + resources = [] if params[:level].to_s == "1" subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.status, COUNT(myshixuns.id) AS myshixun_member_count FROM myshixuns, stage_shixuns, subjects WHERE myshixuns.shixun_id = stage_shixuns.shixun_id AND stage_shixuns.subject_id = subjects.id AND `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 - GROUP BY subjects.id ORDER BY myshixun_member_count DESC limit #{offset},#{limit}") + GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + subjects.each do |subject| resources << {resourceId: subject.id, parentId: nil, resourceName: subject.name, accessType: 0, nodeType: 0, resourceType: 2} end - totalCount = Subject.where(:status => 2, :hidden => 0).count - count = subjects.count + elsif params[:level].to_s == "2" return {error: -1, messages: "请求二级及其更高目录时,parentId不能为空"} if params[:parentId].blank? - stages = Stage.where(:subject_id => params[:parentId]).offset(offset).limit(limit) + stages = Stage.where(:subject_id => params[:parentId]) stages.each do |stage| resources << {resourceId: stage.id, parentId: params[:parentId], resourceName: stage.name, accessType: 0, nodeType: 0, resourceType: 2} end - totalCount = Stage.where(:subject_id => params[:parentId]).count - count = stages.count + elsif params[:level].to_s == "3" return {error: -1, messages: "请求二级及其更高目录时,parentId不能为空"} if params[:parentId].blank? shixun_ids = StageShixun.where(:stage_id => params[:parentId]).pluck(:shixun_id) - shixuns = Shixun.where(:id => shixun_ids).offset(offset).limit(limit) + shixuns = Shixun.where(:id => shixun_ids) shixuns.each do |shixun| resources << {resourceId: shixun.id, parentId: params[:parentId], resourceName: shixun.name, accessType: 2, nodeType: 1, resourceType: 1} end - totalCount = Shixun.where(:id => shixun_ids).count - count = shixuns.count + end - pageCount = ((totalCount / limit.to_f) == (totalCount / limit)) ? (totalCount / limit) : ((totalCount / limit) + 1) {error: 0, messages: "请求成功", - page: {count: count, totalCount: totalCount, pageNo: page, pageSize: limit, pageCount: pageCount}, data: {resources: resources} } end def search_resources params - page = params[:pageNo].to_i - limit = params[:pageSize] || 16 - offset = page * limit.to_i shixuns = Shixun.select([:id, :identifier, :name, :myshixuns_count, :averge_star, :challenges_count, :trainee]). where(status: 2, hidden: 0).where("name like ?", "%#{params[:name]}%") - shixun_count = shixuns.count - pageCount = ((shixun_count / limit.to_f) == (shixun_count / limit)) ? (shixun_count / limit) : ((shixun_count / limit) + 1) - shixuns = shixuns.order("myshixuns_count desc").offset(offset).limit(limit) + + shixuns = shixuns.order("myshixuns_count desc") shixun_list = shixun_data shixuns {error: 0, messages: "请求成功", - page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount}, data: shixun_list } end diff --git a/app/services/management/school_data_grow_service.rb b/app/services/management/school_data_grow_service.rb index 44fc45e1..7afe87af 100644 --- a/app/services/management/school_data_grow_service.rb +++ b/app/services/management/school_data_grow_service.rb @@ -6,7 +6,7 @@ class Management::SchoolDataGrowService attr_reader :params sort_columns :teacher_increase_count, :student_increase_count, - :course_increase_count, :shixun_increase_count, :active_user_count, + :course_increase_count, :shixun_increase_count, :uniq_active_user_count, :shixun_homework_count, :shixun_evaluate_count, default_by: :teacher_increase_count, default_direction: :desc @@ -27,6 +27,7 @@ class Management::SchoolDataGrowService 'SUM(shixun_increase_count) shixun_increase_count,'\ 'SUM(shixun_homework_count) shixun_homework_count,'\ 'SUM(shixun_evaluate_count) shixun_evaluate_count,'\ + 'COUNT(distinct(au.user_id)) uniq_active_user_count,'\ 'SUM(active_user_count) active_user_count' ) @@ -45,6 +46,7 @@ class Management::SchoolDataGrowService 'SUM(shixun_increase_count) shixun_increase_count,'\ 'SUM(shixun_homework_count) shixun_homework_count,'\ 'SUM(shixun_evaluate_count) shixun_evaluate_count,'\ + 'COUNT(distinct(au.user_id)) uniq_active_user_count,'\ 'SUM(active_user_count) active_user_count' ).first end @@ -60,6 +62,7 @@ class Management::SchoolDataGrowService end reports = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id AND #{date_condition}") + reports = reports.joins("LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = sdr.id") keyword = params[:keyword].try(:to_s).try(:strip) if keyword.present? diff --git a/app/services/zip_service.rb b/app/services/zip_service.rb index 759c7afa..cb278e98 100644 --- a/app/services/zip_service.rb +++ b/app/services/zip_service.rb @@ -52,7 +52,7 @@ module ZipService members = exercise.course.members exercise_users.each do |exercise_user| member = members.where(:user_id => exercise_user.user_id).first - group_name = member.try(:course_group_id).to_i == 0 ? '未分班' : member.course_group.name + group_name = member.try(:course_group_id).to_i == 0 ? '未分班' : member.course_group.try(:name) export_file_name = "#{group_name}-#{exercise.course_id}-#{exercise.exercise_name}-#{exercise_user.user.user_extensions.student_id}-#{exercise_user.user.show_real_name}" + ".pdf" out_file = export_user_exercise(exercise, exercise_user, export_file_name) file_name = File::expand_path(out_file) diff --git a/app/tasks/statistic_school_daily_report_task.rb b/app/tasks/statistic_school_daily_report_task.rb index 440d4a97..8a038718 100644 --- a/app/tasks/statistic_school_daily_report_task.rb +++ b/app/tasks/statistic_school_daily_report_task.rb @@ -9,7 +9,9 @@ class StatisticSchoolDailyReportTask student_count = users.where(created_on: yesterday, user_extensions: { identity: User::STUDENT }).count # 活跃用户 - active_user_count = users.where(last_login_on: yesterday).count + active_user_ids = users.where(last_login_on: yesterday).pluck(:id) + active_user_count = active_user_ids.size + # 新增课堂 course_count = school.courses.where(created_at: yesterday).count @@ -38,7 +40,13 @@ class StatisticSchoolDailyReportTask shixun_homework_count: shixun_homework_count, shixun_evaluate_count: shixun_evaluate_count, shixun_increase_count: shixun_count, active_user_count: active_user_count, date: current_date } - SchoolDailyReport.create!(create_params) + report = SchoolDailyReport.create!(create_params) + + if active_user_ids.present? + values = '(' + active_user_ids.join(", #{report.id}),(") + ", #{report.id})" + user_sql = "INSERT INTO school_daily_active_users(user_id, school_daily_report_id) VALUES#{values}" + SchoolDailyActiveUser.connection.execute(user_sql) + end end end diff --git a/app/views/common/index.html.erb b/app/views/common/index.html.erb index 35c63ca6..e833bafa 100644 --- a/app/views/common/index.html.erb +++ b/app/views/common/index.html.erb @@ -1 +1 @@ -
<%= sort_tag('新增实训', name: 'shixun_increase_count', path: school_data_grow_managements_path) %> | <%= sort_tag('新增实训作业', name: 'shixun_homework_count', path: school_data_grow_managements_path) %> | <%= sort_tag('新增实训评测', name: 'shixun_evaluate_count', path: school_data_grow_managements_path) %> | -<%= sort_tag('活跃用户', name: 'active_user_count', path: school_data_grow_managements_path) %> | +<%= sort_tag('活跃用户', name: 'uniq_active_user_count', path: school_data_grow_managements_path) %> | @@ -42,7 +44,7 @@<%= report.shixun_increase_count.to_i %> | <%= report.shixun_homework_count.to_i %> | <%= report.shixun_evaluate_count.to_i %> | -<%= report.active_user_count.to_i %> | +<%= report.uniq_active_user_count.to_i.zero? ? report.active_user_count.to_i : report.uniq_active_user_count.to_i %> | <% end %> diff --git a/db/migrate/20190530025028_migrate_homework_end_time.rb b/db/migrate/20190530025028_migrate_homework_end_time.rb new file mode 100644 index 00000000..cff8d8d8 --- /dev/null +++ b/db/migrate/20190530025028_migrate_homework_end_time.rb @@ -0,0 +1,93 @@ +class MigrateHomeworkEndTime < ActiveRecord::Migration + def up + homework = HomeworkCommon.where(id: 18615).first + if homework.present? + transaction do + homework.student_works.where("work_status = 2 and commit_time is not null and commit_time <= '#{homework.end_time}'").each do |work| + work.work_status = 1 + work.late_penalty = 0 + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + + homework = HomeworkCommon.where(id: 18614).first + if homework.present? + homework.update_column('end_time', '2019-05-20 00:00:00') + transaction do + homework.student_works.where("work_status = 2 and commit_time is not null and commit_time <= '2019-05-20 00:00:00'").each do |work| + work.work_status = 1 + work.late_penalty = 0 + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + + homework = HomeworkCommon.where(id: 18617).first + if homework.present? + homework.update_column('end_time', '2019-05-29 00:00:00') + homework.save + transaction do + homework.student_works.where("work_status = 2 and commit_time is not null and commit_time <= '2019-05-29 00:00:00'").each do |work| + work.work_status = 1 + work.late_penalty = 0 + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + + homework = HomeworkCommon.where(id: 18616).first + if homework.present? + homework.update_column('end_time', '2019-06-10 00:00:00') + homework.save + transaction do + homework.student_works.where("work_status = 2 and commit_time is not null and commit_time <= '2019-06-10 00:00:00'").each do |work| + work.work_status = 1 + work.late_penalty = 0 + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + + homework = HomeworkCommon.where(id: 25901).first + if homework.present? + homework.update_column('end_time', '2019-06-16 00:00:00') + homework.save + transaction do + homework.student_works.where("work_status = 2 and commit_time is not null and commit_time <= '2019-06-16 00:00:00'").each do |work| + work.work_status = 1 + work.late_penalty = 0 + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + + homework = HomeworkCommon.where(id: 25902).first + if homework.present? + homework.update_column('end_time', '2019-06-17 00:00:00') + homework.save + transaction do + homework.student_works.where("work_status = 2 and commit_time is not null and commit_time <= '2019-06-17 00:00:00'").each do |work| + work.work_status = 1 + work.late_penalty = 0 + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + end + + def down + end +end diff --git a/db/migrate/20190530050358_migrate_shixun_student_work_score_2.rb b/db/migrate/20190530050358_migrate_shixun_student_work_score_2.rb new file mode 100644 index 00000000..4eb869b4 --- /dev/null +++ b/db/migrate/20190530050358_migrate_shixun_student_work_score_2.rb @@ -0,0 +1,31 @@ +class MigrateShixunStudentWorkScore2 < ActiveRecord::Migration + def up + homeworks = HomeworkCommon.where(id: [18615, 18614, 18617, 18616, 25901, 25902]) + homeworks.each do |homework| + transaction do + homework.student_works.where("work_status > 0").each do |work| + if homework.end_time > Time.now + work.work_status = 1 + work.late_penalty = 0 + else + myshixun = work.myshixun + + if myshixun.status == 1 && myshixun.try(:done_time) < homework.end_time + work.work_status = 1 + work.late_penalty = 0 + else + work.work_status = 2 + work.late_penalty = homework.late_penalty + end + end + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + end + + def down + end +end diff --git a/db/migrate/20190531011258_create_school_daily_active_users.rb b/db/migrate/20190531011258_create_school_daily_active_users.rb new file mode 100644 index 00000000..e03ef5e9 --- /dev/null +++ b/db/migrate/20190531011258_create_school_daily_active_users.rb @@ -0,0 +1,10 @@ +class CreateSchoolDailyActiveUsers < ActiveRecord::Migration + def change + create_table :school_daily_active_users do |t| + t.integer :school_daily_report_id + t.integer :user_id + end + + add_index :school_daily_active_users, :school_daily_report_id + end +end diff --git a/public/react/package.json b/public/react/package.json index 107f53c9..a6ac3da8 100644 --- a/public/react/package.json +++ b/public/react/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "@novnc/novnc": "^1.1.0", "antd": "^3.6.5", "autoprefixer": "7.1.6", "axios": "^0.18.0", diff --git a/public/react/public/js/js_min_all.js b/public/react/public/js/js_min_all.js index 2036aa1f..19daead5 100644 --- a/public/react/public/js/js_min_all.js +++ b/public/react/public/js/js_min_all.js @@ -154,8 +154,9 @@ var SHRINK = 1; // 缩小 var repositoryTabHeight = 40 function _resizeTpiPanel () { - $("#game_left_contents").width('400px'); - $("#game_right_contents").width( $(".labelN").width() - 400 + 'px'); + var _total = $(".labelN").width(); + $("#game_left_contents").width( _total * 0.35 + 'px'); + $("#game_right_contents").width( _total * 0.65 + 'px'); } $(function(){ function update_rows_and_cols(rows) { diff --git a/public/react/src/context/TPIContextProvider.js b/public/react/src/context/TPIContextProvider.js index 9beea340..75d6b0e2 100644 --- a/public/react/src/context/TPIContextProvider.js +++ b/public/react/src/context/TPIContextProvider.js @@ -426,7 +426,7 @@ pop_box_new(htmlvalue, 480, 182); // const response = {} // response.data = {"tpm_modified":false,"tpm_cases_modified":false,"hide_code":false,"forbid_copy":false,"output_sets":{"test_sets":"{\"is_public\":1,\"result\":null,\"actual_output\":null,\"compile_success\":null,\"input\":\"9\",\"output\":\"3\\r\\n\"},{\"is_public\":1,\"result\":null,\"actual_output\":null,\"compile_success\":null,\"input\":\"110.25\",\"output\":\"10.5\\r\\n\"},{\"is_public\":0,\"result\":null,\"actual_output\":null,\"compile_success\":null,\"input\":\"-100\",\"output\":\"\\u65e0\\u7b97\\u672f\\u5e73\\u65b9\\u6839\\r\\n\"}","had_test_count":0,"test_sets_count":3,"had_passed_testsests_error_count":0},"latest_output":null,"mirror_name":["C/C++"],"multi_webssh":false,"has_answer":true,"st":0,"discusses_count":8,"game_count":3,"myshixun":{"id":140292,"shixun_id":49,"identifier":"ihprfcq2ta","gpid":156599,"status":0,"user_id":116,"commit_id":"5955e66e34b3b70913b4cb2f62ec5d84cdbe26c9","modify_time":"2017-10-13T15:14:34+08:00","reset_time":"2017-10-13T15:14:34+08:00","system_tip":false},"challenge":{"id":81,"subject":"\u6c42\u4e00\u4e2a\u6570\u7684\u7b97\u672f\u5e73\u65b9\u6839","position":2,"shixun_id":49,"st":0,"score":100,"path":"src/step2/SquareRoot.cpp","task_pass":"[TOC]\r\n\r\n---\r\n\r\n####\u4efb\u52a1\u63cf\u8ff0\r\n\u672c\u5173\u4efb\u52a1\u662f\u901a\u8fc7\u8c03\u7528`sqrt`\u51fd\u6570\u6765\u5b9a\u4e49\u4e00\u4e2a\u6c42\u7b97\u672f\u5e73\u65b9\u6839\u7684\u51fd\u6570\u5e76\u4ee5\u6b64\u6765\u8ba1\u7b97\u4e00\u4e2a\u6570\u7684\u7b97\u672f\u5e73\u65b9\u6839\u3002\r\n\r\n####\u76f8\u5173\u77e5\u8bc6\r\n\u5982\u679c\u4e00\u4e2a\u975e\u8d1f\u6570`x`\u7684\u5e73\u65b9\u7b49\u4e8e`a`\uff0c\u5373`$$x^2 = a$$`\uff0c`(a \u2265 0)`\uff0c\u90a3\u4e48\u8fd9\u4e2a\u975e\u8d1f\u6570`x`\u53eb\u505a`a`\u7684\u7b97\u672f\u5e73\u65b9\u6839\u3002`a`\u7684\u7b97\u672f\u5e73\u65b9\u6839\u8bb0\u4e3a`$$\\sqrt{a}$$`\uff0c\u8bfb\u4f5c`\u6839\u53f7a`\uff0c`a`\u53eb\u505a\u88ab\u5f00\u65b9\u6570\u3002\r\n\r\nC++\u4e2d\uff0c\u53ef\u4ee5\u8c03\u7528\u5e93\u51fd\u6570`sqrt()`\u6765\u6c42\u4e00\u4e2a\u6570\u7684\u7b97\u672f\u5e73\u65b9\u6839\u3002\r\n\r\n####\u7f16\u7a0b\u8981\u6c42\r\n\u672c\u5173\u7684\u7f16\u7a0b\u4efb\u52a1\u662f\u901a\u8fc7\u8c03\u7528`sqrt()`\u51fd\u6570\u6765\u8865\u5168`step2/SquareRoot.cpp`\u6587\u4ef6\u4e2d\u7684`SquareRoot(float n)`\u51fd\u6570\uff0c\u4ee5\u5b9e\u73b0\u8ba1\u7b97\u4e00\u4e2a\u6570\u7684\u7b97\u672f\u5e73\u65b9\u6839\u7684\u8981\u6c42\u3002\r\n\r\n\u6ce8\u610f\uff1a\r\n* \u5982\u679c\u8f93\u5165\u7684\u6570\u6ca1\u6709\u7b97\u6570\u5e73\u65b9\u6839\uff0c\u8fd4\u56de`-1`\u3002\r\n* \u5177\u4f53\u8bf7\u53c2\u89c1\u540e\u7eed\u6d4b\u8bd5\u6837\u4f8b\u3002\r\n\r\n\u672c\u5173\u6d89\u53ca\u7684\u4ee3\u7801\u6587\u4ef6`step2/SquareRoot.cpp`\u4e2d\u7684`SquareRoot`\u51fd\u6570\u7684\u4ee3\u7801\u6846\u67b6\u5982\u4e0b\uff1a\r\n\r\n```cpp\r\n#include
---|