Debugging Our Computer Science Trivia Feature


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
The Lounge What is on Your Mind? Debugging Our Computer Science Trivia Feature
# 1  
Debugging Our Computer Science Trivia Feature

Only a few days after I coded this new feature from scratch, we are seeing over 3000 entries in the database from members (mostly guests) playing CS trivia.

I have spend a lot of time coding this (from scratch) and testing the API. From the logs, it seems to have an API bug which appears about 5 times or less per thousand impressions, but I am not sure.

The bug seems to happen when there is some issue where the answer to a question in the Javascript is blank (on rare occasion) or there is a problem with the AJAX XHR request based on a network issue.

I have written a lot of "error trapping" code today to try to see exactly what causes this small bug.

If anyone sees any CS trivia statement and their T/F answer seems wrong, the issue is more-than-likely related to this rare bug, but then again, it could be a typo in the DB (or some strange HTML entity which was not encoded and decoded properly). So, if you do see anything which seems ODD, please take a screenshot of your screen and post it back here.

If you are a savvy at web dev, you can help out by opening your web dev console and inspecting the Javascript console and the Network XHR request and responses (and take a screen shot of any console errors and the XHR request / response).

Either way, if anyone want to help debug the API during the testing phase, the best way to debug is to answer a lot of questions, push NEXT and answer more. I have done this for the past two days for countless hours and I think I have trapped most network and AJAX issues, but I am sure there are more bugs, as there are always bugs in new code, without exception.

Please note that today one user from the Philippines answered over 100 questions. A lot of people worldwide are finding good value with this new feature so you can help me and help others by helping debug, so I can make sure all errors are trapped.

Thanks for help debugging.


Cheers!

Note: Code and other special chars must be encoded before they are submitted to the DB (for DB integrity) and I have written some special code to decode the HTML entities (in JS) but there are some occasional HTML entities (encodings) which are not decoded properly. If you see any of the HTML entities still encoded, please take a screen shot and post back so I can trap those and decode them as well. If you do not know what an HTML entity is, I have screen shots I can share Smilie
# 2  
Here is any example (see screenshot) of an encode HTML entity which I trapped and decoded (in a custom JS function I wrote) yesterday:

Code:
&ndash

Image

However, I don't think these occasional encoded HTML entities are causing the rare bug where the correct answer to a T/F statement is null, causing some rare problem I have am still debugging.

Cheers.
# 3  
OBTW,

I am logging every request and response..... and so far, so good.

I would like to remind everyone that I started coding this from SCRATCH on October 27th. Today is November 1st.

If anyone here can code a new feature so quickly in PHP, HTML and Javascript including building the DB, all the XHR calls, debug the APIs, and create over 600 good CS trivia questions, and a the same time insuring the API is secure, please do so now Smilie

Otherwise.... kindly help me debug by answering a lot of questions, click next, answer more, taking screenshots of any issues you might encounter and if you can use the Web Dev console, please do so!

Smilie

Current user interactions (which is much higher than I anticipated when I started coding this a few days ago):

Code:
mysql> select count(*) from neo_trivia_scoreboard;
+----------+
| count(*) |
+----------+
|     3048 |
+----------+
1 row in set (0.00 sec)

Size of CS trivia DB as of right now:

Code:
mysql> select count(*) from neo_open_trivia;
+----------+
| count(*) |
+----------+
|      625 |
+----------+
1 row in set (0.00 sec)

# 4  
On a specific question note (318) ....

Code:
mysql> select * from neo_open_trivia where id = 318;
+-----+----------+---------+------------+--------------------------+----------------+-------------------+-----------+----------------+------------------+------------------+----------------+--------------------+
| id  | category | type    | difficulty | question                 | correct_answer | incorrect_answers | validated | time_validated | userid_validated | userid_submitted | time_submitted | time_last_modified |
+-----+----------+---------+------------+--------------------------+----------------+-------------------+-----------+----------------+------------------+------------------+----------------+--------------------+
| 318 |       18 | boolean | easy       | MacOS is based on Linux. | False          | True              |         0 |     1572497150 |                0 |                1 |     1572151119 |         1572151119 |
+-----+----------+---------+------------+--------------------------+----------------+-------------------+-----------+----------------+------------------+------------------+----------------+--------------------+
1 row in set (0.00 sec)

