From b94c95e4c6a1a5b2793bf9b990f8dfc75fbd129b Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Thu, 17 Jul 2025 16:36:15 +0700 Subject: [PATCH 01/24] Test_function_list --- assessment/macros.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/assessment/macros.php b/assessment/macros.php index 6c6f226002..66705957e1 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -716,6 +716,17 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $commands = "setBorder(5); initPicture({$winxmin},{$winxmax},{$ymin},{$ymax});".$commands; $alt = "Graphing window shows horizontal axis: {$winxmin} to {$winxmax}, vertical axis: {$ymin} to {$ymax}. ".$alt; + // Adding function list to $commands(For testing purposes) + $function_names = []; + foreach ($funcs as $f) { + if ($f === '') continue; + $parts = explode(',', $f, 2); + $function_names[] = trim($parts[0]); + } + $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; + $commands = "var function_list = $function_list_str; " . $commands; + // + if ($_SESSION['graphdisp']==0) { return $alt; } else { From 57e5cb3cb81ef9e8207764f9c13b9421f25f57d9 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Thu, 17 Jul 2025 17:16:11 +0700 Subject: [PATCH 02/24] Changes to $commands --- assessment/macros.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/assessment/macros.php b/assessment/macros.php index 66705957e1..27b19dd36d 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -177,6 +177,16 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label //$alt = "Graph, window x {$settings[0]} to {$settings[1]}, y {$settings[2]} to {$settings[3]}."; $commands = ''; $alt = ''; + + //Adding function list to $commands + $function_names = []; + foreach ($funcs as $f) { + if ($f === '') continue; + $parts = explode(',', $f, 2); + $function_names[] = trim($parts[0]); + } + $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; + if (strpos($settings[4],':')) { $lbl = explode(':',$settings[4]); $lbl[0] = evalbasic($lbl[0], true, true); @@ -717,13 +727,6 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $alt = "Graphing window shows horizontal axis: {$winxmin} to {$winxmax}, vertical axis: {$ymin} to {$ymax}. ".$alt; // Adding function list to $commands(For testing purposes) - $function_names = []; - foreach ($funcs as $f) { - if ($f === '') continue; - $parts = explode(',', $f, 2); - $function_names[] = trim($parts[0]); - } - $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; $commands = "var function_list = $function_list_str; " . $commands; // From d08fe3d71ace81c5c9575f495afb3c6513cb375a Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Thu, 17 Jul 2025 17:21:28 +0700 Subject: [PATCH 03/24] Testing --- assessment/macros.php | 1 + 1 file changed, 1 insertion(+) diff --git a/assessment/macros.php b/assessment/macros.php index 27b19dd36d..c367003bb8 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -728,6 +728,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label // Adding function list to $commands(For testing purposes) $commands = "var function_list = $function_list_str; " . $commands; + $commands = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".$commands; // if ($_SESSION['graphdisp']==0) { From ecd4f79791aae6b9d3a92cfc803c0736fb07d6ad Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Thu, 17 Jul 2025 17:25:36 +0700 Subject: [PATCH 04/24] TEST --- assessment/macros.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assessment/macros.php b/assessment/macros.php index c367003bb8..0a6d8c7a72 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -728,7 +728,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label // Adding function list to $commands(For testing purposes) $commands = "var function_list = $function_list_str; " . $commands; - $commands = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".$commands; + // $commands = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".$commands; // if ($_SESSION['graphdisp']==0) { From 7f03741f26db8f95c715284fe60c116be4935abe Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Fri, 18 Jul 2025 11:12:25 +0700 Subject: [PATCH 05/24] Function change --- assessment/macros.php | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/assessment/macros.php b/assessment/macros.php index 0a6d8c7a72..3e9d4206e3 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -177,16 +177,6 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label //$alt = "Graph, window x {$settings[0]} to {$settings[1]}, y {$settings[2]} to {$settings[3]}."; $commands = ''; $alt = ''; - - //Adding function list to $commands - $function_names = []; - foreach ($funcs as $f) { - if ($f === '') continue; - $parts = explode(',', $f, 2); - $function_names[] = trim($parts[0]); - } - $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; - if (strpos($settings[4],':')) { $lbl = explode(':',$settings[4]); $lbl[0] = evalbasic($lbl[0], true, true); @@ -727,14 +717,21 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $alt = "Graphing window shows horizontal axis: {$winxmin} to {$winxmax}, vertical axis: {$ymin} to {$ymax}. ".$alt; // Adding function list to $commands(For testing purposes) - $commands = "var function_list = $function_list_str; " . $commands; - // $commands = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".$commands; + $function_names = []; + foreach ($funcs as $f) { + if ($f === '') continue; + $function_names[] = trim($f); + } + $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; + // $commands = "var function_list = $function_list_str; " . $commands; // + + if ($_SESSION['graphdisp']==0) { return $alt; } else { - return "\n"; + return "\n"; } } From 23a7c5c659283a5947f4baa16cb795ba4e0353e0 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 13:59:16 +0700 Subject: [PATCH 06/24] Beautify function --- assessment/macros.php | 1 + 1 file changed, 1 insertion(+) diff --git a/assessment/macros.php b/assessment/macros.php index 3e9d4206e3..a4e6a4ac49 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -723,6 +723,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_names[] = trim($f); } $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; + $function_list_str = makexxpretty($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; // From 5a1923cfc24d093d112c10bf171dbca4f72a5e68 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:12:05 +0700 Subject: [PATCH 07/24] Testing --- assessment/macros.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/assessment/macros.php b/assessment/macros.php index a4e6a4ac49..dd06b3313d 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -725,14 +725,13 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; $function_list_str = makexxpretty($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; - // - + $new_test_only = "THERE IS NOT NOTHING"; if ($_SESSION['graphdisp']==0) { return $alt; } else { - return "\n"; + return "\n"; } } From 73bd3b9dca0028e1f0e5146962406e994fc6ca6d Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:25:04 +0700 Subject: [PATCH 08/24] Beautify function --- assessment/macros.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/assessment/macros.php b/assessment/macros.php index dd06b3313d..f59a7ed1b6 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -723,15 +723,17 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_names[] = trim($f); } $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; + $function_list_str = makepretty($function_list_str); + $function_list_str = makexpretty($function_list_str); $function_list_str = makexxpretty($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; - $new_test_only = "THERE IS NOT NOTHING"; + $new_test_only = "THERE IS NOT NOT NOTHING"; if ($_SESSION['graphdisp']==0) { return $alt; } else { - return "\n"; + return "\n"; } } From 18cbadc14f66a911d1ead309ee9834a9ca539d58 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:33:21 +0700 Subject: [PATCH 09/24] Simplify function --- assessment/macros.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assessment/macros.php b/assessment/macros.php index f59a7ed1b6..943da7fac5 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -726,6 +726,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_list_str = makepretty($function_list_str); $function_list_str = makexpretty($function_list_str); $function_list_str = makexxpretty($function_list_str); + $function_list_str = calclisttoarray($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; $new_test_only = "THERE IS NOT NOT NOTHING"; @@ -733,7 +734,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label if ($_SESSION['graphdisp']==0) { return $alt; } else { - return "\n"; + return "\n"; } } From e29f691158ef0217f3b8bd749a5a235bba41e0fc Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:33:46 +0700 Subject: [PATCH 10/24] Simplify function --- assessment/macros.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assessment/macros.php b/assessment/macros.php index 943da7fac5..e55af0047f 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -728,7 +728,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_list_str = makexxpretty($function_list_str); $function_list_str = calclisttoarray($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; - $new_test_only = "THERE IS NOT NOT NOTHING"; + $new_test_only = "THERE Is NOTHING"; if ($_SESSION['graphdisp']==0) { From 5ec46846d840577506a92852c6de2d470d74dd45 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:55:10 +0700 Subject: [PATCH 11/24] Simplify function 2 --- assessment/macros.php | 1 - 1 file changed, 1 deletion(-) diff --git a/assessment/macros.php b/assessment/macros.php index e55af0047f..7227d52e81 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -726,7 +726,6 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_list_str = makepretty($function_list_str); $function_list_str = makexpretty($function_list_str); $function_list_str = makexxpretty($function_list_str); - $function_list_str = calclisttoarray($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; $new_test_only = "THERE Is NOTHING"; From fb24d33d9b4e9801b8a86ab744d4a99653b605b0 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:09:56 +0700 Subject: [PATCH 12/24] Delete test command --- assessment/macros.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/assessment/macros.php b/assessment/macros.php index 7227d52e81..596552a61f 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -723,17 +723,14 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_names[] = trim($f); } $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; - $function_list_str = makepretty($function_list_str); $function_list_str = makexpretty($function_list_str); $function_list_str = makexxpretty($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; - $new_test_only = "THERE Is NOTHING"; - if ($_SESSION['graphdisp']==0) { return $alt; } else { - return "\n"; + return "\n"; } } From 23a54b9e2ddb6a9dcd4b1cd84a39cc7f3ed3d704 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:48:53 +0700 Subject: [PATCH 13/24] change --- assessment/macros.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/assessment/macros.php b/assessment/macros.php index 596552a61f..bece67f059 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -723,14 +723,15 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_names[] = trim($f); } $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; + // $function_list_str = makepretty($function_list_str); $function_list_str = makexpretty($function_list_str); - $function_list_str = makexxpretty($function_list_str); + // $function_list_str = makexxpretty($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; if ($_SESSION['graphdisp']==0) { return $alt; } else { - return "\n"; + return "\n"; } } From 90cd6dd008fcfc890a7ef6c30932543d7dfa486f Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Tue, 29 Jul 2025 11:07:07 +0700 Subject: [PATCH 14/24] remove test --- assessment/macros.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assessment/macros.php b/assessment/macros.php index bece67f059..1a8a774d38 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -724,7 +724,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label } $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; // $function_list_str = makepretty($function_list_str); - $function_list_str = makexpretty($function_list_str); + // $function_list_str = makexpretty($function_list_str); // $function_list_str = makexxpretty($function_list_str); // $commands = "var function_list = $function_list_str; " . $commands; From f6863fa67f84edc2c6ca589282aeae9c629f58d2 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Mon, 4 Aug 2025 10:45:09 +0700 Subject: [PATCH 15/24] First test commit --- assessment/config.php | 89 +++++++++++++++++++++++++++++++++++++++++++ assessment/macros.php | 21 +++++++++- config.php | 19 ++++----- 3 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 assessment/config.php diff --git a/assessment/config.php b/assessment/config.php new file mode 100644 index 0000000000..36fb2c3004 --- /dev/null +++ b/assessment/config.php @@ -0,0 +1,89 @@ +setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); + $GLOBALS["DBH"] = $DBH; + } catch(PDOException $e) { + die("

Could not connect to database: " . $e->getMessage() . "

"); + } + $DBH->query("set session sql_mode=''"); + unset($dbserver); + unset($dbusername); + unset($dbpassword); + +?> \ No newline at end of file diff --git a/assessment/macros.php b/assessment/macros.php index 1a8a774d38..7c026e2afa 100644 --- a/assessment/macros.php +++ b/assessment/macros.php @@ -720,7 +720,24 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label $function_names = []; foreach ($funcs as $f) { if ($f === '') continue; - $function_names[] = trim($f); + $parts = explode(',', $f); + foreach ($parts as &$part){ + if(substr($part, 0, 1) === '[') { + $temp = '[' . makexxpretty(substr($part, 1)); + $part = $temp; + // $xtsddg = "a"; + } + else { + $part = makexxpretty($part); + } + // $part = makexxpretty($part); + $part = trim($part); + // error_log($part); + // error_log("HET"); + } + $new_f = implode(',', $parts); + $function_names[] = trim($new_f); + } $function_list_str = '["' . implode('","', array_map('addslashes', $function_names)) . '"]'; // $function_list_str = makepretty($function_list_str); @@ -731,7 +748,7 @@ function showplot($funcs) { //optional arguments: $xmin,$xmax,$ymin,$ymax,label if ($_SESSION['graphdisp']==0) { return $alt; } else { - return "\n"; + return "\n"; } } diff --git a/config.php b/config.php index 33a65a6813..24694f0ac8 100644 --- a/config.php +++ b/config.php @@ -3,7 +3,7 @@ //database access settings $dbserver = "host.docker.internal"; -$dbname = "imathasdb"; +$dbname = "imathas"; $dbusername = "root"; $dbpassword = "123456"; @@ -55,17 +55,17 @@ //use more secure password hashes? requires PHP 5.3.7+ $CFG['GEN']['newpasswords'] = 'only'; -//session path -//$sessionpath = ""; +//session path +//$sessionpath = ""; + +//Amazon S3 access for file upload -//Amazon S3 access for file upload +//$AWSkey = ""; -//$AWSkey = ""; - -//$AWSsecret = ""; - -//$AWSbucket = ""; +//$AWSsecret = ""; +//$AWSbucket = ""; + //Uncomment to change the default course theme, also used on the home & admin page: //$defaultcoursetheme = "default.css" @@ -82,6 +82,7 @@ die("

