Added log truncation, keeping stats on map vs level and Death

His Dad [04-20-15 - 09:03]
Added log truncation, keeping stats on map vs level and Death
Filename
HistOffline.lua
history.lua
diff --git a/HistOffline.lua b/HistOffline.lua
index b676380..b82d2f2 100644
--- a/HistOffline.lua
+++ b/HistOffline.lua
@@ -24,7 +24,7 @@ if archivef ==nil then	--create empty file
 end
 archivef:close()
 dofile "../../SavedVariables/History.Archive"
--- ==============
+-- ==============

 function dump(o)
    if type(o) == 'table' then
@@ -66,7 +66,7 @@ function write_saved(o)
 end

 accounts = {}
-for i,_ in pairs(History_SV["Default"]) do
+for i,_ in pairs(History_SV["Default"]) do
 	accounts[i] = {}
 	accounts[i].names = {}	-- intermediate table for sorting. WIP. Array formatted.
 	accounts[i].name = {}
@@ -92,7 +92,7 @@ end
 	  accounts[acc].name[char] = {}		-- stub table to hold char data
   end
  end
-
+
 --	  accounts[acc].name[char].display = {}	-- Hold all the IUP tabs and boxes for that char
 function print_old()
 	for i,j in pairs (History_SV["Default"][myaccount]["$AccountWide"]["old"]) do
@@ -113,11 +113,12 @@ btn_archive = iup.button{title="Archive", FGCOLOR = "#FF0000"}
 	accounts[acc].logtabs  =iup.tabs{}
 	-- Log Display table presentation
 	accounts[acc].logtable = {}
-	accounts[acc].logtable=iup.matrix{numcol=1, numcol_visible=1,  numlin=0}
+	accounts[acc].logtable=iup.matrix{numcol=1, numcol_visible=1,  numlin=0,scrollbar= yes}
 	accounts[acc].logtable:setcell(0,0, L.TStamp)
 	iup.SetAttribute(accounts[acc].logtable,  "ALIGNMENT0", "ACENTER")
 	iup.SetAttribute(accounts[acc].logtable,  "WIDTH0", 80)
 	iup.SetAttribute(accounts[acc].logtable,  "WIDTH1", 200)
+	iup.SetAttribute(accounts[acc].logtable,  "FITTOSIZE","LINES")
 	-- Load log data

 	local Line=0
@@ -130,7 +131,7 @@ btn_archive = iup.button{title="Archive", FGCOLOR = "#FF0000"}
 		accounts[acc].logtable:setcell( Line,0, TimeStr)
 		accounts[acc].logtable:setcell( Line,1, j["text"])
 	end
-
+
 	-- Setup Log Display
 	accounts[acc].log_tab=iup.vbox {
 			["tabtitle"] =L.LogTab,
@@ -145,9 +146,9 @@ btn_archive = iup.button{title="Archive", FGCOLOR = "#FF0000"}
 			iup.fill{}
 			}
 	accounts[acc].tabs =iup.tabs{}  -- Top level of Tabs, Character Info in Here
-  -- ====  END Accountwide Data
-
-
+  -- ====  END Accountwide Data
+
+
 -- Creates boxes, stage from names to allow optional sorting in future.
 	for _,char in ipairs(accounts[acc].names) do
 		accounts[acc].name[char] = {}
@@ -160,7 +161,7 @@ btn_archive = iup.button{title="Archive", FGCOLOR = "#FF0000"}
 		end
 		-- ==Level
 		local level = History_SV["Default"][acc]["$AccountWide"]["data"][char].level
-
+
 		accounts[acc].name[char].level = level
 		if (level <=50) then
 			accounts[acc].name[char].levelstr = tostring(level)
@@ -340,7 +341,7 @@ btn_archive = iup.button{title="Archive", FGCOLOR = "#FF0000"}
 		end

 		accounts[acc].name[char].Vet_box.Redraw= "ALL"
