ScoreCounter.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "StdAfx.h"
  2. #include "ScoreCounter.h"
  3. #include<algorithm>
  4. #include "..\Schema\schema_struct.h"
  5. CScoreCounter::CScoreCounter(void)
  6. {
  7. }
  8. CScoreCounter::~CScoreCounter(void)
  9. {
  10. }
  11. q_std CScoreCounter::get_std(const std::string &question_code)
  12. {
  13. q_std ret;
  14. auto it_find = q_stdm.find(question_code);
  15. if (it_find!= q_stdm.end()){
  16. return it_find->second;
  17. }
  18. return ret;
  19. }
  20. float CScoreCounter::GetScore( const std::string &question_code,const std::string& answer,const int isright ,const float score )
  21. {
  22. float result =0;
  23. q_std& question_std=q_stdm[question_code];
  24. result = GetScore(question_std, answer, result, isright, score);
  25. return result;
  26. }
  27. float CScoreCounter::GetScore_TianKongTi2(const std::string &question_code, const float score)
  28. {
  29. float result = 0;
  30. q_std& question_std = q_stdm[question_code];
  31. switch (question_std.question_type&schema::QTF_QUESTION_TYPE_MASK){
  32. case schema::TIANKONGTI://主观题
  33. result = question_std.score_full >= score ? score : question_std.score_full;
  34. break;
  35. }
  36. return result;
  37. }
  38. float CScoreCounter::GetScore( q_std &question_std, const string & answer, float result, int isright, float score )
  39. {
  40. switch(question_std.question_type&schema::QTF_QUESTION_TYPE_MASK){
  41. case schema::DANXUANTI://选择题
  42. case schema::DUOXUANTI://选择题
  43. case schema::PANDUANTI://选择题
  44. if(question_std.is_case_score){
  45. if(question_std.case_score.find(answer)==question_std.case_score.end()){
  46. result=0;
  47. }else{
  48. result=question_std.case_score[answer];
  49. }
  50. }else if(question_std.mutil_answer){
  51. vector<string> answer_option;
  52. if (answer.empty())
  53. {
  54. return 0;
  55. }
  56. split(answer,",",&answer_option);
  57. //正确选项数
  58. int rule_type = question_std.rule_type;
  59. int right_count=0;
  60. //错误选项数
  61. int error_count =0;
  62. for (int i=0;i<question_std.answer_std_option.size();i++)
  63. {
  64. BOOL isright =FALSE;
  65. for (int j=0;j<answer_option.size();j++)
  66. {
  67. if(question_std.answer_std_option[i]==answer_option[j]){
  68. isright = TRUE;
  69. break;
  70. }
  71. }
  72. if(isright)right_count++;
  73. }
  74. for (int j=0;j<answer_option.size();j++)
  75. {
  76. BOOL isright =FALSE;
  77. for (int i=0;i<question_std.answer_std_option.size();i++)
  78. {
  79. if(question_std.answer_std_option[i]==answer_option[j]){
  80. isright = TRUE;
  81. break;
  82. }
  83. }
  84. if(!isright)error_count++;
  85. }
  86. if (rule_type == 1)//规则A 全对满分 错选漏选0分
  87. {
  88. if (right_count == question_std.answer_std_option.size() && error_count == 0)
  89. return question_std.score_full;
  90. else
  91. return 0;
  92. }
  93. else if (rule_type == 2)//规则B 全对满分 错选0分 没有全部选对且没有错选得半对分
  94. {
  95. if (right_count == question_std.answer_std_option.size() && error_count == 0)
  96. return question_std.score_full;
  97. if (error_count > 0)
  98. return 0;
  99. if (right_count > 0 && error_count < 1)
  100. return question_std.score_half;
  101. }
  102. else if (rule_type == 3)//规则C 全对满分 答案数量不超过正确答案的数量下,部分选对为半对分 答案数量超过正确答案数量或全选错为0分
  103. {
  104. if (right_count == question_std.answer_std_option.size() && error_count == 0)
  105. return question_std.score_full;
  106. if (answer_option.size() <= question_std.answer_std_option.size() && right_count > 0)
  107. {
  108. return question_std.score_half;
  109. }
  110. if (answer_option.size() > question_std.answer_std_option.size() || right_count == 0)
  111. return 0;
  112. }
  113. if(error_count ==0){
  114. if(right_count==question_std.answer_std_option.size())result = question_std.score_full;
  115. else if(right_count>0)result = question_std.score_half;
  116. else result = 0;
  117. }else{
  118. result =0;
  119. }
  120. }else{
  121. result = question_std.answer_std==answer? question_std.score_full:0;
  122. }
  123. break;
  124. case schema::TIANKONGTI://填空题
  125. result = isright ? question_std.score_full : 0;
  126. break;
  127. case schema::BIZUOTI: // 必做题
  128. case schema::ZHUGUANTI://主观题
  129. result = score >= question_std.score_full ? question_std.score_full : score;
  130. break;
  131. case schema::XUANZUO_ZHUGUANTI:
  132. result = score >= question_std.score_full ? question_std.score_full : score;
  133. break;
  134. default: break;
  135. }
  136. return result;
  137. }
  138. void CScoreCounter::Load()
  139. {
  140. CppSQLite3Query query = bantch_db->execQuery("select * from question_std ");
  141. q_stdm.clear();
  142. for (int i=1;!query.eof();i++)
  143. {
  144. q_std qstd;
  145. qstd.mutil_answer = query.getIntField("multi_answer");
  146. qstd.rule_type = query.getIntField("rule_type");
  147. qstd.answer_std=query.getStringField("answer_std");
  148. qstd.option_count = query.getIntField("option_count");
  149. qstd.question_code=query.getStringField("question_code");
  150. qstd.question_type = query.getIntField("question_type");
  151. qstd.score_full =query.getFloatField("score_full");
  152. qstd.score_half = query.getFloatField("score_half");
  153. qstd.answer_all = query.getStringField("answer_all");
  154. split(qstd.answer_std,(string)",",&qstd.answer_std_option);
  155. map<string,float> case_score;
  156. vector<string> cases;
  157. split(qstd.answer_std,(string)";",&cases);
  158. for (int i=0;i<cases.size();i++)
  159. {
  160. vector<string> caseinfos;
  161. split(cases[i],(string)":",&caseinfos);
  162. if(caseinfos.size()==2){
  163. case_score[caseinfos[0]]=atof(caseinfos[1].c_str());
  164. }else{
  165. break;
  166. }
  167. }
  168. qstd.case_score=case_score;
  169. qstd.is_case_score =case_score.size()>0;
  170. q_stdm[qstd.question_code] =qstd;
  171. query.nextRow();
  172. }
  173. }
  174. CScoreCounterEx::CScoreCounterEx(void):
  175. m_bload(false)
  176. {
  177. }
  178. CScoreCounterEx::~CScoreCounterEx(void)
  179. {
  180. }
  181. void CScoreCounterEx::Load()
  182. {
  183. if (!m_bload)
  184. {
  185. __super::Load();
  186. m_bload = true;
  187. }
  188. }