Could not connect to database: " . $e->getMessage() . "

"); } $DBH->query("set session sql_mode=''"); + unset($dbserver); unset($dbusername); unset($dbpassword); From 7a066089964d88feb8c0628de000abdb2c14fb1d Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Tue, 19 Aug 2025 10:46:20 +0700 Subject: [PATCH 16/24] Answer function format --- assess2/AssessStandalone.php | 6 + assess2/questions/ScoreEngine.php | 15 +- .../questions/scorepart/DrawingScorePart.php | 144 +++++++- .../scorepart/convert_ans_to_str.php | 335 ++++++++++++++++++ new_return_class.php | 12 + scores.php | 1 + test_file.php | 68 ++++ 7 files changed, 578 insertions(+), 3 deletions(-) create mode 100644 assess2/questions/scorepart/convert_ans_to_str.php create mode 100644 new_return_class.php create mode 100644 test_file.php diff --git a/assess2/AssessStandalone.php b/assess2/AssessStandalone.php index 42b31d0653..06aeba168a 100644 --- a/assess2/AssessStandalone.php +++ b/assess2/AssessStandalone.php @@ -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 @@ -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']; diff --git a/assess2/questions/ScoreEngine.php b/assess2/questions/ScoreEngine.php index b21a304dff..1b9a44b863 100644 --- a/assess2/questions/ScoreEngine.php +++ b/assess2/questions/ScoreEngine.php @@ -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) { @@ -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: ') @@ -786,6 +794,9 @@ private function scorePartNonMultiPart(ScoreQuestionParams $scoreQuestionParams, $scorePartResult = $scorePart->getResult(); $score = $scorePartResult->getRawScore(); + //TESTING--------------------------------------------- + $this->temp_func[] = $scorePart->get_student_function(); + if (isset($scoremethod) && $scoremethod == "allornothing") { if ($score < .98) { $score = 0; diff --git a/assess2/questions/scorepart/DrawingScorePart.php b/assess2/questions/scorepart/DrawingScorePart.php index ec7433ad13..84cbd3be2d 100644 --- a/assess2/questions/scorepart/DrawingScorePart.php +++ b/assess2/questions/scorepart/DrawingScorePart.php @@ -4,6 +4,7 @@ require_once __DIR__ . '/ScorePart.php'; require_once __DIR__ . '/../models/ScorePartResult.php'; +require_once 'convert_ans_to_str.php'; use IMathAS\assess2\questions\models\ScorePartResult; use IMathAS\assess2\questions\models\ScoreQuestionParams; @@ -11,6 +12,12 @@ class DrawingScorePart implements ScorePart { private $scoreQuestionParams; + private $stu_func_ans =[]; + + public function get_student_function(){ + // error_log(json_encode($this->stu_func_ans)); + return $this->stu_func_ans; + } public function __construct(ScoreQuestionParams $scoreQuestionParams) { @@ -129,6 +136,9 @@ public function getResult(): ScorePartResult $xtopix = my_create_function('$x',"return ((\$x - ({$settings[0]}))*($pixelsperx) + ($imgborder));"); $ytopix = my_create_function('$y',"return (({$settings[7]}) - (\$y- ({$settings[2]}))*($pixelspery) - ($imgborder));"); + $pixtox = my_create_function('$px', "return ((\$px - ($imgborder)) / ($pixelsperx) + ({$settings[0]}));"); + $pixtoy = my_create_function('$py', "return (({$settings[7]} - (\$py + ($imgborder))) / ($pixelspery) + ({$settings[2]}));"); + $anslines = array(); $ansdots = array(); $ansodots = array(); @@ -185,6 +195,12 @@ public function getResult(): ScorePartResult foreach ($line as $j=>$pt) { $line[$j] = explode(',',$pt); } + + for($i = 0; $i < count($line) - 1; $i++){ + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($line[$i][0],$line[$i][1],$line[$i+1][0],$line[$i+1][1],$answerformat[0]), $pixtox, $pixtoy, "line"); + } + if ($isclosed && ($line[0][0]-$line[count($line)-1][0])*($line[0][0]-$line[count($line)-1][0]) + ($line[0][1]-$line[count($line)-1][1])*($line[0][1]-$line[count($line)-1][1]) <=25*max(1,$reltolerance)) { array_pop($line); $stuclosed = true; @@ -245,6 +261,11 @@ public function getResult(): ScorePartResult } //echo "Vals score: $vals, adj score: $adjv.

