Question.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package com.seecoder.dataanalysis.data.entity.eval;
  2. import com.seecoder.dataanalysis.data.entity.competency.KSScore;
  3. import com.seecoder.dataanalysis.vo.question.CompleteQuestionVO;
  4. import lombok.AllArgsConstructor;
  5. import lombok.Data;
  6. import lombok.NoArgsConstructor;
  7. import lombok.experimental.Accessors;
  8. import org.jetbrains.annotations.NotNull;
  9. import org.springframework.data.annotation.Id;
  10. import org.springframework.data.mongodb.core.mapping.Document;
  11. import org.springframework.data.mongodb.core.mapping.Field;
  12. import java.util.ArrayList;
  13. import java.util.Arrays;
  14. import java.util.Collections;
  15. import java.util.List;
  16. /**
  17. * @author Peng Yiyan
  18. */
  19. @NoArgsConstructor
  20. @AllArgsConstructor
  21. @Accessors(chain = true)
  22. @Data
  23. public class Question {
  24. /**
  25. * 题目id
  26. */
  27. private String questionId;
  28. // /**
  29. // * 题目总分值
  30. // */
  31. // private Double questionScore;
  32. /**
  33. * 题目难度,用于Skills
  34. */
  35. private Integer weight;
  36. /**
  37. * 题目考察的能力,可能考察多种不同能力,所以用list存储
  38. */
  39. private List<String> competencies;
  40. // /**
  41. // * 题目考察的K-S对,和competencies中的下标一一对应
  42. // */
  43. // private List<KSScore> ksScores;
  44. /**
  45. * 解析CompleteQuestionVO的内容,并放入Question中
  46. * @param completeQuestionVO
  47. */
  48. public Question(CompleteQuestionVO completeQuestionVO){
  49. this.setQuestionId(completeQuestionVO.getId());
  50. this.setWeight(completeQuestionVO.getWeight());
  51. List<String> knowledgeList = completeQuestionVO.getKnowledgeId();
  52. // String[] testArray = new String[]{"SR.RV.RT","SR.RV","SR.RC.INRP","SC","SC.RT","SR","SSR"};
  53. // List<String> knowledgeList = Arrays.asList(testArray);
  54. // Collections.sort(knowledgeList,(a,b) -> b.split(".").length - a.split(".").length);
  55. Collections.sort(knowledgeList,(a,b) -> countPoint(b) - countPoint(a));
  56. // for(String str : knowledgeList)
  57. // System.out.println(str);
  58. //处理重复知识点后的结果数组
  59. List<String> after = new ArrayList<>();
  60. after.add(knowledgeList.get(0));
  61. int index = 1;
  62. for(;index<knowledgeList.size();index++){
  63. if(countPoint(knowledgeList.get(index)) == countPoint(knowledgeList.get(index-1))){
  64. after.add(knowledgeList.get(index));
  65. }else {
  66. break;
  67. }
  68. }
  69. for(;index<knowledgeList.size();index++){
  70. boolean overlap = false;
  71. for(String have : after){
  72. if(have.contains(knowledgeList.get(index))){
  73. overlap = true;
  74. break;
  75. }
  76. }
  77. if(!overlap){
  78. after.add(knowledgeList.get(index));
  79. }
  80. }
  81. this.setCompetencies(after);
  82. }
  83. //计算字符串中.(分隔符)的数目
  84. int countPoint(String s){
  85. int count = 0;
  86. for(int i=0;i<s.length();i++){
  87. if(s.charAt(i) == '.'){
  88. count++;
  89. }
  90. }
  91. return count;
  92. }
  93. }