feat(kæde): fanen Kæder og forslag i Kræver handling
This commit is contained in:
@@ -258,15 +258,51 @@ function ADStorageStats.attentionList(stats, max)
|
||||
for _, stat in ipairs(stats or {}) do
|
||||
for _, entry in ipairs(attentionEntries(stat)) do table.insert(list, entry) end
|
||||
end
|
||||
return ADStorageStats.rankAttention(list, max)
|
||||
end
|
||||
|
||||
-- Kæde-forslag ligger ikke på en vare (ingen stat): navnet til den stabile rækkefølge tages fra teksten.
|
||||
local function entryName(entry)
|
||||
return tostring(entry.stat ~= nil and entry.stat.title or entry.text)
|
||||
end
|
||||
|
||||
function ADStorageStats.rankAttention(list, max)
|
||||
table.sort(list, function(a, b)
|
||||
if a.score ~= b.score then return a.score > b.score end
|
||||
return tostring(a.stat.title) < tostring(b.stat.title)
|
||||
return entryName(a) < entryName(b)
|
||||
end)
|
||||
local result = {}
|
||||
for index = 1, math.min(#list, max or #list) do result[index] = list[index] end
|
||||
return result
|
||||
end
|
||||
|
||||
-- "Kræver handling" fra kæden (ADChain.last): ét gult punkt pr. afgrødeforslag spilleren skal tage stilling til.
|
||||
-- Rangeres over "sælg nu" (score < 1000) og under røde punkter (>= 3000).
|
||||
ADStorageStats.CHAIN_SCORE = 1000
|
||||
|
||||
function ADStorageStats.chainEntries(last)
|
||||
local entries = {}
|
||||
local titles = last ~= nil and last.titles or {}
|
||||
local function title(name) return tostring((titles or {})[name] or name) end
|
||||
for _, action in ipairs(last ~= nil and last.actions or {}) do
|
||||
if action.mode == "suggest" then
|
||||
local from = (action.from ~= nil and action.from ~= "") and title(action.from) or "-"
|
||||
table.insert(entries, {kind = "chainSuggest", level = "yellow", score = ADStorageStats.CHAIN_SCORE, fieldId = action.fieldId,
|
||||
from = from, to = title(action.to), hectares = action.hectares,
|
||||
text = string.format("F%s %s → %s", tostring(action.fieldId), from, title(action.to))})
|
||||
end
|
||||
end
|
||||
return entries
|
||||
end
|
||||
|
||||
-- Varepunkterne (allerede rangeret) + kædens punkter, samme loft.
|
||||
function ADStorageStats.mergeAttention(attention, chainEntries, max)
|
||||
local list = {}
|
||||
for _, entry in ipairs(attention or {}) do table.insert(list, entry) end
|
||||
for _, entry in ipairs(chainEntries or {}) do table.insert(list, entry) end
|
||||
return ADStorageStats.rankAttention(list, max)
|
||||
end
|
||||
|
||||
function ADStorageStats.kpis(stats)
|
||||
local kpi = {valueNow = 0, gain = 0, emptyCount = 0, fullCount = 0}
|
||||
for _, stat in ipairs(stats or {}) do
|
||||
|
||||
Reference in New Issue
Block a user