"; + // for ($i = 0; $i < count($stu_func_ans); $i++) { + // echo (implode(",", $stu_func_ans[$i])); + // } + // error_log(json_encode($stu_func_ans)); + if ($abstolerance !== '') { if ($totscore<$abstolerance) { $scorePartResult->setRawScore(0); @@ -738,11 +759,23 @@ public function getResult(): ScorePartResult $lines[] = array('y',$slope,$pts[2]+($x2p-$pts[1])*$slope); } } + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "lines"); + } else if ($pts[0]==5.2) { + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],'r'), $pixtox, $pixtoy, "vecs"); + $vecs[] = array($pts[1],$pts[2],$pts[3],$pts[4],'r'); } else if ($pts[0]==5.3) { + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],'ls'), $pixtox, $pixtoy, "vecs"); + $vecs[] = array($pts[1],$pts[2],$pts[3],$pts[4],'ls'); } else if ($pts[0]==5.4) { + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],'v'), $pixtox, $pixtoy, "vecs"); + $vecs[] = array($pts[1],$pts[2],$pts[3],$pts[4],'v'); } else if ($pts[0]==6 || $pts[0] == 6.2) { $leftrightdir = ''; @@ -760,6 +793,10 @@ public function getResult(): ScorePartResult $a = ($pts[4]-$pts[2])/(($pts[3]-$pts[1])*($pts[3]-$pts[1])); $y = $pts[2]+$a*400; $x = $pts[1]+sign($a)*sqrt(abs(20/$a)); + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "parabs"); + $parabs[] = array($pts[1],$pts[2],$y,$x,$leftrightdir); } } else if ($pts[0]==6.1) { @@ -770,6 +807,10 @@ public function getResult(): ScorePartResult $a = ($pts[3]-$pts[1])/(($pts[4]-$pts[2])*($pts[4]-$pts[2])); $x = $pts[1]+$a*400; $y = $pts[2]+sign($a)*sqrt(abs(20/$a)); + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "hparabs"); + $hparabs[] = array($pts[1],$pts[2],$y,$x); } } else if ($pts[0]==6.5) {//sqrt @@ -779,6 +820,10 @@ public function getResult(): ScorePartResult $secxp = $pts[1] + ($x4p-$x0p)/5*$flip; //over 1/5 of grid width $secyp = $stretch*sqrt($flip*($secxp - $pts[1]))+($pts[2]); + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "sqrts"); + $sqrts[] = array($pts[1],$pts[2],$secyp,$flip); } } else if ($pts[0]==6.3) { @@ -788,6 +833,10 @@ public function getResult(): ScorePartResult } else if ($pts[3]!=$pts[1]) { //this is the cube root of the stretch factor $a = safepow($pts[4]-$pts[2], 1/3)/($pts[3]-$pts[1]); + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "cubics"); + $cubics[] = array($pts[1],$pts[2], $a); } } else if ($pts[0]==6.6) { @@ -796,21 +845,40 @@ public function getResult(): ScorePartResult $lines[] = array('y',0,$pts[4]); } else if ($pts[3]!=$pts[1]) { $a = safepow($pts[4]-$pts[2],3)/($pts[3]-$pts[1]); + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "cuberoots"); + $cuberoots[] = array($pts[1],$pts[2],$a); } } else if ($pts[0]==7) { //circle $rad = sqrt(($pts[3]-$pts[1])*($pts[3]-$pts[1]) + ($pts[4]-$pts[2])*($pts[4]-$pts[2])); //$circs[] = array($pts[1],$pts[2],$rad); + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "circs"); + $ellipses[] = array($pts[1],$pts[2],$rad,$rad); } else if ($pts[0]==7.2) { //ellipse + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "ellipses"); + $ellipses[] = array($pts[1],$pts[2],abs($pts[3]-$pts[1]),abs($pts[4]-$pts[2])); } else if ($pts[0]==7.4) { //vert hyperbola + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "vhyperbolas"); + $hyperbolas[] = array($pts[1],$pts[2],abs($pts[3]-$pts[1]),abs($pts[4]-$pts[2]),'vert'); } else if ($pts[0]==7.5) { //horiz hyperbola + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "hhyperbolas"); + $hyperbolas[] = array($pts[1],$pts[2],abs($pts[3]-$pts[1]),abs($pts[4]-$pts[2]),'horiz'); } else if ($pts[0]==8) { //abs @@ -826,6 +894,9 @@ public function getResult(): ScorePartResult $slope *= -1; } } + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "abs"); + $abs[] = array($pts[1],$pts[2], $slope); } else if ($pts[0]==8.3 || $pts[0]==8.5) { if ($pts[0]==8.3) { @@ -850,6 +921,14 @@ public function getResult(): ScorePartResult $str = $adjy2/safepow($base,$Lx2p-$xop); } //$exps[] = array($str,$base); + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + if ($pts[0]==8.5) { + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0], $xop, $yop), $pixtox, $pixtoy, "exps"); + } + else { + //Does not use $pts[5] ans $pts[6] + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],0,0,$pts[0], $xop, $yop), $pixtox, $pixtoy, "exps"); + } $exps[] = array($Lx1p-$xop, $adjy1, $Lx2p-$xop, $adjy2, $base, $horizasy); } } else if ($pts[0]==8.4 || $pts[0]==8.6) { @@ -873,12 +952,25 @@ public function getResult(): ScorePartResult } else { $str = $adjx2/safepow($base,$Ly2p-$yop); } + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + if ($pts[0]==8.6) { + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0], $xop, $yop), $pixtox, $pixtoy, "logs"); + } + else { + //Does not use $pts[5] ans $pts[6] + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],0,0,$pts[0], $xop, $yop), $pixtox, $pixtoy, "logs"); + } + $logs[] = array($Ly1p-$yop, $adjx1, $Ly2p-$yop, $adjx2, $base, $vertasy); } } else if ($pts[0]==8.2) { //rational if ($pts[1]!=$pts[3] && $pts[2]!=$pts[4]) { $stretch = ($pts[3]-$pts[1])*($pts[4]-$pts[2]); $yp = $pts[2]+(($stretch>0)?1:-1)*sqrt(abs($stretch)); + + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "rats"); $rats[] = array($pts[1],$pts[2],$yp); } @@ -887,9 +979,18 @@ public function getResult(): ScorePartResult $pts[1] -= ($pts[3] - $pts[1]); $pts[2] -= ($pts[4] - $pts[2]); } + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "coss"); + if ($pts[4]>$pts[2]) { + // //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + // $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "coss"); + $coss[] = array($pts[3],$pts[1],$pts[4],$pts[2]); } else { + // //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + // $this->stu_func_ans[] = convert_to_str_ans(array($pts[3],$pts[4],$pts[1],$pts[2]), $pixtox, $pixtoy, "coss"); + + $coss[] = array($pts[1],$pts[3],$pts[2],$pts[4]); } } @@ -901,6 +1002,8 @@ public function getResult(): ScorePartResult $dots = explode('),(', substr($dots,1,strlen($dots)-2)); foreach ($dots as $k=>$pt) { $dots[$k] = explode(',',$pt); + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($dots[$k][0], $dots[$k][1], 0, 0), $pixtox, $pixtoy, "dots"); } } if ($odots=='') { @@ -909,6 +1012,8 @@ public function getResult(): ScorePartResult $odots = explode('),(', substr($odots,1,strlen($odots)-2)); foreach ($odots as $k=>$pt) { $odots[$k] = explode(',',$pt); + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($odots[$k][0], $odots[$k][1], 0, 0), $pixtox, $pixtoy, "odots"); } } @@ -1256,6 +1361,7 @@ public function getResult(): ScorePartResult break; } } + $usedcubic = []; foreach ($anscubics as $key=>$anscubic) { $scores[$scoretype[$key]][$key] = 0; @@ -1275,6 +1381,7 @@ public function getResult(): ScorePartResult break; } } + //print_r($anscuberoots); //print_r($cuberoots); $usedcuberoot = []; @@ -1296,6 +1403,7 @@ public function getResult(): ScorePartResult break; } } + $usedsqrt = []; foreach ($anssqrts as $key=>$anssqrt) { $scores[$scoretype[$key]][$key] = 0; @@ -1318,6 +1426,7 @@ public function getResult(): ScorePartResult break; } } + $usedrat = []; foreach ($ansrats as $key=>$ansrat) { $scores[$scoretype[$key]][$key] = 0; @@ -1337,8 +1446,8 @@ public function getResult(): ScorePartResult break; } } - $usedexp = []; + $usedexp = []; foreach ($ansexps as $key=>$ansexp) { $scores[$scoretype[$key]][$key] = 0; for ($i=0; $i$anslog) { $scores[$scoretype[$key]][$key] = 0; @@ -1393,6 +1503,7 @@ public function getResult(): ScorePartResult break; } } + $usedcos = []; foreach ($anscoss as $key=>$anscos) { $scores[$scoretype[$key]][$key] = 0; @@ -1421,6 +1532,7 @@ public function getResult(): ScorePartResult break; } } + $usedabs = []; foreach ($ansabs as $key=>$aabs) { $scores[$scoretype[$key]][$key] = 0; @@ -1442,6 +1554,12 @@ public function getResult(): ScorePartResult break; } } + + // for ($i = 0; $i < count($stu_func_ans); $i++) { + // echo (implode(",", $stu_func_ans[$i])); + // } + // error_log(json_encode($stu_func_ans)); + //extra stuff is total count of drawn items - # of scored items - # of correct optional items $extrastuffpenalty = max((count($tplines)+count($dots)+count($odots)-count($scores[0])-array_sum($scores[1]))/(max(count($scores[0]),count($tplines)+count($dots)+count($odots))),0); // don't need optional scores anymore @@ -1540,6 +1658,8 @@ public function getResult(): ScorePartResult $ineqlines = explode('),(', substr($ineqlines,1,strlen($ineqlines)-2)); foreach ($ineqlines as $k=>$val) { $pts = explode(',',$val); + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0]), $pixtox, $pixtoy, "ineqlines"); if($pts[0]<10.3){//linear if ($pts[3]==$pts[1]) { $slope = 10000; @@ -1578,6 +1698,7 @@ public function getResult(): ScorePartResult } else { $dir = '>'; } + $ineqlines[$k] = array('y',$dir,$pts[0],$aUser,$pts[1],$pts[2]); } } else { //abs @@ -1601,6 +1722,11 @@ public function getResult(): ScorePartResult $deftol = .1; $defpttol = 5; + // for ($i = 0; $i < count($stu_func_ans); $i++) { + // echo (implode(",", $stu_func_ans[$i])); + // } + // error_log(json_encode($stu_func_ans)); + foreach ($anslines as $key=>$ansline) { $scores[$key] = 0; for ($i=0; $istu_func_ans[] = convert_to_str_ans(array($minp[0], $minp[1],$maxp[0],$maxp[1]), $pixtox, $pixtoy, "line1d"); + $lines[$k] = array(min($minp[0], $maxp[0]), max($minp[0], $maxp[0])); } $newlines = array($lines[0]); @@ -1751,6 +1882,8 @@ public function getResult(): ScorePartResult $dots = explode('),(', substr($dots,1,strlen($dots)-2)); foreach ($dots as $k=>$pt) { $dots[$k] = explode(',',$pt); + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($dots[$k][0], $dots[$k][1], 0, 0), $pixtox, $pixtoy, "dots1d"); } //remove duplicate dots for ($k=count($dots)-1;$k>=0;$k--) { @@ -1773,6 +1906,8 @@ public function getResult(): ScorePartResult $odots = explode('),(', substr($odots,1,strlen($odots)-2)); foreach ($odots as $k=>$pt) { $odots[$k] = explode(',',$pt); + //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ + $this->stu_func_ans[] = convert_to_str_ans(array($odots[$k][0], $odots[$k][1], 0, 0), $pixtox, $pixtoy, "odots1d"); } //remove duplicate odots, and dots below odots for ($k=count($odots)-1;$k>=0;$k--) { @@ -1795,6 +1930,12 @@ public function getResult(): ScorePartResult } } } + + // for ($i = 0; $i < count($stu_func_ans); $i++) { + // echo (implode(",", $stu_func_ans[$i])); + // } + // error_log(json_encode($stu_func_ans)); + $scores = array(); if ((count($dots)+count($odots))==0) { $extradots = 0; @@ -1811,6 +1952,7 @@ public function getResult(): ScorePartResult } } } + foreach ($ansodots as $key=>$ansodot) { $scores[$key] = 0; foreach ($odots as $i=>$godot) { diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php new file mode 100644 index 0000000000..6b0df295e8 --- /dev/null +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -0,0 +1,335 @@ + %f, ", $mh, $mx); + if($ans_info[4] == "closedpolygon"){ + $l_type = "closed polygon"; + } + else { + $l_type = "polygon"; + } + $ans = sprintf("This %s includes a line: y = %f * x + %f from %s", $l_type, $ma, $mb, $l_range); + + return array($ans); + } + + elseif ($type == "vecs") { + if($ans_info[4] === 'r') { + $v_type = "ray"; + $v_range = sprintf("x = %f, ", $mh); + } + elseif ($ans_info[4] === 'ls') { + $v_type = "line segment"; + $v_range = sprintf("x = %f -> %f, ", $mh, $mx); + } + else { + $v_type = "vector"; + $v_range = sprintf("x = %f -> %f, ", $mh, $mx); + } + $ma = ($my - $mk) / ($mx - $mh); + $mb = $mk - ($ma * $mh); + + $ans = sprintf("This includes a %s function: y = %f * x + %f from %s", $v_type, $ma, $mb, $v_range); + + return array($ans); + } + + elseif ($type == "circs") { + $ma = floatval(($mx - $mh)*($mx - $mh) + ($my-$mk)*($my-$mk)); + $ans = sprintf("This includes function: (x-%f)^2 + (y-%f)^2 = %f", $mh, $mk, $ma); + + return array($ans); + } + + elseif ($type == "parabs") { + $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); + $ans = sprintf("This includes function: y = %f * (x - %f)^2 + %f", $ma, $mh, $mk); + + return array($ans); + } + + elseif ($type == "hparabs") { + $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); + $ans = sprintf("This includes function: x = %f * (y - %f)^2 + %f", $ma, $mh, $mk); + + return array($ans); + } + + elseif ($type == "sqrts") { + $flip = ($mx < $mh) ? -1 : 1; + + $ma = floatval(($my - $mk) / sqrt($flip * ($mx - $mh))); + $ans = sprintf("This includes function: y = %f * sqrt(x - %f) + %f", $ma, $mh, $mk); + + return array($ans); + } + + elseif ($type == "cubics") { + $ma = floatval(safepow($my-$mk, 1/3)/($mx-$mh)); + $ans = sprintf("This includes function: y = %f * (x - %f)^3 + %f", $ma, $mh, $mk); + return array($ans); + } + + elseif ($type == "cuberoots") { + $ma = floatval(safepow($my-$mk, 3)/($mx-$mh)); + $ans = sprintf("This includes function: x = (1 / %f) * (y - %f)^3 + %f", $ma, $mk, $mh); + return array($ans); + } + + elseif ($type == "ellipses") { + $ma = floatval(abs($mx - $mh)); + $mb = floatval(abs($my - $mk)); + + $ans = sprintf("This includes function: ((1/%f)*(x-%f))^2 + ((1/%f)(y-%f))^2 = 1", $ma, $mh, $mb, $mk); + + return array($ans); + } + + elseif ($type == "hhyperbolas") { + $ma = floatval(abs($mx - $mh)); + $mb = floatval(abs($my - $mk)); + + $ans = sprintf("This includes function: ((1/%f)*(x-%f))^2 - ((1/%f)(y-%f))^2 = 1", $ma, $mh, $mb, $mk); + + return array($ans); + } + + elseif ($type == "vhyperbolas") { + $ma = floatval(abs($mx - $mh)); + $mb = floatval(abs($my - $mk)); + + $ans = sprintf("This includes function: ((1/%f)(y-%f))^2 - ((1/%f)*(x-%f))^2 = 1", $mb, $mk, $ma, $mh); + + return array($ans); + } + + elseif ($type == "abs") { + if ($mh==$mx) { + $ma = 0; + } else { + $ma = ($my-$mk)/($mx-$mh); + if ($mh > $mx) { + $ma *= -1; + } + } + + $ans = sprintf("This includes function: y = %f * abs(x-%f) + %f", $ma, $mh, $mk); + + return array($ans); + } + + elseif ($type == "exps") { + $m4 = $pixtox(floatval($ans_info[4])); + $m5 = $pixtoy(floatval($ans_info[5])); + $xop = $pixtox(floatval($ans_info[7])); + $yop = $pixtoy(floatval($ans_info[8])); + + if ($ans_info[6] == 8.3) { + $horizasy = $yop; + $adjy2 = $horizasy - $my; + $adjy1 = $horizasy - $mk; + $Lx1p = $mh; + $Lx2p = $mx; + } else if ($ans_info[6]==8.5) { + $horizasy = $mk; + $adjy2 = $horizasy - $m5; + $adjy1 = $horizasy - $my; + $Lx1p = $mx; + $Lx2p = $m4; + } + if ($adjy1*$adjy2>0 && $Lx1p!=$Lx2p) { + $base = safepow($adjy2/$adjy1,1/($Lx2p-$Lx1p)); + if (abs($Lx1p-$xop)0 && $Ly1p!=$Ly2p) { + $base = safepow($adjx2/$adjx1,1/($Ly2p-$Ly1p)); + if (abs($pts[2]-$yop) $mh) { + $l_dir = '<'; + } + else { + $l_dir = '>'; + } + $ans = sprintf("This includes function: x %s%s %f", $l_dir, $l_drt, $mh); + + return array($ans); + } + + $ma = ($my - $mk) / ($mx - $mh); + $ynew = $ma * ($mx2 - $mh) + $mk; + if ($my2 < $ynew) { + $l_dir = '<'; + } + else { + $l_dir = '>'; + } + $ans = sprintf("This includes function: y %s%s %f * (x - %f) + %f", $l_dir, $l_drt, $ma, $mh, $mk); + + return array($ans); + } + elseif ($in_type < floatval(10.5)) { + $ma = ($my - $mk) / (($mx - $mh) * ($mx - $mh)); + $ynew = $ma * ($mx2 - $mh) * ($mx2 - $mh) + $mk; + if($my2 < $ynew) { + $l_dir = '<'; + } + else { + $l_dir = '>'; + } + if($in_type === floatval(10.3)) { + $l_drt = '='; + } + $ans = sprintf("This includes function: y %s%s %f * (x - %f)^2 + %f", $l_dir, $l_drt, $ma, $mh, $mk); + + return array($ans); + } + else { + $ma = ($my - $mk) / ($mx - $mh); + if ($mx < $mh) { + $ma *= -1; + } + + $ynew = $ma * abs($mx2 - $mh) + $mk; + if($my2 < $ynew) { + $l_dir = '<'; + } + else { + $l_dir = '>'; + } + if($in_type === floatval(10.5)) { + $l_drt = '='; + } + else { + $l_drt = ''; + } + $ans = sprintf("This includes function: y %s%s %f * abs(x - %f) + %f", $l_dir, $l_drt, $ma, $mh, $mk); + + return array($ans); + } + } + + elseif ($type == "line1d") { + $head = min($mh, $mx); + $tail = max($mh, $mx); + $ans = sprintf("There is a line from: %f to %f", $head, $tail); + + return array($ans); + } + + elseif ($type == "dots1d") { + $ans = sprintf("There is a dot at: %f", $mh); + + return array($ans); + } + + elseif ($type == "odots1d") { + $ans = sprintf("There is an open dot at: %f", $mh); + + return array($ans); + } +} + diff --git a/new_return_class.php b/new_return_class.php new file mode 100644 index 0000000000..a03c44ddf8 --- /dev/null +++ b/new_return_class.php @@ -0,0 +1,12 @@ +id = "qn" . strval($id); + $this->valuef = $valuef; + } +} \ No newline at end of file diff --git a/scores.php b/scores.php index 91520f4717..3b6de8da32 100644 --- a/scores.php +++ b/scores.php @@ -48,6 +48,7 @@ function getPost($key, $default = "") { } $result = $a2->scoreQuestion($qn, $parts_to_score); + // $student_func = $a2->get_student_func(); // Send response header('Content-Type: application/json'); diff --git a/test_file.php b/test_file.php new file mode 100644 index 0000000000..587578a093 --- /dev/null +++ b/test_file.php @@ -0,0 +1,68 @@ +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) { + error_log("AAAAAbbbAAA"); + $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']); +} \ No newline at end of file From 16936ad305e2f49c046e26e1a205d7d6ad441673 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Wed, 20 Aug 2025 11:21:23 +0700 Subject: [PATCH 17/24] Fix signs --- .../scorepart/convert_ans_to_str.php | 306 ++++++++++++++++-- 1 file changed, 279 insertions(+), 27 deletions(-) diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php index 6b0df295e8..8d6268bddc 100644 --- a/assess2/questions/scorepart/convert_ans_to_str.php +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -18,7 +18,13 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { else { $l_type = "polygon"; } - $ans = sprintf("This %s includes a line: y = %f * x + %f from %s", $l_type, $ma, $mb, $l_range); + if ($mb >= 0) { + $sign1 = "+"; + } else { + $sign1 = "-"; + $mb = abs($mb); + } + $ans = sprintf("This %s includes a line: y = %f * x %s %f from %s", $l_type, $ma, $sign1, $mb, $l_range); return array($ans); } @@ -38,59 +44,157 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } $ma = ($my - $mk) / ($mx - $mh); $mb = $mk - ($ma * $mh); - - $ans = sprintf("This includes a %s function: y = %f * x + %f from %s", $v_type, $ma, $mb, $v_range); + if ($mb >= 0) { + $sign1 = "+"; + } else { + $sign1 = "-"; + $mb = abs($mb); + } + $ans = sprintf("This includes a %s function: y = %f * x %s %f from %s", $v_type, $ma, $sign1, $mb, $v_range); return array($ans); } elseif ($type == "circs") { $ma = floatval(($mx - $mh)*($mx - $mh) + ($my-$mk)*($my-$mk)); - $ans = sprintf("This includes function: (x-%f)^2 + (y-%f)^2 = %f", $mh, $mk, $ma); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + if ($mk >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $mk = abs($mk); + } + $ans = sprintf("This includes function: (x %s %f)^2 + (y %s %f)^2 = %f", $sign1, $mh, $sign2, $mk, $ma); return array($ans); } elseif ($type == "parabs") { $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); - $ans = sprintf("This includes function: y = %f * (x - %f)^2 + %f", $ma, $mh, $mk); + + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: y = %f * (x %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); return array($ans); } elseif ($type == "hparabs") { $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); - $ans = sprintf("This includes function: x = %f * (y - %f)^2 + %f", $ma, $mh, $mk); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: x = %f * (y %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); return array($ans); } elseif ($type == "sqrts") { - $flip = ($mx < $mh) ? -1 : 1; - $ma = floatval(($my - $mk) / sqrt($flip * ($mx - $mh))); - $ans = sprintf("This includes function: y = %f * sqrt(x - %f) + %f", $ma, $mh, $mk); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = ""; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: y = %f * sqrt(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); return array($ans); } elseif ($type == "cubics") { $ma = floatval(safepow($my-$mk, 1/3)/($mx-$mh)); - $ans = sprintf("This includes function: y = %f * (x - %f)^3 + %f", $ma, $mh, $mk); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: y = %f * (x %s %f)^3 %s %f", $ma, $sign1, $mh, $sign2, $mk); return array($ans); } elseif ($type == "cuberoots") { $ma = floatval(safepow($my-$mk, 3)/($mx-$mh)); - $ans = sprintf("This includes function: x = (1 / %f) * (y - %f)^3 + %f", $ma, $mk, $mh); + if ($mh >= 0) { + $sign1 = "+"; + } else { + $sign1 = ""; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $mk = abs($mk); + } + $ans = sprintf("This includes function: x = (1 / %f) * (y %s %f)^3 %s %f", $ma, $sign2, $mk, $sign1, $mh); return array($ans); } elseif ($type == "ellipses") { $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } - $ans = sprintf("This includes function: ((1/%f)*(x-%f))^2 + ((1/%f)(y-%f))^2 = 1", $ma, $mh, $mb, $mk); + if ($mk >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: ((1 / %f) * (x %s %f))^2 + ((1 / %f) * (y %s %f))^2 = 1", $ma, $sign1, $mh, $mb, $sign2, $mk); return array($ans); } @@ -98,8 +202,21 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "hhyperbolas") { $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $mk = abs($mk); + } - $ans = sprintf("This includes function: ((1/%f)*(x-%f))^2 - ((1/%f)(y-%f))^2 = 1", $ma, $mh, $mb, $mk); + $ans = sprintf("This includes function: ((1 / %f) * (x %s %f))^2 - ((1 / %f) * (y %s %f))^2 = 1", $ma, $sign1, $mh, $mb, $sign2, $mk); return array($ans); } @@ -108,7 +225,21 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); - $ans = sprintf("This includes function: ((1/%f)(y-%f))^2 - ((1/%f)*(x-%f))^2 = 1", $mb, $mk, $ma, $mh); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: ((1 / %f) * (y %s %f))^2 - ((1 / %f) * (x %s %f))^2 = 1", $mb, $sign2, $mk, $ma, $sign1, $mh); return array($ans); } @@ -123,7 +254,21 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } } - $ans = sprintf("This includes function: y = %f * abs(x-%f) + %f", $ma, $mh, $mk); + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: y = %f * abs(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); return array($ans); } @@ -154,10 +299,23 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } else { $str = $adjy2/safepow($base,$Lx2p-$xop); } - // if($mk < 0) { $str *= -1; - // } - $ans = sprintf("This includes function: y = %f + %f * %f^(x - %f)", $horizasy, $str, $base, $xop); + + if ($str >= 0) { + $sign1 = "+"; + } else { + $sign1 = "-"; + $str = abs($str); + } + + if ($xop >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $xop = abs($xop); + } + + $ans = sprintf("This includes function: y = %f %s %f * %f^(x %s %f)", $horizasy, $sign1, $str, $base, $sign2, $xop); return array($ans); } @@ -189,10 +347,23 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } else { $str = $adjx2/safepow($base,$Ly2p-$yop); } - // if($mk < 0) { $str *= -1; - // } - $ans = sprintf("This includes function: x = %f + %f * %f^(y - %f)", $vertasy, $str, $base, $yop); + + if ($str >= 0) { + $sign1 = "+"; + } else { + $sign1 = "-"; + $str = abs($str); + } + + if ($yop >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $yop = abs($yop); + } + + $ans = sprintf("This includes function: x = %f %s %f * %f^(y %s %f)", $vertasy, $isgn1, $str, $base, $sign2, $yop); return array($ans); } @@ -200,7 +371,22 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "rats") { $ma = ($mx-$mh)*($my-$mk); - $ans = sprintf("This includes function: y = %f + %f / (x - %f)", $mk, $ma, $mh); + + if ($ma >= 0) { + $sign1 = "+"; + } else { + $sign1 = "-"; + $ma = abs($ma); + } + + if ($mh >= 0) { + $sign2 = "-"; + } else { + $sign2 = "+"; + $mh = abs($mh); + } + + $ans = sprintf("This includes function: y = %f %s %f / (x %s %f)", $mk, $sign1, $ma, $sign2, $mh); return array($ans); } @@ -211,7 +397,21 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $mc = max($mx,$mh); $md = ($my + $mk) / 2; - $ans = sprintf("This includes function: y = %f + %f * cos(%f * (x - %f))", $md, $ma, $mb, $mc); + if ($mc >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mc = abs($mc); + } + + if ($ma >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $ma = abs($ma); + } + + $ans = sprintf("This includes function: y = %f %s %f * cos(%f * (x - %f))", $md, $sign2, $ma, $mb, $sign1, $mc); return array($ans); } @@ -220,7 +420,14 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $ma = ($my - $mk) / ($mx - $mh); $mb = $mk - ($ma * $mh); - $ans = sprintf("This includes function: y = %f * x + %f", $ma, $mb); + if ($mb >= 0) { + $sign1 = "+"; + } else { + $sign1 = "-"; + $mb = abs($mb); + } + + $ans = sprintf("This includes function: y = %f * x %s %f", $ma, $sign1, $mb); return array($ans); } @@ -267,7 +474,22 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { else { $l_dir = '>'; } - $ans = sprintf("This includes function: y %s%s %f * (x - %f) + %f", $l_dir, $l_drt, $ma, $mh, $mk); + + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: y %s%s %f * (x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); return array($ans); } @@ -283,7 +505,22 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { if($in_type === floatval(10.3)) { $l_drt = '='; } - $ans = sprintf("This includes function: y %s%s %f * (x - %f)^2 + %f", $l_dir, $l_drt, $ma, $mh, $mk); + + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: y %s%s %f * (x %s %f)^2 + %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); return array($ans); } @@ -306,7 +543,22 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { else { $l_drt = ''; } - $ans = sprintf("This includes function: y %s%s %f * abs(x - %f) + %f", $l_dir, $l_drt, $ma, $mh, $mk); + + if ($mh >= 0) { + $sign1 = "-"; + } else { + $sign1 = "+"; + $mh = abs($mh); + } + + if ($mk >= 0) { + $sign2 = "+"; + } else { + $sign2 = "-"; + $mk = abs($mk); + } + + $ans = sprintf("This includes function: y %s%s %f * abs(x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); return array($ans); } From 45a9ec83d278978c69b02f2735279ef55cc757ea Mon Sep 17 00:00:00 2001 From: Themid1 Date: Thu, 21 Aug 2025 12:40:44 +0700 Subject: [PATCH 18/24] Shorten sign fix --- .../scorepart/convert_ans_to_str.php | 298 ++++-------------- 1 file changed, 65 insertions(+), 233 deletions(-) diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php index 8d6268bddc..a2d498f541 100644 --- a/assess2/questions/scorepart/convert_ans_to_str.php +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -1,6 +1,26 @@ = 0) { + $sign = "+"; + } else { + $sign = "-"; + $num = abs($num); + } + return [$num, $sign]; +} + +function minus_sign($num, $sign) { + if ($num >= 0) { + $sign = "-"; + } else { + $sign = "+"; + $num = abs($num); + } + return [$num, $sign]; +} + function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $mh = $pixtox(floatval($ans_info[0])); @@ -18,12 +38,9 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { else { $l_type = "polygon"; } - if ($mb >= 0) { - $sign1 = "+"; - } else { - $sign1 = "-"; - $mb = abs($mb); - } + + list($mb, $sign1) = add_sign($mb, $sign1); + $ans = sprintf("This %s includes a line: y = %f * x %s %f from %s", $l_type, $ma, $sign1, $mb, $l_range); return array($ans); @@ -44,12 +61,9 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } $ma = ($my - $mk) / ($mx - $mh); $mb = $mk - ($ma * $mh); - if ($mb >= 0) { - $sign1 = "+"; - } else { - $sign1 = "-"; - $mb = abs($mb); - } + + list($mb, $sign1) = add_sign($mb, $sign1); + $ans = sprintf("This includes a %s function: y = %f * x %s %f from %s", $v_type, $ma, $sign1, $mb, $v_range); return array($ans); @@ -57,18 +71,10 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "circs") { $ma = floatval(($mx - $mh)*($mx - $mh) + ($my-$mk)*($my-$mk)); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - if ($mk >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $mk = abs($mk); - } + + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); + $ans = sprintf("This includes function: (x %s %f)^2 + (y %s %f)^2 = %f", $sign1, $mh, $sign2, $mk, $ma); return array($ans); @@ -77,19 +83,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "parabs") { $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign_sign($mk, $sign2); $ans = sprintf("This includes function: y = %f * (x %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); @@ -98,19 +93,9 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "hparabs") { $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: x = %f * (y %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); @@ -119,19 +104,9 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "sqrts") { $ma = floatval(($my - $mk) / sqrt($flip * ($mx - $mh))); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = ""; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: y = %f * sqrt(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); @@ -140,19 +115,9 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "cubics") { $ma = floatval(safepow($my-$mk, 1/3)/($mx-$mh)); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: y = %f * (x %s %f)^3 %s %f", $ma, $sign1, $mh, $sign2, $mk); return array($ans); @@ -160,19 +125,10 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "cuberoots") { $ma = floatval(safepow($my-$mk, 3)/($mx-$mh)); - if ($mh >= 0) { - $sign1 = "+"; - } else { - $sign1 = ""; - $mh = abs($mh); - } - if ($mk >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $mk = abs($mk); - } + list($mh, $sign1) = add_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); + $ans = sprintf("This includes function: x = (1 / %f) * (y %s %f)^3 %s %f", $ma, $sign2, $mk, $sign1, $mh); return array($ans); } @@ -180,19 +136,9 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "ellipses") { $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - if ($mk >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); $ans = sprintf("This includes function: ((1 / %f) * (x %s %f))^2 + ((1 / %f) * (y %s %f))^2 = 1", $ma, $sign1, $mh, $mb, $sign2, $mk); @@ -202,19 +148,9 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "hhyperbolas") { $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - - if ($mk >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $mk = abs($mk); - } + + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); $ans = sprintf("This includes function: ((1 / %f) * (x %s %f))^2 - ((1 / %f) * (y %s %f))^2 = 1", $ma, $sign1, $mh, $mb, $sign2, $mk); @@ -225,19 +161,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - - if ($mk >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); $ans = sprintf("This includes function: ((1 / %f) * (y %s %f))^2 - ((1 / %f) * (x %s %f))^2 = 1", $mb, $sign2, $mk, $ma, $sign1, $mh); @@ -254,19 +179,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } } - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: y = %f * abs(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); @@ -301,19 +215,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } $str *= -1; - if ($str >= 0) { - $sign1 = "+"; - } else { - $sign1 = "-"; - $str = abs($str); - } - - if ($xop >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $xop = abs($xop); - } + list($str, $sign1) = add_sign($str, $sign1); + list($xop, $sign2) = minus_sign($xop, $sign2); $ans = sprintf("This includes function: y = %f %s %f * %f^(x %s %f)", $horizasy, $sign1, $str, $base, $sign2, $xop); @@ -349,19 +252,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { } $str *= -1; - if ($str >= 0) { - $sign1 = "+"; - } else { - $sign1 = "-"; - $str = abs($str); - } - - if ($yop >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $yop = abs($yop); - } + list($str, $sign1) = add_sign($str, $sign1); + list($yop, $sign2) = minus_sign($yop, $sign2); $ans = sprintf("This includes function: x = %f %s %f * %f^(y %s %f)", $vertasy, $isgn1, $str, $base, $sign2, $yop); @@ -372,19 +264,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { elseif ($type == "rats") { $ma = ($mx-$mh)*($my-$mk); - if ($ma >= 0) { - $sign1 = "+"; - } else { - $sign1 = "-"; - $ma = abs($ma); - } - - if ($mh >= 0) { - $sign2 = "-"; - } else { - $sign2 = "+"; - $mh = abs($mh); - } + list($ma, $sign1) = add_sign($ma, $sign1); + list($mh, $sign2) = minus_sign($mh, $sign2); $ans = sprintf("This includes function: y = %f %s %f / (x %s %f)", $mk, $sign1, $ma, $sign2, $mh); @@ -397,19 +278,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $mc = max($mx,$mh); $md = ($my + $mk) / 2; - if ($mc >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mc = abs($mc); - } - - if ($ma >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $ma = abs($ma); - } + list($mc, $sign1) = minus_sign($mc, $sign1); + list($ma, $sign2) = add_sign($ma, $sign2); $ans = sprintf("This includes function: y = %f %s %f * cos(%f * (x - %f))", $md, $sign2, $ma, $mb, $sign1, $mc); @@ -420,12 +290,7 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $ma = ($my - $mk) / ($mx - $mh); $mb = $mk - ($ma * $mh); - if ($mb >= 0) { - $sign1 = "+"; - } else { - $sign1 = "-"; - $mb = abs($mb); - } + list($mb, $sign1) = add_sign($mb, $sign1); $ans = sprintf("This includes function: y = %f * x %s %f", $ma, $sign1, $mb); @@ -475,19 +340,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $l_dir = '>'; } - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: y %s%s %f * (x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); @@ -506,19 +360,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $l_drt = '='; } - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: y %s%s %f * (x %s %f)^2 + %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); @@ -544,19 +387,8 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $l_drt = ''; } - if ($mh >= 0) { - $sign1 = "-"; - } else { - $sign1 = "+"; - $mh = abs($mh); - } - - if ($mk >= 0) { - $sign2 = "+"; - } else { - $sign2 = "-"; - $mk = abs($mk); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: y %s%s %f * abs(x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); From 20caa7ddae6cde9257b995f35c201127a3725ad0 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Fri, 22 Aug 2025 10:17:40 +0700 Subject: [PATCH 19/24] Fix bug --- assess2/questions/scorepart/convert_ans_to_str.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php index a2d498f541..2f6be279b9 100644 --- a/assess2/questions/scorepart/convert_ans_to_str.php +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -84,7 +84,7 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign_sign($mk, $sign2); + list($mk, $sign2) = add_sign($mk, $sign2); $ans = sprintf("This includes function: y = %f * (x %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); @@ -363,7 +363,7 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { list($mh, $sign1) = minus_sign($mh, $sign1); list($mk, $sign2) = add_sign($mk, $sign2); - $ans = sprintf("This includes function: y %s%s %f * (x %s %f)^2 + %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); + $ans = sprintf("This includes function: y %s%s %f * (x %s %f)^2 %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); return array($ans); } From 8609922ecebf73d8f9498620f6c6699f1c283ab5 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Fri, 22 Aug 2025 10:55:16 +0700 Subject: [PATCH 20/24] Fix bugs and polygon change --- test_file.php => StudenDrawFunction.php | 1 - assess2/questions/scorepart/DrawingScorePart.php | 4 +++- assess2/questions/scorepart/convert_ans_to_str.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) rename test_file.php => StudenDrawFunction.php (98%) diff --git a/test_file.php b/StudenDrawFunction.php similarity index 98% rename from test_file.php rename to StudenDrawFunction.php index 587578a093..d1b99ed2cd 100644 --- a/test_file.php +++ b/StudenDrawFunction.php @@ -53,7 +53,6 @@ function getPost($key, $default = "") { $fin_function = array(); foreach ($student_func as $i => $value) { - error_log("AAAAAbbbAAA"); $temp = new DrawResult($value[0], $value[1]); $fin_function[] = $temp; } diff --git a/assess2/questions/scorepart/DrawingScorePart.php b/assess2/questions/scorepart/DrawingScorePart.php index 84cbd3be2d..fd4cd339fa 100644 --- a/assess2/questions/scorepart/DrawingScorePart.php +++ b/assess2/questions/scorepart/DrawingScorePart.php @@ -196,10 +196,12 @@ public function getResult(): ScorePartResult $line[$j] = explode(',',$pt); } + $temp = ""; for($i = 0; $i < count($line) - 1; $i++){ //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($line[$i][0],$line[$i][1],$line[$i+1][0],$line[$i+1][1],$answerformat[0]), $pixtox, $pixtoy, "line"); + $temp .= implode("",convert_to_str_ans(array($line[$i][0],$line[$i][1],$line[$i+1][0],$line[$i+1][1],$answerformat[0]), $pixtox, $pixtoy, "line")); } + $this->stu_func_ans[] = array($temp); if ($isclosed && ($line[0][0]-$line[count($line)-1][0])*($line[0][0]-$line[count($line)-1][0]) + ($line[0][1]-$line[count($line)-1][1])*($line[0][1]-$line[count($line)-1][1]) <=25*max(1,$reltolerance)) { array_pop($line); diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php index 2f6be279b9..59ece0b679 100644 --- a/assess2/questions/scorepart/convert_ans_to_str.php +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -31,7 +31,7 @@ function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { if($type === "line") { $ma = ($my - $mk) / ($mx - $mh); $mb = $mk - ($ma * $mh); - $l_range = sprintf("x = %f -> %f, ", $mh, $mx); + $l_range = sprintf("x = %f -> %f. ", $mh, $mx); if($ans_info[4] == "closedpolygon"){ $l_type = "closed polygon"; } From fae8282e60a085f6fb1e51acdf156c0c8859f3b5 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Fri, 22 Aug 2025 11:18:37 +0700 Subject: [PATCH 21/24] Clean up and update id --- ...rawFunction.php => StudentDrawFunction.php | 0 assess2/questions/ScoreEngine.php | 2 +- .../questions/scorepart/DrawingScorePart.php | 24 ------------------- .../scorepart/convert_ans_to_str.php | 7 ++++-- assessment/macros.php | 5 +--- 5 files changed, 7 insertions(+), 31 deletions(-) rename StudenDrawFunction.php => StudentDrawFunction.php (100%) diff --git a/StudenDrawFunction.php b/StudentDrawFunction.php similarity index 100% rename from StudenDrawFunction.php rename to StudentDrawFunction.php diff --git a/assess2/questions/ScoreEngine.php b/assess2/questions/ScoreEngine.php index 1b9a44b863..e9d37fb7dd 100644 --- a/assess2/questions/ScoreEngine.php +++ b/assess2/questions/ScoreEngine.php @@ -795,7 +795,7 @@ private function scorePartNonMultiPart(ScoreQuestionParams $scoreQuestionParams, $score = $scorePartResult->getRawScore(); //TESTING--------------------------------------------- - $this->temp_func[] = $scorePart->get_student_function(); + $this->temp_func[] = array(27,$scorePart->get_student_function()); if (isset($scoremethod) && $scoremethod == "allornothing") { if ($score < .98) { diff --git a/assess2/questions/scorepart/DrawingScorePart.php b/assess2/questions/scorepart/DrawingScorePart.php index fd4cd339fa..89586cae2e 100644 --- a/assess2/questions/scorepart/DrawingScorePart.php +++ b/assess2/questions/scorepart/DrawingScorePart.php @@ -15,7 +15,6 @@ class DrawingScorePart implements ScorePart private $stu_func_ans =[]; public function get_student_function(){ - // error_log(json_encode($this->stu_func_ans)); return $this->stu_func_ans; } @@ -261,12 +260,6 @@ public function getResult(): ScorePartResult if ($extrapolys>0) { $totscore = $totscore/(1+$extrapolys); } - //echo "Vals score: $vals, adj score: $adjv.

