123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #include "StdAfx.h"
- #include "ScoreCounter.h"
- #include<algorithm>
- #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<string> 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<question_std.answer_std_option.size();i++)
- {
- BOOL isright =FALSE;
- for (int j=0;j<answer_option.size();j++)
- {
- if(question_std.answer_std_option[i]==answer_option[j]){
- isright = TRUE;
- break;
- }
- }
- if(isright)right_count++;
- }
- for (int j=0;j<answer_option.size();j++)
- {
- BOOL isright =FALSE;
- for (int i=0;i<question_std.answer_std_option.size();i++)
- {
- if(question_std.answer_std_option[i]==answer_option[j]){
- isright = TRUE;
- break;
- }
- }
- if(!isright)error_count++;
- }
- if (rule_type == 1)//规则A 全对满分 错选漏选0分
- {
- if (right_count == question_std.answer_std_option.size() && error_count == 0)
- return question_std.score_full;
- else
- return 0;
- }
- else if (rule_type == 2)//规则B 全对满分 错选0分 没有全部选对且没有错选得半对分
- {
- if (right_count == question_std.answer_std_option.size() && error_count == 0)
- return question_std.score_full;
- if (error_count > 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<string,float> case_score;
- vector<string> cases;
- split(qstd.answer_std,(string)";",&cases);
- for (int i=0;i<cases.size();i++)
- {
- vector<string> 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;
- }
- }
|