-
+
 	 -- ====================================
 	--  == Prepare for the user display tabs
 		accounts[acc].name[char].tab = iup.vbox{
@@ -348,7 +349,7 @@ btn_archive = iup.button{title="Archive", FGCOLOR = "#FF0000"}

 					iup.hbox{		--Top Information bar
 							Alignment = "ACENTER",
-							iup.label{title=gender, FONT="Times,BOLD,10"},
+							iup.label{title=accounts[acc].name[char].gender, FONT="Times,BOLD,10"},
 							iup.label{title=History_SV["Default"][acc]["$AccountWide"]["data"][char].Race .." / ".. History_SV["Default"][acc]["$AccountWide"]["data"][char].Class, PADDING="10X0", FONT="Times,BOLD,10"},
 							iup.label{title=History_SV["Default"][acc]["$AccountWide"]["data"][char].Alliance, PADDING="10X0"},
 							iup.label{title=L.Level .. ": ".. accounts[acc].name[char].levelstr, PADDING="10X0"},
@@ -386,7 +387,7 @@ btn_archive = iup.button{title="Archive", FGCOLOR = "#FF0000"}
 		iup.Append(accounts[acc].tabs,accounts[acc].name[char].tab)
 		accounts[acc].panelsize =  tostring(#accounts[acc].names * 40 +350) ..  "x250"
 	end  -- Chars
-
+
 -- Add to end of Characters
 iup.Append(accounts[acc].tabs, accounts[acc].log_tab)
 end -- Accounts
diff --git a/history.lua b/history.lua
index 0334e17..4f020a9 100644
--- a/history.lua
+++ b/history.lua
@@ -8,14 +8,16 @@ hist = {
 	player = "",
 	last="",
 	tz_offset =0,
-	debug = false
+	debug = true
 }

 local function log_truncate(max)
 --Limit log to max
-	for _ = max, #hist.SV.log  do
-		table.remove(hist.SV.log)
-		d("Truncated log.  Size now" .. tostring(hist.SV.log))
+	for _ = max, (#hist.SV.log-1)  do
+		table.remove(hist.SV.log,1)
+		if hist.debug then
+			d("Truncated log.  Size now:  " .. tostring(#hist.SV.log))
+		end
 	end
 end

@@ -98,9 +100,6 @@ end

 local function Activated()
 	hist.me.levels[hist.me.level].time = math.floor(GetSecondsPlayed() /60)
-	log("Activated")
-	log_truncate(5)
-
 end


@@ -115,6 +114,31 @@ local function levelup(eventCode, unitTag,_)
         Ach_Points = GetEarnedAchievementPoints(),
         deaths = 0
     }
+	local map = GetMapName()
+	--Update Level data with map
+	if hist.me.levels[hist.me.level].map == nil then
+		hist.me.levels[hist.me.level].map = {}
+		hist.me.levels[hist.me.level].map[map] = 1
+		local msg = "First Levelup in map " ..map
+		log (msg)
+		if hist.debug then
+			d("First Levelup  in map " ..map)
+		end
+	else
+		hist.me.levels[hist.me.level].map[map] = hist.me.levels[hist.me.level].map[map] +1
+	end
+	-- Update Map data with level
+	if hist.me.map[map] == nil then
+		hist.me.map[map] = {}
+	end
+	-- Duplication of info, but easier to work with
+	if hist.me.map[map].timeslevel == nil then
+		hist.me.map[map].timeslevel = 1
+		hist.me.map[map].firstlevel = hist.me.level
+	else
+		hist.me.map[map].timeslevel = hist.me.map[map].timeslevel + 1
+	end
+
     if hist.debug then
       d("Hist: Leveled:.. ")
           d(hist.me.level)
@@ -149,12 +173,14 @@ local function setup_char()
 		hist.me.level = GetUnitLevel("player") + GetUnitVeteranRank("player")
 		hist.me.Alliance = GetAllianceName(GetUnitAlliance("player"))
 		hist.me.ach={}
+		hist.me.map={}
 		hist.me.levels = {}
 		hist.me.levels[hist.me.level] = {
 			begin = GetTimeStamp(),
 			time  = 0,		-- Accumulated time in Minutes
 			Ach_Points = GetEarnedAchievementPoints(),
-			deaths = 0
+			deaths = 0,
+			map= {}
 		}  -- end of defaults
 		load_history()
 end
@@ -167,10 +193,18 @@ local function Dead()
 	if hist.me.map[map] == nil then
 		hist.me.map[map] = {}
 	end
+	--Update map data with Deaths
 	if hist.me.map[map].deaths == nil then
 		hist.me.map[map].deaths = 0
+		hist.me.map[map].firstdeathlevel = hist.me.level
+		local msg = "First Death in map " .. map
+		log (msg)
+		if hist.debug then
+		d("First Death in map " ..map)
+		end
 	end
 	hist.me.map[map].deaths = hist.me.map[map].deaths +1
+
 end
 function hist.Initialise(_, addOnName)
 	if (hist.name ~= addOnName) then return end
@@ -201,11 +235,8 @@ function hist.Initialise(_, addOnName)
 		hist.SV.old = {}
 		log("hist.SV.old  created")
 	end
-
-	if hist.me.map == nil then
-			hist.me.map = {}
-	end
-
+
+
 	if hist.SV.data[hist.player] == nil
 	then
 		setup_char()
@@ -216,10 +247,17 @@ function hist.Initialise(_, addOnName)
 		if hist.me.level == nil then		-- fix if doesn't exist
 			hist.me.level = level
 		end
+
+		if 	hist.me.levels == nil then
+		hist.me.levels = {}
+		end
+		if hist.me.map == nil then
+			hist.me.map = {}
+		end
 		if hist.me.ach_updates ~= nil then
 			hist.me.ach_updates = nil
 		end
-
+
 		    if hist.debug then
 					log("Begin Duplicate tests, Saved  -- Calculated" )
 					log("Alliance test: " .. hist.me.Alliance .. " -- " .. GetAllianceName(GetUnitAlliance("player")))
@@ -235,7 +273,7 @@ function hist.Initialise(_, addOnName)
 			hist.me.level > level
 			then -- must be different with same name
 			local now = GetTimeStamp()
-			log("Duplicate Detected, moving to old")
+			log("Duplicate " .. hist.player .. " Detected, moving to old")
 			hist.SV.old[now] = {}	-- save old with timestamp
 			hist.SV.old[now][hist.player] = {}
 			hist.SV.old[now][hist.player] = hist.SV.data[hist.player]  -- Saved
@@ -244,6 +282,7 @@ function hist.Initialise(_, addOnName)
 			hist.SV.data[hist.player].OverWrite = true
 		end
 	end
+	log_truncate(20)


 	hist.me["LoginTime"] = GetTimeStamp()