teaching.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. var tmpl = window.template;
  2. tmpl.config({ sTag: "<#", eTag: "#>", compress: true });
  3. var $bodyMain = $("#body-main");
  4. var echartList = [];
  5. build();
  6. publishReady();
  7. function build() {
  8. if (dataStatic.code && dataStatic.code === "500") {
  9. var hTmpl = $("#page-error").html();
  10. var $dom = tmpl(hTmpl, {
  11. message: dataStatic.message
  12. });
  13. $bodyMain.append(createNewBox($dom));
  14. return;
  15. }
  16. var datas = dataParse(dataStatic);
  17. createCover(datas.cover);
  18. // 客观题成绩分析
  19. createTableList(
  20. datas.basic_question_objective,
  21. 32,
  22. "客观题成绩分析",
  23. "question-table"
  24. );
  25. createBarPointChart(
  26. datas.basic_question_objective,
  27. 26,
  28. "客观题成绩分析",
  29. "barPointTopic"
  30. );
  31. // 主观题成绩分析
  32. createTableList(
  33. datas.basic_question_subjective,
  34. 32,
  35. "主观题成绩分析",
  36. "question-table"
  37. );
  38. createBarPointChart(
  39. datas.basic_question_subjective,
  40. 26,
  41. "主观题成绩分析",
  42. "barPointTopic"
  43. );
  44. // 班级成绩分析
  45. createTableList(datas.basic_class, 32, "班级成绩分析", "classes-table");
  46. createBarPointChart(datas.basic_class, 22, "班级成绩分析", "barPointGrade");
  47. // 任课老师成绩分析
  48. createTeacherScore(datas.basic_teacher);
  49. createTeacherGrade(datas.basic_teacher);
  50. // 学院成绩分析;
  51. createTableList(datas.basic_college, 32, "学院成绩分析", "college-table");
  52. createBarPointChart(datas.basic_college, 22, "学院成绩分析", "barPointGrade");
  53. // 大题难度分析
  54. createLineChart(datas.basic_main_question);
  55. // 小题难度分析
  56. createTableList(
  57. datas.basic_question,
  58. 32,
  59. "小题难度分析",
  60. "question-difficulty-table"
  61. );
  62. createLineReverseChart(datas.basic_question); // basic_sub_question
  63. // 区分度分析
  64. createDiscriminationDifficultyLevel(
  65. datas.discrimination_level,
  66. "discrimination"
  67. );
  68. // 大题难度等级构成分析
  69. createDiscriminationDifficultyLevel(datas.difficulty_level, "difficulty");
  70. // 大题结构特征
  71. createBasicMainQuestion(datas.basic_main_question);
  72. // 题目统计特征
  73. createBasicQuestion(datas.basic_question);
  74. // 选项分析
  75. createBasicQuestionOption(datas.basic_question_option);
  76. // 考生分段比例;
  77. createRangeLevel(datas.range_level);
  78. // 频率分布分析
  79. createRange10TotalScore(datas.range_10_totalScore);
  80. // 一分一段分析
  81. createRangeTotalScore(datas.range_1_totalScore);
  82. // 六段频率
  83. createRangeSegment(datas.range_segment_6);
  84. createEchart();
  85. fillCatalogNum();
  86. }
  87. function publishReady() {
  88. var eventEmitInterval = setInterval(function() {
  89. document.body.dispatchEvent(new Event("view-ready"));
  90. }, 25);
  91. document.body.addEventListener("view-ready-acknowledged", function() {
  92. clearInterval(eventEmitInterval);
  93. });
  94. }
  95. function createCover(cover) {
  96. var hTmpl = $("#cover").html();
  97. var $dom = $(tmpl(hTmpl, cover));
  98. $bodyMain.append($dom);
  99. }
  100. // 题型成绩分析,班级成绩分析,学院成绩分析, 题目难度
  101. function createTableList(dataList, splitRange, title, tableType) {
  102. var hTmpl = $("#" + tableType).html();
  103. sectionArr(dataList, splitRange).forEach(function(item) {
  104. var $dom = tmpl(hTmpl, {
  105. title: title,
  106. pageTableClass: tableType + " level-table",
  107. dataList: item
  108. });
  109. $bodyMain.append(createNewBox($dom));
  110. });
  111. }
  112. // 题型成绩分析,班级成绩分析,学院成绩分析
  113. function createBarPointChart(dataList, splitRange, title, chartType) {
  114. var hTmpl = $("#page-chart").html();
  115. var labelHeight = Math.round(1170 / splitRange);
  116. sectionArr(dataList, splitRange).forEach(function(item) {
  117. var chartId = getEchartId();
  118. var $dom = tmpl(hTmpl, {
  119. title: title,
  120. chartId: chartId,
  121. height: 220 + labelHeight * item.length + "px"
  122. });
  123. $bodyMain.append(createNewBox($dom));
  124. addEchart({
  125. chartId: chartId,
  126. chartType: chartType,
  127. datas: item
  128. });
  129. });
  130. }
  131. // 任课老师成绩分析
  132. function createTeacherScore(dataList) {
  133. var hTmpl = $("#teacher-score").html();
  134. var splitList = sectionArr(dataList, 6);
  135. splitList.forEach(function(item) {
  136. var chartId = getEchartId();
  137. var $dom = tmpl(hTmpl, {
  138. chartId: chartId,
  139. dataList: item,
  140. teacherScoreTableTpl: tmpl($("#teacher-score-table").html())
  141. });
  142. $bodyMain.append(createNewBox($dom));
  143. addEchart({
  144. chartId: chartId,
  145. chartType: "barTeachers",
  146. datas: item
  147. });
  148. });
  149. // 总明细表
  150. if (splitList.length > 1) {
  151. var hTmpl2 = $("#teacher-score-table").html();
  152. sectionArr(dataList, 26).forEach(function(item) {
  153. var $dom = tmpl(hTmpl2, {
  154. dataList: item,
  155. pageTableClass: "teacher-table"
  156. });
  157. $bodyMain.append(createNewBox($dom));
  158. });
  159. }
  160. }
  161. // 任课老师班级成绩分析
  162. function createTeacherGrade(dataList) {
  163. var hTmpl = $("#teacher-grade").html();
  164. var sectionDataList = [];
  165. dataList.map(function(item) {
  166. if (item.classes.length <= 8) {
  167. sectionDataList.push(item);
  168. } else {
  169. sectionArr(item.classes, 7).forEach(function(elem) {
  170. sectionDataList.push({
  171. name: item.name,
  172. classes: elem
  173. });
  174. });
  175. }
  176. });
  177. // class-table
  178. var classHTmpl = $("#teacher-class-table").html();
  179. groupSectionArrDynamic(dataList, 32, "classes").forEach(function(item) {
  180. var $dom = tmpl(classHTmpl, {
  181. dataList: item,
  182. pageTableClass: "teacher-class-table level-table"
  183. });
  184. $bodyMain.append(createNewBox($dom));
  185. });
  186. // class-chart
  187. sectionArr(sectionDataList, 3).forEach(function(item) {
  188. var chartList = item.map(function(elem) {
  189. var chartId = getEchartId();
  190. addEchart({
  191. chartId: chartId,
  192. chartType: "barTeacherGrade",
  193. datas: elem
  194. });
  195. return chartId;
  196. });
  197. var $dom = tmpl(hTmpl, {
  198. chartList: chartList
  199. });
  200. $bodyMain.append(createNewBox($dom));
  201. });
  202. }
  203. // 大题难度分析
  204. function createLineChart(dataList) {
  205. if (!dataList.length) return;
  206. // table-parse
  207. createTableList(dataList, 32, "大题难度分析", "question-difficulty-table");
  208. if (dataList.length > 6) {
  209. createLineReverseChart(dataList, "大题难度分析");
  210. return;
  211. }
  212. var hTmpl = $("#page-chart").html();
  213. var chartId = getEchartId();
  214. var $dom = tmpl(hTmpl, {
  215. title: "大题难度分析",
  216. chartId: chartId,
  217. chartClassName: "chart-line"
  218. });
  219. $bodyMain.append(createNewBox($dom));
  220. addEchart({
  221. chartId: chartId,
  222. chartType: "line",
  223. datas: dataList
  224. });
  225. }
  226. // 小题难度分析
  227. function createLineReverseChart(dataList, tableName) {
  228. // table-parse
  229. var hTmpl = $("#page-chart").html();
  230. sectionArr(dataList, 46).forEach(function(item) {
  231. var chartId = getEchartId();
  232. var $dom = tmpl(hTmpl, {
  233. title: tableName || "小题难度分析",
  234. chartId: chartId,
  235. height: 200 + 26 * item.length + "px"
  236. });
  237. $bodyMain.append(createNewBox($dom));
  238. addEchart({
  239. chartId: chartId,
  240. chartType: "lineReverse",
  241. datas: item
  242. });
  243. });
  244. }
  245. // 区分度等级分布,难度等级分布
  246. function createDiscriminationDifficultyLevel(dataList, type) {
  247. var hTmpl = $("#" + type + "-level-table").html();
  248. groupSectionArrDynamic(dataList, 30, "groups").forEach(function(item) {
  249. var $dom = tmpl(hTmpl, {
  250. dataList: item
  251. });
  252. $bodyMain.append(createNewBox($dom));
  253. });
  254. }
  255. // 题目统计特征
  256. function createBasicQuestion(dataList) {
  257. var hTmpl = $("#basic-question-table").html();
  258. sectionArr(dataList, 33).forEach(function(item) {
  259. var $dom = tmpl(hTmpl, {
  260. dataList: item
  261. });
  262. $bodyMain.append(createNewBox($dom));
  263. });
  264. }
  265. // 大题结构特征
  266. function createBasicMainQuestion(dataList) {
  267. var hTmpl = $("#basic-main-question-table").html();
  268. sectionArr(dataList, 33).forEach(function(item) {
  269. var $dom = tmpl(hTmpl, {
  270. dataList: item
  271. });
  272. $bodyMain.append(createNewBox($dom));
  273. });
  274. }
  275. // 选项分析
  276. function createBasicQuestionOption(data) {
  277. if (!data.options || !data.options.length) return;
  278. var hTmpl = $("#basic-question-option-table").html();
  279. // 选项多余7个会分组
  280. var options = sectionArr(data.options, 8);
  281. sectionArr(data.questions, 32).forEach(function(item) {
  282. options.map(function(elem) {
  283. var $dom = tmpl(hTmpl, {
  284. options: elem,
  285. questions: item
  286. });
  287. $bodyMain.append(createNewBox($dom));
  288. });
  289. });
  290. }
  291. // 考生分段比例
  292. function createRangeLevel(dataList) {
  293. var hTmpl = $("#range-level-table").html();
  294. sectionArr(dataList, 31).forEach(function(item) {
  295. var $dom = tmpl(hTmpl, {
  296. dataList: item
  297. });
  298. $bodyMain.append(createNewBox($dom));
  299. });
  300. }
  301. // 总分频率分布
  302. function createRange10TotalScore(datas) {
  303. var pageList = [];
  304. if (datas.total.length) {
  305. pageList.push({
  306. title: "总分频率分布分析",
  307. dataList: datas.total
  308. });
  309. }
  310. // 班级成绩频率分布
  311. // pageList = pageList.concat(
  312. // datas.classes.map(function(item) {
  313. // return {
  314. // title: item.name + " 总分频率分布",
  315. // dataList: item.ranges
  316. // };
  317. // })
  318. // );
  319. var hTmpl = $("#range-totalScore").html();
  320. pageList.forEach(function(item, index) {
  321. var chartId = getEchartId();
  322. addEchart({
  323. chartId: chartId,
  324. chartType: "lineSmooth",
  325. datas: {
  326. index: index,
  327. dataList: item.dataList
  328. }
  329. });
  330. sectionArrFirstPage(item.dataList, 32, 22).map(function(elem, index) {
  331. var pageTableClass =
  332. elem.length > 16 ? "table-ave-5 table-range-long" : "table-ave-5";
  333. if (index > 0) pageTableClass += " page-table-pad";
  334. var $dom = tmpl(hTmpl, {
  335. title: item.title,
  336. isOneStep: false,
  337. pageTableClass: pageTableClass,
  338. dataList: elem,
  339. chartId: index === 0 ? chartId : ""
  340. });
  341. $bodyMain.append(createNewBox($dom));
  342. });
  343. });
  344. }
  345. // 总分一分一段表
  346. function createRangeTotalScore(datas) {
  347. var pageList = [];
  348. if (datas.total.length) {
  349. pageList.push({
  350. title: "总分一分一段表",
  351. dataList: datas.total
  352. });
  353. }
  354. // 班级成绩统计
  355. // pageList = pageList.concat(
  356. // datas.classes.map(function(item) {
  357. // return {
  358. // title: item.name + " 总分一分一段表",
  359. // dataList: item.ranges
  360. // };
  361. // })
  362. // );
  363. var hTmpl = $("#range-totalScore").html();
  364. pageList.forEach(function(item, index) {
  365. sectionArr(item.dataList, 32).forEach(function(elem) {
  366. var $dom = tmpl(hTmpl, {
  367. title: item.title,
  368. isOneStep: true,
  369. pageTableClass: "table-ave-5 page-table-pad",
  370. dataList: elem,
  371. chartId: ""
  372. });
  373. $bodyMain.append(createNewBox($dom));
  374. });
  375. });
  376. }
  377. // 六段频率统计
  378. function createRangeSegment(dataList) {
  379. var hTmpl = $("#range-segment-table").html();
  380. dataList.map(function(item) {
  381. sectionArrDynamic(item.groups, 30, "segments").map(function(elem) {
  382. var $dom = tmpl(hTmpl, {
  383. title: item.name + " 六段频率统计",
  384. dataList: elem
  385. });
  386. $bodyMain.append(createNewBox($dom));
  387. });
  388. });
  389. }
  390. /**
  391. * 渲染模板
  392. * @param {Object} renderItem 渲染配置
  393. */
  394. function renderTmp(renderItem) {
  395. var hTmpl = $("#" + renderItem.templateName).html();
  396. var $dom = $(tmpl(hTmpl, renderItem.datas || {}));
  397. return $dom;
  398. }
  399. /**
  400. * 创建新的box
  401. * @param {DomStr} bodyDom 页面填充内容
  402. * @param {String} boxType box类型,默认report-box
  403. */
  404. function createNewBox(bodyDom, boxType) {
  405. return renderTmp({
  406. templateName: "page-box",
  407. datas: {
  408. bodyDom: bodyDom || "",
  409. boxType: boxType || "report-box"
  410. }
  411. });
  412. }
  413. /**
  414. * 创建echart图表
  415. *
  416. */
  417. function createEchart() {
  418. echartList.forEach(function(elem) {
  419. var charts = new Charts(
  420. document.getElementById(elem.chartId),
  421. elem.datas,
  422. elem.chartType
  423. );
  424. charts.renderChart();
  425. });
  426. }
  427. /**
  428. * 渲染页码
  429. */
  430. function fillCatalogNum() {
  431. var hTmpl = $("#page-foot").html();
  432. $(".report-box").each(function(index) {
  433. var page = index + 1;
  434. var dom = tmpl(hTmpl, {
  435. name: cover.name,
  436. time: cover.time,
  437. pageNum: page < 10 ? "0" + page : page
  438. });
  439. $(this)
  440. .attr("id", "page-" + page)
  441. .append($(dom));
  442. });
  443. }
  444. /**
  445. *
  446. * @param {Array} arrayList 要分段的数组
  447. * @param {Number} sectionLength 每段的长度
  448. */
  449. function sectionArr(arrayList, sectionLength) {
  450. var splitArr = [];
  451. for (var i = 0, len = arrayList.length; i < len; i += sectionLength) {
  452. splitArr.push(arrayList.slice(i, i + sectionLength));
  453. }
  454. return splitArr;
  455. }
  456. /**
  457. *
  458. * @param {Array} arrayList 要分段的数组
  459. * @param {Number} sectionLength 每段的长度
  460. * @param {Number} firstPageNum 第一段的长度
  461. */
  462. function sectionArrFirstPage(arrayList, sectionLength, firstPageNum) {
  463. var splitArr = [];
  464. var currentSectionLength = 0;
  465. for (var i = 0, len = arrayList.length; i < len; i += currentSectionLength) {
  466. if (i === 0) {
  467. currentSectionLength = firstPageNum;
  468. } else {
  469. currentSectionLength = sectionLength;
  470. }
  471. splitArr.push(arrayList.slice(i, i + currentSectionLength));
  472. }
  473. return splitArr;
  474. }
  475. /**
  476. * 组元素个数少于10个时,此法更方便
  477. * @param {Array} arrayList 要分段的数组
  478. * @param {Number} sectionMaxItemLength 最大分段元素个数
  479. */
  480. function sectionArrDynamic(arrayList, sectionMaxItemLength, childrenName) {
  481. var splitArr = [];
  482. var splitSectionItemLen = 0;
  483. var splitSectionArr = [];
  484. for (var i = 0, len = arrayList.length; i < len; i++) {
  485. if (
  486. splitSectionItemLen + arrayList[i][childrenName].length >
  487. sectionMaxItemLength
  488. ) {
  489. splitArr.push(splitSectionArr);
  490. splitSectionItemLen = 0;
  491. splitSectionArr = [];
  492. }
  493. splitSectionItemLen += arrayList[i][childrenName].length;
  494. splitSectionArr.push(arrayList[i]);
  495. }
  496. splitArr.push(splitSectionArr);
  497. return splitArr;
  498. }
  499. /**
  500. * 组元素过多,且无规律时,使用此方法更合理
  501. * @param {*} arrayList
  502. * @param {*} sectionMaxItemLength
  503. * @param {*} childrenName
  504. */
  505. function groupSectionArrDynamic(arrayList, sectionMaxItemLength, childrenName) {
  506. var splitArr = [];
  507. var splitSectionItemLen = 0;
  508. var splitSectionArr = [];
  509. arrayList.map(function(item) {
  510. var groupsList = [];
  511. item[childrenName].map(function(elem) {
  512. splitSectionItemLen++;
  513. groupsList.push(elem);
  514. if (splitSectionItemLen >= sectionMaxItemLength) {
  515. splitSectionArr.push({
  516. name: item.name,
  517. [childrenName]: groupsList
  518. });
  519. splitArr.push(splitSectionArr);
  520. splitSectionItemLen = 0;
  521. splitSectionArr = [];
  522. groupsList = [];
  523. }
  524. });
  525. if (groupsList.length)
  526. splitSectionArr.push({
  527. name: item.name,
  528. [childrenName]: groupsList
  529. });
  530. });
  531. if (splitSectionArr.length) splitArr.push(splitSectionArr);
  532. return splitArr;
  533. }
  534. /**
  535. * 获取chartId
  536. */
  537. function getEchartId() {
  538. return "chart-" + echartList.length;
  539. }
  540. /**
  541. * 添加chart渲染队列
  542. * @param {Object} option chart配置
  543. */
  544. function addEchart(option) {
  545. echartList.push({
  546. chartId: option.chartId || getEchartId(),
  547. chartType: option.chartType,
  548. datas: option.datas
  549. });
  550. }