A user got a wrong answer and it was not recorded (submitted) to the DB (this error was due to a bug in the browser, not in the DB):

Code:
mysql> select uid,results from neo_trivia_scoreboard where trivia_id = 318;
+-----+---------+
| uid | results |
+-----+---------+
|   0 | right   |
|   0 | right   |
|   0 | right   |
|   0 | right   |
|   0 | right   |
|   0 | right   |
|   0 | right   |
|   0 | right   |
+-----+---------+
8 rows in set (0.00 sec)

So, I am pretty sure there is still a small bug somewhere which is causing some rare errors, so I am logging every request at this time, debugging.

Javascript must be enabled in order to work properly. If your browser is blocking JS, you will get wrong answers (errors) because the app needs JS to work properly and I have not written any code yet to check for JS, etc, and block users from trivia who have JS disabled or their browser is blocking JS.
# 5  
Also regarding id: 318:

Code:
 grep 318 *

neo_trivia_api_debug.log:source: unix {"response_code":0,"id":318,"results":[{"category":"Science: Computers","type":"boolean","difficulty":"easy","question":"MacOS is based on Linux.","correct_answer":"False","incorrect_answers":["True"]}]}: {"response_code":0,"id":318,"results":[{"category":"Science: Computers","type":"boolean","difficulty":"easy","question":"MacOS is based on Linux.","correct_answer":"False","incorrect_answers":["True"]}]} api: https://www.unix.com/trivia/api.php
neo_trivia_api_debug.log:source: unix {"response_code":0,"id":318,"results":[{"category":"Science: Computers","type":"boolean","difficulty":"easy","question":"MacOS is based on Linux.","correct_answer":"False","incorrect_answers":["True"]}]}: {"response_code":0,"id":318,"results":[{"category":"Science: Computers","type":"boolean","difficulty":"easy","question":"MacOS is based on Linux.","correct_answer":"False","incorrect_answers":["True"]}]} api: https://www.unix.com/trivia/api.php
neo_trivia_api_debug.log:source: unix trivia: {"response_code":0,"id":318,"results":[{"category":"Science: Computers","type":"boolean","difficulty":"easy","question":"MacOS is based on Linux.","correct_answer":"False","incorrect_answers":["True"]}]} api: https://www.unix.com/trivia/api.php
neo_trivia_api_debug.log:source: unix trivia: {"response_code":0,"id":318,"results":[{"category":"Science: Computers","type":"boolean","difficulty":"easy","question":"MacOS is based on Linux.","correct_answer":"False","incorrect_answers":["True"]}]} api: https://www.unix.com/trivia/api.php
neo_trivia_user_neo.log:Thu, 31 Oct 2019 05:04:57 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: FR Name: Unregistered
neo_trivia_user_neo.log:Thu, 31 Oct 2019 05:27:37 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: RU Name: Unregistered
neo_trivia_user_neo.log:Thu, 31 Oct 2019 06:30:20 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: US Name: Unregistered
neo_trivia_user_neo.log:Thu, 31 Oct 2019 09:52:51 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: CZ Name: Unregistered
neo_trivia_user_neo.log:Thu, 31 Oct 2019 09:52:55 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: AR Name: Unregistered
neo_trivia_user_neo.log:Thu, 31 Oct 2019 18:44:52 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: US Name: Unregistered
neo_trivia_user_neo.log:Thu, 31 Oct 2019 22:58:31 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: AU Name: Unregistered
neo_trivia_user_neo.log:Fri, 01 Nov 2019 06:21:31 -0400: userid: 0 site: unix id: 318 answer: right Category: 18 IP: masked Country: IN Name: Unregistered

Regarding this question, there is no recorded "wrong answer" (True) in the DB.... all the answers so far, recorded in the DB and logs, were "False" (which is "right")
# 6  
Looking at the log files and inside the DB this morning, I have added some additional string filtering for questions, for example:

Code:
<?php
$question =  filter_var($question, FILTER_SANITIZE_STRING,FILTER_FLAG_STRIP_HIGH);

because I was seeing some unprintable chars in the JSON response to the AJAX request, so hopefully, stripping out these symbols will help.

Status Update:



Total Interactions in DB (questions answered so far):

Code:
mysql> select count(*) from neo_trivia_scoreboard;
+----------+
| count(*) |
+----------+
|     3540 |
+----------+
1 row in set (0.00 sec)

