#include "StdAfx.h" #include "ScoreCounter.h" #include #include "..\Schema\schema_struct.h" CScoreCounter::CScoreCounter(void) { } CScoreCounter::~CScoreCounter(void) { } q_std CScoreCounter::get_std(const std::string &question_code) { q_std ret; auto it_find = q_stdm.find(question_code); if (it_find!= q_stdm.end()){ return it_find->second; } return ret; } float CScoreCounter::GetScore( const std::string &question_code,const std::string& answer,const int isright ,const float score ) { float result =0; q_std& question_std=q_stdm[question_code]; result = GetScore(question_std, answer, result, isright, score); return result; } float CScoreCounter::GetScore_TianKongTi2(const std::string &question_code, const float score) { float result = 0; q_std& question_std = q_stdm[question_code]; switch (question_std.question_type&schema::QTF_QUESTION_TYPE_MASK){ case schema::TIANKONGTI://主观题 result = question_std.score_full >= score ? score : question_std.score_full; break; } return result; } float CScoreCounter::GetScore( q_std &question_std, const string & answer, float result, int isright, float score ) { switch(question_std.question_type&schema::QTF_QUESTION_TYPE_MASK){ case schema::DANXUANTI://选择题 case schema::DUOXUANTI://选择题 case schema::PANDUANTI://选择题 if(question_std.is_case_score){ if(question_std.case_score.find(answer)==question_std.case_score.end()){ result=0; }else{ result=question_std.case_score[answer]; } }else if(question_std.mutil_answer){ vector answer_option; if (answer.empty()) { return 0; } split(answer,",",&answer_option); //正确选项数 int rule_type = question_std.rule_type; int right_count=0; //错误选项数 int error_count =0; for (int i=0;i 0) return 0; if (right_count > 0 && error_count < 1) return question_std.score_half; } else if (rule_type == 3)//规则C 全对满分 答案数量不超过正确答案的数量下,部分选对为半对分 答案数量超过正确答案数量或全选错为0分 { if (right_count == question_std.answer_std_option.size() && error_count == 0) return question_std.score_full; if (answer_option.size() <= question_std.answer_std_option.size() && right_count > 0) { return question_std.score_half; } if (answer_option.size() > question_std.answer_std_option.size() || right_count == 0) return 0; } if(error_count ==0){ if(right_count==question_std.answer_std_option.size())result = question_std.score_full; else if(right_count>0)result = question_std.score_half; else result = 0; }else{ result =0; } }else{ result = question_std.answer_std==answer? question_std.score_full:0; } break; case schema::TIANKONGTI://填空题 result = isright ? question_std.score_full : 0; break; case schema::BIZUOTI: // 必做题 case schema::ZHUGUANTI://主观题 result = score >= question_std.score_full ? question_std.score_full : score; break; case schema::XUANZUO_ZHUGUANTI: result = score >= question_std.score_full ? question_std.score_full : score; break; default: break; } return result; } void CScoreCounter::Load() { CppSQLite3Query query = bantch_db->execQuery("select * from question_std "); q_stdm.clear(); for (int i=1;!query.eof();i++) { q_std qstd; qstd.mutil_answer = query.getIntField("multi_answer"); qstd.rule_type = query.getIntField("rule_type"); qstd.answer_std=query.getStringField("answer_std"); qstd.option_count = query.getIntField("option_count"); qstd.question_code=query.getStringField("question_code"); qstd.question_type = query.getIntField("question_type"); qstd.score_full =query.getFloatField("score_full"); qstd.score_half = query.getFloatField("score_half"); qstd.answer_all = query.getStringField("answer_all"); split(qstd.answer_std,(string)",",&qstd.answer_std_option); map case_score; vector cases; split(qstd.answer_std,(string)";",&cases); for (int i=0;i caseinfos; split(cases[i],(string)":",&caseinfos); if(caseinfos.size()==2){ case_score[caseinfos[0]]=atof(caseinfos[1].c_str()); }else{ break; } } qstd.case_score=case_score; qstd.is_case_score =case_score.size()>0; q_stdm[qstd.question_code] =qstd; query.nextRow(); } } CScoreCounterEx::CScoreCounterEx(void): m_bload(false) { } CScoreCounterEx::~CScoreCounterEx(void) { } void CScoreCounterEx::Load() { if (!m_bload) { __super::Load(); m_bload = true; } }