Skip to content

Commit

Permalink
server: begin work on adding parts to pallet cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzzeb committed Nov 22, 2024
1 parent face45b commit f534616
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ DateTime nowUTC
var newEvts = db.RecordLoadUnloadComplete(
toLoad: matsToLoad.Select((m) => m.Item1).ToImmutableList(),
toUnload: toUnload,
previouslyLoaded: null, // TODO: previouslyLoaded
previouslyUnloaded: null, // TODO: previouslyUnloaded
lulNum: loadNum,
pallet: pal.PalletNum,
totalElapsed: nowUTC - (LoadUnloadStartTime(pal) ?? nowUTC),
Expand Down
114 changes: 100 additions & 14 deletions server/lib/BlackMaple.MachineFramework/db/EventLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,9 @@ IReadOnlyDictionary<string, string> externalQueues

public IEnumerable<LogEntry> RecordLoadUnloadComplete(
IReadOnlyList<MaterialToLoadOntoFace> toLoad,
IReadOnlyList<EventLogMaterial> previouslyLoaded,
IReadOnlyList<MaterialToUnloadFromFace> toUnload,
IReadOnlyList<EventLogMaterial> previouslyUnloaded,
int lulNum,
int pallet,
TimeSpan totalElapsed,
Expand Down Expand Up @@ -1650,7 +1652,46 @@ IReadOnlyDictionary<string, string> externalQueues
sendToExternal: sendToExternal,
trans: trans
);
RecordPalletCycle(pallet: pallet, timeUTC: timeUTC, logs: logs, trans: trans, foreignId: null);

var allUnload = (previouslyUnloaded ?? []).Concat(
(toUnload ?? []).SelectMany(u =>
u.MaterialIDToQueue.Keys.Select(mid => new EventLogMaterial()
{
MaterialID = mid,
Process = u.Process,
Face = u.FaceNum,
})
)
);
if (allUnload.Any())
{
RecordPalletCycleEnd(pallet: pallet, mats: allUnload, timeUTC: timeUTC, logs: logs, trans: trans);
}

RecordLoadMaterialPaths(toLoad: toLoad, trans: trans);

var allLoad = (previouslyLoaded ?? []).Concat(
(toLoad ?? []).SelectMany(l =>
l.MaterialIDs.Select(mid => new EventLogMaterial()
{
MaterialID = mid,
Process = l.Process,
Face = l.FaceNum,
})
)
);
if (allLoad.Any())
{
RecordPalletCycleStart(
pallet: pallet,
mats: allLoad,
timeUTC: timeUTC,
logs: logs,
trans: trans,
foreignId: null
);
}

RecordLoadEnd(
toLoad: toLoad,
lulNum: lulNum,
Expand Down Expand Up @@ -1679,7 +1720,14 @@ public IEnumerable<LogEntry> RecordEmptyPallet(int pallet, DateTime timeUTC, str
trans =>
{
var logs = new List<LogEntry>();
RecordPalletCycle(pallet: pallet, timeUTC: timeUTC, logs: logs, trans: trans, foreignId: foreignId);
RecordPalletCycleStart(
pallet: pallet,
mats: [],
timeUTC: timeUTC,
logs: logs,
trans: trans,
foreignId: foreignId
);
return logs;
},
foreignId: foreignId
Expand Down Expand Up @@ -1785,13 +1833,45 @@ IDbTransaction trans
}
}

private void RecordPalletCycle(
private void RecordPalletCycleStart(
int pallet,
IEnumerable<EventLogMaterial> mats,
DateTime timeUTC,
List<LogEntry> logs,
IDbTransaction trans,
string foreignId
)
{
logs.Add(
AddLogEntry(
trans,
new NewEventLogEntry()
{
Material = mats,
Pallet = pallet,
LogType = LogType.PalletCycle,
LocationName = "Pallet Cycle",
LocationNum = 1,
Program = "",
StartOfCycle = true,
EndTimeUTC = timeUTC,
Result = "PalletCycle",
ElapsedTime = TimeSpan.Zero,
ActiveOperationTime = TimeSpan.Zero,
},
foreignID: foreignId,
null
)
);
}

private void RecordPalletCycleEnd(
int pallet,
IEnumerable<EventLogMaterial> mats,
DateTime timeUTC,
List<LogEntry> logs,
IDbTransaction trans
)
{
using var lastTimeCmd = _connection.CreateCommand();
lastTimeCmd.CommandText =
Expand All @@ -1809,7 +1889,7 @@ string foreignId
trans,
new NewEventLogEntry()
{
Material = [],
Material = mats,
Pallet = pallet,
LogType = LogType.PalletCycle,
LocationName = "Pallet Cycle",
Expand All @@ -1821,12 +1901,26 @@ string foreignId
ElapsedTime = elapsedTime,
ActiveOperationTime = TimeSpan.Zero,
},
foreignID: foreignId,
null,
null
)
);
}

