| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- <?php
- require_once __DIR__ . '/TkAnswerStore.php';
- class TK2 {
-
- private $data = [];
- private $subjectsList = [
- // Math
- [['numbers',1,0],// number sequences
- ['addition',1,10000],// Numeracy adding
- ['subtraction',1,20000],// Numeracy minus'
- ['multiplication',1,200000],// Numeracy times'
- ['division',0,0],// Numeracy deviding
- ['rounding',0,0],// Numeracy rounding
- ['worded_add',0,0],// Numeracy worded adding
- ['worded_sub',0,0],// Numeracy worded minusing
- ['worded_mult',0,0],// Numeracy worded timesing
- ['worded_devi',0,0],// Numeracy worded deviding
- ],
- // English
- [['spelling',1,0],// Plain spelling
- ['anagrams',1,4000000],// Shuffle letters in a word
- ],
- // General knowledge
- [['generalKnowledge',0,0],// Name kinda says it all
- ],
- // Science
- [['elements',1,150000],// Periodic table of elements
- ],
- // Geography
- [['continents',0,0],// Point to the continent
- ['countries',0,0],// Point to the country
- ['flags',0,0],// Name the country by the flag picture
- ['capitalCities',0,0],// Name the capital for a country
- ],
- // History
-
- // Art
- [['artists',0,0],// Name the artist for famous paintings
- ],
- // Technology
-
-
- // language
- [['malaySpelling',0,0],// This could be interesting
- ],
- // Health - Health and Physical Education
- [['nameBodyParts',0,0],// Name the body parts from the images or point to the part
- ['nameBodyOrgans',0,0],// Name the organs or what they do
- ['basicFirstAid',0,0],// Some BASIC things to know for first aid
- ],
- ];
- /**
- * Run the timekeeper functionality
- */
- public function run(): void {
- if (check_class("TIMEKEEPER_STUDENT")) {
- $this->student();
- }
- if (check_class("TIMEKEEPER_TEACHER")) {
- $this->teacher();
- }
- if (check_class("Main Admin")) {
- $this->adminDev();
- }
- }
-
- /**
- * Run the sequence for admin/developer
- */
- /**
- * Run the sequence for admin/developer
- */
- private function adminDev(): void {
- e107::getRender()->tablerender('Developer', '=================================================================');
-
- ///////////////////////
- //// testing !!!!!!!
- ///////////////////////
- $sign = 'X';
- $difficulty = [
- 'count' => 64,
- 'percent' => 75
- ];
- if($sign=='X'||$sign=='/')
- {
- $difficulty['count'] = (int)$difficulty['count'] / 4;
- $difficulty['percent'] = (int)$difficulty['percent'] / 6;
- }
-
- if($difficulty['count'] >= 300) {
- $startingNumber = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2));
- $endingNumber = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2));
- $returnNumbers = [$startingNumber, $endingNumber];
- } elseif($difficulty['count'] >= 200) {
- $startingNumber = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/100)*2);
- $endingNumber = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/100)*2);
- $returnNumbers = [$startingNumber, $endingNumber];
- } elseif($difficulty['count'] >= 100) {
- $startingNumber = mt_rand(0, (int) ($difficulty['percent'])*2);
- $endingNumber = mt_rand(0, (int) ($difficulty['percent'])*2);
- $returnNumbers = [$startingNumber, $endingNumber];
- } else {
- $startingNumber = mt_rand(0, $difficulty['count'] + 1);
- $endingNumber = mt_rand(0, $difficulty['count'] + 1);
- $returnNumbers = [$startingNumber, $endingNumber];
- }
- print_a(['testingData'=>['$sign'=>$sign,'$difficulty[\'count\']'=>$difficulty['count'],'$difficulty[\'percent\']'=>$difficulty['percent'],'$startingNumber'=>$startingNumber,'$endingNumber'=>$endingNumber,'$returnNumbers'=>$returnNumbers]]);
-
- ///////////////////////
- //// Overrides !!!!!!!
- ///////////////////////
- $this->data['user'] = 'silas';
-
- $this->getScores($this->data['user']);
- $this->showMessage();
- $this->data['user'] = 'silas';//'gregory';
- $this->getScores($this->data['user']);
- $this->showMessage();
- $this->data['user'] = 'elliot';//'gregory';
- $this->getScores($this->data['user']);
- $this->showMessage();
-
- // =====================================================================
- // =========== Testing area ============================================
- // =====================================================================
- //$difficulty = ['count'=>22,'percent'=>63.6364]; // Silas add
- //$difficulty = ['count'=>213,'percent'=>99.0610]; // Elliot add
- //$difficulty = ['count'=>21,'percent'=>33.3333]; // Silas sub
- //$difficulty = ['count'=>207,'percent'=>97.5845]; // Elliot sub
- //$difficulty = ['count'=>0,'percent'=>null]; // Silas mult
- $difficulty = ['count'=>201,'percent'=>98.5075]; // Elliot mult
-
-
- $startingNumber4 = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2));
- $endingNumber4 = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2));
-
- $startingNumber3 = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/50)*2);
- $endingNumber3 = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/50)*2);
-
- $startingNumber2 = mt_rand(0, (int) ($difficulty['percent']/10)*4);
- $endingNumber2 = mt_rand(0, (int) ($difficulty['percent']/10)*4);
-
- $startingNumber1 = mt_rand(0, $difficulty['count'] + 5);
- $endingNumber1 = mt_rand(0, 10);
-
-
- print_a([['startingNumber1'=>$startingNumber1,'endingNumber1'=>$endingNumber1],
- ['startingNumber2'=>$startingNumber2,'endingNumber2'=>$endingNumber2],
- ['startingNumber3'=>$startingNumber3,'endingNumber3'=>$endingNumber3],
- ['startingNumber4'=>$startingNumber4,'endingNumber4'=>$endingNumber4],]);
- // =====================================================================
- // =========== End Testing area ========================================
- // =====================================================================
-
- //$this->checkAnswer();
-
-
- // If the last question has not been answered ask again.
- // if($this->getLastQuestion()){
- // return;
- // }
- //$this->data['selectedSubject'] = 'addition';
- //$this->getQuestion();
- //$this->data['selectedSubject'] = 'subtraction';
- //$this->getQuestion();
-
- //$this->data['selectedSubject'] = 'multiplication';
- $this->data['selectedSubject'] = 'continents';
-
- $this->getQuestion();
-
- //$this->data['selectedSubject'] = 'division';
- //$this->getQuestion();
-
- //$this->data['selectedSubject'] = 'rounding';
- //$this->getQuestion();
-
- date_default_timezone_set('Australia/Perth');
- $QuestionsAnswered = e107::getDb()->retrieve('tkReport', 'COUNT(id)', 'username="elliot" '
- . 'AND answereddatestamp >= "' . mktime(0, 0, 0, date('n'), date('j')) . '" '
- . 'AND answereddatestamp <= "' . mktime(23, 59, 59, date('n'), date('j')) . '"');
- $settings = e107::getDb()->retrieve('timekeeper', '*', 'username="elliot"');
- print_a(['ElliotsCounter'=>$QuestionsAnswered,'ElliotsSettings'=>$settings]);
-
- //print_a($this->subjectsList);
- print_a($this->data);
-
- $stats = e107::getDb()->retrieve("SELECT (SUM(correct)/COUNT(correct)*100) as percent,COUNT(correct) as count
- FROM e107.`e107_tkReport` WHERE
- answereddatestamp >= unix_timestamp((NOW()) - INTERVAL 1 MONTH)
- AND username = 'elliot' AND subject = 'multiplication';");
- print_a($stats);
- // Look inside data bases
- if(false)
- {
- //e107_timekeeper
- //e107_timekeeperPending
- //e107_timekeeperQuestions
- //e107_timekeeperReport
- //e107_timekeeperScore
- //e107_timekeeperStatistics
- //e107_timekeeperStats
- //e107_tkLastQuestion
- //e107_tkReport
- //e107_tk_wordList
-
- //e107::getDb()->gen("SHOW TABLES;");
- e107::getDb()->gen("SHOW COLUMNS FROM e107_tkReport;");
-
- while ($row = e107::getDb()->fetch()) {
-
- print_a( $row );
-
- }
- }
-
- e107::getRender()->tablerender('Developer.', '=================================================================');
- }
-
-
- /**
- * Run the sequence for teachers
- */
- /**
- * Run the sequence for teachers
- */
- private function teacher(): void {
-
- }
-
- /**
- * Run the sequence for students
- */
- /**
- * Run the sequence for students
- */
- private function student(): void {
-
- $this->checkAnswer(e107::getUser()->getLoginName());
-
- $this->getScores(e107::getUser()->getLoginName());
- $this->showMessage();
-
- // If the last question has not been answered ask again.
- if($this->getLastQuestion()){
- return;
- }
-
- $this->getSubject();
- $this->getQuestion();
- }
-
- /**
- * Check if the last question was answered and check the answer
- */
- /**
- * Check if the last question was answered and check the answer
- * @param string $user
- */
- private function checkAnswer($user): void {
- $subject = filter_input(INPUT_POST,'subject');
- if(isset($subject)){
- include './answerChecker2.php';
- $ac = new answerChecker2();
- $ac->checkQuestionSubject($subject,$user);
- e107::getDb()->delete('tkLastQuestion',"user = '".$user."'",true);
- }
- }
-
- /**
- * Get the the last question asked if available
- */
- /**
- * Get the last question asked if available
- * @return bool
- */
- private function getLastQuestion(): bool {
- $lastQuestion = e107::getDb()->retrieve("SELECT LastQuestionHtml FROM e107.`e107_tkLastQuestion` WHERE user = '".$this->data['user']."';");
- //print_a(base64_decode($lastQuestion));
- if(isset($lastQuestion)){
- e107::getRender()->tablerender('Last Question', base64_decode($lastQuestion));
- return true;
- }
- return false;
- }
-
- /**
- * Get the list of available subjects and select a random one.
- */
- /**
- * Get the question based on selected subject
- * @return void
- */
- private function getQuestion(): void {
- switch ($this->data['selectedSubject']) {
- case 'numbers':
- include './questionGenerators/math/numbers2.php';
- $questionGen = new numbers2($this->data['user']);
- $questionGen->getNumbers();
- break;
- case 'addition':
- case 'subtraction':
- case 'multiplication':
- case 'division':
- case 'rounding':
- include './questionGenerators/math/numeracy2.php';
- $questionGen = new numeracy2($this->data['user'],$this->data['selectedSubject']);
- $questionGen->getNumeracy();
- break;
- case 'worded_add':
- case 'worded_sub':
- case 'worded_mult':
- case 'worded_devi':
- case 'spelling':
- include './questionGenerators/english/spelling2.php';
- $questionGen = new spelling2($this->data['user']);
- $questionGen->getSpellingWord();
- break;
- case 'anagrams':
- include './questionGenerators/english/anagrams.php';
- $questionGen = new anagrams($this->data['user']);
- $questionGen->getanagram();
- break;
- case 'generalKnowledge':
- include './questionGenerators/general/generalKnowledge.php';//=========================== TODO:not working yet
- $questionGen = new generalKnowledge($this->data['user']);
- $questionGen->getgeneralKnowledge();
- case 'elements':
- include './questionGenerators/science/elements2.php';
- $questionGen = new elements2($this->data['user']);
- $questionGen->getElements();
- break;
- case 'continents':
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
- $questionGen = new continents($this->data['user']);
- $questionGen->getContinents();
- break;
- case 'countries':
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
- $questionGen = new elements2($this->data['user']);
- $questionGen->getElements();
- break;
- case 'flags':
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
- $questionGen = new elements2($this->data['user']);
- $questionGen->getElements();
- break;
- case 'capitalCities':
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
- $questionGen = new elements2($this->data['user']);
- $questionGen->getElements();
- break;
- case 'artists':
- case 'malaySpelling':
- case 'nameBodyParts':
- case 'nameBodyOrgans':
- case 'basicFirstAid':
-
- default:
- print_a('An error has been detected in the question selector. Please report this and refresh the page.');
- break;
- }
- }
-
- /**
- * Get the list of available subjects and select a random one.
- */
- /**
- * Get the list of available subjects and select a random one.
- * @return void
- */
- private function getSubject(): void {
- $usableSubjects = [];
- foreach ($this->subjectsList as $subjects){
- foreach ($subjects as $subject){
- if($subject[1]===1&&$this->data['difficulty']>=$subject[2]){
- $usableSubjects[] = $subject[0];
- }
- }
- }
- $this->data['selectedSubject'] = $usableSubjects[mt_rand('0',count($usableSubjects)-1)];
- }
-
- /**
- * Show an initial stats message to the user.
- */
- /**
- * Show an initial stats message to the user.
- * @return void
- */
- private function showMessage(): void {
- $ns = e107::getRender();
- $text = "You have answered ".$this->data['cntr']." questions this month.<br/>"
- . "Your accuacy for the month is ".$this->data['percent']."%.<br/>"
- . "Your difficulty is set at ".$this->data['difficulty'].".<br/><br/>";
-
- $ns->tablerender('Your stats '.ucfirst($this->data['user']), $text);
- }
-
- /**
- * Get the initial values needed to generate a sane question.
- * @param type $user
- */
- /**
- * Get the initial values needed to generate a sane question.
- * @param string $user
- * @return void
- */
- private function getScores($user): void {
- $returnArray = [];
- $returnArray['totalQuestionCount'] = e107::getDb()->count("tkReport", "(id)", "username = '" . $user . "'");
- e107::getDb()->gen("SELECT COUNT(id) as cntr, CAST((SUM(correct)/COUNT(id)*100) as DECIMAL(5,2)) as percent
- FROM e107.`e107_tkReport` WHERE username = '" . $user . "'
- AND answereddatestamp >= unix_timestamp(CURRENT_DATE() - INTERVAL 1 MONTH)
- AND answereddatestamp <= unix_timestamp(CURRENT_DATE() + INTERVAL 1 DAY)");
- while ($row = e107::getDb()->fetch()) {
- $returnArray = array_merge($returnArray,$row);
- }
- $returnArray['user'] = $user;
- $returnArray['difficulty'] = $returnArray['totalQuestionCount']*$returnArray['percent'];
-
- $this->data = $returnArray;
-
- }
-
- }
|