tbc loop change part 5

This commit is contained in:
Manuel Simon Hirsig
2017-06-02 20:19:32 +02:00
parent 0fe79adf99
commit d9da99b537
6 changed files with 41 additions and 25 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ do
end end
function LOAD2() function LOAD2()
characters = realm_data'characters' characters = realm_data'characters'
for k, v in characters do for k, v in pairs(characters) do
if GetTime() > v + 60 * 60 * 24 * 30 then if GetTime() > v + 60 * 60 * 24 * 30 then
characters[k] = nil characters[k] = nil
end end
+1 -1
View File
@@ -37,7 +37,7 @@ local WEAPON = S(
function M.value(slot, quality, level) function M.value(slot, quality, level)
local expectation local expectation
for _, event in distribution(slot, quality, level) do for _, event in pairs(distribution(slot, quality, level)) do
local value = history.value(event.item_id .. ':' .. 0) local value = history.value(event.item_id .. ':' .. 0)
if not value then if not value then
return return
+5 -5
View File
@@ -65,12 +65,12 @@ function M.value(item_key)
item_record = read_record(item_key) item_record = read_record(item_key)
if getn(item_record.data_points) > 0 then if getn(item_record.data_points) > 0 then
local total_weight, weighted_values = 0, temp-T local total_weight, weighted_values = 0, temp-T
for _, data_point in item_record.data_points do for _, data_point in pairs(item_record.data_points) do
local weight = .99 ^ round((item_record.data_points[1].time - data_point.time) / (60 * 60 * 24)) local weight = .99 ^ round((item_record.data_points[1].time - data_point.time) / (60 * 60 * 24))
total_weight = total_weight + weight total_weight = total_weight + weight
tinsert(weighted_values, O('value', data_point.value, 'weight', weight)) tinsert(weighted_values, O('value', data_point.value, 'weight', weight))
end end
for _, weighted_value in weighted_values do for _, weighted_value in pairs(weighted_values) do
weighted_value.weight = weighted_value.weight / total_weight weighted_value.weight = weighted_value.weight / total_weight
end end
value = weighted_median(weighted_values) value = weighted_median(weighted_values)
@@ -89,10 +89,10 @@ end
function weighted_median(list) function weighted_median(list)
sort(list, function(a,b) return a.value < b.value end) sort(list, function(a,b) return a.value < b.value end)
local weight = 0 local weight = 0
for i = 1, getn(list) do for _, v in ipairs(list) do
weight = weight + list[i].weight weight = weight + v.weight
if weight >= .5 then if weight >= .5 then
return list[i].value return v.value
end end
end end
end end
+3 -3
View File
@@ -27,14 +27,14 @@ do
function M.abort(scan_id) function M.abort(scan_id)
local aborted = T local aborted = T
for type, state in scan_states do for type, state in pairs(scan_states) do
if not scan_id or state.id == scan_id then if not scan_id or state.id == scan_id then
kill_thread(state.id) kill_thread(state.id)
scan_states[type] = nil scan_states[type] = nil
tinsert(aborted, state) tinsert(aborted, state)
end end
end end
for _, state in aborted do for _, state in pairs(aborted) do
do (state.params.on_abort or nop)() end do (state.params.on_abort or nop)() end
end end
end end
@@ -50,7 +50,7 @@ do
end end
function get_state() function get_state()
for _, state in scan_states do for _, state in pairs(scan_states) do
if state.id == thread_id then if state.id == thread_id then
return state return state
end end
+2 -3
View File
@@ -18,7 +18,7 @@ function LOAD()
settings = character_data('tooltip', {value=true}) settings = character_data('tooltip', {value=true})
do do
local inside_hook = false local inside_hook = false
for name, f in game_tooltip_hooks do for name, f in pairs(game_tooltip_hooks) do
local name, f = name, f local name, f = name, f
hook(name, GameTooltip, vararg-function(arg) hook(name, GameTooltip, vararg-function(arg)
inside_hook = true inside_hook = true
@@ -61,8 +61,7 @@ function M.extend_tooltip(tooltip, link, quantity)
if settings.disenchant_distribution then if settings.disenchant_distribution then
tooltip:AddLine('Disenchants into:', color.tooltip.disenchant.distribution()) tooltip:AddLine('Disenchants into:', color.tooltip.disenchant.distribution())
sort(distribution, function(a,b) return a.probability > b.probability end) sort(distribution, function(a,b) return a.probability > b.probability end)
for i = 1, getn(distribution) do for _, event in ipairs(distribution) do
local event = distribution[i]
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, info.display_name(event.item_id, true) or 'item:' .. event.item_id, event.min_quantity, event.max_quantity), color.tooltip.disenchant.distribution()) tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, info.display_name(event.item_id, true) or 'item:' .. event.item_id, event.min_quantity, event.max_quantity), color.tooltip.disenchant.distribution())
end end
end end
+29 -12
View File
@@ -32,7 +32,10 @@ end
M.index = vararg-function(arg) M.index = vararg-function(arg)
local t = tremove(arg, 1) local t = tremove(arg, 1)
for i = 1, getn(arg) do t = t and t[arg[i]] end return t for _, v in ipairs(arg) do
t = t and t[v]
end
return t
end end
M.huge = 1.8 * 10 ^ 308 M.huge = 1.8 * 10 ^ 308
@@ -43,46 +46,58 @@ end
function M.copy(t) function M.copy(t)
local copy = T local copy = T
for k, v in t do copy[k] = v end for k, v in pairs(t) do
copy[k] = v
end
table.setn(copy, getn(t)) table.setn(copy, getn(t))
return setmetatable(copy, getmetatable(t)) return setmetatable(copy, getmetatable(t))
end end
function M.size(t) function M.size(t)
local size = 0 local size = 0
for _ in t do size = size + 1 end for _ in pairs(t) do
size = size + 1
end
return size return size
end end
function M.key(t, value) function M.key(t, value)
for k, v in t do if v == value then return k end end for k, v in pairs(t) do
if v == value then
return k
end
end
end end
function M.keys(t) function M.keys(t)
local keys = T local keys = T
for k in t do tinsert(keys, k) end for k in pairs(t) do
tinsert(keys, k)
end
return keys return keys
end end
function M.values(t) function M.values(t)
local values = T local values = T
for _, v in t do tinsert(values, v) end for _, v in pairs(t) do
tinsert(values, v)
end
return values return values
end end
function M.eq(t1, t2) function M.eq(t1, t2)
if not t1 or not t2 then return false end if not t1 or not t2 then return false end
for key, value in t1 do for key, value in pairs(t1) do
if t2[key] ~= value then return false end if t2[key] ~= value then return false end
end end
for key, value in t2 do for key, value in pairs(t2) do
if t1[key] ~= value then return false end if t1[key] ~= value then return false end
end end
return true return true
end end
function M.any(t, predicate) function M.any(t, predicate)
for _, v in t do for _, v in pairs(t) do
if predicate then if predicate then
if predicate(v) then return true end if predicate(v) then return true end
elseif v then elseif v then
@@ -93,7 +108,7 @@ function M.any(t, predicate)
end end
function M.all(t, predicate) function M.all(t, predicate)
for _, v in t do for _, v in pairs(t) do
if predicate then if predicate then
if not predicate(v) then return false end if not predicate(v) then return false end
elseif not v then elseif not v then
@@ -104,14 +119,16 @@ function M.all(t, predicate)
end end
function M.filter(t, predicate) function M.filter(t, predicate)
for k, v in t do for k, v in pairs(t) do
if not predicate(v, k) then t[k] = nil end if not predicate(v, k) then t[k] = nil end
end end
return t return t
end end
function M.map(t, f) function M.map(t, f)
for k, v in t do t[k] = f(v, k) end for k, v in pairs(t) do
t[k] = f(v, k)
end
return t return t
end end