Total question in DB:

Code:
mysql> select count(*) from neo_open_trivia;
+----------+
| count(*) |
+----------+
|      629 |
+----------+
1 row in set (0.00 sec)

If anyone sees any "strangeness" please take a screen shot and post it, and if possible please look into your web dev console and post any the XHR response to the API query and any JS errors in the JS console (if you know how to do it, if not just post the screen shots). I hope filtering the string will solve this tiny, occasional bug.

Top 20 interactions by country:


Code:
mysql> select country, count(country) from neo_trivia_scoreboard  group by country order by count(country) desc limit 20;
+---------+----------------+
| country | count(country) |
+---------+----------------+
| US      |            874 |
| IN      |            418 |
| TH      |            411 |  <---- my testing
| GB      |            185 |
| DE      |            131 |
| NL      |            115 |
| IT      |            111 |
| PH      |            109 |
| BR      |            105 |
| FR      |             93 |
| AU      |             82 |
| BG      |             81 |
| CA      |             79 |
| RU      |             73 |
| ES      |             60 |
| PL      |             58 |
| SE      |             48 |
| XX      |             47 |
| CH      |             44 |
| MX      |             33 |
+---------+----------------+
20 rows in set (0.00 sec)

# 7  
I also just noticed that line breaks in question string in the JSON response will cause a problem so, for now, I am stripping out line breaks, like this:

Code:
$question = str_replace(array("\n", "\r"), '', $question );

I hope I have trapped all the issues which cause bugs when processing the JSON AJAX response, but I doubt it..... Smilie

In addition, I have added the database id to the text box so if there are any questions or issues, we have the id to reference, for example:

Image
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #452
Difficulty: Medium
San Francisco has a Linux-based traffic controller computer that meets the latest Advanced Transportation Controller (ATC) standards.
True or False?

7 More Discussions You Might Find Interesting

1. What is on Your Mind?

New Member and Country Computer Trivia Leaderboards

Thanks to Akshay, who helped me write the core MySQL queries, we now have two new draft leaderboards, by (1) member and by (2) country: https://www.unix.com/trivia_stats.php Currently milhan leads the members with a high score of 90%: ... (3 Replies)
Discussion started by: Neo
3 Replies

2. What is on Your Mind?

1000+ Computer Science Trivia Questions at UNIX.COM

The UNIX and Linux Forums now has over 1000 TRUE / FALSE computer science and computer related trivia question in our database. These questions are of relatively high quality (compared to similar sites on the web) and are fun (according to feedback by users). In the first week during the... (1 Reply)
Discussion started by: Neo
1 Replies

3. What is on Your Mind?

Forum Trivial Pursuit - New Computer Science and Mathematics Trivia for UNIX.com

I have added a new experimental "Computer Science and Mathematics Trivia - True or False" section in the discussions, currently under the tags box. In the future, I plan to Expand this feature to add more trivia categories from math, science and technology. Keep track of correct and... (20 Replies)
Discussion started by: Neo
20 Replies

4. Web Development

Is Web Development is a part of computer science ?

I am now a student in university in 2nd year. I am studying computer science. But I am not sure what type of jobs computer science provide. I know some of them are software programming or network management. Recently, I hear some about Web Development. I wonder if it is a part of computer... (3 Replies)
Discussion started by: Anna Hussie
3 Replies

5. Programming

Is Web Development is a part of computer science ?

I am now a student in university in 2nd year. I am studying computer science. But I am not sure what type of jobs computer science provide. I know some of them are software programming or network management. Recently, I hear some about Web Development. I wonder if it is a part of computer science.... (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. What is on Your Mind?

Computer Science and Information Technology

Hi, I haven't posted on the forums for a while now, I tried to find the most appropriate section for this post, but if this is in the wrong section please forgive me. First, let me say I'm a sophomore in HS. I know that job wise I definitely want to do something in computers. A while ago I was... (5 Replies)
Discussion started by: hpicracing
5 Replies

7. UNIX for Dummies Questions & Answers

xterm trivia

Thanks Livin Free... Here's another one... Why is it that I always get the error message "Error: Can't open display:" in my mail whenever I execute or try to call an xterm command using cron to activate the command. What did I miss? Thanks in advance UNIX gurus... (3 Replies)
Discussion started by: jfsuminist
3 Replies

Featured Tech Videos