Finish dumpSkillDataJson to working

Sasky [04-18-15 - 06:12]
Finish dumpSkillDataJson to working
Filename
inc/extract.lua
inc/util.lua
runScript.lua
scripts/dumpSkillDataJson.lua
diff --git a/inc/extract.lua b/inc/extract.lua
index 1aa8403..0ba2fb0 100644
--- a/inc/extract.lua
+++ b/inc/extract.lua
@@ -13,10 +13,10 @@ function T:getFitData(data)
     local health_array = {}
     local type = "Unknown"
     for k,v in pairs(data) do
-        local msu, primary, power, health = k:match("([MSU])([0-9.]+)P([0-9.]+)H?([0-9.]+)?")
+        local msu, primary, power, health = k:match("([MSU])([0-9.]+)P([0-9.]+)")--H?([0-9.]+)?
         table.insert(mainstat_array, tonumber(primary))
         table.insert(power_array, tonumber(power))
-        table.insert(health_array, tonumber(health) or 0)
+        table.insert(health_array, tonumber(0)) --health
         table.insert(value_array, tonumber(v))
         type = self.types[msu] or "Unknown"
     end
diff --git a/inc/util.lua b/inc/util.lua
index e24556b..0b956e2 100644
--- a/inc/util.lua
+++ b/inc/util.lua
@@ -34,6 +34,6 @@ function u.makeDepth(t, list)
 end

 function u.makeKey(...)
-    return table.join({...},"/")
+    return table.concat({...},"/")
 end
 return u
\ No newline at end of file
diff --git a/runScript.lua b/runScript.lua
index acb080c..e74dab7 100644
--- a/runScript.lua
+++ b/runScript.lua
@@ -15,6 +15,25 @@ local scripts = {
     { file = "scripts/skillNamesByLine.lua", desc = "Skill Names -> console" },
 }

+--Global include function
+function inc(file)
+    local f = assert(loadfile("inc/" .. file .. ".lua"))
+    return f()
+end
+
+local d = print
+function print(str)
+    d(str)
+    io.stdout:flush()
+end
+
+--TODO: Prompt user for this if cfg.lua not present
+cfg = assert(loadfile("cfg.lua"))()
+
+--Short-circuit for now
+dofile(scripts[3].file)
+os.exit(0)
+
 print("Selection function to run:")
 for i,desc in ipairs(scripts) do
     print("  " .. i .. ") " .. desc.desc)
diff --git a/scripts/dumpSkillDataJson.lua b/scripts/dumpSkillDataJson.lua
index 99a6717..e3da07f 100644
--- a/scripts/dumpSkillDataJson.lua
+++ b/scripts/dumpSkillDataJson.lua
@@ -20,24 +20,29 @@
 --- Required: Rserve must be ruu.nning for this script

 print("Loading libraries")
-local cfg = assert(loadfile("cfg.lua"))()
-local u = assert(loadfile("inc/util.lua"))()
-local sv = assert(loadfile("inc/loadfile.lua"))()
-local JSON = assert(loadfile "inc/JSON.lua")()
+local cfg = cfg or assert(loadfile("cfg.lua"))()
+local u = inc("util")
+local sv = inc("loadfile")
+local JSON = inc("JSON")
+local r = inc("extract")

 print("Account: " .. cfg.account)
 print("Server: " .. cfg.server)

 print("Loading saved variables")
 sv:loadSavedVariables(cfg.account, cfg.server)
-local r = assert(loadfile "inc/extract.lua")()

 local skilldata = sv:getSVEntry("SkillsCurve")
 local skillfull = sv:getSVEntry("SkillsFullInfo")
 local skillref = r:initSkillData(sv)

 print("Processing raw data into fit info")
-local outfile = {}
+
+local outfile = {
+    skills = {},
+    lines = {},
+}
+
 for skill_lvl,numbers in pairs(skilldata) do
     local skill = skill_lvl:gsub("..$","")
     local ref = skillref[skill]
@@ -72,7 +77,7 @@ for skill_lvl,numbers in pairs(skilldata) do
         local delta = 1E-5
         if fit.main < delta then fit.main = 0 end
         if fit.power < delta then fit.power = 0 end
-        if fit.health < delta then fit.health = 0 end
+        if (fit.health or 0) < delta then fit.health = 0 end
         if fit.int < delta then fit.int = 0 end

         local desc = skillInfo.description
@@ -86,7 +91,7 @@ for skill_lvl,numbers in pairs(skilldata) do
         else
             if not formulae[formulasig] then
                 formulae[formulasig] = "##f" .. formulaNum .. "##"
-                skillInfo.fit[formulasig] = {
+                skillInfo.fit[formulae[formulasig]] = {
                     mainCoef=fit.main,
                     powerCoef=fit.power,
                     healthCoef=fit.health,
@@ -100,7 +105,9 @@ for skill_lvl,numbers in pairs(skilldata) do
         end
     end

-    outfile[skill] = skillInfo
+    outfile.skills[skill] = skillInfo
+    u.makeDepth(outfile.lines, { ref.type, ref.line });
+    table.insert(outfile.lines[ref.type][ref.line], skill)
 end

 print("Writing results to: skilldata.json")