Example #1
0
 /**
  * public $DSEX;
  * public $EAGEL;
  * public $DAGEH;
  * public $EM;
  * public $ESD;
  * public $NM;
  * public $NSD;
  * public $PM;
  * public $PSD;
  * public $LM;
  * public $LSD;
  * @throws Exception
  * @return boolean
  */
 private static function startMysqlEpqamdMemory()
 {
     $epqamd_first = EpqamdMemory::findFirst();
     if (isset($epqamd_first->DSEX)) {
         return true;
     } else {
         try {
             $manager = new TxManager();
             $transaction = $manager->get();
             $epqamd_data = Epqamd::find();
             foreach ($epqamd_data as $epqamd_record) {
                 $epqamd_memory = new EpqamdMemory();
                 $epqamd_memory->setTransaction($transaction);
                 $epqamd_memory->DSEX = $epqamd_record->DSEX;
                 $epqamd_memory->DAGEL = $epqamd_record->DAGEL;
                 $epqamd_memory->DAGEH = $epqamd_record->DAGEH;
                 $epqamd_memory->EM = $epqamd_record->EM;
                 $epqamd_memory->ESD = $epqamd_record->ESD;
                 $epqamd_memory->NM = $epqamd_record->NM;
                 $epqamd_memory->NSD = $epqamd_record->NSD;
                 $epqamd_memory->PM = $epqamd_record->PM;
                 $epqamd_memory->PSD = $epqamd_record->PSD;
                 $epqamd_memory->LM = $epqamd_record->LM;
                 $epqamd_memory->LSD = $epqamd_record->LSD;
                 if ($epqamd_memory->create() == false) {
                     unset($epqamd_data);
                     $transaction->rollback("EPQAMD DATA INSERT INTO MEMORY TABLE ERROR!");
                 }
             }
             if (isset($epqamd_data)) {
                 unset($epqamd_data);
             }
             $transaction->commit();
             return true;
         } catch (TxFailed $e) {
             throw new Exception("Failed, reason: " . $e->getMessage());
         }
     }
 }
Example #2
0
 /**
  * @usage EPQA计算
  */
 protected static function calEPQA(&$resultsets)
 {
     #首先判断是否需要写入epqa相关的因子分数
     if (empty(self::$factors_list_all)) {
         self::getFactorsAll($resultsets->examinee_id);
     }
     if (!isset(self::$factors_list_all['EPQA'])) {
         #true 表示不用写入EPQA的相关因子
         return true;
     }
     #计算全部因子的得分
     $score_array = explode('|', $resultsets->score);
     $score_array = array_count_values($score_array);
     unset($score_array['']);
     #标准分及最终分计算
     #确保加载内存表
     if (!self::$memory_state) {
         self::loadMemoryTable();
     }
     if (empty(self::$examinee_info)) {
         self::getExamineeInfo($resultsets->examinee_id);
     }
     $dage = self::$examinee_info['age'];
     if ($dage < 16 || $dage >= 150) {
         throw new Exception(self::$error_state . "EPQA年龄范围超限(16~150)" . $dage);
     }
     $dsex = self::$examinee_info['sex'] == 1 ? 1 : 2;
     #根据$factors_list_all['epqa'];
     $rt_array = array();
     foreach (self::$factors_list_all['EPQA'] as $key => $value) {
         $rt_array_record = array();
         #判断要写入的因子是否存在于之前的结果集中,若不存在,则置为0
         $score = 0;
         if (isset($score_array[$value])) {
             $score = $score_array[$value];
         }
         $m = 0;
         $sd = 0;
         $std_score = 0;
         $ans_score = 0;
         $epqamd = EpqamdMemory::findFirst(array('DAGEL <= :age: AND DAGEH > :age: AND DSEX = :sex:', 'bind' => array('age' => $dage, 'sex' => $dsex)));
         if (!isset($epqamd->DSEX)) {
             throw new Exception(self::$error_state . "-EPQAmd不存在记录-" . 'age-' . $dage . '-sex-' . $dsex);
         }
         switch ($value) {
             case 'epqae':
                 $m = $epqamd->EM;
                 $sd = $epqamd->ESD;
                 $std_score = sprintf("%.2f", 50 + 10 * ($score - $m) / $sd);
                 $ans_score = sprintf("%.2f", $std_score / 10);
                 break;
             case 'epqan':
                 $m = $epqamd->NM;
                 $sd = $epqamd->NSD;
                 $std_score = sprintf("%.2f", 50 + 10 * ($score - $m) / $sd);
                 $ans_score = sprintf("%.2f", 10 - $std_score / 10);
                 break;
             case 'epqap':
                 $m = $epqamd->PM;
                 $sd = $epqamd->PSD;
                 $std_score = sprintf("%.2f", 50 + 10 * ($score - $m) / $sd);
                 $ans_score = sprintf("%.2f", 10 - $std_score / 10);
                 break;
             case 'epqal':
                 $m = $epqamd->LM;
                 $sd = $epqamd->LSD;
                 $std_score = sprintf("%.2f", 50 + 10 * ($score - $m) / $sd);
                 $ans_score = sprintf("%.2f", 10 - $std_score / 10);
                 break;
             default:
                 throw new Exception(self::$error_state . '-EPQAmd不存在因子-' . $value);
         }
         $rt_array_record['score'] = floatval($score);
         $rt_array_record['std_score'] = floatval($std_score);
         $rt_array_record['ans_score'] = floatval($ans_score);
         $rt_array[$key] = $rt_array_record;
     }
     return $rt_array;
 }