Last active
July 28, 2021 01:45
-
-
Save Putnam3145/acd1a457c65ac315719f713677e6c13d to your computer and use it in GitHub Desktop.
gives you the normalized death-by-max-age times in buckets for every hist fig in the world in DF, to test the distribution thereof (it's linear)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
utils = require('utils') | |
local validArgs = utils.invert({ | |
'printAll', | |
'bucketSize' | |
}) | |
local args = utils.processArgs({...}, validArgs) | |
local bucketSize = args.bucketSize or 0.125 | |
local function oldAgeNormalized(fig) | |
local a = df.creature_raw.find(fig.race).caste[fig.caste].misc | |
local ageAtDeath = (fig.old_year - fig.born_year) + (fig.old_seconds / 403200) | |
return math.max(0,math.min(1,(ageAtDeath - a.maxage_min) / (a.maxage_max - a.maxage_min))) | |
end | |
local dist = {} | |
for k,v in ipairs(df.global.world.history.figures) do | |
if v.old_year >= 0 then | |
table.insert(dist, oldAgeNormalized(v)) | |
end | |
end | |
table.sort(dist) | |
local last = 0 | |
local cur = -1 | |
if args.printAll then | |
for _,v in ipairs(dist) do | |
print(v) | |
end | |
else | |
for _,v in ipairs(dist) do | |
if (v - last) >= bucketSize then | |
print(last..".."..last + bucketSize, cur) | |
last = math.floor(v*1000)/1000 | |
cur = 0 | |
else | |
cur = cur + 1 | |
end | |
end | |
if last ~= 1 then | |
print(last.."..1.0",cur) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment