Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Auc-Stat-auctiondB - auctiondB price statistics module
- This is an Auctioneer statistics module that returns price data from
- TradeSkillMaster_auctiondB addon. You must have either The Undermine Journal
- or TradeSkillMaster_auctiondB addon installed for this module to have any
- effect.
- Copyright (c) 2011 Johnny C. Lam, 2012 Chris Hennick
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- --]]
- if not AucAdvanced then
- -- error("AucAdvanced not found!")
- return end
- -- register this file with Ace Libraries
- local auctionDB = select(2, ...)
- auctionDB = LibStub("AceAddon-3.0"):NewAddon(auctionDB, "Auc-Stat-AuctionDB", "AceConsole-3.0")
- local TSMAPI = _G.TSMAPI
- local AceGUI = LibStub("AceGUI-3.0") -- load the AceGUI libraries
- local libType, libName = "Stat", "AuctionDB"
- local lib, parent, private = AucAdvanced.NewModule(libType, libName)
- if not lib then return end
- local aucPrint, decode, _, _, replicate, empty, get, set, default, debugPrint, fill, _TRANS = AucAdvanced.GetModuleLocals()
- local GetFaction = AucAdvanced.GetFaction
- lib.Processors = {}
- lib.Processors.tooltip = function(callbackType, ...)
- -- private.ProcessTooltip(...)
- end
- lib.Processors.config = function(callbackType, gui)
- if private.SetupConfigGui then
- private.SetupConfigGui(gui)
- end
- end
- lib.Processors.load = function(callbackType, addon)
- -- check that this is our load message, and that our OnLoad function still exists
- if addon == "auc-stat-auctiondb" and private.OnLoad then
- private.OnLoad(addon)
- end
- end
- function lib.GetPrice(hyperlink, serverKey)
- local array = lib.GetPriceArray(hyperlink, serverKey)
- return array.price, array.stddev, array.seen
- end
- function lib.GetPriceColumns()
- return "Market Value", "Market Std Dev", "Seen Count"
- end
- function lib.GetDay(t)
- t = t or time()
- return floor(t / (60*60*24))
- end
- local array = {}
- local seen
- local confidence
- function lib.GetPriceArray(id, serverKey)
- confidence = get("stat.auctiondb.confidence") or 1
- seen = TSMAPI:GetData("seenCount", TSMAPI:GetItemID(id))
- local price = TSMAPI:GetData("market", id)
- local scans = TSMAPI:GetData("adbScans", id)
- if not scans or not price then return end
- local variance, n = 0, 0
- local day = lib.GetDay()
- local i, x
- for i=0, 14 do
- local data = scans[day-i]
- if data then
- if type(data) == "table" then
- for _, x in pairs(data) do
- variance = variance + (x-price)^2
- n = n + 1
- end
- else
- variance = variance + (data-price)^2
- n = n + 1
- end
- end
- end
- wipe(array)
- array.price = price
- array.seen = seen
- variance = variance * sqrt(seen / n) -- central limit theorem (simplifying assumption that scans are equal-size independent samples)
- local minvariance = get("stat.auctiondb.minerrorpct")*.01*price
- if variance < minvariance then variance = minvariance*price end
- if variance <= 0 then return end
- if n >= 2 then
- array.stddev = sqrt(variance)/(confidence*(n-1))
- end
- return array
- end
- local bellCurve = AucAdvanced.API.GenerateBellCurve()
- local mean, stddev
- local pdfcache = {} -- FIXME: should be cleared when settings change
- function lib.GetItemPDF(itemLink, serverKey)
- local array = lib.GetPriceArray(itemLink, serverKey)
- if not array then return end
- mean = array.price
- stddev = array.stddev
- -- print(string.format("%s: Mean %f, stddev %f\n", itemLink, mean, stddev))
- -- Calculate the lower and upper bounds as +/- 3 standard deviations
- if mean and stddev then
- local lower, upper = (mean - 3 * stddev), (mean + 3 * stddev)
- bellCurve:SetParameters(mean, stddev)
- return bellCurve, lower, upper
- else
- return
- end
- end
- function lib.IsValidAlgorithm()
- if not get("stat.auctiondb.enable") then return false end
- if not TSMAPI then return false end
- return true
- end
- function private.OnLoad(addon)
- TSMAPI = _G.TSMAPI
- default("stat.auctiondb.enable", false)
- default("stat.auctiondb.confidence", 1)
- -- default("stat.auctiondB.shockconfidence", 10)
- -- default("stat.auctiondb.fallbackconfidence", 2)
- -- default("stat.auctiondb.projection", -3.5)
- -- default("stat.auctiondb.regionagreement", 1)
- -- default("stat.auctiondB.maxz", 2) -- because this parameter is used to effectively apply median-centered Bollinger Bands
- default("stat.auctiondb.minerrorpct", 1)
- -- default("stat.auctiondB.detectpriceshocks", true)
- -- default("stat.auctiondB.detectstddevshocks", false)
- -- default("stat.auctiondb.n", 492) -- 2 factions * 246 US realms as of 2012-09-17 (excludes Arena Pass)
- private.OnLoad = nil -- only run this function once
- end
- --~ function private.GetInfo(hyperlink, serverKey)
- --~ if not private.IsauctiondBLoaded() then return end
- --~ local linkType, itemId, suffix, factor = decode(hyperlink)
- --~ if (linkType ~= "item") then return end
- --~ local dta = TSMAPI:GetData(itemId, serverKey)
- --~ return dta
- --~ end
- -- Localization via Auctioneer's Babylonian; from Auc-Advanced/CoreUtil.lua
- local Babylonian = LibStub("Babylonian")
- assert(Babylonian, "Babylonian is not installed")
- local babylonian = Babylonian(AucStatAuctionDBLocalizations)
- _TRANS = function (stringKey)
- local locale = get("SelectedLocale") -- locales are user choose-able
- -- translated key or english Key or Raw Key
- return babylonian(locale, stringKey) or babylonian[stringKey] or stringKey
- end
- function private.SetupConfigGui(gui)
- local id = gui:AddTab(lib.libName, lib.libType.." Modules")
- gui:AddHelp(id, "what auctiondb",
- _TRANS('auctionDB_Help_auctionDB'),
- _TRANS('auctionDB_Help_auctionDBAnswer')
- )
- -- All options in here will be duplicated in the tooltip frame
- local function addTooltipControls(id)
- -- FIXME: cache needs to clear when settings change
- gui:AddControl(id, "Header", 0, _TRANS('auctionDB_Interface_auctionDBOptions'))
- gui:AddControl(id, "Note", 0, 1, nil, nil, " ")
- gui:AddControl(id, "Checkbox", 0, 1, "stat.auctiondb.enable", _TRANS('auctionDB_Interface_EnableauctionDB'))
- gui:AddTip(id, _TRANS('auctionDB_HelpTooltip_EnableauctionDB'))
- gui:AddControl(id, "WideSlider", 0, 1, "stat.auctiondb.minerrorpct", 0, 10, 0.5, _TRANS('auctiondB_Interface_MinErrorPercent') )
- gui:AddTip(id, _TRANS('auctionDB_HelpTooltip_MinErrorPercent'))
- gui:AddControl(id, "WideSlider", 0, 1, "stat.auctiondb.confidence", 1, 30, 1, _TRANS('auctionDB_Interface_Confidence') )
- gui:AddTip(id, _TRANS('auctionDB_HelpTooltip_Confidence'))
- end
- local tooltipID = AucAdvanced.Settings.Gui.tooltipID
- addTooltipControls(id)
- if tooltipID then addTooltipControls(tooltipID) end
- private.SetupConfigGui = nil -- only run once
- end
- function private.IsauctionDBLoaded()
- TSMAPI = _G.TSMAPI
- return TSMAPI and true or false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement