Doing some housekeeping and removing items that cannot be parsed, in order to avoid errors when trying to calculate suggested price

Yaron Kfir [06-05-14 - 18:00]
Doing some housekeeping and removing items that cannot be parsed, in order to avoid errors when trying to calculate suggested price
Filename
Changelog
PriceTracker.lua
diff --git a/Changelog b/Changelog
index 75740b6..593d0d6 100644
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,8 @@
 Changelog

+v1.0
+ - Doing some housekeeping and removing items that cannot be parsed, in order to avoid errors when trying to calculate suggested price
+
 v0.9
  - More bug fixes
  - Fixed Median and Mode methods
diff --git a/PriceTracker.lua b/PriceTracker.lua
index d3abea0..4895223 100644
--- a/PriceTracker.lua
+++ b/PriceTracker.lua
@@ -35,6 +35,9 @@ function PriceTracker:OnLoad(eventCode, addOnName)
 	-- Load saved settings
 	self.settings = ZO_SavedVars:NewAccountWide("PriceTrackerSettings", self.settingsVersion, nil, defaults)

+	-- Do some housekeeping and remove inparsable items
+	self:Housekeeping()
+
 	-- Create a button in the trading house window
 	self.button = PriceTrackerControlButton
 	self.button:SetParent(ZO_TradingHouseLeftPaneBrowseItemsCommon)
@@ -60,6 +63,12 @@ function PriceTracker:CommandHandler(text)
 		return
 	end

+	-- Hidden option
+	if text == "housekeeping" then
+		self:Housekeeping()
+		return
+	end
+
 end

 function PriceTracker:ShowHelp()
@@ -70,6 +79,18 @@ function PriceTracker:ShowHelp()
 	d("pt clean - Remove stale items (experimental)")
 end

+-- This method makes sure the item list is intact and parsable, in order to avoid exceptions later on
+function PriceTracker:Housekeeping()
+	if not self.settings.itemList then return end
+	for k, v in pairs(self.settings.itemList) do
+		-- Remove any empty items
+		for p, q in pairs(v) do
+			if not q.purchasePrice or not q.stackCount then v[p] = nil end
+		end
+		if not next(v) then self.settings.itemList[k] = nil end
+	end
+end
+
 function PriceTracker:OnUpdateTooltip(item)
 	if not item or not item.dataEntry or not item.dataEntry.data or self.selectedItem == item then return end
 	self.selectedItem = item
@@ -146,6 +167,8 @@ function PriceTracker:OnTradingHouseClosed()
 end

 function PriceTracker:AddItem(icon, itemName, quality, stackCount, sellerName, timeRemaining, purchasePrice)
+	if not purchasePrice or not stackCount then return end
+
 	local item = {}
 	item.expiry = timeRemaining + GetTimeStamp()
 	item.icon = icon