I kind of missed how you were getting your information coming in. The format that it's given to you will affect how you want to process it.
I was actually just working on a script to sort a particular format of table I'm using a lot. I'll throw it up here in case it's helpful to you. It takes a dictionary of dictionaries having the same key names and spits out a sorted list of the outer keys. If you were to output a table called myTable to an array called myArray, you could then do something like
for i,v in ipairs(myArray) do myWindow:echo(i..", "..v[1]..", "..v[2].."\n") end and it would print a series of lines like "1, firstsortedkey, maximumvalue" -> "2, secondsortedkey, secondvalue" -> etc.
You could also echo any of the other key/value pairs in myTable by replacing the v[1]'s and v[2]'s with
myTable[v[1]].someKey
I haven't implemented much error checking yet so use at your own risk.
Here's a link on repl.it if you want to see it run.
-- example
--[[
examplepd = {
["174366"] = {
name = "a hideous abomination",
ppMean = 0,
},
["43183"] = {
name = "a Nuskuwen man",
ppMean = 69.571428571429,
},
["314932"] = {
name = "a Vertani guard",
ppMean = 75,
},
--]]
-- 'pd' for 'parallel dictionary'
-- take the above type of dictionary, sort by field
-- returns a sorted array with entries {index,orignal key,field value}
-- eg: sorted = sortpd(examplepd,"ppMean")
--- display(sorted) -> {{1,"314932",75},{2,"43183",69.571428571429,},{3,"174366",0}}
--- uses insertion sort
function sortpd (pd,field)
--TODO: error checking
if not field then return false end
if not pd then return false end
--objective: get an indexed array of keys, ordered by 'field'
local skeys = {}
-- copy into skeys as {1={key,field},2={key,field},...}
for k,v in pairs(pd) do
local entry = {}
entry[1] = k
entry[2] = v[field]
table.insert(skeys,entry)
end--for
--sort skeys
n = table.getn(skeys)
size = table.getn(skeys)
while n > 1 do
local maxi = size
for i= size, (size + 2 - n), -1 do
if skeys[i-1][2] >= skeys[i][2] then
maxi = i-1
end --if
end
--insert biggest element at head of table
local tkey = table.remove(skeys,maxi)
table.insert(skeys,(size + 1 - n),tkey)
n = n - 1
end--while
return skeys
end
EDIT: accidentally pasted a version with a couple of old syntax errors and debug messages