-
Notifications
You must be signed in to change notification settings - Fork 8
/
Utils.lua
197 lines (158 loc) · 4.77 KB
/
Utils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
---@type AuctionFaster
local AuctionFaster = unpack(select(2, ...));
--- @type StdUi
local StdUi = LibStub('StdUi');
local L = LibStub('AceLocale-3.0'):GetLocale('AuctionFaster');
function AuctionFaster:FormatDuration(duration)
if duration >= 172800 then
return format('%.1f %s', duration/86400, L['days ago'])
elseif duration >= 7200 then
return format('%.1f %s', duration/3600, L['hours ago'] )
elseif duration <= 60 then
return '0' .. L['minutes ago']
else
return format('%.1f %s', duration/60, L['minutes ago'])
end
end
function AuctionFaster:FormatAuctionDuration(duration)
if duration == 1 then
return L['12h'];
elseif duration == 2 then
return L['24h'];
elseif duration == 3 then
return L['48h'];
else
return '---';
end
end
function AuctionFaster:TableCombine(keys, values)
local result = {};
for i = 1, #keys do
result[keys[i]] = values[i];
end
return result;
end
function AuctionFaster:TableMap(func, array)
local newArray = {};
for i, v in ipairs(array) do
newArray[i] = func(v);
end
return newArray;
end
function AuctionFaster:TableMapN(func, ...)
local newArray = {};
local i = 1;
local arg = {...};
local argLength = #arg;
while true do
local argList = self:TableMap(function(arr)
return arr[i];
end, arg);
if #argList < argLength then
return newArray;
end
newArray[i] = func(unpack(argList));
i = i + 1;
end
end
function AuctionFaster:TableSum(t)
local sum = 0;
for k, v in pairs(t) do
sum = sum + v;
end
return sum;
end
function AuctionFaster:TrendLine(X, Y)
-- assuming its a table with {{X, Y}, {X, Y}}
-- Now convert to log-scale for X
local logX = self:TableMap(math.log, X);
local function square(x)
return math.pow(x, 2);
end
local function multi(x, y)
return x * y;
end
-- Now estimate a and b using equations from Math World
local xSquared = self:TableSum(self:TableMap(square, logX));
local xy = self:TableSum(self:TableMapN(multi, logX, Y));
local bFit = (#X * xy - self:TableSum(Y) * self:TableSum(logX)) /
(#X * xSquared - math.pow(self:TableSum(logX), 2));
local aFit = (self:TableSum(Y) - bFit * self:TableSum(logX)) / #X;
local trendData = {};
for i = 1, #X do
trendData[i] = {X[i], aFit + bFit * math.log(X[i])};
end
return trendData;
end
function AuctionFaster:ParseBattlePetLink(link)
local _, speciesId, petLevel, breedQuality = strsplit(":", link);
speciesId = tonumber(speciesId);
petLevel = tonumber(petLevel);
breedQuality = tonumber(breedQuality);
local itemName, icon, _, _, tooltipSource = C_PetJournal.GetPetInfoBySpeciesID(speciesId);
return itemName, icon, speciesId, petLevel, breedQuality;
end
local AuctionHouseTooltipType = {
PetLink = 1;
ItemLink = 2;
ItemKey = 3;
};
local function GetAuctionHouseTooltipType(rowData)
if rowData.itemLinkProper then
local linkType = LinkUtil.ExtractLink(rowData.itemLink);
if linkType == 'battlepet' then
return AuctionHouseTooltipType.PetLink, rowData.itemLink;
elseif linkType == "item" then
return AuctionHouseTooltipType.ItemLink, rowData.itemLink;
end
elseif rowData.itemKey then
local restrictQualityToFilter = true;
local itemKeyInfo = C_AuctionHouse.GetItemKeyInfo(rowData.itemKey, restrictQualityToFilter);
if itemKeyInfo and itemKeyInfo.battlePetLink then
return AuctionHouseTooltipType.PetLink, itemKeyInfo.battlePetLink;
end
return AuctionHouseTooltipType.ItemKey, rowData.itemKey;
end
return nil;
end
function AuctionFaster:ShowTooltip(frame, rowData, show, anchor)
GameTooltip_Hide();
if show then
local tooltip;
local tooltipType, data = GetAuctionHouseTooltipType(rowData);
if not tooltipType then
return;
end
GameTooltip:SetOwner(frame, 'ANCHOR_RIGHT');
if tooltipType == AuctionHouseTooltipType.PetLink then
BattlePetToolTip_ShowLink(data);
tooltip = BattlePetTooltip;
else
tooltip = GameTooltip;
if tooltipType == AuctionHouseTooltipType.ItemLink then
local hideVendorPrice = true;
GameTooltip:SetHyperlink(rowData.itemLink, nil, nil, nil, hideVendorPrice);
elseif tooltipType == AuctionHouseTooltipType.ItemKey then
GameTooltip:SetItemKey(data.itemID, data.itemLevel, data.itemSuffix);
end
end
if rowData.owners then
--local methodFound, auctionHouseFrame = CallMethodOnNearestAncestor(owner, "GetAuctionHouseFrame");
--local bidStatus = auctionHouseFrame and auctionHouseFrame:GetBidStatus(rowData) or nil;
--AuctionHouseUtil.AddAuctionHouseTooltipInfo(tooltip, rowData, bidStatus);
end
if tooltip == GameTooltip then
GameTooltip:Show();
GameTooltip:ClearAllPoints();
StdUi:GlueOpposite(GameTooltip, frame, 0, 0, anchor);
else
BattlePetTooltip:ClearAllPoints();
StdUi:GlueOpposite(BattlePetTooltip, frame, 0, 0, anchor);
end
else
GameTooltip:Hide();
if BattlePetTooltip then
BattlePetTooltip:Hide();
end
end
end