From e6aa3fc0b12615ffcd9a21725cf6623f3bd571b9 Mon Sep 17 00:00:00 2001 From: "baloh.matevz" Date: Sat, 3 Sep 2011 01:00:01 +0000 Subject: [PATCH] My very own feedback gathering system! The blackbox can now gather feedback via the feedback_set(var_name,amt), feedback_inc(var_name,amt) and feedback_dec(var_name,amt) procs. The way feedback is gathered is that the three procs are placed in code where feedback is wanted, these in turn set variables in the blackbox (Yes, I could have done it in an out-of-world datum or object, but I just prefer having an actual physical object gather this stuff.) At the end of the round, all acquired data is saved to a database. I still need to get ahold of TLE to make the required tables and bugtest some things. The saving proc exsists, but is not yet called due to the lack for a table to save to. The rest of it should work fine tho, so you can place the feedbac_set, _inc and _dec procs around code and see what they provide via view variables, it just won't save it to the database yet. git-svn-id: http://tgstation13.googlecode.com/svn/trunk@2092 316c924e-a436-60f5-8080-3fe189b3f50e --- code/defines/procs/statistics.dm | 68 ++++++++++++++++++ code/modules/research/message_server.dm | 92 ++++++++++++++++++++++++- 2 files changed, 159 insertions(+), 1 deletion(-) diff --git a/code/defines/procs/statistics.dm b/code/defines/procs/statistics.dm index d73962fcd9..9795af10b0 100644 --- a/code/defines/procs/statistics.dm +++ b/code/defines/procs/statistics.dm @@ -197,3 +197,71 @@ proc/statistic_cycle() sleep(600) sql_poll_admins() sleep(6000) // Poll every ten minutes + +//This proc is used for feedback. It is executed at round end. +proc/sql_commit_feedback() + 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 + + var/DBConnection/dbcon = new() + dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]") + 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 erro_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 erro_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") + + dbcon.Disconnect() + + +proc/debug_sql_commit_feedback() + if(!blackbox) + world << "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) + world << "Round ended without any feedback being generated. No feedback was sent to the database." + return + + for(var/datum/feedback_variable/item in content) + var/variable = item.get_variable() + var/value = item.get_value() + + world << "INSERT INTO erro_feedback (id, roundid, time, variable, value) VALUES (null, ABC, Now(), '[variable]', '[value]')" + + + world << "end" \ No newline at end of file diff --git a/code/modules/research/message_server.dm b/code/modules/research/message_server.dm index 7585e6cc08..4d6966a54c 100644 --- a/code/modules/research/message_server.dm +++ b/code/modules/research/message_server.dm @@ -65,6 +65,49 @@ +/datum/feedback_variable + var/variable + var/value + + New(var/param_variable,var/param_value = 0) + variable = param_variable + value = param_value + + proc/inc(var/num = 1) + if(isnum(value)) + value += num + else + value = text2num(value) + if(isnum(value)) + value += num + else + value = num + + proc/dec(var/num = 1) + if(isnum(value)) + value -= num + else + value = text2num(value) + if(isnum(value)) + value -= num + else + value = -num + + proc/set_value(var/num) + if(isnum(num)) + value = num + + proc/get_value() + return value + + proc/get_variable() + return variable + + proc/get_parsed() + return list(variable,value) + +var/obj/machinery/blackbox_recorder/blackbox + /obj/machinery/blackbox_recorder icon = 'stationobjs.dmi' icon_state = "blackbox" @@ -86,4 +129,51 @@ var/msg_deathsquad = list() var/msg_syndicate = list() var/msg_mining = list() - var/msg_cargo = list() \ No newline at end of file + var/msg_cargo = list() + + var/list/datum/feedback_variable/feedback = new() + + //Only one can exsist in the world! + New() + for(var/obj/machinery/blackbox_recorder/BR in world) + if(BR != src) + del(src) + blackbox = src + + proc/find_feedback_datum(var/variable) + for(var/datum/feedback_variable/FV in feedback) + if(FV.get_variable() == variable) + return FV + var/datum/feedback_variable/FV = new(variable) + feedback += FV + return FV + + proc/get_round_feedback() + return feedback + +proc/feedback_set(var/variable,var/value) + if(!blackbox) return + + var/datum/feedback_variable/FV = blackbox.find_feedback_datum(variable) + + if(!FV) return + + FV.set_value(value) + +proc/feedback_inc(var/variable,var/value) + if(!blackbox) return + + var/datum/feedback_variable/FV = blackbox.find_feedback_datum(variable) + + if(!FV) return + + FV.inc(value) + +proc/feedback_dec(var/variable,var/value) + if(!blackbox) return + + var/datum/feedback_variable/FV = blackbox.find_feedback_datum(variable) + + if(!FV) return + + FV.dec(value) \ No newline at end of file