raze-gles/polymer/eduke32/source/lunatic/mapastats.lua
helixhorned 3697842bc5 Add ART loader for the LuaJIT BUILD struct loader module, 2 more examples.
The map iterator now has init/finish capability, making it possible to
write scripts that aggregate data over multiple map files.  One such example
calculates some statistics, the other loads art metadata and looks for
red walls with non-pow2 ysize tiles.

git-svn-id: https://svn.eduke32.com/eduke32@2814 1a8010ca-5511-0410-912e-c29ae57300e0
2012-07-08 21:47:11 +00:00

50 lines
998 B
Lua

-- Print out some aggregate statistics for passed BUILD maps,
-- foreachmap module.
local string = require "string"
local math = require "math"
local print = print
module(...)
local function printf(fmt, ...)
print(string.format(fmt, ...))
end
local N = 0
local sumnumsectors = 0
local sumnumwalls = 0
local sumratio = 0
local sumsqratio = 0
function success(map, fn)
local ns = map.numsectors
local nw = map.numwalls
N = N+1
sumratio = sumratio + nw/ns
sumsqratio = sumsqratio + (nw/ns)^2
sumnumsectors = sumnumsectors+ns
sumnumwalls = sumnumwalls+nw
end
function finish()
printf("%d maps\n", N)
printf("total sectors: %d", sumnumsectors)
printf("total walls: %d", sumnumwalls)
printf("total walls / total sectors: %.02f", sumnumwalls/sumnumsectors)
printf("")
printf("Walls/sector")
local meanwpers = sumratio/N
printf(" mean: %.02f", meanwpers)
printf(" stdev: %.02f", math.sqrt(sumsqratio/N - meanwpers^2))
end