Esempio n. 1
0
 /**
  * Return the 'distance' of the user's answer from the correct answer as a percentage of the correct answer
  * @return float Distance from the correct answer
  */
 public function get_answer_distance()
 {
     if (!isset($this->useranswer['cans_dist'])) {
         $enhancedcalcType = $this->configObj->get('enhancedcalc_type');
         if (!is_null($enhancedcalcType)) {
             require_once $enhancedcalcType . '.php';
             $name = 'enhancedcalc_' . $enhancedcalcType;
             $enhancedcalcObj = new $name($this->configObj->getbyref($enhancedcalcType));
         } else {
             require_once 'Rrserve.php';
             $enhancedcalcObj = new EnhancedCalc_Rrserve($this->configObj->getbyref('enhancedcalculation'));
         }
         if (isset($this->useranswer['status']['exact']) and $this->useranswer['status']['exact'] === false or !isset($this->useranswer['status']['exact'])) {
             $this->useranswer['cans_dist'] = $enhancedcalcObj->distance_from_correct_answer($this->useranswer['uansnumb'], $this->useranswer['cans']);
         } else {
             $this->useranswer['cans_dist'] = '0';
         }
     }
     $data = false;
     if (isset($this->useranswer['cans_dist']) and $this->useranswer['cans_dist'] !== 'ERROR') {
         $data = $this->useranswer['cans_dist'];
     }
     return $data;
 }
             } else {
                 $variable_array = array();
             }
             $varno = 0;
             foreach ($variable_array as $individual_variable) {
                 if ($individual_variable != '') {
                     $varsdata[$vars[$varno]] = $individual_variable;
                 }
                 $varno++;
             }
             if (isset($varsdata)) {
                 $new_user_answer['vars'] = $varsdata;
             }
             $new_user_answer['original'] = $user_answer;
             // Calculate distance from correct if needed
             $new_user_answer['cans_dist'] = $enhancedcalcObj->distance_from_correct_answer($new_user_answer['uansnumb'], $new_user_answer['cans']);
             $jsoned = json_encode($new_user_answer);
             $update->bind_param('si', $jsoned, $uid);
             $update->execute();
             $loop++;
             if ($loop % 200 == 0) {
                 $mysqli->commit();
                 echo '<br>';
                 @ob_flush();
             }
         }
     }
     $mysqli->commit();
     $update->close();
     $result->close();
 }