CS/INFO 4154:Analytics-driven Game Design
SQL
Class 20:
Final Course Deadlines We will not meet during the scheduled exam time Final report will be due at the end of exam time Cornell cannot delete exam from Student Center Final (Kongregate) Report due: Saturday,
December 9th, NOON Final Peer Evaluations due: Monday, December
11th, 11:59pm
Mon Wed Fri
10/11MySQL
10/13Beta Playtesting 1
10/16Beta Playtesting 2
10/18Beta Postmortems
10/19: Midterm Peer Evaluations Due
Beta Postmortems Similar to Alpha postmortems Report something learned from analytics
perfectly fine if not very insightful e.g. players clicked 5436 times!
Today Basic MySQL How the tables are implemented on GDIAC Open office hours
Today Basic MySQL How the tables are implemented on GDIAC Open office hours
SQL Structured Query Language a programming language designed to manage data
stored in relational databases
SHOW TABLES Shows tables within current database
mysql> SHOW TABLES;
+----------------------------+| player_action_log || player_pageload_log || player_quest_log || users |+----------------------------+4 rows in set (0.00 sec)
Sample table: actionsplayer_id quest_id action_id time detail0 0 0 14 (2, 2)0 0 1 16 (2, 4)0 0 2 19 (1, 3)0 1 2 20 (1, 1)1 0 2 78 (2, 1)1 1 2 80 (3, 8)
DESCRIBE Tells you the table schema Example:
DESCRIBE actions;important
+-----------+--------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-----------+--------------+------+-----+---------+-------+| player_id | int(11) | YES | | NULL | || quest_id | int(11) | YES | | NULL | || level_id | int(11) | YES | | NULL | || time | int(11) | YES | | NULL | || detail | varchar(255) | YES | | NULL | |+-----------+--------------+------+-----+---------+-------+
SELECT The basic query
SELECT <attributes>FROM <one or more tables>;
SELECTplayer_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT player_id FROM actions;player_id
0
0
0
0
1
1
DISTINCT Filters results for unique values Can be used as a keyword:
SELECT DISTINCT player_id FROM actions; Can also be used as a function:
SELECT DISTINCT(player_id) FROM actions;
DISTINCTplayer_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT DISTINCT player_idFROM actions; player_id
0
1
COUNT() Function that counts number of rows Usage: COUNT(<rows>) Example:
SELECT COUNT(player_id) FROM actions;
COUNT()player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT COUNT(player_id)FROM actions; COUNT(player_id)
6
How do I?player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
How do I get the number of unique players?SELECT COUNT(DISTINCT(player_id)) FROM actions
COUNT(DISTINCT(player_id))
2
SELECT *
player_id quest_id action_id time detail0 0 0 14 (2, 2)0 0 1 16 (2, 4)0 0 2 19 (1, 3)0 1 2 20 (1, 1)1 0 2 78 (2, 1)1 1 2 80 (3, 8)
SELECT * returns all rows Example:
SELECT * FROM actions;
WHERE Specifies constraints Example:
SELECT * FROM actions WHERE time>20;
WHEREplayer_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT * FROM actions WHERE time>20player_id quest_id action_id time detail
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
WHERE Specifies constraints Example:
SELECT * FROM actions WHERE time>20; Can combine WHERE constraints with AND:
SELECT * FROM actions WHERE time<15 AND player_id=0;
How do I?
Count # of actions with id=2?
player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT COUNT(*) FROM actions WHERE action_id=2;
How do I?
Count # of players who had an action with id=1?
player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT COUNT(DISTINCT(player_id)) FROM actions WHERE action_id=1;
How do I?
Count # of players who performed an action at (2,x)?
player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
Can’t do this yet.
LIKE Specifies looser constraints:
_ matches a single character % matches any number of characters
Example:SELECT * FROM actions WHERE detail LIKE ‘(2,_)’;
WHEREplayer_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT * FROM actions WHERE detail LIKE ‘(2,_)’;player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
1 0 2 78 (2, 1)
How do I?
Count # of players who performed an action in quest #1 at (x,8)
player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
SELECT COUNT(DISTINCT(player_id)) FROM actionsWHERE quest_id=1 AND detail LIKE '(_,8)';
How do I…player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
player_id player_info
0 Windows
1 Linux
actions
players
Get all actions performed on Windows?
INNER JOIN Merges tables Example:
SELECT * FROM actions INNER JOIN players ON players.player_id=actions.player_id;
player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
player_id player_info
0 Windows
1 Linuxactions
players
SELECT * FROM actions INNER JOIN players ON players.player_id=actions.player_id;
player_id quest_id action_id time detail player_id player_info
0 0 0 14 (2, 2) 0 Windows
0 0 1 16 (2, 4) 0 Windows
0 0 2 19 (1, 3) 0 Windows
0 1 2 20 (1, 1) 0 Windows
1 0 2 78 (2, 1) 1 Linux
1 1 2 80 (3, 8) 1 Linux
player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
player_id player_info
0 Windows
1 Linuxactions
players
SELECT * FROM actions INNER JOIN players ON players.player_id=actions.player_id WHERE players.player_info=‘Windows’;
player_id quest_id action_id time detail player_id player_info
0 0 0 14 (2, 2) 0 Windows
0 0 1 16 (2, 4) 0 Windows
0 0 2 19 (1, 3) 0 Windows
0 1 2 20 (1, 1) 0 Windows
Count the # of actions that happened on Linux at (2,x)? SELECT COUNT(*) FROM actions INNER JOIN players ONplayers.player_id=actions.player_id WHERE player_info='Linux' AND detail LIKE '(2,_)';
player_id quest_id action_id time detail
0 0 0 14 (2, 2)
0 0 1 16 (2, 4)
0 0 2 19 (1, 3)
0 1 2 20 (1, 1)
1 0 2 78 (2, 1)
1 1 2 80 (3, 8)
player_id player_info
0 Windows
1 Linuxactions
players
Count the # of unique players that played on Windows and performed an action after time=15?SELECT COUNT(DISTINCT(players.player_id)) FROM actions INNER JOIN players ON players.player_id=actions.player_idWHERE player_info='Windows' AND actions.time>15;
Today Basic MySQL How the tables are implemented on GDIAC Open office hours
Four tables
Users
Sessions
Tasks
Actions
users
player_pageload_log
player_quest_log
player_action_log
Users: users user_id user_info
user ID (automatic)user details (if you provided them)
Sessions: player_pageload_log client_timestamp log_id user_id server_timestamp game_id version_id session_id
when the client recorded the eventoverall ID; continually incrementsuser ID (automatic)when the server recorded the eventyour game IDyour version IDID for this play session (automatic)
Tasks: player_quest_log log_quest_id quest_id log_quest_ts user_id game_id version_id dynamic_quest_id quest_detail session_seq_id session_id client_timestamp level_end_timestamp
overall ID; continually incrementsID for the task/level/questwhen the server recorded the eventuser ID (automatic)your game IDyour version IDunique ID for this specific quest instancequest details (if you provided them)which task in this sessionID for this play session (automatic)when the client recorded the eventwhen the client finished the task
Actions: player_action_log client_timestamp log_id game_id quest_id user_id action_id action_detail log_timestamp session_seq_id quest_seq_id
when the client recorded the eventoverall ID; continually incrementsyour game IDID for this task/level/questuser ID (automatic)ID for this actionaction details (if you provided them)when the server recorded the eventwhich action in this sessionwhich action in this task
Today Basic MySQL How the tables are implemented on GDIAC Open office hours