- More bug fixes

Yaron Kfir [06-03-14 - 21:11]
 - More bug fixes
 - Fixed Median and Mode methods
 - Correctly calculating median value per item, instead of per stack
Filename
Changelog
MathUtils.lua
diff --git a/Changelog b/Changelog
index 019a907..75740b6 100644
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,10 @@
 Changelog

+v0.9
+ - More bug fixes
+ - Fixed Median and Mode methods
+ - Correctly calculating median value per item, instead of per stack
+
 v0.8
  - Fixed a typo when calculating a weighted average

diff --git a/MathUtils.lua b/MathUtils.lua
index 149b592..5089a79 100644
--- a/MathUtils.lua
+++ b/MathUtils.lua
@@ -18,19 +18,21 @@ function MathUtils:WeightedAverage(itemTable)
 		weight = weight + itemTable[i].stackCount
 	end
 	item = {
-		price = math.floor(sum / weight)
+		purchasePrice = math.floor(sum / weight),
+		stackCount = 1
 	}
 	return item
 end

 function MathUtils:Median(itemTable)
 	local itemTable = self:GetSortedPriceTable(itemTable)
-	local index = (#itemTable + 1) / 2
-	if (#itemTable / 2) == (math.floor(#itemTable / 2)) then
+	local index = math.floor((#itemTable + 1) / 2)
+	if (index * 2 == #itemTable) then
 		local item = {
-			price = math.floor((itemTable[index].price + itemtTable[index + 1]).price / 2)
+			purchasePrice = math.floor((itemTable[index].purchasePrice / itemTable[index].stackCount) + (itemTable[index + 1].purchasePrice / itemTable[index + 1].stackCount)),
+			stackCount = 1
 		}
-		return
+		return item
 	else
 		return itemTable[index]
 	end