fix: morgenbriefing skelner mellem i gang, venter på såtid og venter på maskine — 1.62.299

This commit is contained in:
2026-10-17 08:34:56 +02:00
parent ed0f6cc1ee
commit f027402fdf
3 changed files with 31 additions and 8 deletions
+29 -7
View File
@@ -15,15 +15,25 @@ function ADBriefing.isNewDay(lastDay, day)
return lastDay ~= nil and day ~= nil and day ~= lastDay
end
-- s = {working = {{fieldId, stage}}, awaiting = {{fieldId, label}}, readyOff = {fieldId}, careOff = {{fieldId, care}},
-- missing = {{role, fieldIds}}}; roleName(role) -> tekst. Returnerer teksten eller nil (intet at sige).
function ADBriefing.compose(s, roleName)
-- s = {working = {{fieldId, stage, active, waitFruit, waitMachine}}, awaiting = {{fieldId, label}}, readyOff = {fieldId},
-- careOff = {{fieldId, care}}, missing = {{role, fieldIds}}}; roleName(role) -> tekst, fruitName(fruit) -> tekst.
-- active = nil/true: en maskine arbejder; waitFruit: står i såtrinnet, men afgrøden kan ikke sås endnu (17/10: "I gang:
-- F6 sås …" i november var misvisende); waitMachine: venter på en ledig maskine. Returnerer teksten eller nil.
function ADBriefing.compose(s, roleName, fruitName)
local lines = {}
local working = {}
local working, waitSowing, waitMachine = {}, {}, {}
for _, entry in ipairs(s.working or {}) do
table.insert(working, string.format("F%s %s", tostring(entry.fieldId), ADManualTransport.stageVerb(entry.stage)))
if entry.waitFruit ~= nil then
table.insert(waitSowing, string.format("F%s (%s)", tostring(entry.fieldId), tostring(fruitName ~= nil and fruitName(entry.waitFruit) or entry.waitFruit)))
elseif entry.active == false and entry.waitMachine then
table.insert(waitMachine, string.format("F%s %s", tostring(entry.fieldId), ADManualTransport.stageVerb(entry.stage)))
else
table.insert(working, string.format("F%s %s", tostring(entry.fieldId), ADManualTransport.stageVerb(entry.stage)))
end
end
if #working > 0 then table.insert(lines, "I gang: " .. table.concat(working, ", ")) end
if #waitSowing > 0 then table.insert(lines, "Venter på såtid: " .. table.concat(waitSowing, ", ")) end
if #waitMachine > 0 then table.insert(lines, "Venter på en ledig maskine: " .. table.concat(waitMachine, ", ")) end
for _, entry in ipairs(s.awaiting or {}) do
table.insert(lines, string.format("Venter på dig: kør '%s' til F%s", tostring(entry.label), tostring(entry.fieldId)))
end
@@ -62,8 +72,16 @@ local function collect()
if awaiting ~= nil then
table.insert(s.awaiting, {fieldId = info.id, label = ADRuns.vehicleLabel(awaiting.vehicle)})
elseif ADFieldModel.isWorking(field) then
table.insert(s.working, {fieldId = info.id, stage = field.stage})
local reason = type(field.reason) == "table" and field.reason or nil
local active = #(ADFieldJobs.assignmentsFor(info.id) or {}) > 0
local waitFruit = nil
if not active and field.stage == "sowing" then
local target = field.plan ~= nil and field.plan.targetFruit or nil
local env = ADFieldJobs.environment ~= nil and ADFieldJobs.environment() or nil
if target ~= nil and target ~= "" and env ~= nil and env.plantable ~= nil and not env.plantable(target) then waitFruit = target end
end
local waitMachine = not active and reason ~= nil and (reason.key == "spu_field_reason_allBusy" or reason.key == "spu_field_reason_cannotDo")
table.insert(s.working, {fieldId = info.id, stage = field.stage, active = active, waitFruit = waitFruit, waitMachine = waitMachine})
if reason ~= nil and reason.key == "spu_field_reason_noRig" and reason.role ~= nil then
if missingByRole[reason.role] == nil then
missingByRole[reason.role] = {role = reason.role, fieldIds = {}}
@@ -97,7 +115,11 @@ function ADBriefing.tick()
if not isNew then return end
local mode = ADSettings ~= nil and ADSettings.get("morningBriefing") or 2
if mode == 0 then return end
local text = ADBriefing.compose(collect(), roleName)
local fruitName = function(name)
local fruit = g_fruitTypeManager ~= nil and g_fruitTypeManager.getFruitTypeByName ~= nil and g_fruitTypeManager:getFruitTypeByName(name) or nil
return fruit ~= nil and fruit.fillType ~= nil and fruit.fillType.title ~= nil and tostring(fruit.fillType.title) or tostring(name)
end
local text = ADBriefing.compose(collect(), roleName, fruitName)
if text == nil then return end
Logging.info("ADSmartPickup: morgenbriefing:\n%s", text)
if mode == 2 and InfoDialog ~= nil and InfoDialog.show ~= nil then