Пример #1
0
function enhancedcalc_remark($paper_type, $paper_id, $q_id, $settings, $db, $mode = 'unmarked')
{
    $status = array(-13 => 0, -12 => 0, -11 => 0, -10 => 0, -9 => 0, -8 => 0, -7 => 0, -6 => 0, -5 => 0, -4 => 0, -3 => 0, -2 => 0, -1 => 0, 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
    $configObject = Config::get_instance();
    $enhancedcalc = new EnhancedCalc($configObject);
    $data['settings'] = $settings;
    $data['q_id'] = $q_id;
    $enhancedcalc->load($data);
    $mode_sql = $mode == 'all' ? '' : ' AND mark IS NULL';
    $result = $db->prepare("SELECT log{$paper_type}.id, user_answer FROM log{$paper_type}, log_metadata WHERE log{$paper_type}.metadataID = log_metadata.id AND q_id = ? AND paperID = ? {$mode_sql}");
    $result->bind_param('ii', $q_id, $paper_id);
    $result->execute();
    $result->store_result();
    $result->bind_result($id, $user_answer);
    while ($result->fetch()) {
        $enhancedcalc->set_useranswer($user_answer);
        $returnarray = $enhancedcalc->calculate_user_mark();
        $status[$returnarray]++;
        if ($returnarray !== Q_MARKING_UNMARKED and $returnarray !== Q_MARKING_ERROR) {
            // Save the extra data back into the log record.
            $sql = "UPDATE log{$paper_type} set mark = ?, adjmark = ?, totalpos = ?, user_answer = ? WHERE id = ? LIMIT 1";
            $storemark = $db->prepare($sql);
            $new_useranswerstring = $enhancedcalc->useranswer_to_string();
            $totalpos = $enhancedcalc->calculate_question_mark();
            $storemark->bind_param('dddsi', $enhancedcalc->qmark, $enhancedcalc->qmark, $totalpos, $new_useranswerstring, $id);
            $storemark->execute();
        }
    }
    $result->close();
    return $status;
}
Пример #2
0
$root = str_replace('/plugins/questions/enhancedcalc/tools', '/', str_replace('\\', '/', dirname(__FILE__)));
include_once $root . 'include/load_config.php';
require $configObject->get('cfg_web_root') . '/plugins/questions/enhancedcalc/enhancedcalc.class.php';
$settings = '{"strictdisplay":"on","strictzeros":true,"dp":"2","tolerance_full":"2","fulltoltyp":"%","tolerance_partial":"5","parttoltyp":"#","marks_partial":"0.5","marks_incorrect":"0","marks_correct":"1","marks_unit":0,"show_units":true,"answers":[{"formula":"$A - $B","units":"mm"},{"formula":"($A - $B)\\/1000","units":"m"}],"vars":{"$A":{"min":"1000","max":"2000","inc":"5","dec":"0"},"$B":{"min":"1000","max":"100000","inc":"5","dec":"0"}}}';
$uans[1] = '{"vars":{"$A":"182.0","$B":"88.0"},"uans":"94.00","uansunit":"mm"}';
$uans[2] = '{"vars":{"$A":"182.0","$B":"88.0"},"uans":"92.00","uansunit":"mm"}';
$uans[3] = '{"vars":{"$A":"182.0","$B":"88.0"},"uans":"90.00","uansunit":"mm"}';
$uans[4] = '{"vars":{"$A":"182.0","$B":"88.0"},"uans":"70.00","uansunit":"mm"}';
//$configObj = new Config();
$q = new EnhancedCalc($configObject);
$q->set_settings($settings);
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
echo "<h1>Marking 500 User answers</h1>";
$i = 0;
while ($i <= 500) {
    $q->set_useranswer($uans[array_rand($uans)]);
    $q->calculate_user_mark();
    echo "<br/> {$i} ::" . $q->qmark . "<br/>";
    $i++;
}
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = $endtime - $starttime;
echo '<h1>Script execution took ' . $totaltime . ' seconds</h1>';
?>
</html>