Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions NeutralFlip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,18 @@ function NF.CurrentKind() return currentKind end
function NF.KindLabel(kind) return kind == NEUTRAL and "neutral" or (kind or "?") end

local function fresh(rec, now)
return rec and (now - rec.t) <= settings.maxAgeHours * 3600
if type(rec) ~= "table" then return false end
local p, t = C.SafeNumber(rec.p), C.SafeNumber(rec.t)
if not (p and p > 0 and p < math.huge and t and t > 0 and t <= now
and now - t <= settings.maxAgeHours * 3600) then return false end
-- Missing listing quantities are permitted; malformed or secret quantities are not.
for _, key in ipairs({ "q", "n" }) do
if rec[key] ~= nil then
local n = C.SafeNumber(rec[key])
if not n or n < 0 or n >= math.huge or n ~= math.floor(n) then return false end
end
end
return true
end

-- One route: buy at `from` for buy.p, list at `to` 1c under its lowest listing.
Expand Down Expand Up @@ -255,11 +266,12 @@ local function ago(sec)
end

function NF.FormatLine(i, o)
local s = ("%d. %s: BUY at %s AH at %s or less (%s%d) -> LIST at %s AH at %s -> +%s each, about %s total"):format(
local s = ("%d. %s: BUY at %s AH at %s or less (%s%d) -> LIST at %s AH at %s -> +%s each, about %s if all sell"):format(
i, o.name, NF.KindLabel(o.from), C.Money(o.buy), o.qtyKnown and "x" or "x?", o.qty,
NF.KindLabel(o.to), C.Money(o.listAt), C.Money(o.profit), C.Money(o.total))
local notes = { ("%s %s %s, %s %s %s"):format(NF.KindLabel(o.from), L["price"], ago(o.buyAge), NF.KindLabel(o.to), L["price"], ago(o.sellAge)) .. " " .. L["old"] }
if o.deposit then notes[#notes + 1] = "deposit at risk " .. C.Money(o.deposit) end
if not o.qtyKnown then notes[#notes + 1] = "quantity at lowest buy price unknown" end
if o.deposit then notes[#notes + 1] = "deposit at risk " .. C.Money(o.deposit) else notes[#notes + 1] = "deposit unknown" end
if o.carried > 0 then notes[#notes + 1] = "you carry " .. o.carried end
if o.thin then notes[#notes + 1] = "THIN MARKET: check by hand" end
return s .. " [" .. table.concat(notes, ", ") .. "]"
Expand All @@ -279,7 +291,7 @@ function NF.ListText(now)
end
for i = 1, math.min(#list, settings.listSize) do lines[#lines + 1] = NF.FormatLine(i, list[i]) end
lines[#lines + 1] = ""
lines[#lines + 1] = "You press every buy and post. Prices are the lowest listing you last saw; they may have moved."
lines[#lines + 1] = "You press every buy and post. Observed listings are not completed sales or proof of demand. Prices may have moved; unsold auctions can lose the deposit."
return table.concat(lines, "\n"), #list
end

Expand Down
14 changes: 14 additions & 0 deletions tests/test_neutralflip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ check(not o.thin, "19x ratio not thin")
local text = NF.ListText()
check(text:find("BUY at Alliance AH") and text:find("LIST at neutral AH"), "list text: " .. text)

-- Invalid data must not produce a recommendation, and listing profits are conditional.
check(text:find("if all sell", 1, true) and text:find("not completed sales", 1, true), "conditional estimated profit")
local savedHome = db.houses["TestRealm-Alliance"].items[785]
for _, bad in ipairs({
{ p = 100, q = 40, n = 50, t = W.now + 60 },
{ p = 100, q = 40, n = 50 },
{ p = "100", q = 40, n = 50, t = W.now },
{ p = 100, q = "40", n = 50, t = W.now },
}) do
db.houses["TestRealm-Alliance"].items[785] = bad
check(#NF.ItemRoutes(785, W.now, {}) == 0, "invalid comparison ignored")
end
db.houses["TestRealm-Alliance"].items[785] = savedHome

-- Reverse direction, outlier flag
W.commodity[2589] = { { unitPrice = 10, quantity = 100 } }
W.fire("COMMODITY_SEARCH_RESULTS_UPDATED", 2589)
Expand Down
Loading