Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions StudentDrawFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
require_once "init_without_validate.php";
require_once 'assess2/AssessStandalone.php';
require_once "new_return_class.php";

function getPost($key, $default = "") {
return $_POST[$key] ?? $default;
}

$a2 = new AssessStandalone($DBH);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$seed = getPost('seed');
$qtype = getPost('qtype');
$control = getPost('control');
$answer = getPost("answer");

$input = '{"email":"u@abc.co","id":"36","uniqueid":"1699501100492899","adddate":"1699501100","lastmoddate":"1699501137","ownerid":"1","author":"Nguyen,Vu","userights":"0","license":"1","description":"Algebra problem","qtype":"multipart","control":"","qcontrol":"","qtext":"","answer":"","solution":"","extref":"","hasimg":"0","deleted":"0","avgtime":"0","ancestors":"","ancestorauthors":"","otherattribution":"","importuid":"","replaceby":"0","broken":"0","solutionopts":"6","sourceinstall":"","meantimen":"1","meantime":"19","vartime":"0","meanscoren":"1","meanscore":"50","varscore":"0","isrand":"1"}';
$qn = 27;

$line = json_decode($input, true);

$line["qtype"] = $qtype;
$line["control"] = $control;

$a2->setQuestionData($qn, $line);

$state = array(
'seeds' => array($qn => $seed),
'qsid' => array($qn => $qn),
'stuanswers' => array(),
'stuanswersval' => array(),
'scorenonzero' => array(($qn+1) => -1),
'scoreiscorrect' => array(($qn+1) => -1),
'partattemptn' => array($qn => array()),
'rawscores' => array($qn => array())
);

$a2->setState($state);

$toscoreqn = getPost("toscoreqn");
if ($toscoreqn != "") {
$toscoreqn = json_decode($toscoreqn, true);
$parts_to_score = array();
if (isset($toscoreqn[$qn])) {
foreach ($toscoreqn[$qn] as $pn) {
$parts_to_score[$pn] = true;
};
}
}

$result = $a2->scoreQuestion($qn, $parts_to_score);
$student_func = $a2->get_student_func();
$fin_function = array();

foreach ($student_func as $i => $value) {
$temp = new DrawResult($value[0], $value[1]);
$fin_function[] = $temp;
}

header('Content-Type: application/json');
echo json_encode($fin_function);

} else {
header('HTTP/1.0 405 Method Not Allowed');
header('Content-Type: application/json');
echo json_encode(['status' => false, 'message' => 'Method Not Allowed']);
}
6 changes: 6 additions & 0 deletions assess2/AssessStandalone.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class AssessStandalone {
private $qdata = array();
private $now = 0;
private $question = null;
private $student_func;

public function get_student_func() {
return $this->student_func;
}

/**
* Construct object
Expand Down Expand Up @@ -303,6 +308,7 @@ public function scoreQuestion($qn, $parts_to_score = true) {
->setQnpointval(1);

$scoreResult = $scoreEngine->scoreQuestion($scoreQuestionParams);
$this->student_func = $scoreEngine->get_temp_func();

$scores = $scoreResult['scores'];
$rawparts = $scoreResult['rawScores'];
Expand Down
15 changes: 13 additions & 2 deletions assess2/questions/ScoreEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class ScoreEngine
private $randWrapper;
private $userRights;
private $errors = array(); // Populated by this class' error handlers.
private $temp_func = array();

public function get_temp_func() {
return $this->temp_func;
}

public function __construct(PDO $dbh, Rand $randWrapper)
{
Expand Down Expand Up @@ -674,8 +679,11 @@ private function scorePartMultiPart(ScoreQuestionParams $scoreQuestionParams,

$raw[$partnum] = 0;
try {
$scorePart = ScorePartFactory::getScorePart($scoreQuestionParams);
$scorePartResult = $scorePart->getResult();
$scorePart = ScorePartFactory::getScorePart($scoreQuestionParams);
$scorePartResult = $scorePart->getResult();
//TESTING---------------------------------------------
$this->temp_func[] = array($inputReferenceNumber,$scorePart->get_student_function());

} catch (\Throwable $t) {
$this->addError(
_('Caught error while scoring parts in this question: ')
Expand Down Expand Up @@ -786,6 +794,9 @@ private function scorePartNonMultiPart(ScoreQuestionParams $scoreQuestionParams,
$scorePartResult = $scorePart->getResult();
$score = $scorePartResult->getRawScore();

//TESTING---------------------------------------------
$this->temp_func[] = array(27,$scorePart->get_student_function());

if (isset($scoremethod) && $scoremethod == "allornothing") {
if ($score < .98) {
$score = 0;
Expand Down
Loading