From 3f0e5b95ec0df2e52434c25d67624cbb3e86f3ff Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 09:58:07 +0800 Subject: [PATCH 01/11] 1 --- app/models/shixun.rb | 3 +++ .../subjects/data_statistic_service.rb | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 app/services/subjects/data_statistic_service.rb diff --git a/app/models/shixun.rb b/app/models/shixun.rb index d8a41ba6a..b77038a78 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -59,6 +59,9 @@ class Shixun < ApplicationRecord # Jupyter数据集,附件 has_many :data_sets, ->{where(attachtype: 2)}, class_name: 'Attachment', as: :container, dependent: :destroy + # 试卷的实训题 + has_many :exercise_questions + scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", "%#{keyword}%", "%#{keyword}%") } diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb new file mode 100644 index 000000000..9311953ca --- /dev/null +++ b/app/services/subjects/data_statistic_service.rb @@ -0,0 +1,22 @@ +class Subjects::DataStatisticService < ApplicationService + attr_reader :subject, :user + def initialize(subject, user) + @subject = subject + @user = user + @shixuns = subject.shixuns + end + + # 学习总人数 + def study_count + @shixuns.includes(:myshixuns).map{|shixun| shixun.myshixuns.pluck(:user_id)}.uniq + end + + # 课堂学习人数 + def course_study_count + # 实训作业 + sw_user_ids = StudentWork.where.not(myshixun_id: nil).pluck(:user_id) + # 试卷的实训题 + esa_user_ids = ExerciseShixunAnswer.where() + end + +end From a165d895c3ec1739dd9e16b2bb504d909da4169e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 10:59:32 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/subjects/data_statistic_service.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb index 9311953ca..29696cf15 100644 --- a/app/services/subjects/data_statistic_service.rb +++ b/app/services/subjects/data_statistic_service.rb @@ -3,7 +3,7 @@ class Subjects::DataStatisticService < ApplicationService def initialize(subject, user) @subject = subject @user = user - @shixuns = subject.shixuns + @shixun_ids = subject.shixuns.pluck(:id) end # 学习总人数 @@ -14,9 +14,11 @@ class Subjects::DataStatisticService < ApplicationService # 课堂学习人数 def course_study_count # 实训作业 - sw_user_ids = StudentWork.where.not(myshixun_id: nil).pluck(:user_id) + sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixuns) + .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id") # 试卷的实训题 - esa_user_ids = ExerciseShixunAnswer.where() + esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun) + .where(shixuns: {id: @shixun_ids}).pluck("exercise_shixun_answers.user_id") end end From 908dbb87cae041b39b3ca95c10312bbd0faec907 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 11:39:51 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E6=95=8F=E6=84=9F=E8=AF=8D=E6=B1=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chinese_dictionary.txt | 136 +----------------- config/harmonious_dictionary/harmonious.hash | Bin 48913 -> 46347 bytes 2 files changed, 2 insertions(+), 134 deletions(-) diff --git a/config/harmonious_dictionary/chinese_dictionary.txt b/config/harmonious_dictionary/chinese_dictionary.txt index 3040d9d0e..ce247eb45 100644 --- a/config/harmonious_dictionary/chinese_dictionary.txt +++ b/config/harmonious_dictionary/chinese_dictionary.txt @@ -10,26 +10,21 @@ 李源潮 李干成 戴秉国 -黄镇 刘延东 刘瑞龙 俞正声 -黄敬 薄熙来 薄一波 周小川 周建南 温云松 -徐明 江绵康 李小鹏 李小琳 朱云来 让国人愤怒的第二代身份证 -第二代身份证 文化大革命 胡海峰 -六四 陈良宇 老丁 莱仕德事件 @@ -68,11 +63,9 @@ PK黑社会 反华 官商勾结 升达毕业证 -手机复制 戴海静 自杀指南 自杀手册 -张小平 佳静安定片 蒙汗药粉 古方迷香 @@ -105,7 +98,6 @@ PK黑社会 反政府 禁书 特码 -成人 国民党 贪污 骚妇 @@ -154,7 +146,6 @@ PK黑社会 AV 十八禁 性虐待 -激情 耽美 金瓶梅 藏春阁 @@ -181,15 +172,13 @@ AV 政府无能 九评 十七大代表 -办证 暴力拆迁 轮暴致死 -人民报 暴力镇压 高干子弟名单 性免费电影 全裸 -偷 拍 +偷拍 中共十七大 徐和柴学友 修炼之歌 @@ -250,7 +239,6 @@ A集中营 中共特务 乙醚 党内分裂 -新生网 圆明网 和平修炼 放下生死 @@ -303,10 +291,6 @@ A集中营 明慧周刊 九评共产党 江泽民其人 -秘密文件 -机密文件 -红头文件 -政府文件 破网软件 无界浏览 亲共来源 @@ -341,7 +325,6 @@ H漫画 香港GHB水 色空寺 周容重 -朱蒙 汕頭頻傳擄童割器官 法輪功 六决不 @@ -371,15 +354,12 @@ H漫画 敢坐飞机吗 韩国身份证 台湾身份证 -广电总局 学生暴动 镇压学生 广安第二人民医院 -山不过来 胡新宇 趙紫陽 自由亚州 -明慧 践踏中国女性 拉凳 南京大学法学院 @@ -389,7 +369,6 @@ H漫画 崔英杰 松花江污染 火药制作 -江氏 第十六次代表 仁寿警方 愈快乐愈堕落 @@ -433,7 +412,6 @@ H漫画 二奶 2奶 纪股票市场五卅惨案 -这年头就这样 代开普通发票 代开商品发票 代开国税发票 @@ -487,7 +465,6 @@ H漫画 死刑过程 学生与警察 鬼村 -周容 重题工 先烈的电电 身份证生成 @@ -509,17 +486,14 @@ H漫画 生成身份证 华国锋 叶剑英 -陈云 李先念 汪东兴 韦国清 乌兰夫 -方毅 刘伯承 许世友 纪登奎 苏振华 -吴德 余秋里 张廷发 陈永贵 @@ -528,15 +502,12 @@ H漫画 聂荣臻 倪志福 徐向前 -彭冲 -王震 邓颖超 杨尚昆 杨得志 宋任穷 胡乔木 胡耀邦 -彭真 廖承志 秦基伟 陈慕华 @@ -549,21 +520,16 @@ H漫画 芮杏文 杨白冰 邹家华 -谢非 谭绍文 王汉斌 任建新 于永波 傅全有 -吴仪 -王克 王乐泉 王兆国 -刘淇 刘云山 张立昌 张德江 -王刚 隐形耳机 隐形摄像头 裸聊 @@ -629,11 +595,7 @@ a级情片 藏独 曹长青 曹刚川 -柴玲 -常劲 陈炳基 -陈军 -陈蒙 陈破空 陈希同 陈小同 @@ -641,17 +603,13 @@ a级情片 陈一谘 陈总统 程铁军 -程真 迟浩田 持不同政见 赤匪 赤化 达赖 大参考 -大法 大纪园 -大家论坛 -大史记 大史纪 戴相龙 弹劾 @@ -663,7 +621,6 @@ a级情片 电视流氓 钓鱼岛 丁关根 -丁元 丁子霖 东北独立 东社 @@ -702,7 +659,6 @@ a级情片 炼功 李总统 李登辉 -李鹏 李瑞环 吐血 18禁 @@ -828,7 +784,6 @@ A片 薄格 調教 乱伦 -偷拍 更衣 無修正 虐待 @@ -854,16 +809,12 @@ A片 伊東 武藤蘭 叶子楣 -舒淇 -麻衣 櫻井 風花 星野桃 -宝来 桜田 藤井彩 小森美王 -平井 桃井望 榊彩弥 桜井 @@ -876,7 +827,6 @@ A片 長瀬愛 中野千夏 春菜 -望月 岡崎美女 宮下杏奈 加藤 @@ -884,24 +834,12 @@ A片 北島優 一本道 夜勤病栋 -三个代表 -一党 -多党 -民主 -专政 避孕套 你妈逼 大鸡巴 政治 -洪志 -红志 -洪智 -红智 -民运 -王丹 卖春 买春 -天安门 朱容基 朱镕基 温家宝 @@ -915,14 +853,12 @@ A片 黑社会 夜总会 妈个 -公款 坐台 腐败 城管 暴动 李远哲 司法警官 -高干 尉健行 李岚清 黄丽满 @@ -938,19 +874,10 @@ A片 吴邦国 曾庆红 黄菊 -罗干 吴官正 贾庆林 专制 -三個代表 -一黨 -多黨 -專政 大紀元 -紅志 -紅智 -李鵬 -天安門 江澤民 朱鎔基 李長春 @@ -963,9 +890,7 @@ A片 溫家寶 吳邦國 曾慶紅 -黃菊 賈慶林 -專制 反人类 反社会 方励之 @@ -984,12 +909,10 @@ A片 付申奇 傅申奇 傅志寰 -高官 高文谦 高薪养廉 高瞻 高自联 -戈扬 鸽派 个人崇拜 工自联 @@ -1000,10 +923,8 @@ A片 共军 关卓中 贯通两极法 -广闻 郭伯雄 郭罗基 -郭平 郭岩华 国家安全 国家机密 @@ -1017,13 +938,11 @@ A片 红色恐怖 宏法 洪传 -洪吟 洪哲胜 胡紧掏 胡锦滔 胡锦淘 胡景涛 -胡平 胡总书记 护法 花花公子 @@ -1046,9 +965,7 @@ A片 江core 江八点 江流氓 -江罗 江绵恒 -江青 江戏子 江则民 江泽慧 @@ -1064,9 +981,7 @@ A片 教养院 揭批书 金尧如 -锦涛 禁看 -经文 开放杂志 抗议 邝锦文 @@ -1079,8 +994,6 @@ A片 李洪宽 李继耐 李兰菊 -李录 -李禄 李少民 李淑娴 李旺阳 @@ -1099,16 +1012,13 @@ A片 林长盛 林樵清 林慎立 -凌锋 刘宾深 刘宾雁 -刘刚 刘国凯 刘华清 刘俊国 刘凯中 刘千石 -刘青 刘山青 刘士贤 刘文胜 @@ -1153,17 +1063,12 @@ A片 潘国平 泡沫经济 迫害 -祁建 -齐墨 -钱达 钱国梁 钱其琛 抢粮记 -乔石 亲美 钦本立 情妇 -庆红 热比娅 热站政论网 人民内情真相 @@ -1174,11 +1079,8 @@ A片 上海帮 邵家健 神通加持法 -沈彤 升天 盛华仁 -盛雪 -石戈 时代论坛 时事论坛 世界经济导报 @@ -1191,7 +1093,6 @@ A片 司徒华 斯诺 四川独立 -宋平 宋书元 苏绍智 苏晓康 @@ -1204,11 +1105,9 @@ A片 太子党 汤光中 唐柏桥 -唐捷 滕文生 天怒 天葬 -童屹 统独 统独论坛 统战 @@ -1216,10 +1115,8 @@ A片 外交与方略 万润南 万晓东 -汪岷 王宝森 王炳章 -王策 王超华 王辅臣 王涵万 @@ -1246,11 +1143,9 @@ A片 吴学璨 吾尔开希 五不 -伍凡 洗脑 项怀诚 项小吉 -肖强 邪恶 谢长廷 谢选骏 @@ -1269,10 +1164,7 @@ A片 徐匡迪 徐水良 许家屯 -薛伟 学潮 -学联 -学运 学自联 雪山狮子 严家其 @@ -1282,13 +1174,9 @@ A片 央视内部晚会 杨怀安 杨建利 -杨巍 杨月清 -杨周 姚月谦 一中一台 -义解 -亦凡 异见人士 异议人士 易丹轩 @@ -1296,38 +1184,27 @@ A片 尹庆民 由喜贵 游行 -幼齿 于大海 于浩成 余英时 舆论反制 宇明网 远志明 -岳武 -则民 -择民 -泽民 贼民 曾培炎 张伯笠 -张钢 张宏堡 -张健 -张林 张万年 张伟国 张昭富 张志清 赵海青 -赵南 赵品潞 赵晓微 赵紫阳 -哲民 镇压 争鸣论坛 正见网 -郑义 正义党论坛 换妻 真木加美 @@ -1350,12 +1227,9 @@ A片 东京热 菅野亚梨沙 吉岡美穗 -红音 原千寻 熟女 轮奸 -朱琳 -朱毛 朱溶剂 猪聋畸 猪毛 @@ -1373,7 +1247,6 @@ A片 fa轮 亲日 汉奸 -政权 政治反对派 政治犯 支那 @@ -1392,9 +1265,7 @@ fa轮 周锋锁 周天法 陈水扁 -周旋 朱嘉明 -阿扁 二逼 小鸡鸡 卖逼 @@ -1436,7 +1307,6 @@ fa轮 喷你 操逼 淫水 -他妈 操比 杂种 他母亲 @@ -1499,13 +1369,11 @@ B样 北美自由论坛 博讯 蔡崇国 -程凯 大纪元新闻网 大众真人真事 东南西北论谈 封杀 -何勇 江猪媳 酱猪媳 枪支 -毒品 +毒品 \ No newline at end of file diff --git a/config/harmonious_dictionary/harmonious.hash b/config/harmonious_dictionary/harmonious.hash index 9ce3b2f93690dda331a3df2e4e06990a362ffef1..456a8254b258a810b2e661f5130946a71a39a915 100644 GIT binary patch delta 1259 zcmXX_X-rgC810>f_a3t%LmUPjEZVZqAf>c`LL>zOA~IBLLW-!Q2(pukB%o0S5b8E~ zrc|sf!XT7Ew#!n6rD&U&YJW88V%q8tBil5Tk|s7yTbjOk@aN{sx18^sbMI~bPjvZL zkyOG~i{5UQT8XUr*87ZGvLEZbbQN(eUZ^x{5J+^&wrg%NuNekORLDo z1Utkv=oOpLA1Q}yLWwZRr$mcyBnkLuN{$ez3MtaJ(9|x6T^dMVNFzk5#m1Wgmd1rO zJ%MMV-qyPx1`8cQwVzl-=S7v8iWB$lHAk*nLhmYOaLhz!4X>9%7thBCkcO>#Nk z+>l(zpMNAr(ae-2f_GC>h&%dH)2Q^2S;8&OS%e809>`{CqiJ1+m!%%CpHgBqfTP{n zUlGD0KPO1MFw;pNzEDmz2> zRMd;O<$(bq<%R>deq>+z=1@rHAa`<}I+WHAZ2zv5s4`j0wvX=x*4D zwT4-gHKo&#k5;AJa^GgN8{V_%DJ*^xhUFJ`d$p-oHs_c5LyS1Lo?)$qeEHPc%4-U?`ybO zsIr(pXvN6T2}BmE#S7CH>EU5JpSp3+Oi6^uW*<)YQqvJ6|yfQWe zGNI*G#>WLD4zEu7;_zfT9FuQQ_Vd3aNSO8E7N%RaX!y_Su|BJ#IkS5SGQu^ygwx@A ISmrMN56iLGQUCw| delta 2573 zcmZuzeNa@_74Lg*VRvD_kOkkmfDvg{Rt$c`IFw{YF`(Abpe8XS5hd|EXv8*(wbccM zT}0*M$4B^b6=5O3igJm3tbn$*owVaPolerm)K;ha-m;E0nNB*>KWfwa-rFwgv@^`| z?mg$8^EkOdNPYk47#=L;@m!Rh3wWFG(97eD z$w+oZSy)@pcUsofNnjhDk>|w5f$$P{p6@WYK9<+BCB(k#_%4aZ<0u^-IgGfewsPW# z6L-~{SywAoWt*`;a}qDQOn5mqR{BqVp($i|VX`*tPW)J5Kw=BiKb+8t*W9wu3VVz< zNhY+dQh^}3Z0l6MCG~G&)^p<38j=}1i!#|T64GvfjvpO;hA+&e?WpKZsvV3PxGn;pkGPnUufZ1@GpS6^ zV(9iwdmcMjhN9QZM8EJQ23v>CDz${RcsKkq3xpuekM&BA?+4wjuJob?#UPhVZb;P2h$L@lLJJo8Km2$dC>wMf~8q&RYtn(CEphvkf(NabSXKGn&a>BIJg8B@zBvO{VH88G}xL#84 z8dki7J-^e&+>_(ZafYGh1?&GD7QFW*N8@347tazZo@p0BUoZ0W%vhPKB0t%k%Fx@=vF9sJ7&(XHy|mBN^}@OL z)|{~^8JwgP9b>=Lh%A@{cOkqymvR>TH2yWddHwFd*;4 zW4QNW8R;)cQ!SgGY6&9}#%73&BvrV2Ev!TJQA~Jp_oD;`JCozk>(;@s(*QkfV5XyA zP#yzEOF401l58m*RV|S!U*+q1CwWDYOXD#(qJx5<$ih4iwQIlr$Di`MhVQXAnY>qNuJ zUmGTr{v@NT9KsS$f-ywY6=n8l@xCKV?rF7-TBMfe>y?6&vKZ{RfD4^Gw)N$alJdVr zaiV(|PtAOqFgh9zPB=3ZhC$B+dKJ4G>~W>w6^~XM^5+~R$6PO{Xf-}O8xP-E0~ef_ zA`@o|nM4WQ^kj&8MV(Gbl6pR*)p@?B#N9xv5#w3B0b(>58op@}E;O>-Dd zY;VI8nzVuDO&lMXP%fn$``8Rf3|>yb)7EWkg{w+$meUoHB8gkq^=E<_R&pVm`ro_0 zv2BD4`c7ex;}O-KP7by2V2q+mu`b`{ssY^Y_?pH(eBlT9DA|Z77gA~7gw)lM?s z{SPKN*q~el`M`B$mPi#Nk?Ox=u|p! z$V{+a;aDoK>B&iXCMR{j!THA;P@~~d(rv^2!&Xde(cohDX0&?VqadGpQc{9#eUUx_ zZW4A+<0QtOe#X!r>Z_99Yh%RQo6Q*gH$u-JY14TLfBIxUTi#Sx$fL8b*f`x3ijqqG zH{4+R@7n!i${>-uQ_tl{um15Ff~Ya_%lPY1(L)Fw|AK_cxvW-K)sV+c~wz1zpqJlEoa;ls*_MMT9x;a Y{788+l!D(3S&5A-W^m_-78ox54+d+N761SM From 2949271f86a6e37ef17b095429fb92e3a172f53f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 15:21:12 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/myshixun.rb | 1 + .../subjects/data_statistic_service.rb | 57 +++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 1a89c755e..54d068be6 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -5,6 +5,7 @@ class Myshixun < ApplicationRecord has_one :shixun_modify, :dependent => :destroy belongs_to :user + belongs_to :user_extension belongs_to :shixun, counter_cache: true has_one :last_executable_task, -> { where(status: [0, 1]).reorder(created_at: :asc) }, class_name: 'Game' diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb index 29696cf15..4ab7488c6 100644 --- a/app/services/subjects/data_statistic_service.rb +++ b/app/services/subjects/data_statistic_service.rb @@ -3,15 +3,20 @@ class Subjects::DataStatisticService < ApplicationService def initialize(subject, user) @subject = subject @user = user - @shixun_ids = subject.shixuns.pluck(:id) + @shixuns = subject.shixuns + @shixun_ids = @shixuns.pluck(:id) end - # 学习总人数 + # 学习总人数: + # 文案解释:学习该课程的全部人数(学习总人数=课堂学习人数+自主学习人数) + # 开发备注:只要点击该课程的任何一个实训(生成了tpi),都算一个学习人数;(去重,一个人数计算1次) def study_count - @shixuns.includes(:myshixuns).map{|shixun| shixun.myshixuns.pluck(:user_id)}.uniq + @shixuns.joins(:myshixuns).select("myshixuns.user_id").distinct.size end - # 课堂学习人数 + # 课堂学习人数: + # 文案解释:通过课堂学习该课程的人数 + # 开发备注:只要通过课堂进入,并点击了实训(生成了tpi),则算一个可以学习人数;(去重,一个人数计算1次) def course_study_count # 实训作业 sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixuns) @@ -19,6 +24,50 @@ class Subjects::DataStatisticService < ApplicationService # 试卷的实训题 esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun) .where(shixuns: {id: @shixun_ids}).pluck("exercise_shixun_answers.user_id") + (sw_user_ids + esa_user_ids).uniq.size end + # 自主学习人数: + # 文案解释:通过自主学习该课程的人数 + # 开发备注:非课程进入,生成了实训的tpi(去重。一个人数计算1次 + def initiative_study + study_count - course_study_count + end + + # 通关总人数: + # 文案解释: + # 通关该课程所有实训的人数(去重。一个人数计算1次) + def passed_count + @shixuns.includes(:myshixuns).where(myshixuns: {status: 1}).select("myshixuns.user_id").distinct.size + end + + # 使用课堂数: + # 文案解释:使用该课程的课堂数量 + # 开发备注:课堂加入该课程的实训到自己课堂,则算一个使用课堂数。(去重,一个课堂计算1次) + def course_used_count + hc_course_ids = + HomeworkCommon.joins(:homework_commons_shixun) + .where(homework_type: %i[practice]) + .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("homework_commons.course_id").uniq + ex_course_ids = + Exercise.joins(:exercise_questions) + .where(exercise_questions: {question_type: 5, shixun_id: @shixun_ids}).pluck("exercises.course_id").uniq + + (hc_course_ids + ex_course_ids).uniq.size + end + + # 使用单位数: + # 文案解释:使用该课程的单位数量(包括自主学习者所在单位) + # 开发备注:凡事该单位有使用该课程的实训(自主学习+课堂使用)都算;(去重,一个单位计算一次) + def school_used_count + school_ids.size + end + + + private + def school_ids + @shixuns.joins(myshixuns: :user_extension).select("user_extensions.school_id").distinct + end + + end From 024da3edf644a84f14b79cf676b84aa090220daa Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 16:51:44 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subjects/course_used_info_service.rb | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/services/subjects/course_used_info_service.rb diff --git a/app/services/subjects/course_used_info_service.rb b/app/services/subjects/course_used_info_service.rb new file mode 100644 index 000000000..188a96fd7 --- /dev/null +++ b/app/services/subjects/course_used_info_service.rb @@ -0,0 +1,42 @@ +class Subjects::CourseUsedInfoService < ApplicationService + attr_reader :subject, :user + def initialize(subject, user) + @subject = subject + @user = user + @shixuns = subject.shixuns + @shixun_ids = @shixuns.pluck(:id) + end + + def call + return if subject.blank? + homework_commons = + HomeworkCommon.joins(:homework_commons_shixun) + .where(homework_type: %i[practice]) + .where(homework_commons_shixuns: {shixun_id: @shixun_ids}) + course_ids = homework_commons.pluck(:course_id) + homework_common_ids = homework_commons.pluck("homework_commons.id") + schools = School.joins(courses: [:course_members, :homework_commons]) + + # name:将该课程使用到课堂的单位 + # course_count: 将该课程使用到课堂的数量 + # student_count: 课堂的学生总数(去掉重复) + # choice_shixun_num: 选用该课程实训的个数(去重) + # choice_shixun_frequency: 选用该课程实训的次数 + course_info = + schools.map do |school| + name = school.name + course_count = school.where(courses: {id: course_ids}).count + student_count = school.where(course_members: {role: 4}).select("course_members.user_id").distinct.size + homework_commons = school.where(homework_commons: {id: homework_common_ids}) + .select("homework_commons.id") + choice_shixun_num = homework_commons.distinct.size + choice_shixun_frequency = homework_commons.size + {name: name, course_count: course_count, student_count: student_count, choice_shixun_num: choice_shixun_num, + choice_shixun_frequency: choice_shixun_frequency} + end + # 默认按照选用实训的次数作为排序 + course_info.sort{|x,y| y['choice_shixun_frequency'] <=> x['choice_shixun_frequency']} + end + +end + From dc0e45c0ed535a5a3e0bc3273265e556cbae23fe Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 18:51:53 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subjects/course_used_info_service.rb | 8 ++--- .../subjects/data_statistic_service.rb | 5 ++- .../subjects/shixun_used_info_service.rb | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 app/services/subjects/shixun_used_info_service.rb diff --git a/app/services/subjects/course_used_info_service.rb b/app/services/subjects/course_used_info_service.rb index 188a96fd7..f60c4a6ca 100644 --- a/app/services/subjects/course_used_info_service.rb +++ b/app/services/subjects/course_used_info_service.rb @@ -1,10 +1,8 @@ class Subjects::CourseUsedInfoService < ApplicationService - attr_reader :subject, :user - def initialize(subject, user) + attr_reader :subject + def initialize(subject) @subject = subject - @user = user - @shixuns = subject.shixuns - @shixun_ids = @shixuns.pluck(:id) + @shixun_ids = subject.shixuns.pluck(:id) end def call diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb index 4ab7488c6..9dc2db09a 100644 --- a/app/services/subjects/data_statistic_service.rb +++ b/app/services/subjects/data_statistic_service.rb @@ -1,8 +1,7 @@ class Subjects::DataStatisticService < ApplicationService - attr_reader :subject, :user - def initialize(subject, user) + attr_reader :subject + def initialize(subject) @subject = subject - @user = user @shixuns = subject.shixuns @shixun_ids = @shixuns.pluck(:id) end diff --git a/app/services/subjects/shixun_used_info_service.rb b/app/services/subjects/shixun_used_info_service.rb new file mode 100644 index 000000000..1dda483d4 --- /dev/null +++ b/app/services/subjects/shixun_used_info_service.rb @@ -0,0 +1,31 @@ +class Subjects::ShixunUsedInfoService < ApplicationService + attr_reader :subject, :stages + def initialize(subject) + @subject = subject + @stages = subject.stages.includes(shixuns: [myshixuns: :games, homework_commons_shixuns: [homework_common: :course]]) + end + + def call + shixun_infos = [] + stages.each do |stage| + position = stage.position + stage.shixuns.each_with_index do |shixun, index| + stage = "#{position}-#{index+1}" + name = shixun.name + challenge_count = shixun.challenges_count + course_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course_id}.uniq.size + school_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course.school_id}.uniq.size + used_count = shixun.myshixuns_count + passed_count = shixun.myshixuns.select{|m| m.status == 1}.size + evaluate_count = shixun.myshixuns.map{|m| m.games.sum(:evaluate_count).to_i}.sum + passed_ave_time = (passed_count > 0) ? + (shixun.myshixuns.map{|m| m.status == 1 && m.games.sum(:cost_time).to_i}.sum / passed_count) : 0 + shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, + school_count: school_count, used_count: used_count, passed_count: passed_count, + evaluate_count: evaluate_count, passed_ave_time: passed_ave_time} + end + shixun_infos + end + end + +end From 11155590fa5f397d682577c8f41874d394dfcea5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 20:09:05 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 1 + .../subjects/user_used_info_service.rb | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 app/services/subjects/user_used_info_service.rb diff --git a/app/models/user.rb b/app/models/user.rb index 54aa8d85e..dd606f7bc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,6 +43,7 @@ class User < ApplicationRecord has_many :shixun_members, :dependent => :destroy has_many :shixuns, :through => :shixun_members has_many :myshixuns, :dependent => :destroy + has_many :games, :dependent => :destroy has_many :study_shixuns, through: :myshixuns, source: :shixun # 已学习的实训 has_many :course_messages has_many :courses, foreign_key: 'tea_id', dependent: :destroy diff --git a/app/services/subjects/user_used_info_service.rb b/app/services/subjects/user_used_info_service.rb new file mode 100644 index 000000000..4d5f54f9e --- /dev/null +++ b/app/services/subjects/user_used_info_service.rb @@ -0,0 +1,30 @@ +class Subject::UserUsedInfoService < ApplicationService + attr_reader :subject, :shixun_ids + + def initialize(subject) + @subject = subject + @shixun_ids = subject.shixuns.pluck(:id) + + end + + def call + users = User.joins(:myshixuns).where(myshixuns: {shixun_id: shixun_ids}).group(:user_id) + + users_info = [] + users.includes(:myshixuns, :games).each do |user| + games = user.games + name = "#{user.lastname}#{user.firstname}" + passed_myshixun_count = user.myshixuns.select{|m| m.status == 1}.size + passed_games_count = games.select{|g| g.status == 2}.size + code_line_count = "未完成" + evaluate_count = games.sum(evaluate_count) + cost_time = games.sum(:cost_time) + user_login = user.login + users_info << {login: user_login, name: name, passed_myshixun_count: passed_myshixun_count, + passed_games_count: passed_games_count, code_line_count: code_line_count, + evaluate_count: evaluate_count, cost_time: cost_time} + end + users_info + end + +end From ab02572d066816a0c3074ad277a85c82ce404362 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 9 Jan 2020 13:39:07 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 19 +++++++++++++++ app/models/myshixun.rb | 4 ++-- .../subjects/course_used_info_service.rb | 12 +++++----- .../subjects/data_statistic_service.rb | 8 +++---- .../subjects/shixun_used_info_service.rb | 13 +++++++--- .../subjects/user_used_info_service.rb | 24 +++++++++---------- config/routes.rb | 1 + 7 files changed, 53 insertions(+), 28 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 7df9aae89..eb12c4f0d 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -456,6 +456,25 @@ class SubjectsController < ApplicationController end end + def statistics_new + # data = Subjects::DataStatisticService.new(@subject) + # Rails.logger.info("study_count: #{data.study_count}") + # Rails.logger.info("course_study_count: #{ data.course_study_count}") + # Rails.logger.info("passed_count: #{data.passed_count}") + # Rails.logger.info("course_used_count: #{data.course_used_count}") + # Rails.logger.info("school_used_count: #{data.school_used_count}") + + # data_1 = Subjects::CourseUsedInfoService.call(@subject) + # Rails.logger.info("study_count: #{data_1}") + + # data_2 = Subjects::ShixunUsedInfoService.call(@subject) + # Rails.logger.info("study_count: #{data_2}") + + data_3 = Subjects::UserUsedInfoService.call(@subject) + Rails.logger.info("study_count: #{data_3}") + render_ok() + end + def shixun_report end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 54d068be6..8d2012381 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -5,7 +5,7 @@ class Myshixun < ApplicationRecord has_one :shixun_modify, :dependent => :destroy belongs_to :user - belongs_to :user_extension + belongs_to :user_extension, foreign_key: :user_id belongs_to :shixun, counter_cache: true has_one :last_executable_task, -> { where(status: [0, 1]).reorder(created_at: :asc) }, class_name: 'Game' @@ -22,7 +22,7 @@ class Myshixun < ApplicationRecord end def output_times - games.pluck(:evaluate_count).sum.to_i + games.map(&:evaluate_count).sum.to_i end def repo_path diff --git a/app/services/subjects/course_used_info_service.rb b/app/services/subjects/course_used_info_service.rb index f60c4a6ca..5553c7222 100644 --- a/app/services/subjects/course_used_info_service.rb +++ b/app/services/subjects/course_used_info_service.rb @@ -13,7 +13,7 @@ class Subjects::CourseUsedInfoService < ApplicationService .where(homework_commons_shixuns: {shixun_id: @shixun_ids}) course_ids = homework_commons.pluck(:course_id) homework_common_ids = homework_commons.pluck("homework_commons.id") - schools = School.joins(courses: [:course_members, :homework_commons]) + schools = School.joins(:courses).where(courses: {id: course_ids}).select("schools.*, count(courses.id) course_count") # name:将该课程使用到课堂的单位 # course_count: 将该课程使用到课堂的数量 @@ -23,11 +23,11 @@ class Subjects::CourseUsedInfoService < ApplicationService course_info = schools.map do |school| name = school.name - course_count = school.where(courses: {id: course_ids}).count - student_count = school.where(course_members: {role: 4}).select("course_members.user_id").distinct.size - homework_commons = school.where(homework_commons: {id: homework_common_ids}) - .select("homework_commons.id") - choice_shixun_num = homework_commons.distinct.size + course_count = school.course_count + student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids}) + homework_commons = school.courses.joins(:homework_commons).where(homework_commons: {id: homework_common_ids}) + .pluck("homework_commons.id") + choice_shixun_num = homework_commons.uniq.size choice_shixun_frequency = homework_commons.size {name: name, course_count: course_count, student_count: student_count, choice_shixun_num: choice_shixun_num, choice_shixun_frequency: choice_shixun_frequency} diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb index 9dc2db09a..25a83aa26 100644 --- a/app/services/subjects/data_statistic_service.rb +++ b/app/services/subjects/data_statistic_service.rb @@ -10,7 +10,7 @@ class Subjects::DataStatisticService < ApplicationService # 文案解释:学习该课程的全部人数(学习总人数=课堂学习人数+自主学习人数) # 开发备注:只要点击该课程的任何一个实训(生成了tpi),都算一个学习人数;(去重,一个人数计算1次) def study_count - @shixuns.joins(:myshixuns).select("myshixuns.user_id").distinct.size + @shixuns.joins(:myshixuns).pluck("myshixuns.user_id").uniq.size end # 课堂学习人数: @@ -18,7 +18,7 @@ class Subjects::DataStatisticService < ApplicationService # 开发备注:只要通过课堂进入,并点击了实训(生成了tpi),则算一个可以学习人数;(去重,一个人数计算1次) def course_study_count # 实训作业 - sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixuns) + sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixun) .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id") # 试卷的实训题 esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun) @@ -37,7 +37,7 @@ class Subjects::DataStatisticService < ApplicationService # 文案解释: # 通关该课程所有实训的人数(去重。一个人数计算1次) def passed_count - @shixuns.includes(:myshixuns).where(myshixuns: {status: 1}).select("myshixuns.user_id").distinct.size + @shixuns.includes(:myshixuns).where(myshixuns: {status: 1}).pluck("myshixuns.user_id").uniq.size end # 使用课堂数: @@ -65,7 +65,7 @@ class Subjects::DataStatisticService < ApplicationService private def school_ids - @shixuns.joins(myshixuns: :user_extension).select("user_extensions.school_id").distinct + @shixuns.joins(myshixuns: :user_extension).pluck("user_extensions.school_id").uniq end diff --git a/app/services/subjects/shixun_used_info_service.rb b/app/services/subjects/shixun_used_info_service.rb index 1dda483d4..f1c4a373d 100644 --- a/app/services/subjects/shixun_used_info_service.rb +++ b/app/services/subjects/shixun_used_info_service.rb @@ -17,15 +17,22 @@ class Subjects::ShixunUsedInfoService < ApplicationService school_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course.school_id}.uniq.size used_count = shixun.myshixuns_count passed_count = shixun.myshixuns.select{|m| m.status == 1}.size - evaluate_count = shixun.myshixuns.map{|m| m.games.sum(:evaluate_count).to_i}.sum - passed_ave_time = (passed_count > 0) ? - (shixun.myshixuns.map{|m| m.status == 1 && m.games.sum(:cost_time).to_i}.sum / passed_count) : 0 + evaluate_count = shixun.myshixuns.map{|m| m.output_times }.sum + passed_ave_time = passed_count > 0 ? shixun.myshixuns.map{|m| m.total_cost_time}.sum : 0 + #evaluate_count = shixun.myshixuns.joins(:games).select("SUM(games.evaluate_count) evaluate_count").first.evaluate_count + # passed_ave_time = (passed_count > 0) ? + # (shixun.myshixuns.joins(:games) + # .where(myshixuns: {status: 1}) + # .select("SUM(games.cost_time) cost_time").first.cost_time / passed_count) : 0 + shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, school_count: school_count, used_count: used_count, passed_count: passed_count, evaluate_count: evaluate_count, passed_ave_time: passed_ave_time} end shixun_infos end + + end end diff --git a/app/services/subjects/user_used_info_service.rb b/app/services/subjects/user_used_info_service.rb index 4d5f54f9e..6e3738f42 100644 --- a/app/services/subjects/user_used_info_service.rb +++ b/app/services/subjects/user_used_info_service.rb @@ -1,4 +1,4 @@ -class Subject::UserUsedInfoService < ApplicationService +class Subjects::UserUsedInfoService < ApplicationService attr_reader :subject, :shixun_ids def initialize(subject) @@ -8,21 +8,19 @@ class Subject::UserUsedInfoService < ApplicationService end def call - users = User.joins(:myshixuns).where(myshixuns: {shixun_id: shixun_ids}).group(:user_id) - users_info = [] - users.includes(:myshixuns, :games).each do |user| - games = user.games - name = "#{user.lastname}#{user.firstname}" - passed_myshixun_count = user.myshixuns.select{|m| m.status == 1}.size - passed_games_count = games.select{|g| g.status == 2}.size + users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2}) + users.each do |user| + myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)} + name = "#{user.lastname}#{user.firstname}" + passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size + passed_games_count = myshixuns.map{|m| m.games.select{|g| g.status == 2}.size }.size code_line_count = "未完成" - evaluate_count = games.sum(evaluate_count) - cost_time = games.sum(:cost_time) - user_login = user.login - users_info << {login: user_login, name: name, passed_myshixun_count: passed_myshixun_count, + evaluate_count = myshixuns.map{|m| m.output_times }.sum + cost_time = myshixuns.map{|m|m.total_cost_time }.sum + users_info << {login: user.login, name: name, passed_myshixun_count: passed_myshixun_count, passed_games_count: passed_games_count, code_line_count: code_line_count, - evaluate_count: evaluate_count, cost_time: cost_time} + evaluate_count: evaluate_count, cost_time: cost_time} end users_info end diff --git a/config/routes.rb b/config/routes.rb index a65a7f4c1..39e9aca18 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -394,6 +394,7 @@ Rails.application.routes.draw do get 'cancel_publish' get 'cancel_has_publish' get 'statistics' + get 'statistics_new' get 'shixun_report' get 'school_report' post 'update_attr' From bbf6c47ccf73c33520b64fd8f2a671b28aa7476e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 9 Jan 2020 18:38:50 +0800 Subject: [PATCH 09/11] 1 --- app/models/subject.rb | 5 + app/models/subject_course_record.rb | 3 + app/models/subject_record.rb | 3 + app/models/subject_shixun_info.rb | 3 + app/models/subject_user_info.rb | 3 + .../subjects/course_used_info_service.rb | 4 +- .../subjects/shixun_used_info_service.rb | 2 +- .../subjects/user_used_info_service.rb | 4 +- .../20200109062658_create_subject_records.rb | 14 +++ ...109070211_create_subject_course_records.rb | 16 +++ ...00109084427_create_subject_shixun_infos.rb | 21 ++++ ...0200109091016_create_subject_user_infos.rb | 18 +++ lib/tasks/statistic_subject_info.rake | 103 ++++++++++++++++++ spec/models/subject_course_record_spec.rb | 5 + spec/models/subject_record_spec.rb | 5 + spec/models/subject_shixun_info_spec.rb | 5 + spec/models/subject_user_info_spec.rb | 5 + 17 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 app/models/subject_course_record.rb create mode 100644 app/models/subject_record.rb create mode 100644 app/models/subject_shixun_info.rb create mode 100644 app/models/subject_user_info.rb create mode 100644 db/migrate/20200109062658_create_subject_records.rb create mode 100644 db/migrate/20200109070211_create_subject_course_records.rb create mode 100644 db/migrate/20200109084427_create_subject_shixun_infos.rb create mode 100644 db/migrate/20200109091016_create_subject_user_infos.rb create mode 100644 lib/tasks/statistic_subject_info.rake create mode 100644 spec/models/subject_course_record_spec.rb create mode 100644 spec/models/subject_record_spec.rb create mode 100644 spec/models/subject_shixun_info_spec.rb create mode 100644 spec/models/subject_user_info_spec.rb diff --git a/app/models/subject.rb b/app/models/subject.rb index 28c45e4ba..df9271e5f 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -25,6 +25,11 @@ class Subject < ApplicationRecord has_many :courses, -> { where("is_delete = 0").order("courses.created_at ASC") } has_many :laboratory_subjects, dependent: :destroy + # 学习统计 + has_one :subject_record, dependent: :destroy + has_many :subject_course_records, dependent: :destroy + has_many :subject_shixun_infos, dependent: :destroy + has_many :subject_user_infos, dependent: :destroy validates :name, length: { maximum: 60 } validates :description, length: { maximum: 8000 } diff --git a/app/models/subject_course_record.rb b/app/models/subject_course_record.rb new file mode 100644 index 000000000..2240c0eb3 --- /dev/null +++ b/app/models/subject_course_record.rb @@ -0,0 +1,3 @@ +class SubjectCourseRecord < ApplicationRecord + belongs_to :subject +end diff --git a/app/models/subject_record.rb b/app/models/subject_record.rb new file mode 100644 index 000000000..cdd5b15e4 --- /dev/null +++ b/app/models/subject_record.rb @@ -0,0 +1,3 @@ +class SubjectRecord < ApplicationRecord + belongs_to :subject +end diff --git a/app/models/subject_shixun_info.rb b/app/models/subject_shixun_info.rb new file mode 100644 index 000000000..6ce4ccb50 --- /dev/null +++ b/app/models/subject_shixun_info.rb @@ -0,0 +1,3 @@ +class SubjectShixunInfo < ApplicationRecord + belongs_to :subject +end diff --git a/app/models/subject_user_info.rb b/app/models/subject_user_info.rb new file mode 100644 index 000000000..4435a1aea --- /dev/null +++ b/app/models/subject_user_info.rb @@ -0,0 +1,3 @@ +class SubjectUserInfo < ApplicationRecord + belongs_to :subject +end diff --git a/app/services/subjects/course_used_info_service.rb b/app/services/subjects/course_used_info_service.rb index 5553c7222..01e0723eb 100644 --- a/app/services/subjects/course_used_info_service.rb +++ b/app/services/subjects/course_used_info_service.rb @@ -29,8 +29,8 @@ class Subjects::CourseUsedInfoService < ApplicationService .pluck("homework_commons.id") choice_shixun_num = homework_commons.uniq.size choice_shixun_frequency = homework_commons.size - {name: name, course_count: course_count, student_count: student_count, choice_shixun_num: choice_shixun_num, - choice_shixun_frequency: choice_shixun_frequency} + {school_id: school.id, school_name: name, course_count: course_count, student_count: student_count, + choice_shixun_num: choice_shixun_num, choice_shixun_frequency: choice_shixun_frequency} end # 默认按照选用实训的次数作为排序 course_info.sort{|x,y| y['choice_shixun_frequency'] <=> x['choice_shixun_frequency']} diff --git a/app/services/subjects/shixun_used_info_service.rb b/app/services/subjects/shixun_used_info_service.rb index f1c4a373d..62548b4ef 100644 --- a/app/services/subjects/shixun_used_info_service.rb +++ b/app/services/subjects/shixun_used_info_service.rb @@ -27,7 +27,7 @@ class Subjects::ShixunUsedInfoService < ApplicationService shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, school_count: school_count, used_count: used_count, passed_count: passed_count, - evaluate_count: evaluate_count, passed_ave_time: passed_ave_time} + evaluate_count: evaluate_count, passed_ave_time: passed_ave_time, shixun_id: shixun.id} end shixun_infos end diff --git a/app/services/subjects/user_used_info_service.rb b/app/services/subjects/user_used_info_service.rb index 6e3738f42..3b1b969f0 100644 --- a/app/services/subjects/user_used_info_service.rb +++ b/app/services/subjects/user_used_info_service.rb @@ -15,10 +15,10 @@ class Subjects::UserUsedInfoService < ApplicationService name = "#{user.lastname}#{user.firstname}" passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size passed_games_count = myshixuns.map{|m| m.games.select{|g| g.status == 2}.size }.size - code_line_count = "未完成" + code_line_count = 0 evaluate_count = myshixuns.map{|m| m.output_times }.sum cost_time = myshixuns.map{|m|m.total_cost_time }.sum - users_info << {login: user.login, name: name, passed_myshixun_count: passed_myshixun_count, + users_info << {user_id: user.id, name: name, passed_myshixun_count: passed_myshixun_count, passed_games_count: passed_games_count, code_line_count: code_line_count, evaluate_count: evaluate_count, cost_time: cost_time} end diff --git a/db/migrate/20200109062658_create_subject_records.rb b/db/migrate/20200109062658_create_subject_records.rb new file mode 100644 index 000000000..97741fd8c --- /dev/null +++ b/db/migrate/20200109062658_create_subject_records.rb @@ -0,0 +1,14 @@ +class CreateSubjectRecords < ActiveRecord::Migration[5.2] + def change + create_table :subject_records do |t| + t.references :subject, unique: true + t.integer :study_count, default: 0 + t.integer :course_study_count, default: 0 + t.integer :initiative_study, default: 0 + t.integer :passed_count, default: 0 + t.integer :course_used_count, default: 0 + t.integer :school_used_count, default: 0 + t.timestamps + end + end +end diff --git a/db/migrate/20200109070211_create_subject_course_records.rb b/db/migrate/20200109070211_create_subject_course_records.rb new file mode 100644 index 000000000..cd88e7e40 --- /dev/null +++ b/db/migrate/20200109070211_create_subject_course_records.rb @@ -0,0 +1,16 @@ +class CreateSubjectCourseRecords < ActiveRecord::Migration[5.2] + def change + create_table :subject_course_records do |t| + t.references :subject + t.references :school + t.string :school_name + t.integer :course_count, default: 0 + t.integer :student_count, default: 0 + t.integer :choice_shixun_num, default: 0 + t.integer :choice_shixun_frequency, default: 0 + t.timestamps + end + + add_index :subject_course_records, [:school_id, :subject_id], unique: true, name: "couse_and_school_index" + end +end diff --git a/db/migrate/20200109084427_create_subject_shixun_infos.rb b/db/migrate/20200109084427_create_subject_shixun_infos.rb new file mode 100644 index 000000000..8916b2129 --- /dev/null +++ b/db/migrate/20200109084427_create_subject_shixun_infos.rb @@ -0,0 +1,21 @@ +class CreateSubjectShixunInfos < ActiveRecord::Migration[5.2] + def change + create_table :subject_shixun_infos do |t| + t.references :subject + t.references :shixun + t.string :stage + t.string :shixun_name + t.integer :challenge_count, default: 0 + t.integer :course_count, default: 0 + t.integer :school_count, default: 0 + t.integer :used_count, default: 0 + t.integer :passed_count, default: 0 + t.integer :evaluate_count, default: 0 + t.integer :passed_ave_time, default: 0 + + t.timestamps + end + + add_index :subject_shixun_infos, [:shixun_id, :subject_id], unique: true + end +end diff --git a/db/migrate/20200109091016_create_subject_user_infos.rb b/db/migrate/20200109091016_create_subject_user_infos.rb new file mode 100644 index 000000000..7f2671a71 --- /dev/null +++ b/db/migrate/20200109091016_create_subject_user_infos.rb @@ -0,0 +1,18 @@ +class CreateSubjectUserInfos < ActiveRecord::Migration[5.2] + def change + create_table :subject_user_infos do |t| + t.references :user + t.references :subject + t.string :username + t.integer :passed_myshixun_count, default: 0 + t.integer :passed_games_count, default: 0 + t.integer :code_line_count, default: 0 + t.integer :evaluate_count, default: 0 + t.integer :cost_time, default: 0 + t.timestamps + end + + add_index :subject_user_infos, [:user_id, :subject_id], unique: true + + end +end diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake new file mode 100644 index 000000000..dbce739f2 --- /dev/null +++ b/lib/tasks/statistic_subject_info.rake @@ -0,0 +1,103 @@ +desc "统计实践课程的学习统计数据" + +namespace :subjects do + task data_statistic: :environment do + puts("---------------------data_statistic_begin") + Rails.logger.info("---------------------data_statistic_begin") + subjects = Subject.where(status: 2) + subjects.find_each do |subject| + puts("---------------------data_statistic: #{subject.id}") + Rails.logger.info("---------------------data_statistic: #{subject.id}") + sr = SubjectRecord.find_or_create_by!(subject_id: subject.id) + data = Subjects::DataStatisticService.new(subject) + update_params = { + study_count: data.study_count, + course_study_count: data.course_study_count, + initiative_study: data.initiative_study, + passed_count: data.passed_count, + course_used_count: data.course_used_count, + school_used_count: data.school_used_count + } + sr.update_attributes!(update_params) + end + puts("---------------------data_statistic_end") + Rails.logger.info("---------------------data_statistic_end") + end + + task course_info_statistic: :environment do + puts("---------------------course_info_statistic_begin") + Rails.logger.info("---------------------course_info_statistic_begin") + subjects = Subject.where(status: 2) + subjects.find_each do |subject| + puts("---------------------course_info_statistic: #{subject.id}") + Rails.logger.info("---------------------course_info_statistic: #{subject.id}") + data = Subjects::DataStatisticService.call(subject) + data.each do |key| + scr = SubjectCourseRecord.find_or_create_by!(school_id: key[:school_id], subject_id: subject.id) + update_params = { + school_name: key[:school_name], + course_count: key[:course_count], + student_count: key[:student_count], + choice_shixun_num: key[:choice_shixun_num], + choice_shixun_frequency: key[:choice_shixun_frequency] + } + scr.update_attributes(update_params) + end + end + puts("---------------------course_info_statistic_end") + Rails.logger.info("---------------------course_info_statistic_end") + end + + task shixun_info_statistic: :environment do + puts("---------------------shixun_info_statistic_begin") + Rails.logger.info("---------------------shixun_info_statistic_begin") + subjects = Subject.where(status: 2) + subjects.find_each(batch_size: 100) do |subject| + data = Subjects::ShixunUsedInfoService.call(subject) + data.each do |key| + ssi = SubjectShixunInfo.find_or_create_by!(shixun_id: key[:shixun_id], subject_id: subject.id) + update_params = { + stage: key[:stage], + shixun_name: key[:name], + challenge_count: key[:challenge_count], + course_count: key[:course_count], + school_count: key[:school_count], + used_count: key[:used_count], + passed_count: key[:passed_count], + evaluate_count: key[:evaluate_count], + passed_ave_time: key[:passed_ave_time] + } + ssi.update_attributes(update_params) + end + end + puts("---------------------shixun_info_statistic_end") + Rails.logger.info("---------------------shixun_info_statistic_end") + end + + task user_info_statistic: :environment do + puts("---------------------user_info_statistic_begin") + Rails.logger.info("---------------------user_info_statistic_begin") + subjects = Subject.where(status: 2) + subjects.find_each(batch_size: 100) do |subject| + puts("---------------------user_info_statistic: #{subject.id}") + data = Subjects::UserUsedInfoService.call(subject) + data.each do |key| + sui = SubjectUserInfo.find_or_create_by!(user_id: key[:user_id], subject_id: subject.id) + update_params = { + username: key[:name], + passed_myshixun_count: key[:passed_myshixun_count], + passed_games_count: key[:passed_games_count], + code_line_count: key[:code_line_count], + evaluate_count: key[:evaluate_count], + cost_time: key[:cost_time] + } + sui.update_attributes(update_params) + end + end + puts("---------------------user_info_statistic_end") + Rails.logger.info("---------------------user_info_statistic_end") + end + + + + end diff --git a/spec/models/subject_course_record_spec.rb b/spec/models/subject_course_record_spec.rb new file mode 100644 index 000000000..bf2daffc8 --- /dev/null +++ b/spec/models/subject_course_record_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SubjectCourseRecord, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/subject_record_spec.rb b/spec/models/subject_record_spec.rb new file mode 100644 index 000000000..6dd9f7b4d --- /dev/null +++ b/spec/models/subject_record_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SubjectRecord, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/subject_shixun_info_spec.rb b/spec/models/subject_shixun_info_spec.rb new file mode 100644 index 000000000..83d4b4bf9 --- /dev/null +++ b/spec/models/subject_shixun_info_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SubjectShixunInfo, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/subject_user_info_spec.rb b/spec/models/subject_user_info_spec.rb new file mode 100644 index 000000000..60c8a76e6 --- /dev/null +++ b/spec/models/subject_user_info_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SubjectUserInfo, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 9ad2a0ffe60080fd8f9b94939967d8ce91e6ea08 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 9 Jan 2020 20:53:34 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/shixun.rb | 2 ++ .../subjects/course_used_info_service.rb | 30 +++++++++---------- .../subjects/data_statistic_service.rb | 2 +- .../subjects/shixun_used_info_service.rb | 14 ++------- ...24_modify_myshixun_id_for_student_works.rb | 5 ++++ lib/tasks/statistic_subject_info.rake | 22 +++++++++----- 6 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20200109105024_modify_myshixun_id_for_student_works.rb diff --git a/app/models/shixun.rb b/app/models/shixun.rb index b77038a78..c16c4df4e 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -30,6 +30,8 @@ class Shixun < ApplicationRecord has_one :first_tag_repertoire, through: :first_shixun_tag_repertoire, source: :tag_repertoire has_many :homework_commons_shixuns, class_name: 'HomeworkCommonsShixun' + has_many :homework_commons, through: :homework_commons_shixuns + has_many :fork_shixuns, foreign_key: "fork_from", class_name: 'Shixun' #实训的关卡 diff --git a/app/services/subjects/course_used_info_service.rb b/app/services/subjects/course_used_info_service.rb index 01e0723eb..2561f3aa4 100644 --- a/app/services/subjects/course_used_info_service.rb +++ b/app/services/subjects/course_used_info_service.rb @@ -13,27 +13,27 @@ class Subjects::CourseUsedInfoService < ApplicationService .where(homework_commons_shixuns: {shixun_id: @shixun_ids}) course_ids = homework_commons.pluck(:course_id) homework_common_ids = homework_commons.pluck("homework_commons.id") - schools = School.joins(:courses).where(courses: {id: course_ids}).select("schools.*, count(courses.id) course_count") + schools = School.joins(:courses).where(courses: {id: course_ids}).group("schools.id").select("schools.*, count(courses.id) course_count") # name:将该课程使用到课堂的单位 # course_count: 将该课程使用到课堂的数量 # student_count: 课堂的学生总数(去掉重复) # choice_shixun_num: 选用该课程实训的个数(去重) # choice_shixun_frequency: 选用该课程实训的次数 - course_info = - schools.map do |school| - name = school.name - course_count = school.course_count - student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids}) - homework_commons = school.courses.joins(:homework_commons).where(homework_commons: {id: homework_common_ids}) - .pluck("homework_commons.id") - choice_shixun_num = homework_commons.uniq.size - choice_shixun_frequency = homework_commons.size - {school_id: school.id, school_name: name, course_count: course_count, student_count: student_count, - choice_shixun_num: choice_shixun_num, choice_shixun_frequency: choice_shixun_frequency} - end - # 默认按照选用实训的次数作为排序 - course_info.sort{|x,y| y['choice_shixun_frequency'] <=> x['choice_shixun_frequency']} + course_info = [] + schools.map do |school| + name = school.name + course_count = school.course_count + student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids}).size + shixun_ids = school.courses.joins(homework_commons: :homework_commons_shixun) + .where(homework_commons: {id: homework_common_ids}) + .pluck("homework_commons_shixuns.shixun_id") + choice_shixun_frequency = shixun_ids.size + choice_shixun_num = shixun_ids.uniq.size + course_info << {school_id: school.id, school_name: name, course_count: course_count, student_count: student_count, + choice_shixun_num: choice_shixun_num, choice_shixun_frequency: choice_shixun_frequency} + end + course_info end end diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb index 25a83aa26..32b636400 100644 --- a/app/services/subjects/data_statistic_service.rb +++ b/app/services/subjects/data_statistic_service.rb @@ -18,7 +18,7 @@ class Subjects::DataStatisticService < ApplicationService # 开发备注:只要通过课堂进入,并点击了实训(生成了tpi),则算一个可以学习人数;(去重,一个人数计算1次) def course_study_count # 实训作业 - sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixun) + sw_user_ids = StudentWork.where.not(myshixun_id: 0).joins(homework_common: :homework_commons_shixun) .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id") # 试卷的实训题 esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun) diff --git a/app/services/subjects/shixun_used_info_service.rb b/app/services/subjects/shixun_used_info_service.rb index 62548b4ef..32309fd59 100644 --- a/app/services/subjects/shixun_used_info_service.rb +++ b/app/services/subjects/shixun_used_info_service.rb @@ -13,26 +13,18 @@ class Subjects::ShixunUsedInfoService < ApplicationService stage = "#{position}-#{index+1}" name = shixun.name challenge_count = shixun.challenges_count - course_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course_id}.uniq.size - school_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course.school_id}.uniq.size + course_count = shixun.homework_commons.map{|hc| hc.course_id}.uniq.size + school_count = shixun.homework_commons.map{|hc| hc.course&.school_id}.uniq.size used_count = shixun.myshixuns_count passed_count = shixun.myshixuns.select{|m| m.status == 1}.size evaluate_count = shixun.myshixuns.map{|m| m.output_times }.sum passed_ave_time = passed_count > 0 ? shixun.myshixuns.map{|m| m.total_cost_time}.sum : 0 - #evaluate_count = shixun.myshixuns.joins(:games).select("SUM(games.evaluate_count) evaluate_count").first.evaluate_count - # passed_ave_time = (passed_count > 0) ? - # (shixun.myshixuns.joins(:games) - # .where(myshixuns: {status: 1}) - # .select("SUM(games.cost_time) cost_time").first.cost_time / passed_count) : 0 - shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, school_count: school_count, used_count: used_count, passed_count: passed_count, evaluate_count: evaluate_count, passed_ave_time: passed_ave_time, shixun_id: shixun.id} end - shixun_infos end - - + shixun_infos end end diff --git a/db/migrate/20200109105024_modify_myshixun_id_for_student_works.rb b/db/migrate/20200109105024_modify_myshixun_id_for_student_works.rb new file mode 100644 index 000000000..afecb4df5 --- /dev/null +++ b/db/migrate/20200109105024_modify_myshixun_id_for_student_works.rb @@ -0,0 +1,5 @@ +class ModifyMyshixunIdForStudentWorks < ActiveRecord::Migration[5.2] + def change + StudentWork.where(myshixun_id: nil).update_all(myshixun_id: 0) + end +end diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake index dbce739f2..6373d7170 100644 --- a/lib/tasks/statistic_subject_info.rake +++ b/lib/tasks/statistic_subject_info.rake @@ -10,13 +10,19 @@ namespace :subjects do Rails.logger.info("---------------------data_statistic: #{subject.id}") sr = SubjectRecord.find_or_create_by!(subject_id: subject.id) data = Subjects::DataStatisticService.new(subject) + study_count = data.study_count + # 总人数没有变化的话,不同课堂之类的变化了 + course_study_count = (study_count == sr.study_count ? sr.course_study_count : data.course_study_count) + passed_count = (study_count == sr.study_count ? sr.passed_count : data.passed_count) + course_used_count = (study_count == sr.study_count ? sr.course_used_count : data.course_used_count) + school_used_count = (study_count == sr.study_count ? sr.school_used_count : data.school_used_count) update_params = { - study_count: data.study_count, - course_study_count: data.course_study_count, - initiative_study: data.initiative_study, - passed_count: data.passed_count, - course_used_count: data.course_used_count, - school_used_count: data.school_used_count + study_count: study_count, + course_study_count: course_study_count, + initiative_study: (study_count - course_study_count), + passed_count: passed_count, + course_used_count: course_used_count, + school_used_count: school_used_count } sr.update_attributes!(update_params) end @@ -31,7 +37,7 @@ namespace :subjects do subjects.find_each do |subject| puts("---------------------course_info_statistic: #{subject.id}") Rails.logger.info("---------------------course_info_statistic: #{subject.id}") - data = Subjects::DataStatisticService.call(subject) + data = Subjects::CourseUsedInfoService.call(subject) data.each do |key| scr = SubjectCourseRecord.find_or_create_by!(school_id: key[:school_id], subject_id: subject.id) update_params = { @@ -53,6 +59,8 @@ namespace :subjects do Rails.logger.info("---------------------shixun_info_statistic_begin") subjects = Subject.where(status: 2) subjects.find_each(batch_size: 100) do |subject| + puts("---------------------shixun_info_statistic: #{subject.id}") + Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}") data = Subjects::ShixunUsedInfoService.call(subject) data.each do |key| ssi = SubjectShixunInfo.find_or_create_by!(shixun_id: key[:shixun_id], subject_id: subject.id) From faf6aedc975164187543f84480ba6d4a6abe4298 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 10 Jan 2020 10:10:20 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/decorators/tiding_decorator.rb | 2 +- app/models/memo.rb | 5 +++++ app/models/message.rb | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb index 58345b601..c56fa596e 100644 --- a/app/decorators/tiding_decorator.rb +++ b/app/decorators/tiding_decorator.rb @@ -206,7 +206,7 @@ module TidingDecorator format_str % [parent_container.shixun.name, parent_container.position] end when 'Memo', 'Message' then - message = parent_container.parent_id.present? ? message_content_helper(parent_container.content) : parent_container.subject + message = parent_container.main_subject I18n.t(locale_format(parent_container_type, parent_container.parent_id.present?)) % message when 'HomeworkCommon' then I18n.t(locale_format(parent_container_type)) % parent_container.name diff --git a/app/models/memo.rb b/app/models/memo.rb index d79081350..da768e535 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -39,6 +39,11 @@ class Memo < ApplicationRecord Memo.where(parent_id: id).includes(:author).reorder("created_at asc") end + # 主贴的名称 + def main_subject + parent.present? ? parent.subject : subject + end + private def send_tiding diff --git a/app/models/message.rb b/app/models/message.rb index 7588ddc2a..1fb0c2b85 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -39,6 +39,11 @@ class Message < ApplicationRecord message_detail.update_attributes(content: content) end + # 主贴的名称 + def main_subject + parent.present? ? parent.subject : subject + end + def copy_attachments_to_new_message(new_message, user) attachments.each do |attach| new_message.attachments << Attachment.new(attach.attributes.except("id").merge(