From 8aca14df24948705cd7209cebca5339dc3e75838 Mon Sep 17 00:00:00 2001 From: Lucas Woltmann Date: Tue, 2 Aug 2016 10:45:02 +0200 Subject: [PATCH] refactors analysis page also: documentation! --- analysis.php | 81 ++++++++-------------------------- analysisTut.php | 81 ++++++++-------------------------- libs/chartLib.php | 110 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 140 insertions(+), 132 deletions(-) diff --git a/analysis.php b/analysis.php index 25d3f4b..83d679c 100755 --- a/analysis.php +++ b/analysis.php @@ -10,7 +10,7 @@ include_once 'libs/formLib.php'; include_once 'libs/questionnaireLib.php'; include_once 'libs/loggingLib.php'; - include_once 'libs/chartLib.php'; + include_once 'libs/chartLib.php'; // variables for the log data $questionData; @@ -62,43 +62,19 @@ echo " \n"; echo "
\n"; echo "
\n"; + + $width = 800; + $height = 300; - $width = 800; - $height = 300; - - //find max of answers to set max of x-axis, max of y-axis is always seven, because there are six possibilities to answer - $values = $question; - array_shift($values); - $maxX = max($values)+1; - $maxY = 7; - - $img = CreateImage($width, $height); - - // the amount of answers for the different options and a nice group of bars - for ($i = 1; $i < 7; $i++) - { - echo "

" . $question[$i] . "

\n"; - $green = 150*($question[$i]/$maxX) + 40; - $color = ImageColorAllocate($img, 0.57 * $green, $green, 0.45 * $green); - DrawBar($img, $question[$i], $maxX, $i+1, $maxY, $question[$i], $color); - } - - //finish image and save it - $caption = array("N/A","--","-", "0", "+", "++"); - DrawCoords($img, $maxX, $maxY, $caption); - - $file=str_replace("?", "", str_replace(" ", "", $question[0])); - - ImagePNG($img,"question".$file.".png"); - ImageDestroy($img); + $file = CreateQuestionBar($width, $height, $question); echo "
\n"; echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo " "; - echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo " "; + echo "
\n"; echo "\n"; } } @@ -126,39 +102,18 @@ echo "
\n"; echo "
\n"; - $width = 800; - $height = 300; + $width = 800; + $height = 300; - //find max of answers to set max of x-axis, max of y-axis is always seven, because there are six possibilities to answer - $maxX = max($tutor)+1; - $maxY = 7; - - $img = CreateImage($width, $height); - - // the amount of answers for the different options and a picture - for ($i = 0; $i < 6; $i++) - { - echo "

" . $tutor[$i] . "

\n"; - $green = 150*($tutor[$i]/$maxX) + 40; - $color = ImageColorAllocate($img, 0.54 * $green, $green, 0.45 * $green); - DrawBar($img, $tutor[$i], $maxX, $i+2, $maxY, $tutor[$i], $color); - } - - //finish image and save it - $caption = array("N/A","--","-", "0", "+", "++"); - DrawCoords($img, $maxX, $maxY, $caption); - - $file = str_replace(" ", "", $tutorName); - ImagePNG($img,"tutor".$file.".png"); - ImageDestroy($img); + $file = CreateTutorBar($width, $height, $tutorName, $tutor); echo "
\n"; echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo " "; - echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo " "; + echo "
\n"; echo "\n"; } diff --git a/analysisTut.php b/analysisTut.php index 6691cd4..e5d958f 100644 --- a/analysisTut.php +++ b/analysisTut.php @@ -63,42 +63,18 @@ echo "
\n"; echo "
\n"; - $width = 800; - $height = 300; - - //find max of answers to set max of x-axis, max of y-axis is always seven, because there are six possibilities to answer - $values = $question; - array_shift($values); - $maxX = max($values)+1; - $maxY = 7; - - $img = CreateImage($width, $height); - - // the amount of answers for the different options and a nice group of bars - for ($i = 1; $i < 7; $i++) - { - echo "

" . $question[$i] . "

