UQM 2.0 - Predictions Extensions

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I just had a look at the code responsible for the stats, it might be a quick fix (it seemed to fix the problem here at CMX just then).

Open includes/quiz_stats_class.php

FIND:

Code: Select all

		$sql = 'SELECT SUM(quiz_correct) AS sum_correct, SUM(quiz_incorrect) AS sum_incorrect, user_id FROM ' . QUIZ_STATISTICS_OVERVIEW_TABLE . '
				GROUP BY quiz_correct
				ORDER BY sum_correct DESC';
REPLACE WITH

Code: Select all

		$sql = 'SELECT SUM(quiz_correct) AS sum_correct, SUM(quiz_incorrect) AS sum_incorrect, user_id FROM ' . QUIZ_STATISTICS_OVERVIEW_TABLE . '
				GROUP BY user_id
				ORDER BY sum_correct DESC';
I'll get to the script question in a minute :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Your attention to detail is applaudable...ill check this now

edit: looks fixed here too!
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Try this, open subvertbeats_quiz.php (control_quiz.php) and FIND:

FIND

Code: Select all

foreach($users_names as $key => $val)
				{
REPLACE WITH

Code: Select all

				$counter = 0;
				foreach($users_names as $key => $val)
				{
					if( $counter == 0 )
					{
						$counter++;
						echo 'QUIZ ID: ' . $quiz_id_key . '<br />';
					}
Then FIND:

Code: Select all

					echo 'Info for ' . $val . ';<br />';
					echo '-- Correct: ' .  $correct_answers . '<br />';
					echo '-- Incorrect: ' .  $incorrect_answers . '<br />';
					echo '-- Quiz ID: ' . $quiz_id_key . '<br />';
REPLACE WITH

Code: Select all

					echo $val . ' (correct: ' .  $correct_answers . ', incorrect: ' .  $incorrect_answers . ')<br />';
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

I think we're almost there....
User Dent answered question 31 INCORRECTLY. They entered the answer F.
User subvertbeats answered question 31 CORRECTLY
User Dent answered question 30 INCORRECTLY. They entered the answer D.
User subvertbeats answered question 30 INCORRECTLY. They entered the answer D.
User Dent answered question 29 CORRECTLY
User subvertbeats answered question 29 INCORRECTLY. They entered the answer A.
QUIZ ID:
Dent (correct: 1, incorrect: 2)
subvertbeats (correct: 1, incorrect: 2)
SQL Query entered

So, QUIZ ID and QUIZ NAME are not being outputted (need these), and the per user per question responses are still being printed (want to get rid of these, ideally just by commenting out so can re-enable later if any debugging needed)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Sorry for the delay in replying, I was adding a new stats module (users with the highest quiz percentage) you can see it at http://forums.cricketmx.com/quiz.php?mode=stats (down the bottom).

To comment out the question parts... find these two lines and add // before them:

Code: Select all

							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';

Code: Select all

							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';

To fix the QUIZ_ID bit, find:

Code: Select all

					if( $counter == 0 )
					{
						$counter++;
						echo 'QUIZ ID: ' . $quiz_id_key . '<br />';
					}
BEFORE ADD (there is another instance of this a little bit below, below the $incorrect_answers line - you can remove that now).

Code: Select all

$quiz_id_key = $users_information[$key]['quiz_id'];
To add the quiz name afterwards:

Now to add the QUIZ NAME...

FIND

Code: Select all

echo 'QUIZ ID: ' . $quiz_id_key . '<br />';

REPLACE WITH

Code: Select all

 echo 'QUIZ ID: ' . $quiz_id_key . ' QUIZ NAME: ' . get_quiz_title($quiz_id_key) . '<br />';

Let me know if that works.
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Ok.....

So, its all looking great.

One safety feature Id like to put in is for the stats for a given comp to be removed when you change the answers (i.e. to prevent stats being recorded twice).
In reality, it shouldnt happen - but human error could easily mean an incorrect result is submitted with the form, or a result may be overturned after the event, in which case we need to update the quiz with the new answer.

Currently, new statistics get added when you resubmit answers

if its too complex dont worry, I guess Im hoping its a simple thing to do.


One the enter answers page, the questions are still in an incorrect order.
Strange, as I cant see why that would be. Is it working of for you there?

Here is my completes control_quiz.php

Code: Select all

<?php
// control_quiz.php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_quiz.' . $phpEx);
include($phpbb_root_path . 'includes/quiz_stats_class.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);

   if( !$auth->acl_get('a_') )
   {
      die('No access');
   }

   else
   {
      if( $_GET['mode'] == 'deactivate' )
      {
         $deactivate_id = (int) $_GET['id'];

         $sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 1
               WHERE quiz_id = $deactivate_id";
         $db->sql_query($sql);
         die('Quiz id ' . $deactivate_id . ' has been deactivated');
      }

      if( $_GET['mode'] == 'activate' )
      {
         $activate_id = (int) $_GET['id'];

         $sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 0
               WHERE quiz_id = $activate_id";
         $db->sql_query($sql);
         die('Quiz id ' . $activate_id . ' has been activated');
      }

      if( $_GET['mode'] == 'enter_answers' )
      {
         if( $_GET['a'] == 'submit' )
         {
            $question_id_hidden = $_POST['questions'];
            $question_id_set = explode(',', $question_id_hidden);
            $question_id_set_count = sizeof($question_id_set) - 1;

            $users = array();
            $users_information = array();
            $users_names = array();

            for($i = 0; $i < $question_id_set_count; $i++ )
            {
               $sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
                     WHERE quiz_question_id = ' . $question_id_set[$i] . '
                     ORDER BY quiz_question_id ASC';
               $result = $db->sql_query($sql);
               while( $row = $db->sql_fetchrow($result) )
               {
                  $users[$i] = $row['quiz_player'];

                  $user_sql = 'SELECT username FROM ' . USERS_TABLE . '
                            WHERE user_id = ' . $row['quiz_player'];
                  $user_result = $db->sql_query($user_sql);
                  $user_name_fetch = $db->sql_fetchfield('username');
                  $db->sql_freeresult($user_result);

                  $users_names[$row['quiz_player']] = $user_name_fetch;

                  $is_correct = 0;
                  $is_incorrect = 0;

                  if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
                  {
                     // echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
         
                     $users_information[$row['quiz_player']]['quiz_correct']++;
                     $users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
                     $users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' correct';
                  }

                  else
                  {
                     // echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';

                     $users_information[$row['quiz_player']]['quiz_incorrect']++;
                     $users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
                     $users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
                  }
               }
            }

            /* for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
            {
               echo 'Username: ' . $users_names[$users[$j]] . '<br />';
               echo '-- Correct: ' .  $users_information[$users[$j]]['quiz_correct'] . '<br />';
               echo '-- Incorrect: ' .  $users_information[$users[$j]]['quiz_incorrect'] . '<br />';
               echo '-- Quiz ID: ' .  $users_information[$users[$j]]['quiz_id'] . '<br />';
            } */

            $counter = 0;
            foreach($users_names as $key => $val)
            {
				$quiz_id_key = $users_information[$key]['quiz_id'];
               if( $counter == 0 )
               {
                  $counter++;
                  echo 'QUIZ ID: ' . $quiz_id_key . ' QUIZ NAME: ' . get_quiz_title($quiz_id_key) . '<br />';
               }
               // $key is the user_id, $val is the username
               $correct_answers = ($users_information[$key]['quiz_correct']) ? $users_information[$key]['quiz_correct'] : 0;
               $incorrect_answers = ($users_information[$key]['quiz_incorrect']) ? $users_information[$key]['quiz_incorrect'] : 0;

               echo $val . ' (correct: ' .  $correct_answers . ', incorrect: ' .  $incorrect_answers . ')<br />';

               $statistical_overview_setup[] = array(
                  'quiz_id'         => (int) $quiz_id_key,
                    'quiz_correct'      => (int) $correct_answers,
                    'quiz_incorrect'   => (int) $incorrect_answers,
                  'user_id'         => (int) $key,
                  'quiz_time'         => (int) 0,
               );
            }

            $db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $statistical_overview_setup);

            echo 'SQL Query entered';

            die();
         }

         $quiz_id = (int) $_GET['id'];
         $sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
               WHERE quiz_related_id = ' . $quiz_id;
         $result = $db->sql_query($sql);
         echo '<form action="control_quiz.php?mode=enter_answers&id=' . $quiz_id . '&a=submit" method="post">';
         $question_id_hidden = '';
         while( $row = $db->sql_fetchrow($result) )
         {   
            $question_id_hidden .= $row['quiz_question_id'] . ',';
            echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
            // echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
            echo 'Correct answer:';

            $ans = 'SELECT quiz_answer FROM ' . QUIZ_DATA_TABLE . '
                  WHERE quiz_question_id = ' . $row['quiz_question_id'];
            $ans_res = $db->sql_query($ans);
            while( $ans_row = $db->sql_fetchrow($ans_res) )
            {
               echo '<input type="radio" value="' . $ans_row['quiz_answer'] . '" name="question' . $row['quiz_question_id'] . '" /> ' . $ans_row['quiz_answer'] . '&nbsp;&nbsp;&nbsp;';
            } 

            echo '<br /><br />';
         }
         echo '<input type="hidden" value="' . $question_id_hidden . '" name="questions" />';
         echo '<input type="submit" value="Submit" name="submit" />';
         echo '</form>';

         die(); // new
      }

      else
      {
         echo 'Mode types:<br />
            <strong>control_quiz.php?mode=deactivate&id=XXX</strong><br />
            <strong>control_quiz.php?mode=activate&id=XXX</strong><br />
            <strong>control_quiz.php?mode=enter_answers&id=XXX</strong>';
         die();
      }
   }
?>
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

One safety feature Id like to put in is for the stats for a given comp to be removed when you change the answers (i.e. to prevent stats being recorded twice).
In reality, it shouldnt happen - but human error could easily mean an incorrect result is submitted with the form, or a result may be overturned after the event, in which case we need to update the quiz with the new answer.

Currently, new statistics get added when you resubmit answers
You could remove all stats for a certain quiz with a single SQL query, run in phpMyAdmin:

Code: Select all

DELETE FROM phpbb_quiz_statistics_overview WHERE quiz_id = XXX;
Then re-run the control_quiz script with the correct answer.
One the enter answers page, the questions are still in an incorrect order.
Strange, as I cant see why that would be. Is it working of for you there?
Does the incorrect order matter? It doesn't really have an effect on anything. I did try and order them by id, but it seems like quite a minor thing.
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

It is indeed a minor thing, and with that SQL code to delete the stats for a given quiz ID I think we're set!

Ive updated the OP, and everything in Phase 1 seems to be taken care of!
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Ahh not quite there....

The correct/incorrect ordering seems wrong:

QUIZ ID: 8 QUIZ NAME: Heres my test comp
Dent (correct: 1, incorrect: 2)
subvertbeats (correct: 2, incorrect: 1)
SQL Query entered

(in the above example subvertbeats should be above Dent, with less incorrect answers).

Is this working on your side?


edit: just fyi this is important because we get hundreds of users entering the comps, so proper sorting here enables us to easily find the winners, without risk of error
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Hmm, okay. I don't want to go too far down this path because this could be a very timely exercise.

FIND

Code: Select all

				$counter = 0;
				$highest_correct = 0;
AFTER ADD

Code: Select all

				$output_array = array();
FIND

Code: Select all

echo $val . ' (correct: ' .  $correct_answers . ', incorrect: ' .  $incorrect_answers . ')<br />';
REPLACE WITH

Code: Select all

					$output_array[$correct_answers][] = $val . ' (correct: ' .  $correct_answers . ', incorrect: ' .  $incorrect_answers . ')<br />';
					$highest_correct = ($correct_answers > $highest_correct) ? $correct_answers : $highest_correct;
FIND

Code: Select all

				$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $statistical_overview_setup);
BEFORE ADD

Code: Select all

				for( $m = 0; $m <= $highest_correct; $m++ )
				{
					$size_current_ca = sizeof($output_array[$m]);
					if( $size_current_ca > 0 )
					{
						for( $n = 0; $n < $size_current_ca; $n++ )
						{
							echo $output_array[$m][$n];
						}
					}
				}
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Many thanks battye......Looks to be working, but in reverse:
QUIZ ID: 9 QUIZ NAME: Test Event
Kamara666 (correct: 0, incorrect: 3)
jnrpepaseed (correct: 1, incorrect: 2)
Dragonfoxy (correct: 1, incorrect: 2)
subvertbeats (correct: 2, incorrect: 1)
SQL Query entered
Is it simple to swap the order to be correct descending (aka incorrect ascending) ?
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Find:

Code: Select all

for( $m = 0; $m <= $highest_correct; $m++ )
REPLACE WITH

Code: Select all

for( $m = $highest_correct; $m >= 0; $m-- )
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

In the spirit of the site....and to remember one of the greats

Image
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

One usage question on this battye....

If a match is cancelled, perhaps mid way through the week, when the comp is still open and lots of people have made their votes already, what is the correct procedure to remove that question from the comp (or mark it as invalid if removal is not possible), such that future entrants dont vote on that particular match, and most importantly, so the results for that particular match are not counted?

Thanks for your advice...
User avatar
moongirl
Moderator
Moderator
Posts: 19016
Joined: Mon Jan 12, 2004 8:07 am

subvertbeats wrote:One usage question on this battye....

If a match is cancelled, perhaps mid way through the week, when the comp is still open and lots of people have made their votes already, what is the correct procedure to remove that question from the comp (or mark it as invalid if removal is not possible), such that future entrants dont vote on that particular match, and most importantly, so the results for that particular match are not counted?

Thanks for your advice...

Subvertbeats...CMX's quiet achiever! :wink:
Congratulations on the Image rank that I missed at 25 posts...
and the new rank of Image you achieved at 50 posts! =D>
http://forums.cricketmx.com/viewtopic.p ... 221#p99221
Image
That's not the man in the moon...that's me ;)
Post Reply