Ejemplo n.º 1
0
 /**
  * public $NLL;
  * public $NLH;
  * public $B95;
  * public $B90;
  * public $B75;
  * public $B50;
  * public $B25;
  * public $B10;
  * public $B5;
  */
 private static function startMysqlSpmmdMemory()
 {
     $spmmd_first = SpmmdMemory::findFirst();
     if (isset($spmmd_first->NLL)) {
         return true;
     } else {
         try {
             $manager = new TxManager();
             $transaction = $manager->get();
             $spmmd_data = Spmmd::find();
             foreach ($spmmd_data as $spmmd_record) {
                 $spmmd_memory = new SpmmdMemory();
                 $spmmd_memory->setTransaction($transaction);
                 $spmmd_memory->NLL = $spmmd_record->NLL;
                 $spmmd_memory->NLH = $spmmd_record->NLH;
                 $spmmd_memory->B95 = $spmmd_record->B95;
                 $spmmd_memory->B90 = $spmmd_record->B90;
                 $spmmd_memory->B75 = $spmmd_record->B75;
                 $spmmd_memory->B50 = $spmmd_record->B50;
                 $spmmd_memory->B25 = $spmmd_record->B25;
                 $spmmd_memory->B10 = $spmmd_record->B10;
                 $spmmd_memory->B5 = $spmmd_record->B5;
                 if ($spmmd_memory->create() == false) {
                     unset($ksmd_data);
                     $transaction->rollback("SPMMD DATA INSERT INTO MEMORY TABLE ERROR!");
                 }
             }
             if (isset($spmmd_data)) {
                 unset($spmmd_data);
             }
             $transaction->commit();
             return true;
         } catch (TxFailed $e) {
             throw new Exception("Failed, reason: " . $e->getMessage());
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * SPM
  */
 protected static function calSPM(&$resultsets)
 {
     #首先判断是否需要写入SPM相关的因子分数
     if (empty(self::$factors_list_all)) {
         self::getFactorsAll($resultsets->examinee_id);
     }
     if (!isset(self::$factors_list_all['SPM'])) {
         #true 表示不用写入SPM的相关因子
         return true;
     }
     #确保加载内存表
     if (!self::$memory_state) {
         self::loadMemoryTable();
     }
     #确保个人信息
     if (empty(self::$examinee_info)) {
         self::getExamineeInfo($resultsets->examinee_id);
     }
     #整理SPM题目答案
     $question_ans_array = self::getAnswers($resultsets);
     #确定所有涉及的因子,不再进行全局遍历
     $array_all_use = array();
     foreach (self::$factors_list_all['SPM'] as $key => $value) {
         $factor_detail = MemoryCache::getFactorDetail($value);
         if ($factor_detail->action == 'sum') {
             if (!in_array($value, $array_all_use)) {
                 $array_all_use[$key] = $value;
             }
         } else {
             if (!in_array($value, $array_all_use)) {
                 $array_all_use[$key] = $value;
             }
             $child_factor_str = $factor_detail->children;
             $child_factor_array = explode(',', $child_factor_str);
             foreach ($child_factor_array as $fvalue) {
                 if (!in_array($fvalue, $array_all_use)) {
                     $fvalue_tmp = MemoryCache::getFactorDetail($fvalue);
                     $fkey = $fvalue_tmp->id;
                     $array_all_use[$fkey] = $fvalue;
                 }
             }
         }
     }
     ksort($array_all_use);
     #得到一个完全有效数组
     #返回数组
     $rt_array = array();
     #保存基础数组
     $basic_array = array();
     #简单因子先处理,复杂因子后处理,由于复杂因子使用简单因子的原始分,那么我们次序对其进行运算
     foreach ($array_all_use as $key => $value) {
         $factor_record = MemoryCache::getFactorDetail($value);
         $score = 0;
         if ($factor_record->action == 'sum') {
             #前5项(至多) 简单因子的原始得分
             $factor_record_number_array = explode(',', $factor_record->children);
             foreach ($factor_record_number_array as $skey) {
                 if (isset($question_ans_array[$skey])) {
                     $score += $question_ans_array[$skey];
                 }
             }
             $basic_array[$value] = $score;
         } else {
             #至多2项
             $code = preg_replace('/[a-z]+/', '\\$basic_array[\'$0\']', $factor_record->action);
             $code = "\$score = {$code};";
             eval($code);
             $basic_array[$value] = $score;
         }
     }
     #basic_array >= $factor_list_all['SPM'];
     foreach ($basic_array as $key => $value) {
         if (!in_array($key, self::$factors_list_all['SPM'])) {
             unset($basic_array[$key]);
         }
     }
     #现在的$basic_array为有效数组的原始的分
     $age = self::$examinee_info['age'];
     #spm的年龄区间 5.25~110
     if ($age < 5.25 || $age >= 110) {
         throw new Exception(self::$error_state . "SPM年龄范围越界" . $age);
     }
     foreach ($basic_array as $key => $score) {
         $factor_record = MemoryCache::getFactorDetail($key);
         $array_record = array();
         $std_score = 0;
         $ans_score = 0;
         if ($key == 'spm') {
             $spmmd = SpmmdMemory::findFirst(array('NLH >= :age: AND NLL <= :age:', 'bind' => array('age' => $age)));
             if (!isset($spmmd->NLH)) {
                 throw new Exception(self::$error_state . '-Spmmd不存在记录-' . 'age-' . $age);
             }
             if ($score >= $spmmd->B95) {
                 $std_score = 195;
             } else {
                 if ($score >= $spmmd->B90) {
                     $std_score = 290;
                 } else {
                     if ($score >= $spmmd->B75) {
                         $std_score = 275;
                     } else {
                         if ($score >= $spmmd->B50) {
                             $std_score = 350;
                         } else {
                             if ($score >= $spmmd->B25) {
                                 $std_score = 325;
                             } else {
                                 if ($score >= $spmmd->B10) {
                                     $std_score = 410;
                                 } else {
                                     if ($score >= $spmmd->B5) {
                                         $std_score = 45;
                                     } else {
                                         $std_score = 51;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // std_score 第一位 智力等级  之后位为 百分等级
             $flag = substr($std_score, 0, 1);
             if ($flag == 1) {
                 $ans_score = 9;
             } else {
                 if ($flag == 2) {
                     $ans_score = 7.5;
                 } else {
                     if ($flag == 3) {
                         $ans_score = 6;
                     } else {
                         if ($flag == 4) {
                             $ans_score = 5;
                         } else {
                             if ($flag == 5) {
                                 $ans_score = 4;
                             } else {
                                 $ans_score = 1;
                             }
                         }
                     }
                 }
             }
         } else {
             $std_score = $score;
             if ($key == 'spmabc') {
                 $ans_score = sprintf("%.2f", $std_score / 3.6);
             } else {
                 $ans_score = sprintf("%.2f", $std_score / 1.2);
             }
         }
         $array_record['score'] = floatval($score);
         $array_record['std_score'] = floatval($std_score);
         $array_record['ans_score'] = floatval($ans_score);
         $rt_array[$factor_record->id] = $array_record;
     }
     return $rt_array;
 }