Skip to content

Commit

Permalink
feat: analysis stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kiedtl committed Oct 5, 2023
1 parent b7f5ee8 commit 30175ef
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tools/json-wrangler-prefabs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
local json = require("rxi-json")

local input = io.read("*a")
local json = json.decode(input)

local mode = nil
if not arg[1] then
io.stderr:write("Need arg ('total'/'occurred')\n")
return
elseif arg[1] == "total" then
mode = "total"
elseif arg[1] == "occurred" then
mode = "occurred"
else
io.stderr:write("Invalid arg\n")
return
end

local data = {}
for set = 1,#json do
local temp = {}
for floor = 1,#json[set] do
for fabno = 1, #json[set][floor].prefabs do
local fab = json[set][floor].prefabs[fabno]
if not data[fab.id] then
data[fab.id] = { floors = {} }
data[fab.id].type = fab.t
for z = 1, #json[set] do data[fab.id].floors[z] = 0 end
end
if not temp[fab.id] then
temp[fab.id] = { floors = {} }
for z = 1, #json[set] do temp[fab.id].floors[z] = 0 end
end
data[fab.id].floors[floor] = data[fab.id].floors[floor] + fab.c
temp[fab.id].floors[floor] = temp[fab.id].floors[floor] + fab.c
if mode == "occurred" then
data[fab.id].floors[floor] = data[fab.id].floors[floor]
- (temp[fab.id].floors[floor] - 1)
end
end
end
end

for fab, dataset in pairs(data) do
io.stdout:write(fab)
for _, number in ipairs(dataset.floors) do
io.stdout:write("," .. number)
end
io.stdout:write("\n")
end

0 comments on commit 30175ef

Please sign in to comment.