private void RecordLoadMaterialPaths(IEnumerable<MaterialToLoadOntoFace> toLoad, IDbTransaction trans)
{
foreach (var face in toLoad ?? [])
{
if (face.Path.HasValue)
{
foreach (var mat in face.MaterialIDs)
{
RecordPathForProcess(mat, face.Process, face.Path.Value, trans);
}
}
}
}

private void RecordLoadEnd(
IEnumerable<MaterialToLoadOntoFace> toLoad,
int lulNum,
Expand Down Expand Up @@ -1860,14 +1954,6 @@ IDbTransaction trans
);
}

if (face.Path.HasValue)
{
foreach (var mat in face.MaterialIDs)
{
RecordPathForProcess(mat, face.Process, face.Path.Value, trans);
}
}

TimeSpan elapsed;
if (totalActive.HasValue)
{
Expand Down Expand Up @@ -2742,7 +2828,7 @@ public SwapMaterialResult SwapMaterialInCurrentPalletCycle(
}

// load old events
var oldEvents = CurrentPalletLog(pallet, includeLastPalletCycleEvt: false, trans);
var oldEvents = CurrentPalletLog(pallet, includeLastPalletCycleEvt: true, trans);
var oldMatProcM = oldEvents
.SelectMany(e => e.Material)
.Where(m => m.MaterialID == oldMatId)
Expand Down
2 changes: 2 additions & 0 deletions server/lib/BlackMaple.MachineFramework/db/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ IReadOnlyDictionary<string, string> externalQueues
);
IEnumerable<LogEntry> RecordLoadUnloadComplete(
IReadOnlyList<MaterialToLoadOntoFace> toLoad,
IReadOnlyList<EventLogMaterial> previouslyLoaded,
IReadOnlyList<MaterialToUnloadFromFace> toUnload,
IReadOnlyList<EventLogMaterial> previouslyUnloaded,
int lulNum,
int pallet,
TimeSpan totalElapsed,
Expand Down
2 changes: 2 additions & 0 deletions server/machines/makino/LogBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ ref bool newLogEntries
{
logDb.RecordLoadUnloadComplete(
toLoad: toLoad,
previouslyLoaded: [],
toUnload: toUnload,
previouslyUnloaded: [],
lulNum: loc.Num,
pallet: ws.Key.PalletID,
totalElapsed: elapsed,
Expand Down
2 changes: 2 additions & 0 deletions server/machines/mazak/sync/LogTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ private void HandleLoadEnd(IReadOnlyList<LogEntry> es)

repo.RecordLoadUnloadComplete(
toLoad: toLoad,
previouslyLoaded: null,
toUnload: toUnload,
previouslyUnloaded: null,
pallet: pallet,
lulNum: es[0].StationNumber,
totalElapsed: CalculateElapsed(es[0].TimeUTC, LogType.LoadUnloadCycle, cycle, es[0].StationNumber),
Expand Down
2 changes: 2 additions & 0 deletions server/machines/niigata/CellState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,9 @@ IRepository logDB

var lulEvts = logDB.RecordLoadUnloadComplete(
toLoad: toLoad,
previouslyLoaded: null,
toUnload: toUnload,
previouslyUnloaded: null,
lulNum: loadBegin.LocationNum,
pallet: pallet.Status.Master.PalletNum,
totalElapsed: nowUtc.Subtract(loadBegin.EndTimeUTC),
Expand Down
2 changes: 2 additions & 0 deletions server/test/InspectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ private void AddCycle(LogMaterial[] mat, int pal, LogType loc, int statNum)
},
],
toUnload: null,
previouslyLoaded: null,
previouslyUnloaded: null,
lulNum: statNum,
totalElapsed: TimeSpan.FromMinutes(10),
pallet: pal,
Expand Down
Loading

0 comments on commit f534616

Please sign in to comment.