diff options
author | Aki <please@ignore.pl> | 2024-11-02 22:24:01 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-11-02 22:24:01 +0100 |
commit | cc77d7ccc034aecba64278e43112a61cf8c7f12c (patch) | |
tree | 61b107ba7a9c0b784f5ac8f655e23d1dc58fe4e7 /stats.lua | |
parent | 1abde5fcd3fde372cdefdc6c967d680a2cc82410 (diff) | |
download | noita-eyes-cc77d7ccc034aecba64278e43112a61cf8c7f12c.zip noita-eyes-cc77d7ccc034aecba64278e43112a61cf8c7f12c.tar.gz noita-eyes-cc77d7ccc034aecba64278e43112a61cf8c7f12c.tar.bz2 |
Calculate delta bar IoC for 2-124 long periods
Diffstat (limited to 'stats.lua')
-rw-r--r-- | stats.lua | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/stats.lua b/stats.lua new file mode 100644 index 0000000..1cb485d --- /dev/null +++ b/stats.lua @@ -0,0 +1,68 @@ +local format = require "format" +local stats = {} +local mt = {__index=stats} + + +local function new (name_or_obj, parent) + if type(name_or_obj) == "string" then + name_or_obj = { + name = name_or_obj, + parent = parent, + letters = 0, + length = 0, + counts = {}, + children = {}, + } + end + return setmetatable(name_or_obj, mt) +end + + +function stats:add (value) + local current = self.counts[value] or 0 + if current == 0 then + self.letters = self.letters + 1 + end + self.length = self.length + 1 + self.counts[value] = current + 1 + if self.parent then + self.parent:add(value) + end +end + + +function stats:sub (name) + local child = new(name, self) + table.insert(self.children, child) + return child +end + + +function stats:ioc (letters) + letters = letters or self.letters + local subtotal = 0 + for _, count in pairs(self.counts) do + subtotal = subtotal + count * (count - 1) + end + return subtotal / (self.length * (self.length - 1) / letters) +end + + +function stats:dump () + local function dump (stat) + local letters = (stat.parent or {}).letters + io.write(stat.name, "\t", stat.length, "\t", stat.letters, "\t", format.float(stat:ioc(letters))) + if letters then + io.write("\t", format.float(stat:ioc())) + end + print() + end + + dump(self) + for _, child in ipairs(self.children) do + dump(child) + end +end + + +return new |