if not PriceTracker then return end local MathUtils = {} PriceTracker.mathUtils = MathUtils function MathUtils:GetSortedPriceTable(itemTable) local prices = {} for i = 1, #itemTable do table.insert(prices, math.floor(itemTable[i].purchasePrice / itemTable[i].stackCount)) end table.sort(prices) return prices end function MathUtils:WeightedAverage(itemTable) local sum = 0 local weight = 0 for i = 1, #itemTable do sum = sum + itemTable[i].purchasePrice weight = weight + itemTable[i].stackCount end return math.floor(sum / weight) end function MathUtils:Median(itemTable) local prices = self:GetSortedPriceTable(itemTable) local index = (#prices + 1) / 2 if (#prices / 2) == (math.floor(#prices / 2)) then return math.floor((prices[index] + prices[index + 1]) / 2) else return prices[index] end end function MathUtils:Mode(itemTable) local prices = self:GetSortedPriceTable(itemTable) local number = prices[1] local mode = number local count = 1 local countMode = 1 for i = 2, #prices do if prices[i] == number then count = count + 1 else if count > countMode then countMode = count mode = number end count = 1 number = prices[i] end end return mode end function MathUtils:Max(itemTable) local price = math.floor(itemTable[1].purchasePrice / itemTable[1].stackCount) for i = 1, #itemTable do local newPrice = math.floor(itemTable[i].purchasePrice / itemTable[i].stackCount) if newPrice > price then price = newPrice end end return price end function MathUtils:Min(itemTable) local price = math.floor(itemTable[1].purchasePrice / itemTable[1].stackCount) for i = 1, #itemTable do local newPrice = math.floor(itemTable[i].purchasePrice / itemTable[i].stackCount) if newPrice < price then price = newPrice end end return price end