Skip to content

Commit

Permalink
blackbox: Add accumulating feedback types for numeric and text values. (
Browse files Browse the repository at this point in the history
#26645)

* blackbox: Add accumulating feedback types for numeric and text values.

* correct introduction

* i swear to god i can count to 7

* bloody VSC formatting on save

* formatting changes and doc additions
  • Loading branch information
warriorstar-orion authored Sep 27, 2024
1 parent 900271a commit a42b91e
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 76 deletions.
2 changes: 1 addition & 1 deletion SQL/paradise_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ CREATE TABLE `feedback` (
`datetime` datetime NOT NULL,
`round_id` int(8) NOT NULL,
`key_name` varchar(32) NOT NULL,
`key_type` enum('text', 'amount', 'tally', 'nested tally', 'associative') NOT NULL,
`key_type` ENUM('text', 'amount', 'tally', 'nested tally', 'associative', 'ledger', 'nested ledger') NOT NULL,
`version` tinyint(3) UNSIGNED NOT NULL,
`json` LONGTEXT NOT NULL COLLATE 'utf8mb4_general_ci',
PRIMARY KEY (`id`)
Expand Down
23 changes: 23 additions & 0 deletions SQL/updates/59-60.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Migration: 59-60
-- Author: warriorstar
-- Introduced: PR# 26645

-- This migration adds the 'ledger' and 'nested ledger' enum values to the
-- `feedback` table in conjunction with making those feedback types available
-- through SSblackbox.
-- No data migration is required.

ALTER TABLE
`feedback`
MODIFY
COLUMN `key_type` ENUM(
'text',
'amount',
'tally',
'nested tally',
'associative',
'ledger',
'nested ledger'
) NOT NULL
AFTER
`key_name`;
2 changes: 1 addition & 1 deletion code/__DEFINES/misc_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@
#define INVESTIGATE_HOTMIC "hotmic"

// The SQL version required by this version of the code
#define SQL_VERSION 59
#define SQL_VERSION 60

// Vending machine stuff
#define CAT_NORMAL (1<<0)
Expand Down
50 changes: 36 additions & 14 deletions code/controllers/subsystem/SSblackbox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,16 @@ SUBSYSTEM_DEF(blackbox)
* Arguments:
* * key_type - Type of key. Either "text", "amount", "tally", "nested tally", "associative"
* * key - Key of the data to be used (EG: "admin_verb")
* * increment - If using "amount", how much to increment why
* * stat - Either a number accumulated via "amount", "tally", or "nested tally"; or a number/string collected by "ledger" or "nested ledger".
* * data - The actual data to logged
* * overwrite - Do we want to overwrite the existing key
* * ignore_seal - Does the feedback go in regardless of blackbox sealed status? (EG: map vote results)
*/
/datum/controller/subsystem/blackbox/proc/record_feedback(key_type, key, increment, data, overwrite, ignore_seal)
if((sealed && !ignore_seal) || !key_type || !istext(key) || !isnum(increment || !data))
/datum/controller/subsystem/blackbox/proc/record_feedback(key_type, key, stat, data, overwrite, ignore_seal)
var/is_invalid_value = !isnum(stat || !data)
if(key_type == "ledger" || key_type == "nested ledger")
is_invalid_value &&= !istext(stat)
if((sealed && !ignore_seal) || !key_type || !istext(key) || is_invalid_value)
return
var/datum/feedback_variable/FV = find_feedback_datum(key, key_type)
switch(key_type)
Expand All @@ -215,17 +218,17 @@ SUBSYSTEM_DEF(blackbox)
else
FV.json["data"] |= data
if("amount")
FV.json["data"] += increment
FV.json["data"] += stat
if("tally")
if(!islist(FV.json["data"]))
FV.json["data"] = list()
FV.json["data"]["[data]"] += increment
FV.json["data"]["[data]"] += stat
if("nested tally")
if(!islist(data))
return
if(!islist(FV.json["data"]))
FV.json["data"] = list()
FV.json["data"] = record_feedback_recurse_list(FV.json["data"], data, increment)
FV.json["data"] = record_feedback_recurse_list(FV.json["data"], data, stat)
if("associative")
if(!islist(data))
return
Expand All @@ -235,6 +238,18 @@ SUBSYSTEM_DEF(blackbox)
FV.json["data"]["[pos]"] = list()
for(var/i in data)
FV.json["data"]["[pos]"]["[i]"] = "[data[i]]"
if("ledger")
if(!islist(FV.json["data"]))
FV.json["data"] = list()
if(!islist(FV.json["data"]["[data]"]))
FV.json["data"]["[data]"] = list()
FV.json["data"]["[data]"] += list(stat)
if("nested ledger")
if(!islist(data))
return
if(!islist(FV.json["data"]))
FV.json["data"] = list()
FV.json["data"] = record_feedback_recurse_list(FV.json["data"], data, stat, accumulate = FALSE)

/**
* Recursive list recorder
Expand All @@ -244,21 +259,28 @@ SUBSYSTEM_DEF(blackbox)
* Arguments:
* * L - List to use
* * key_list - List of keys to add
* * increment - How much to increase by
* * value - How much to increase by or append to
* * depth - Depth to use
* * accumulate - TRUE if we are adding `value` to a tally, FALSE if we are appending it to a record
*/
/datum/controller/subsystem/blackbox/proc/record_feedback_recurse_list(list/L, list/key_list, increment, depth = 1)
/datum/controller/subsystem/blackbox/proc/record_feedback_recurse_list(list/L, list/key_list, value, depth = 1, accumulate = TRUE)
var/key_depth = key_list[depth]
if(depth == length(key_list))
if(L.Find(key_list[depth]))
L["[key_list[depth]]"] += increment
if(L.Find(key_depth))
if(accumulate)
L["[key_depth]"] += value
else
if(!islist(L["[key_depth]"]))
L["[key_depth]"] = list()
L["[key_depth]"] += list(value)
else
var/list/list_found_index = list(key_list[depth] = increment)
var/list/list_found_index = accumulate ? list("[key_depth]" = value) : list("[key_depth]" = list(value))
L += list_found_index
else
if(!L.Find(key_list[depth]))
var/list/list_go_down = list(key_list[depth] = list())
if(!L.Find(key_depth))
var/list/list_go_down = list("[key_depth]" = list())
L += list_go_down
L["[key_list[depth-1]]"] = .(L["[key_list[depth]]"], key_list, increment, ++depth)
L["[key_list[depth-1]]"] = .(L["[key_depth]"], key_list, value, ++depth, accumulate = accumulate)
return L

/**
Expand Down
2 changes: 1 addition & 1 deletion config/example/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ ipc_screens = [
# Enable/disable the database on a whole
sql_enabled = false
# SQL version. If this is a mismatch, round start will be delayed
sql_version = 59
sql_version = 60
# SQL server address. Can be an IP or DNS name
sql_address = "127.0.0.1"
# SQL server port
Expand Down
Loading

0 comments on commit a42b91e

Please sign in to comment.