"; - - // for ($i = 0; $i < count($stu_func_ans); $i++) { - // echo (implode(",", $stu_func_ans[$i])); - // } - // error_log(json_encode($stu_func_ans)); if ($abstolerance !== '') { if ($totscore<$abstolerance) { @@ -1384,8 +1377,6 @@ public function getResult(): ScorePartResult } } - //print_r($anscuberoots); - //print_r($cuberoots); $usedcuberoot = []; foreach ($anscuberoots as $key=>$anscuberoot) { $scores[$scoretype[$key]][$key] = 0; @@ -1557,11 +1548,6 @@ public function getResult(): ScorePartResult } } - // for ($i = 0; $i < count($stu_func_ans); $i++) { - // echo (implode(",", $stu_func_ans[$i])); - // } - // error_log(json_encode($stu_func_ans)); - //extra stuff is total count of drawn items - # of scored items - # of correct optional items $extrastuffpenalty = max((count($tplines)+count($dots)+count($odots)-count($scores[0])-array_sum($scores[1]))/(max(count($scores[0]),count($tplines)+count($dots)+count($odots))),0); // don't need optional scores anymore @@ -1724,11 +1710,6 @@ public function getResult(): ScorePartResult $deftol = .1; $defpttol = 5; - // for ($i = 0; $i < count($stu_func_ans); $i++) { - // echo (implode(",", $stu_func_ans[$i])); - // } - // error_log(json_encode($stu_func_ans)); - foreach ($anslines as $key=>$ansline) { $scores[$key] = 0; for ($i=0; $i Date: Fri, 22 Aug 2025 14:07:16 +0700 Subject: [PATCH 22/24] Fix bugs, clean up --- assess2/questions/scorepart/convert_ans_to_str.php | 9 +++++++++ new_return_class.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php index efd127e345..759a466d66 100644 --- a/assess2/questions/scorepart/convert_ans_to_str.php +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -21,12 +21,21 @@ function minus_sign($num, $sign) { return [$num, $sign]; } +function clean_up($marray) { + foreach ($marray as $key => $value) { + $marray[$key] = preg_replace("/[^0-9.\-]/", "", $value); + } + return $marray; +} + // @param $ans_info is an array with structure depending on the drawing type // @param $pixtox is a function to convert pixel x to real x // @param $pixtoy is a function to convert pixel y to real y // @param $type is the type of drawing, e.g., "line", "vecs", "circs", etc. // @return an array with a string description of the drawing function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { + + $ans_info = clean_up($ans_info); $mh = $pixtox(floatval($ans_info[0])); $mk = $pixtoy(floatval($ans_info[1])); diff --git a/new_return_class.php b/new_return_class.php index a03c44ddf8..09d40951f7 100644 --- a/new_return_class.php +++ b/new_return_class.php @@ -5,7 +5,7 @@ class DrawResult public $id; public $valuef; - public function DrawResult($id, $valuef) { + public function __construct($id, $valuef) { $this->id = "qn" . strval($id); $this->valuef = $valuef; } From 4b9bb5337a7ecb3b93291453266c50ceba1f3985 Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Fri, 22 Aug 2025 15:45:54 +0700 Subject: [PATCH 23/24] Update all answer function --- .../questions/scorepart/DrawingScorePart.php | 54 +- .../scorepart/convert_ans_to_str.php | 628 +++++++++--------- 2 files changed, 356 insertions(+), 326 deletions(-) diff --git a/assess2/questions/scorepart/DrawingScorePart.php b/assess2/questions/scorepart/DrawingScorePart.php index 89586cae2e..94a8b3541d 100644 --- a/assess2/questions/scorepart/DrawingScorePart.php +++ b/assess2/questions/scorepart/DrawingScorePart.php @@ -198,7 +198,7 @@ public function getResult(): ScorePartResult $temp = ""; for($i = 0; $i < count($line) - 1; $i++){ //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $temp .= implode("",convert_to_str_ans(array($line[$i][0],$line[$i][1],$line[$i+1][0],$line[$i+1][1],$answerformat[0]), $pixtox, $pixtoy, "line")); + $temp .= implode("",fans_polygon($line[$i][0],$line[$i][1],$line[$i+1][0],$line[$i+1][1],$answerformat[0], $pixtox, $pixtoy)); } $this->stu_func_ans[] = array($temp); @@ -755,21 +755,21 @@ public function getResult(): ScorePartResult } } //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "lines"); + $this->stu_func_ans[] = fans_lines($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); } else if ($pts[0]==5.2) { //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],'r'), $pixtox, $pixtoy, "vecs"); + $this->stu_func_ans[] = fans_vecs($pts[1],$pts[2],$pts[3],$pts[4],'r', $pixtox, $pixtoy); $vecs[] = array($pts[1],$pts[2],$pts[3],$pts[4],'r'); } else if ($pts[0]==5.3) { //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],'ls'), $pixtox, $pixtoy, "vecs"); + $this->stu_func_ans[] = fans_vecs($pts[1],$pts[2],$pts[3],$pts[4],'ls', $pixtox, $pixtoy); $vecs[] = array($pts[1],$pts[2],$pts[3],$pts[4],'ls'); } else if ($pts[0]==5.4) { //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],'v'), $pixtox, $pixtoy, "vecs"); + $this->stu_func_ans[] = fans_vecs($pts[1],$pts[2],$pts[3],$pts[4],'v', $pixtox, $pixtoy); $vecs[] = array($pts[1],$pts[2],$pts[3],$pts[4],'v'); } else if ($pts[0]==6 || $pts[0] == 6.2) { @@ -790,7 +790,7 @@ public function getResult(): ScorePartResult $x = $pts[1]+sign($a)*sqrt(abs(20/$a)); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "parabs"); + $this->stu_func_ans[] = fans_parabs($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $parabs[] = array($pts[1],$pts[2],$y,$x,$leftrightdir); } @@ -804,7 +804,7 @@ public function getResult(): ScorePartResult $y = $pts[2]+sign($a)*sqrt(abs(20/$a)); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "hparabs"); + $this->stu_func_ans[] = fans_hparabs($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $hparabs[] = array($pts[1],$pts[2],$y,$x); } @@ -817,7 +817,7 @@ public function getResult(): ScorePartResult $secyp = $stretch*sqrt($flip*($secxp - $pts[1]))+($pts[2]); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "sqrts"); + $this->stu_func_ans[] = fans_sqrts($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $sqrts[] = array($pts[1],$pts[2],$secyp,$flip); } @@ -830,7 +830,7 @@ public function getResult(): ScorePartResult $a = safepow($pts[4]-$pts[2], 1/3)/($pts[3]-$pts[1]); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "cubics"); + $this->stu_func_ans[] = fans_cubics($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $cubics[] = array($pts[1],$pts[2], $a); } @@ -842,7 +842,7 @@ public function getResult(): ScorePartResult $a = safepow($pts[4]-$pts[2],3)/($pts[3]-$pts[1]); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "cuberoots"); + $this->stu_func_ans[] = fans_cuberoots($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $cuberoots[] = array($pts[1],$pts[2],$a); } @@ -852,27 +852,27 @@ public function getResult(): ScorePartResult //$circs[] = array($pts[1],$pts[2],$rad); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "circs"); + $this->stu_func_ans[] = fans_circs($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $ellipses[] = array($pts[1],$pts[2],$rad,$rad); } else if ($pts[0]==7.2) { //ellipse //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "ellipses"); + $this->stu_func_ans[] = fans_ellipses($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $ellipses[] = array($pts[1],$pts[2],abs($pts[3]-$pts[1]),abs($pts[4]-$pts[2])); } else if ($pts[0]==7.4) { //vert hyperbola //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "vhyperbolas"); + $this->stu_func_ans[] = fans_vhyperbolas($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $hyperbolas[] = array($pts[1],$pts[2],abs($pts[3]-$pts[1]),abs($pts[4]-$pts[2]),'vert'); } else if ($pts[0]==7.5) { //horiz hyperbola //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "hhyperbolas"); + $this->stu_func_ans[] = fans_hhyperbolas($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $hyperbolas[] = array($pts[1],$pts[2],abs($pts[3]-$pts[1]),abs($pts[4]-$pts[2]),'horiz'); } else if ($pts[0]==8) { @@ -890,7 +890,7 @@ public function getResult(): ScorePartResult } } //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "abs"); + $this->stu_func_ans[] = fans_abs($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $abs[] = array($pts[1],$pts[2], $slope); } else if ($pts[0]==8.3 || $pts[0]==8.5) { @@ -918,11 +918,11 @@ public function getResult(): ScorePartResult //$exps[] = array($str,$base); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ if ($pts[0]==8.5) { - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0], $xop, $yop), $pixtox, $pixtoy, "exps"); + $this->stu_func_ans[] = fans_exps($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0], $xop, $yop, $pixtox, $pixtoy); } else { //Does not use $pts[5] ans $pts[6] - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],0,0,$pts[0], $xop, $yop), $pixtox, $pixtoy, "exps"); + $this->stu_func_ans[] = fans_exps($pts[1],$pts[2],$pts[3],$pts[4],0,0,$pts[0], $xop, $yop, $pixtox, $pixtoy); } $exps[] = array($Lx1p-$xop, $adjy1, $Lx2p-$xop, $adjy2, $base, $horizasy); } @@ -950,11 +950,11 @@ public function getResult(): ScorePartResult //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ if ($pts[0]==8.6) { - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0], $xop, $yop), $pixtox, $pixtoy, "logs"); + $this->stu_func_ans[] = fans_logs($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0], $xop, $yop, $pixtox, $pixtoy); } else { //Does not use $pts[5] ans $pts[6] - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],0,0,$pts[0], $xop, $yop), $pixtox, $pixtoy, "logs"); + $this->stu_func_ans[] = fans_logs($pts[1],$pts[2],$pts[3],$pts[4],0,0,$pts[0], $xop, $yop, $pixtox, $pixtoy); } $logs[] = array($Ly1p-$yop, $adjx1, $Ly2p-$yop, $adjx2, $base, $vertasy); @@ -965,7 +965,7 @@ public function getResult(): ScorePartResult $yp = $pts[2]+(($stretch>0)?1:-1)*sqrt(abs($stretch)); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "rats"); + $this->stu_func_ans[] = fans_rats($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); $rats[] = array($pts[1],$pts[2],$yp); } @@ -974,7 +974,7 @@ public function getResult(): ScorePartResult $pts[1] -= ($pts[3] - $pts[1]); $pts[2] -= ($pts[4] - $pts[2]); } - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4]), $pixtox, $pixtoy, "coss"); + $this->stu_func_ans[] = fans_coss($pts[1],$pts[2],$pts[3],$pts[4], $pixtox, $pixtoy); if ($pts[4]>$pts[2]) { // //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ @@ -998,7 +998,7 @@ public function getResult(): ScorePartResult foreach ($dots as $k=>$pt) { $dots[$k] = explode(',',$pt); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($dots[$k][0], $dots[$k][1], 0, 0), $pixtox, $pixtoy, "dots"); + $this->stu_func_ans[] = fans_dots($dots[$k][0], $dots[$k][1], $pixtox, $pixtoy); } } if ($odots=='') { @@ -1008,7 +1008,7 @@ public function getResult(): ScorePartResult foreach ($odots as $k=>$pt) { $odots[$k] = explode(',',$pt); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($odots[$k][0], $odots[$k][1], 0, 0), $pixtox, $pixtoy, "odots"); + $this->stu_func_ans[] = fans_odots($odots[$k][0], $odots[$k][1], $pixtox, $pixtoy); } } @@ -1647,7 +1647,7 @@ public function getResult(): ScorePartResult foreach ($ineqlines as $k=>$val) { $pts = explode(',',$val); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0]), $pixtox, $pixtoy, "ineqlines"); + $this->stu_func_ans[] = fans_ineqlines($pts[1],$pts[2],$pts[3],$pts[4],$pts[5],$pts[6],$pts[0], $pixtox, $pixtoy); if($pts[0]<10.3){//linear if ($pts[3]==$pts[1]) { $slope = 10000; @@ -1830,7 +1830,7 @@ public function getResult(): ScorePartResult $maxp = explode(',', $lines[$k][count($lines[$k])-1]); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($minp[0], $minp[1],$maxp[0],$maxp[1]), $pixtox, $pixtoy, "line1d"); + $this->stu_func_ans[] = fans_line1d($minp[0], $maxp[0], $pixtox, $pixtoy); $lines[$k] = array(min($minp[0], $maxp[0]), max($minp[0], $maxp[0])); } @@ -1866,7 +1866,7 @@ public function getResult(): ScorePartResult foreach ($dots as $k=>$pt) { $dots[$k] = explode(',',$pt); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($dots[$k][0], $dots[$k][1], 0, 0), $pixtox, $pixtoy, "dots1d"); + $this->stu_func_ans[] = fans_dots1d($dots[$k][0], $pixtox, $pixtoy); } //remove duplicate dots for ($k=count($dots)-1;$k>=0;$k--) { @@ -1890,7 +1890,7 @@ public function getResult(): ScorePartResult foreach ($odots as $k=>$pt) { $odots[$k] = explode(',',$pt); //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $this->stu_func_ans[] = convert_to_str_ans(array($odots[$k][0], $odots[$k][1], 0, 0), $pixtox, $pixtoy, "odots1d"); + $this->stu_func_ans[] = fans_odots1d($odots[$k][0], $pixtox, $pixtoy); } //remove duplicate odots, and dots below odots for ($k=count($odots)-1;$k>=0;$k--) { diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php index 759a466d66..603757d799 100644 --- a/assess2/questions/scorepart/convert_ans_to_str.php +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -21,411 +21,441 @@ function minus_sign($num, $sign) { return [$num, $sign]; } -function clean_up($marray) { +function clean_up($marray, $pixtox, $pixtoy) { foreach ($marray as $key => $value) { - $marray[$key] = preg_replace("/[^0-9.\-]/", "", $value); + $marray[$key] = $pixtox(floatval(preg_replace("/[^0-9.\-]/", "", $value))); } return $marray; } -// @param $ans_info is an array with structure depending on the drawing type -// @param $pixtox is a function to convert pixel x to real x -// @param $pixtoy is a function to convert pixel y to real y -// @param $type is the type of drawing, e.g., "line", "vecs", "circs", etc. -// @return an array with a string description of the drawing -function convert_to_str_ans(array $ans_info, $pixtox, $pixtoy, $type) { - - $ans_info = clean_up($ans_info); - - $mh = $pixtox(floatval($ans_info[0])); - $mk = $pixtoy(floatval($ans_info[1])); - $mx = $pixtox(floatval($ans_info[2])); - $my = $pixtoy(floatval($ans_info[3])); - - if($type === "line") { - $ma = ($my - $mk) / ($mx - $mh); - $mb = $mk - ($ma * $mh); - $l_range = sprintf("x = %f -> %f. ", $mh, $mx); - if($ans_info[4] == "closedpolygon"){ - $l_type = "closed polygon"; - } - else { - $l_type = "polygon"; - } + +function fans_polygons($mh, $mk, $mx, $my, $type, $pixtox, $pixtoy) { - list($mb, $sign1) = add_sign($mb, $sign1); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - $ans = sprintf("This %s includes a line: y = %f * x %s %f from %s", $l_type, $ma, $sign1, $mb, $l_range); - - return array($ans); + $ma = ($my - $mk) / ($mx - $mh); + $mb = $mk - ($ma * $mh); + $l_range = sprintf("x = %f -> %f. ", $mh, $mx); + if($type == "closedpolygon"){ + $l_type = "closed polygon"; + } + else { + $l_type = "polygon"; } - elseif ($type == "vecs") { - if($ans_info[4] === 'r') { - $v_type = "ray"; - $v_range = sprintf("x = %f, ", $mh); - } - elseif ($ans_info[4] === 'ls') { - $v_type = "line segment"; - $v_range = sprintf("x = %f -> %f, ", $mh, $mx); - } - else { - $v_type = "vector"; - $v_range = sprintf("x = %f -> %f, ", $mh, $mx); - } - $ma = ($my - $mk) / ($mx - $mh); - $mb = $mk - ($ma * $mh); + list($mb, $sign1) = add_sign($mb, $sign1); - list($mb, $sign1) = add_sign($mb, $sign1); + $ans = sprintf("This %s includes a line: y = %f * x %s %f from %s", $l_type, $ma, $sign1, $mb, $l_range); + + return array($ans); +} - $ans = sprintf("This includes a %s function: y = %f * x %s %f from %s", $v_type, $ma, $sign1, $mb, $v_range); +function fans_vecs($mh, $mk, $mx, $my, $type, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - return array($ans); + if($type === 'r') { + $v_type = "ray"; + $v_range = sprintf("x = %f, ", $mh); + } + elseif ($type === 'ls') { + $v_type = "line segment"; + $v_range = sprintf("x = %f -> %f, ", $mh, $mx); } + else { + $v_type = "vector"; + $v_range = sprintf("x = %f -> %f, ", $mh, $mx); + } + $ma = ($my - $mk) / ($mx - $mh); + $mb = $mk - ($ma * $mh); - elseif ($type == "circs") { - $ma = floatval(($mx - $mh)*($mx - $mh) + ($my-$mk)*($my-$mk)); + list($mb, $sign1) = add_sign($mb, $sign1); - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = minus_sign($mk, $sign2); + $ans = sprintf("This includes a %s function: y = %f * x %s %f from %s", $v_type, $ma, $sign1, $mb, $v_range); - $ans = sprintf("This includes function: (x %s %f)^2 + (y %s %f)^2 = %f", $sign1, $mh, $sign2, $mk, $ma); + return array($ans); +} - return array($ans); - } +function fans_circs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - elseif ($type == "parabs") { - $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); + $ma = floatval(($mx - $mh)*($mx - $mh) + ($my-$mk)*($my-$mk)); - $ans = sprintf("This includes function: y = %f * (x %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); - return array($ans); - } + $ans = sprintf("This includes function: (x %s %f)^2 + (y %s %f)^2 = %f", $sign1, $mh, $sign2, $mk, $ma); - elseif ($type == "hparabs") { - $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); + return array($ans); +} - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); +function fans_parabs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - $ans = sprintf("This includes function: x = %f * (y %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); + $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); - return array($ans); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); - elseif ($type == "sqrts") { - $ma = floatval(($my - $mk) / sqrt($flip * ($mx - $mh))); + $ans = sprintf("This includes function: y = %f * (x %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); + return array($ans); +} - $ans = sprintf("This includes function: y = %f * sqrt(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); +function fans_hparabs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - return array($ans); - } + $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); - elseif ($type == "cubics") { - $ma = floatval(safepow($my-$mk, 1/3)/($mx-$mh)); + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); + $ans = sprintf("This includes function: x = %f * (y %s %f)^2 %s %f", $ma, $sign1, $mh, $sign2, $mk); - $ans = sprintf("This includes function: y = %f * (x %s %f)^3 %s %f", $ma, $sign1, $mh, $sign2, $mk); - return array($ans); - } + return array($ans); +} - elseif ($type == "cuberoots") { - $ma = floatval(safepow($my-$mk, 3)/($mx-$mh)); +function fans_sqrts ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - list($mh, $sign1) = add_sign($mh, $sign1); - list($mk, $sign2) = minus_sign($mk, $sign2); + $ma = floatval(($my - $mk) / sqrt($flip * ($mx - $mh))); - $ans = sprintf("This includes function: x = (1 / %f) * (y %s %f)^3 %s %f", $ma, $sign2, $mk, $sign1, $mh); - return array($ans); - } + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); - elseif ($type == "ellipses") { - $ma = floatval(abs($mx - $mh)); - $mb = floatval(abs($my - $mk)); + $ans = sprintf("This includes function: y = %f * sqrt(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = minus_sign($mk, $sign2); + return array($ans); +} - $ans = sprintf("This includes function: ((1 / %f) * (x %s %f))^2 + ((1 / %f) * (y %s %f))^2 = 1", $ma, $sign1, $mh, $mb, $sign2, $mk); +function fans_cubics ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - return array($ans); - } + $ma = floatval(safepow($my-$mk, 1/3)/($mx-$mh)); - elseif ($type == "hhyperbolas") { - $ma = floatval(abs($mx - $mh)); - $mb = floatval(abs($my - $mk)); - - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = minus_sign($mk, $sign2); + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); - $ans = sprintf("This includes function: ((1 / %f) * (x %s %f))^2 - ((1 / %f) * (y %s %f))^2 = 1", $ma, $sign1, $mh, $mb, $sign2, $mk); + $ans = sprintf("This includes function: y = %f * (x %s %f)^3 %s %f", $ma, $sign1, $mh, $sign2, $mk); + return array($ans); +} - return array($ans); - } +function fans_cuberoots ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - elseif ($type == "vhyperbolas") { - $ma = floatval(abs($mx - $mh)); - $mb = floatval(abs($my - $mk)); + $ma = floatval(safepow($my-$mk, 3)/($mx-$mh)); - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = minus_sign($mk, $sign2); + list($mh, $sign1) = add_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); - $ans = sprintf("This includes function: ((1 / %f) * (y %s %f))^2 - ((1 / %f) * (x %s %f))^2 = 1", $mb, $sign2, $mk, $ma, $sign1, $mh); + $ans = sprintf("This includes function: x = (1 / %f) * (y %s %f)^3 %s %f", $ma, $sign2, $mk, $sign1, $mh); + return array($ans); +} - return array($ans); - } +function fans_ellipses ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - elseif ($type == "abs") { - if ($mh==$mx) { - $ma = 0; - } else { - $ma = ($my-$mk)/($mx-$mh); - if ($mh > $mx) { - $ma *= -1; - } - } + $ma = floatval(abs($mx - $mh)); + $mb = floatval(abs($my - $mk)); - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = minus_sign($mk, $sign2); - $ans = sprintf("This includes function: y = %f * abs(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); + $ans = sprintf("This includes function: ((1 / %f) * (x %s %f))^2 + ((1 / %f) * (y %s %f))^2 = 1", $ma, $sign1, $mh, $mb, $sign2, $mk); - return array($ans); - } + return array($ans); +} - elseif ($type == "exps") { - $m4 = $pixtox(floatval($ans_info[4])); - $m5 = $pixtoy(floatval($ans_info[5])); - $xop = $pixtox(floatval($ans_info[7])); - $yop = $pixtoy(floatval($ans_info[8])); - - if ($ans_info[6] == 8.3) { - $horizasy = $yop; - $adjy2 = $horizasy - $my; - $adjy1 = $horizasy - $mk; - $Lx1p = $mh; - $Lx2p = $mx; - } else if ($ans_info[6]==8.5) { - $horizasy = $mk; - $adjy2 = $horizasy - $m5; - $adjy1 = $horizasy - $my; - $Lx1p = $mx; - $Lx2p = $m4; - } - if ($adjy1*$adjy2>0 && $Lx1p!=$Lx2p) { - $base = safepow($adjy2/$adjy1,1/($Lx2p-$Lx1p)); - if (abs($Lx1p-$xop)0 && $Ly1p!=$Ly2p) { - $base = safepow($adjx2/$adjx1,1/($Ly2p-$Ly1p)); - if (abs($pts[2]-$yop) $mx) { + $ma *= -1; } } - elseif ($type == "rats") { - $ma = ($mx-$mh)*($my-$mk); + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); + + $ans = sprintf("This includes function: y = %f * abs(x %s %f) %s %f", $ma, $sign1, $mh, $sign2, $mk); - list($ma, $sign1) = add_sign($ma, $sign1); - list($mh, $sign2) = minus_sign($mh, $sign2); + return array($ans); +} + +function fans_exps ($mh, $mk, $mx, $my, $m4, $m5, $type, $xop, $yop, $pixtox, $pixtoy) { + + list($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop) = clean_up(array($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop), $pixtox, $pixtoy); + + if ($type == 8.3) { + $horizasy = $yop; + $adjy2 = $horizasy - $my; + $adjy1 = $horizasy - $mk; + $Lx1p = $mh; + $Lx2p = $mx; + } else if ($type ==8.5) { + $horizasy = $mk; + $adjy2 = $horizasy - $m5; + $adjy1 = $horizasy - $my; + $Lx1p = $mx; + $Lx2p = $m4; + } + if ($adjy1*$adjy2>0 && $Lx1p!=$Lx2p) { + $base = safepow($adjy2/$adjy1,1/($Lx2p-$Lx1p)); + if (abs($Lx1p-$xop)0 && $Ly1p!=$Ly2p) { + $base = safepow($adjx2/$adjx1,1/($Ly2p-$Ly1p)); + if (abs($pts[2]-$yop) $mh) { - $l_dir = '<'; - } - else { - $l_dir = '>'; - } - $ans = sprintf("This includes function: x %s%s %f", $l_dir, $l_drt, $mh); - - return array($ans); - } + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - $ma = ($my - $mk) / ($mx - $mh); - $ynew = $ma * ($mx2 - $mh) + $mk; - if ($my2 < $ynew) { - $l_dir = '<'; - } - else { - $l_dir = '>'; - } + $ma = (max($my,$mk)-min($my,$mk))/2; + $mb = pi()/(abs($mx - $mh)); + $mc = max($mx,$mh); + $md = ($my + $mk) / 2; - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); + list($mc, $sign1) = minus_sign($mc, $sign1); + list($ma, $sign2) = add_sign($ma, $sign2); - $ans = sprintf("This includes function: y %s%s %f * (x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); + $ans = sprintf("This includes function: y = %f %s %f * cos(%f * (x - %f))", $md, $sign2, $ma, $mb, $sign1, $mc); - return array($ans); + return array($ans); +} + +function fans_lines ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + $ma = ($my - $mk) / ($mx - $mh); + $mb = $mk - ($ma * $mh); + + list($mb, $sign1) = add_sign($mb, $sign1); + + $ans = sprintf("This includes function: y = %f * x %s %f", $ma, $sign1, $mb); + + return array($ans); +} + +function fans_dots ($mh, $mk, $pixtox, $pixtoy) { + + list($mh, $mk) = clean_up(array($mh, $mk), $pixtox, $pixtoy); + + $ans = sprintf("There is a dot at: (%f, %f)", $mh, $mk); + + return array($ans); +} + +function fans_odots ($mh, $mk, $pixtox, $pixtoy) { + + list($mh, $mk) = clean_up(array($mh, $mk), $pixtox, $pixtoy); + + $ans = sprintf("There is an open dot at: (%f, %f)", $mh, $mk); + + return array($ans); +} + +function fans_ineqlines ($mh, $mk, $mx, $my, $mx2, $my2, $type, $pixtox, $pixtoy) { + + list($mh, $mk, $mx, $my, $mx2, $my2) = clean_up(array($mh, $mk, $mx, $my, $mx2, $my2), $pixtox, $pixtoy); + + $in_type = floatval($type); + if($in_type < floatval(10.3)) { + if ($in_type === floatval(10)) { + $l_drt = '='; } - elseif ($in_type < floatval(10.5)) { - $ma = ($my - $mk) / (($mx - $mh) * ($mx - $mh)); - $ynew = $ma * ($mx2 - $mh) * ($mx2 - $mh) + $mk; - if($my2 < $ynew) { + if ($mx === $mh) { + if ($mx2 > $mh) { $l_dir = '<'; } else { $l_dir = '>'; } - if($in_type === floatval(10.3)) { - $l_drt = '='; - } - - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); - - $ans = sprintf("This includes function: y %s%s %f * (x %s %f)^2 %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); + $ans = sprintf("This includes function: x %s%s %f", $l_dir, $l_drt, $mh); return array($ans); } - else { - $ma = ($my - $mk) / ($mx - $mh); - if ($mx < $mh) { - $ma *= -1; - } - $ynew = $ma * abs($mx2 - $mh) + $mk; - if($my2 < $ynew) { - $l_dir = '<'; - } - else { - $l_dir = '>'; - } - if($in_type === floatval(10.5)) { - $l_drt = '='; - } - else { - $l_drt = ''; - } + $ma = ($my - $mk) / ($mx - $mh); + $ynew = $ma * ($mx2 - $mh) + $mk; + if ($my2 < $ynew) { + $l_dir = '<'; + } + else { + $l_dir = '>'; + } - list($mh, $sign1) = minus_sign($mh, $sign1); - list($mk, $sign2) = add_sign($mk, $sign2); + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); - $ans = sprintf("This includes function: y %s%s %f * abs(x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); + $ans = sprintf("This includes function: y %s%s %f * (x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); - return array($ans); - } + return array($ans); } + elseif ($in_type < floatval(10.5)) { + $ma = ($my - $mk) / (($mx - $mh) * ($mx - $mh)); + $ynew = $ma * ($mx2 - $mh) * ($mx2 - $mh) + $mk; + if($my2 < $ynew) { + $l_dir = '<'; + } + else { + $l_dir = '>'; + } + if($in_type === floatval(10.3)) { + $l_drt = '='; + } - elseif ($type == "line1d") { - $head = min($mh, $mx); - $tail = max($mh, $mx); - $ans = sprintf("There is a line from: %f to %f", $head, $tail); + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); + + $ans = sprintf("This includes function: y %s%s %f * (x %s %f)^2 %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); return array($ans); } + else { + $ma = ($my - $mk) / ($mx - $mh); + if ($mx < $mh) { + $ma *= -1; + } - elseif ($type == "dots1d") { - $ans = sprintf("There is a dot at: %f", $mh); + $ynew = $ma * abs($mx2 - $mh) + $mk; + if($my2 < $ynew) { + $l_dir = '<'; + } + else { + $l_dir = '>'; + } + if($in_type === floatval(10.5)) { + $l_drt = '='; + } + else { + $l_drt = ''; + } + + list($mh, $sign1) = minus_sign($mh, $sign1); + list($mk, $sign2) = add_sign($mk, $sign2); + + $ans = sprintf("This includes function: y %s%s %f * abs(x %s %f) %s %f", $l_dir, $l_drt, $ma, $sign1, $mh, $sign2, $mk); return array($ans); } +} - elseif ($type == "odots1d") { - $ans = sprintf("There is an open dot at: %f", $mh); +function fans_line1d ($mh, $mx, $pixtox, $pixtoy) { + list($mh, $mx) = clean_up(array($mh, $mx), $pixtox, $pixtoy); - return array($ans); - } + $head = min($mh, $mx); + $tail = max($mh, $mx); + $ans = sprintf("There is a line from: %f to %f", $head, $tail); + + return array($ans); +} + +function fans_dots1d ($mh, $pixtox, $pixtoy) { + + list($mh) = clean_up(array($mh), $pixtox, $pixtoy); + + $ans = sprintf("There is a dot at: %f", $mh); + + return array($ans); +} + +function fans_odots1d ($mh, $pixtox, $pixtoy) { + + list($mh) = clean_up(array($mh), $pixtox, $pixtoy); + + $ans = sprintf("There is an open dot at: %f", $mh); + + return array($ans); } From 49c51a131733e74a3e6e8ae1ff1d08889e2bb31d Mon Sep 17 00:00:00 2001 From: Themid1 <127655716+Themid1@users.noreply.github.com> Date: Fri, 22 Aug 2025 17:34:10 +0700 Subject: [PATCH 24/24] Final change --- .../questions/scorepart/DrawingScorePart.php | 2 +- .../scorepart/convert_ans_to_str.php | 115 +++++++++++++----- 2 files changed, 84 insertions(+), 33 deletions(-) diff --git a/assess2/questions/scorepart/DrawingScorePart.php b/assess2/questions/scorepart/DrawingScorePart.php index 94a8b3541d..0dbaebe200 100644 --- a/assess2/questions/scorepart/DrawingScorePart.php +++ b/assess2/questions/scorepart/DrawingScorePart.php @@ -198,7 +198,7 @@ public function getResult(): ScorePartResult $temp = ""; for($i = 0; $i < count($line) - 1; $i++){ //ADD TO ANSWER AS FUNCTION------------------------------------------------------------ - $temp .= implode("",fans_polygon($line[$i][0],$line[$i][1],$line[$i+1][0],$line[$i+1][1],$answerformat[0], $pixtox, $pixtoy)); + $temp .= implode("",fans_polygons($line[$i][0],$line[$i][1],$line[$i+1][0],$line[$i+1][1],$answerformat[0], $pixtox, $pixtoy)); } $this->stu_func_ans[] = array($temp); diff --git a/assess2/questions/scorepart/convert_ans_to_str.php b/assess2/questions/scorepart/convert_ans_to_str.php index 603757d799..a9208795b5 100644 --- a/assess2/questions/scorepart/convert_ans_to_str.php +++ b/assess2/questions/scorepart/convert_ans_to_str.php @@ -21,17 +21,28 @@ function minus_sign($num, $sign) { return [$num, $sign]; } -function clean_up($marray, $pixtox, $pixtoy) { +function clean_up($marray) { foreach ($marray as $key => $value) { - $marray[$key] = $pixtox(floatval(preg_replace("/[^0-9.\-]/", "", $value))); + $marray[$key] = preg_replace("/[^0-9.\-]/", "", $value); } return $marray; } +function change_to_math($xarray, $yarray, $pixtox, $pixtoy) { + foreach ($xarray as $key => $value) { + $xarray[$key] = $pixtox(floatval($value)); + } + foreach ($yarray as $key => $value) { + $yarray[$key] = $pixtoy(floatval($value)); + } + return [$xarray, $yarray]; +} + function fans_polygons($mh, $mk, $mx, $my, $type, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); $ma = ($my - $mk) / ($mx - $mh); $mb = $mk - ($ma * $mh); @@ -51,8 +62,10 @@ function fans_polygons($mh, $mk, $mx, $my, $type, $pixtox, $pixtoy) { } function fans_vecs($mh, $mk, $mx, $my, $type, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + if($type === 'r') { $v_type = "ray"; $v_range = sprintf("x = %f, ", $mh); @@ -77,8 +90,9 @@ function fans_vecs($mh, $mk, $mx, $my, $type, $pixtox, $pixtoy) { function fans_circs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(($mx - $mh)*($mx - $mh) + ($my-$mk)*($my-$mk)); list($mh, $sign1) = minus_sign($mh, $sign1); @@ -90,8 +104,10 @@ function fans_circs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_parabs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); list($mh, $sign1) = minus_sign($mh, $sign1); @@ -103,8 +119,10 @@ function fans_parabs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_hparabs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(($my - $mk) / (($mx-$mh)*($mx-$mh))); list($mh, $sign1) = minus_sign($mh, $sign1); @@ -116,8 +134,11 @@ function fans_hparabs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_sqrts ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + + $flip = ($mx < $mh) ? -1 : 1; $ma = floatval(($my - $mk) / sqrt($flip * ($mx - $mh))); list($mh, $sign1) = minus_sign($mh, $sign1); @@ -129,20 +150,24 @@ function fans_sqrts ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_cubics ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(safepow($my-$mk, 1/3)/($mx-$mh)); - + list($mh, $sign1) = minus_sign($mh, $sign1); list($mk, $sign2) = add_sign($mk, $sign2); - $ans = sprintf("This includes function: y = %f * (x %s %f)^3 %s %f", $ma, $sign1, $mh, $sign2, $mk); + $ans = sprintf("This includes function: y = (%f * (x %s %f))^3 %s %f", $ma, $sign1, $mh, $sign2, $mk); return array($ans); } function fans_cuberoots ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(safepow($my-$mk, 3)/($mx-$mh)); list($mh, $sign1) = add_sign($mh, $sign1); @@ -153,8 +178,10 @@ function fans_cuberoots ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_ellipses ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); @@ -167,8 +194,10 @@ function fans_ellipses ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_hhyperbolas ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); @@ -181,8 +210,10 @@ function fans_hhyperbolas ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_vhyperbolas ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = floatval(abs($mx - $mh)); $mb = floatval(abs($my - $mk)); @@ -195,8 +226,10 @@ function fans_vhyperbolas ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { } function fans_abs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + if ($mh==$mx) { $ma = 0; } else { @@ -216,7 +249,8 @@ function fans_abs ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { function fans_exps ($mh, $mk, $mx, $my, $m4, $m5, $type, $xop, $yop, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop) = clean_up(array($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop) = clean_up(array($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop)); + list(list($mh, $mx, $m4, $xop), list($mk, $my, $m5, $yop)) = change_to_math(array($mh, $mx, $m4, $xop), array($mk, $my, $m5, $yop), $pixtox, $pixtoy); if ($type == 8.3) { $horizasy = $yop; @@ -251,7 +285,8 @@ function fans_exps ($mh, $mk, $mx, $my, $m4, $m5, $type, $xop, $yop, $pixtox, $p function fans_logs ($mh, $mk, $mx, $my, $m4, $m5, $type, $xop, $yop, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop) = clean_up(array($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop) = clean_up(array($mh, $mk, $mx, $my, $m4, $m5, $xop, $yop)); + list(list($mh, $mx, $m4, $xop), list($mk, $my, $m5, $yop)) = change_to_math(array($mh, $mx, $m4, $xop), array($mk, $my, $m5, $yop), $pixtox, $pixtoy); if ($type == 8.4) { $vertasy = $xop; @@ -278,7 +313,7 @@ function fans_logs ($mh, $mk, $mx, $my, $m4, $m5, $type, $xop, $yop, $pixtox, $p list($str, $sign1) = add_sign($str, $sign1); list($yop, $sign2) = minus_sign($yop, $sign2); - $ans = sprintf("This includes function: x = %f %s %f * %f^(y %s %f)", $vertasy, $isgn1, $str, $base, $sign2, $yop); + $ans = sprintf("This includes function: x = %f %s %f * %f^(y %s %f)", $vertasy, $sign1, $str, $base, $sign2, $yop); return array($ans); } @@ -286,8 +321,9 @@ function fans_logs ($mh, $mk, $mx, $my, $m4, $m5, $type, $xop, $yop, $pixtox, $p function fans_rats ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = ($mx-$mh)*($my-$mk); list($ma, $sign1) = add_sign($ma, $sign1); @@ -300,23 +336,27 @@ function fans_rats ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { function fans_coss ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); - - $ma = (max($my,$mk)-min($my,$mk))/2; + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + + $ma = (abs($my - $mk))/2; $mb = pi()/(abs($mx - $mh)); - $mc = max($mx,$mh); + $mc = ($mh + $mx + (($mk > $my) - ($mk < $my)) * ($mh - $mx)) / 2; $md = ($my + $mk) / 2; list($mc, $sign1) = minus_sign($mc, $sign1); list($ma, $sign2) = add_sign($ma, $sign2); - $ans = sprintf("This includes function: y = %f %s %f * cos(%f * (x - %f))", $md, $sign2, $ma, $mb, $sign1, $mc); + $ans = sprintf("This includes function: y = %f %s %f * cos(%f * (x %s %f))", $md, $sign2, $ma, $mb, $sign1, $mc); return array($ans); } function fans_lines ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my), $pixtox, $pixtoy); + + list($mh, $mk, $mx, $my) = clean_up(array($mh, $mk, $mx, $my)); + list(list($mh, $mx), list($mk, $my)) = change_to_math(array($mh, $mx), array($mk, $my), $pixtox, $pixtoy); + $ma = ($my - $mk) / ($mx - $mh); $mb = $mk - ($ma * $mh); @@ -329,6 +369,9 @@ function fans_lines ($mh, $mk, $mx, $my, $pixtox, $pixtoy) { function fans_dots ($mh, $mk, $pixtox, $pixtoy) { + list($mh, $mk) = clean_up(array($mh, $mk)); + list(list($mh), list($mk)) = change_to_math(array($mh), array($mk), $pixtox, $pixtoy); + list($mh, $mk) = clean_up(array($mh, $mk), $pixtox, $pixtoy); $ans = sprintf("There is a dot at: (%f, %f)", $mh, $mk); @@ -338,7 +381,8 @@ function fans_dots ($mh, $mk, $pixtox, $pixtoy) { function fans_odots ($mh, $mk, $pixtox, $pixtoy) { - list($mh, $mk) = clean_up(array($mh, $mk), $pixtox, $pixtoy); + list($mh, $mk) = clean_up(array($mh, $mk)); + list(list($mh), list($mk)) = change_to_math(array($mh), array($mk), $pixtox, $pixtoy); $ans = sprintf("There is an open dot at: (%f, %f)", $mh, $mk); @@ -347,7 +391,8 @@ function fans_odots ($mh, $mk, $pixtox, $pixtoy) { function fans_ineqlines ($mh, $mk, $mx, $my, $mx2, $my2, $type, $pixtox, $pixtoy) { - list($mh, $mk, $mx, $my, $mx2, $my2) = clean_up(array($mh, $mk, $mx, $my, $mx2, $my2), $pixtox, $pixtoy); + list($mh, $mk, $mx, $my, $mx2, $my2) = clean_up(array($mh, $mk, $mx, $my, $mx2, $my2)); + list(list($mh, $mx, $mx2), list($mk, $my, $my2)) = change_to_math(array($mh, $mx, $mx2), array($mk, $my, $my2), $pixtox, $pixtoy); $in_type = floatval($type); if($in_type < floatval(10.3)) { @@ -434,6 +479,10 @@ function fans_ineqlines ($mh, $mk, $mx, $my, $mx2, $my2, $type, $pixtox, $pixtoy function fans_line1d ($mh, $mx, $pixtox, $pixtoy) { list($mh, $mx) = clean_up(array($mh, $mx), $pixtox, $pixtoy); + list($mh, $mx) = clean_up(array($mh, $mx)); + list(list($mh, $mx), ) = change_to_math(array($mh, $mx), array(), $pixtox, $pixtoy); + + $head = min($mh, $mx); $tail = max($mh, $mx); $ans = sprintf("There is a line from: %f to %f", $head, $tail); @@ -443,7 +492,8 @@ function fans_line1d ($mh, $mx, $pixtox, $pixtoy) { function fans_dots1d ($mh, $pixtox, $pixtoy) { - list($mh) = clean_up(array($mh), $pixtox, $pixtoy); + list($mh) = clean_up(array($mh)); + list(list($mh), ) = change_to_math(array($mh), array(), $pixtox, $pixtoy); $ans = sprintf("There is a dot at: %f", $mh); @@ -452,7 +502,8 @@ function fans_dots1d ($mh, $pixtox, $pixtoy) { function fans_odots1d ($mh, $pixtox, $pixtoy) { - list($mh) = clean_up(array($mh), $pixtox, $pixtoy); + list($mh) = clean_up(array($mh)); + list(list($mh), ) = change_to_math(array($mh), array(), $pixtox, $pixtoy); $ans = sprintf("There is an open dot at: %f", $mh);