Overhauls stats gathering to include the game_id (#1211)

Changed Stats gathering to include game_id.
Removed a duplicate proc that's never used.

This introduces a breaking chance in the feedback table.
The table should be renamed and recreated with the new schema.
This commit is contained in:
Werner
2016-12-12 22:15:09 +01:00
committed by skull132
parent 4d1054b3bb
commit 2c9203951f
3 changed files with 6 additions and 59 deletions

View File

@@ -251,7 +251,7 @@ CREATE TABLE `ss13_directives` (
CREATE TABLE `ss13_feedback` ( CREATE TABLE `ss13_feedback` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`time` datetime NOT NULL, `time` datetime NOT NULL,
`round_id` int(8) NOT NULL, `game_id` varchar(32) NOT NULL,
`var_name` varchar(32) CHARACTER SET latin1 NOT NULL, `var_name` varchar(32) CHARACTER SET latin1 NOT NULL,
`var_value` int(16) DEFAULT NULL, `var_value` int(16) DEFAULT NULL,
`details` text CHARACTER SET latin1, `details` text CHARACTER SET latin1,

View File

@@ -99,49 +99,3 @@ proc/statistic_cycle()
while(1) while(1)
sql_poll_population() sql_poll_population()
sleep(6000) sleep(6000)
//This proc is used for feedback. It is executed at round end.
proc/sql_commit_feedback()
if(!config.sql_enabled || !config.sql_stats)
return
if(!blackbox)
log_game("Round ended without a blackbox recorder. No feedback was sent to the database.")
return
//content is a list of lists. Each item in the list is a list with two fields, a variable name and a value. Items MUST only have these two values.
var/list/datum/feedback_variable/content = blackbox.get_round_feedback()
if(!content)
log_game("Round ended without any feedback being generated. No feedback was sent to the database.")
return
establish_db_connection(dbcon)
if(!dbcon.IsConnected())
log_game("SQL ERROR during feedback reporting. Failed to connect.")
else
var/DBQuery/max_query = dbcon.NewQuery("SELECT MAX(roundid) AS max_round_id FROM ss13_feedback")
max_query.Execute()
var/newroundid
while(max_query.NextRow())
newroundid = max_query.item[1]
if(!(isnum(newroundid)))
newroundid = text2num(newroundid)
if(isnum(newroundid))
newroundid++
else
newroundid = 1
for(var/datum/feedback_variable/item in content)
var/variable = item.get_variable()
var/value = item.get_value()
var/DBQuery/query = dbcon.NewQuery("INSERT INTO ss13_feedback (id, roundid, time, variable, value) VALUES (null, [newroundid], Now(), '[variable]', '[value]')")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR during death reporting. Error : \[[err]\]\n")

View File

@@ -229,6 +229,8 @@ var/obj/machinery/blackbox_recorder/blackbox
blackbox = src blackbox = src
/obj/machinery/blackbox_recorder/Destroy() /obj/machinery/blackbox_recorder/Destroy()
feedback_set_details("blackbox_destroyed","true")
feedback_set("blackbox_destroyed",1)
var/turf/T = locate(1,1,2) var/turf/T = locate(1,1,2)
if(T) if(T)
blackbox = null blackbox = null
@@ -302,20 +304,11 @@ var/obj/machinery/blackbox_recorder/blackbox
round_end_data_gathering() //round_end time logging and some other data processing round_end_data_gathering() //round_end time logging and some other data processing
establish_db_connection(dbcon) establish_db_connection(dbcon)
if(!dbcon.IsConnected()) return if(!dbcon.IsConnected())
var/round_id return
var/DBQuery/query = dbcon.NewQuery("SELECT MAX(round_id) AS round_id FROM ss13_feedback")
query.Execute()
while(query.NextRow())
round_id = query.item[1]
if(!isnum(round_id))
round_id = text2num(round_id)
round_id++
for(var/datum/feedback_variable/FV in feedback) for(var/datum/feedback_variable/FV in feedback)
var/sql = "INSERT INTO ss13_feedback VALUES (null, Now(), [round_id], \"[FV.get_variable()]\", [FV.get_value()], \"[FV.get_details()]\")" var/sql = "INSERT INTO ss13_feedback VALUES (null, Now(), \"[game_id]\", \"[FV.get_variable()]\", [FV.get_value()], \"[FV.get_details()]\")"
var/DBQuery/query_insert = dbcon.NewQuery(sql) var/DBQuery/query_insert = dbcon.NewQuery(sql)
query_insert.Execute() query_insert.Execute()