ToolsService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. package com.qxgmat.service.extend;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.qxgmat.data.constants.enums.QuestionDifficult;
  5. import com.qxgmat.data.constants.enums.QuestionSubject;
  6. import com.qxgmat.data.constants.enums.SettingKey;
  7. import com.qxgmat.data.dao.entity.*;
  8. import com.qxgmat.data.relation.entity.QuestionNoRelation;
  9. import com.qxgmat.data.relation.entity.SentenceQuestionRelation;
  10. import com.qxgmat.data.relation.entity.TextbookQuestionRelation;
  11. import com.qxgmat.service.inline.RankService;
  12. import com.qxgmat.service.inline.SettingService;
  13. import org.springframework.beans.factory.annotation.Value;
  14. import org.springframework.stereotype.Service;
  15. import javax.annotation.Resource;
  16. import java.util.List;
  17. @Service
  18. public class ToolsService {
  19. @Value("${examination.verbalA}")
  20. private Integer verbalA;
  21. @Value("${examination.verbalB}")
  22. private Integer verbalB;
  23. @Value("${examination.quantC}")
  24. private Integer quantC;
  25. @Value("${examination.quantD}")
  26. private Integer quantD;
  27. private Integer scoreMax = 51;
  28. private Integer scoreMin = 6;
  29. @Resource
  30. private SettingService settingService;
  31. @Resource
  32. private RankService rankService;
  33. /**
  34. * 根据练习时间设置计算考题考试时间
  35. * setting: {struct: {difficult: ""}}
  36. * @param relationList
  37. * @return
  38. */
  39. public Integer computerTime(QuestionNoRelation[] relationList){
  40. Setting setting = settingService.getByKey(SettingKey.EXERCISE_TIME);
  41. JSONObject value = setting.getValue();
  42. Integer time = 0;
  43. for(QuestionNoRelation relation:relationList){
  44. JSONObject difficultMap = null;
  45. for (Integer struct : relation.getModuleStruct()){
  46. // 判断结构体
  47. difficultMap = value.getJSONObject(String.valueOf(struct));
  48. if (difficultMap != null) break;
  49. }
  50. if (difficultMap == null) continue;
  51. // 判断难度
  52. String t = difficultMap.getString(relation.getQuestion().getDifficult());
  53. if (t == null || t.isEmpty()) continue;
  54. time += Integer.valueOf(t);
  55. }
  56. return time;
  57. }
  58. /**
  59. * 根据练习时间设置获取单个考题时间
  60. * setting: {struct: {difficult: ""}}
  61. * @param relation
  62. * @return
  63. */
  64. public Integer computerTime(QuestionNoRelation relation){
  65. Setting setting = settingService.getByKey(SettingKey.EXERCISE_TIME);
  66. JSONObject value = setting.getValue();
  67. JSONObject difficultMap = null;
  68. for (Integer struct : relation.getModuleStruct()){
  69. // 判断结构体
  70. difficultMap = value.getJSONObject(String.valueOf(struct));
  71. if (difficultMap != null) break;
  72. }
  73. if (difficultMap == null) return 0;
  74. // 判断难度
  75. String t = difficultMap.getString(relation.getQuestion().getDifficult());
  76. if (t == null || t.isEmpty()) return 0;
  77. return Integer.valueOf(t);
  78. }
  79. /**
  80. * 根据练习时间设置获取单个考题时间
  81. * setting: {struct: {difficult: ""}}
  82. * @param relation
  83. * @return
  84. */
  85. public Integer computerTime(TextbookQuestionRelation relation){
  86. Setting setting = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  87. JSONObject value = setting.getValue();
  88. String t = value.getString("time");
  89. if (t == null || t.isEmpty()) return 0;
  90. return Integer.valueOf(t);
  91. }
  92. /**
  93. * 根据练习时间设置计算考题考试时间
  94. * setting: {struct: {difficult: ""}}
  95. * @param relationList
  96. * @return
  97. */
  98. public Integer computerTime(TextbookQuestionRelation[] relationList){
  99. Setting setting = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  100. JSONObject value = setting.getValue();
  101. String t = value.getString("time");
  102. if (t == null || t.isEmpty()) return 0;
  103. return Integer.valueOf(t) * relationList.length;
  104. }
  105. /**
  106. * 根据长难句时间设置获取单个考题时间
  107. * setting: {time: ""}
  108. * @param relation
  109. * @return
  110. */
  111. public Integer computerTime(SentenceQuestionRelation relation){
  112. Setting scoreSwitch = settingService.getByKey(SettingKey.SCORE_SWITCH);
  113. if (scoreSwitch.getValue().getBooleanValue("all")){
  114. // todo 计算全站平均时间
  115. return 0;
  116. } else {
  117. Setting setting = settingService.getByKey(SettingKey.SENTENCE_TIME);
  118. JSONObject value = setting.getValue();
  119. String t = value.getString("time");
  120. if (t == null || t.isEmpty()) return 0;
  121. return Integer.valueOf(t);
  122. }
  123. }
  124. /**
  125. * 根据长难句时间设置获取考题考试时间
  126. * setting: {time: ""}
  127. * @param relationList
  128. * @return
  129. */
  130. public Integer computerTime(SentenceQuestionRelation[] relationList){
  131. Setting scoreSwitch = settingService.getByKey(SettingKey.SCORE_SWITCH);
  132. if (scoreSwitch.getValue().getBooleanValue("all")){
  133. // todo 计算全站平均时间
  134. return 0;
  135. } else {
  136. Setting setting = settingService.getByKey(SettingKey.SENTENCE_TIME);
  137. JSONObject value = setting.getValue();
  138. String t = value.getString("time");
  139. if (t == null || t.isEmpty()) return 0;
  140. return Integer.valueOf(t) * relationList.length;
  141. }
  142. }
  143. /**
  144. * 根据后台设置剔除时间,判断试题统计情况
  145. * @param question
  146. * @return
  147. */
  148. public boolean filterTime(UserQuestion question){
  149. Setting setting = settingService.getByKey(SettingKey.FILTER_TIME);
  150. JSONObject value = setting.getValue();
  151. if (value.getInteger("min")> question.getTime()) return false;
  152. if (value.getInteger("max") < question.getTime()) return false;
  153. return true;
  154. }
  155. /**
  156. * 根据考试设置,得到做题时间,做题数量
  157. * setting: {subject: { time: "", number: "" }}
  158. * @param order
  159. */
  160. public void examinationReportInit(UserReport userReport, JSONArray order){
  161. Setting setting = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  162. JSONObject value = setting.getValue();
  163. Integer number = 0;
  164. Integer time = 0;
  165. for(String subject : order.toJavaList(String.class)){
  166. JSONObject one = value.getJSONObject(subject);
  167. if(one!= null && !one.isEmpty()){
  168. number += one.getInteger("number");
  169. time += one.getInteger("time");
  170. }
  171. }
  172. userReport.setQuestionNumber(number);
  173. userReport.setTime(time);
  174. }
  175. /**
  176. * 得到单个科目做题总时间
  177. * @param subject
  178. * @return
  179. */
  180. public Integer examinationSubjectTime(String subject){
  181. Setting setting = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  182. JSONObject value = setting.getValue();
  183. JSONObject info = value.getJSONObject(subject);
  184. return info.getInteger("time");
  185. }
  186. /**
  187. * 得到单个科目做题总题数
  188. * @param subject
  189. * @return
  190. */
  191. public Integer examinationSubjectNumber(String subject){
  192. Setting setting = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  193. JSONObject value = setting.getValue();
  194. JSONObject info = value.getJSONObject(subject);
  195. return info.getInteger("number");
  196. }
  197. /**
  198. * 获取模考学科数据:
  199. * { time: '', number: '' }
  200. * @param subject
  201. * @return
  202. */
  203. public JSONObject examinationSubjectInit(QuestionSubject subject){
  204. Setting setting = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  205. JSONObject value = setting.getValue();
  206. return value.getJSONObject(subject.key);
  207. }
  208. /**
  209. * Quant分数计算:系数c * Quant部分平均正确率 + 系数d * Quant部分题目平均难度
  210. * @param number
  211. * @param userNumber
  212. * @param difficultScore
  213. * @param correctNumber
  214. * @return
  215. */
  216. // public Integer quantScore(Integer number, Integer userNumber, Integer difficultScore, Integer correctNumber){
  217. // return quantC * correctNumber / number + quantD * difficultScore / userNumber;
  218. // }
  219. /**
  220. * Quant分数计算:17+平均正确率*19.45+平均难度*0.72
  221. * @param number
  222. * @param userNumber
  223. * @param difficultScore
  224. * @param correctNumber
  225. * @return
  226. */
  227. public Integer quantScore(Integer number, Integer userNumber, float difficultScore, Integer correctNumber){
  228. int score = (int)Math.round(17 + 19.45 * correctNumber / number + 0.72 * difficultScore / userNumber);
  229. if (score > scoreMax) return scoreMax;
  230. if (score < scoreMin) return scoreMin;
  231. return score;
  232. }
  233. /**
  234. * Verbal分数计算:系数a * Verbal部分题目平均正确率 + 系数b * Verbal部分题目平均难度
  235. * @param number
  236. * @param userNumber
  237. * @param difficultScore
  238. * @param correctNumber
  239. * @return
  240. */
  241. // public Integer verbalScore(Integer number, Integer userNumber, Integer difficultScore, Integer correctNumber){
  242. // return verbalA * correctNumber / number + verbalB * difficultScore / userNumber;
  243. // }
  244. /**
  245. * Verbal分数计算:23.59 + 平均正确率*29.6+平均难度*1.72
  246. * @param number
  247. * @param userNumber
  248. * @param difficultScore
  249. * @param correctNumber
  250. * @return
  251. */
  252. public Integer verbalScore(Integer number, Integer userNumber, float difficultScore, Integer correctNumber){
  253. int score = (int)Math.round(23.59 + 29.6 * correctNumber / number + 1.72 * difficultScore / userNumber);
  254. if (score > scoreMax) return scoreMax;
  255. if (score < scoreMin) return scoreMin;
  256. return score;
  257. }
  258. /**
  259. * IR分数计算:最高8分
  260. * @param number
  261. * @param userNumber
  262. * @param difficultScore
  263. * @param correctNumber
  264. * @return
  265. */
  266. public int irScore(Integer number, Integer userNumber, Integer difficultScore, Integer correctNumber){
  267. switch(correctNumber){
  268. case 0:
  269. case 1:
  270. return 1;
  271. case 2:
  272. return 2;
  273. case 3:
  274. case 4:
  275. return 3;
  276. case 5:
  277. return 4;
  278. case 6:
  279. return 5;
  280. case 7:
  281. return 6;
  282. case 8:
  283. return 7;
  284. case 9:
  285. default:
  286. return 8;
  287. }
  288. }
  289. /**
  290. * avg diff correct= [500 + 10*(1-0.7)+500+10*(1-0.6)+500+10*(1-0.5)
  291. * +600+10*(1-0.4)+600+10*(1-0.7)+700+10*(1-0.1)+700+10*(1-0.9)] / (3+2+2)
  292. * { all: '' }
  293. * @param totalNumber
  294. * @param totalCorrect
  295. * @param questionDifficult
  296. * @return
  297. */
  298. public float diffScore(Integer totalNumber, Integer totalCorrect, QuestionDifficult questionDifficult){
  299. Setting setting = settingService.getByKey(SettingKey.SCORE_SWITCH);
  300. JSONObject value = setting.getValue();
  301. if (value.getBooleanValue("all")){
  302. Integer difficultScore = QuestionDifficult.GetScore(questionDifficult);
  303. return difficultScore + 10 * (1 - (float)totalCorrect / totalNumber);
  304. }else{
  305. return QuestionDifficult.GetScoreBase(questionDifficult);
  306. }
  307. }
  308. /**
  309. * 当这个结果低于500的时候统一显示为500,
  310. * 高于500时,是多少就显示多少,且必须为10的倍数,722=720,754=750,756=760
  311. * 四舍五入
  312. * @param totalDiffScore
  313. * @param number
  314. * @return
  315. */
  316. public int avgDiffScore(float totalDiffScore, Integer number){
  317. int avg = (int)(totalDiffScore / number);
  318. if (avg < 500){
  319. return 500;
  320. }
  321. return (int) (Math.round((int)(avg / 10)) * 10);
  322. }
  323. /**
  324. * 得出V小分和Q小分后根据总分-小分excel对应表(我方提供)算出最后考试的总分
  325. * @param quantScore
  326. * @param verbalScore
  327. * @return
  328. */
  329. public Rank totalScore(Integer quantScore, Integer verbalScore){
  330. Rank rank = rankService.search(quantScore, verbalScore);
  331. return rank != null ? rank : new Rank();
  332. }
  333. /**
  334. * 根据模考分数获取排名
  335. * @param score
  336. * @return
  337. */
  338. public Rank scoreRank(JSONObject score){
  339. Rank rank = rankService.search(score.getInteger("quant"), score.getInteger("verbal"));
  340. return rank != null ? rank : new Rank();
  341. }
  342. }