\n"; - $green = 150*($question[$i]/$maxX) + 40; - $color = ImageColorAllocate($img, 0.57 * $green, $green, 0.45 * $green); - DrawBar($img, $question[$i], $maxX, $i+1, $maxY, $question[$i], $color); - } - - //finish image and save it - $caption = array("N/A","--","-", "0", "+", "++"); - DrawCoords($img, $maxX, $maxY, $caption); - - $file=str_replace("?", "", str_replace(" ", "", $question[0])); - - ImagePNG($img,"question".$file.".png"); - ImageDestroy($img); + $width = 800; + $height = 300; + + $file = CreateQuestionBar($width, $height, $question); echo "
\n"; echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo " "; - echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo " "; + echo "
\n"; echo "\n"; } } @@ -126,39 +102,18 @@ echo "
\n"; echo "
\n"; - $width = 800; - $height = 300; - - //find max of answers to set max of x-axis, max of y-axis is always seven, because there are six possibilities to answer - $maxX = max($tutor)+1; - $maxY = 7; - - $img = CreateImage($width, $height); - - // the amount of answers for the different options and a picture - for ($i = 0; $i < 6; $i++) - { - echo "

" . $tutor[$i] . "

\n"; - $green = 150*($tutor[$i]/$maxX) + 40; - $color = ImageColorAllocate($img, 0.54 * $green, $green, 0.45 * $green); - DrawBar($img, $tutor[$i], $maxX, $i+2, $maxY, $tutor[$i], $color); - } - - //finish image and save it - $caption = array("N/A","--","-", "0", "+", "++"); - DrawCoords($img, $maxX, $maxY, $caption); - - $file = str_replace(" ", "", $tutorName); - ImagePNG($img,"tutor".$file.".png"); - ImageDestroy($img); + $width = 800; + $height = 300; + + $file = CreateTutorBar($width, $height, $tutorName, $tutor); echo "
\n"; echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo " "; - echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo " "; + echo "
\n"; echo "\n"; } diff --git a/libs/chartLib.php b/libs/chartLib.php index ce2cbd8..0de65d0 100755 --- a/libs/chartLib.php +++ b/libs/chartLib.php @@ -1,12 +1,20 @@ \ No newline at end of file +/** + * Creates a new bar plot for the given question data. Returns name of saved png file. + * + * @param integer $width The desired width of the image. + * @param integer $height The desired height of the image. + * @param array $question The question data. + */ +function CreateQuestionBar($width, $height, $question) +{ + //find max of answers to set max of x-axis, max of y-axis is always seven, because there are six possibilities to answer + $values = $question; + array_shift($values); + $maxX = max($values)+1; + $maxY = 7; + + $img = CreateImage($width, $height); + + // the amount of answers for the different options and a nice group of bars + for ($i = 1; $i < 7; $i++) + { + echo "

" . $question[$i] . "

\n"; + $green = 150*($question[$i]/$maxX) + 40; + $color = ImageColorAllocate($img, 0.57 * $green, $green, 0.45 * $green); + DrawBar($img, $question[$i], $maxX, $i+1, $maxY, $question[$i], $color); + } + + //finish image and save it + $caption = array("N/A","--","-", "0", "+", "++"); + DrawCoords($img, $maxX, $maxY, $caption); + + $file = str_replace("?", "", str_replace(" ", "", $question[0])); + $file = "question".$file.".png"; + + ImagePNG($img, $file); + ImageDestroy($img); + + return $file; +} +/** + * Creates a new bar plot for the given tutor data. Returns name of saved png file. + * + * @param integer $width The desired width of the image. + * @param integer $height The desired height of the image. + * @param string $title The file name of the image. (Should be tutor's name) + * @param array $tutor The tutor data. + */ +function CreateTutorBar($width, $height, $title, $tutor) +{ + //find max of answers to set max of x-axis, max of y-axis is always seven, because there are six possibilities to answer + $maxX = max($tutor)+1; + $maxY = 7; + + $img = CreateImage($width, $height); + + // the amount of answers for the different options and a picture + for ($i = 0; $i < 6; $i++) + { + echo "

" . $tutor[$i] . "

\n"; + $green = 150*($tutor[$i]/$maxX) + 40; + $color = ImageColorAllocate($img, 0.54 * $green, $green, 0.45 * $green); + DrawBar($img, $tutor[$i], $maxX, $i+2, $maxY, $tutor[$i], $color); + } + + //finish image and save it + $caption = array("N/A","--","-", "0", "+", "++"); + DrawCoords($img, $maxX, $maxY, $caption); + + $file = str_replace(" ", "", $title); + $file = "tutor".$file.".png"; + + ImagePNG($img, $file); + ImageDestroy($img); + + return $file; +} +?>