diff --git a/server/test/JobLogTest.cs b/server/test/JobLogTest.cs index 775837a2..e7aeaac4 100644 --- a/server/test/JobLogTest.cs +++ b/server/test/JobLogTest.cs @@ -416,56 +416,61 @@ public void AddLog() "2" ); - var loadEndActualCycle = _jobLog.RecordLoadEnd( + var loadEndActualCycle = _jobLog.RecordLoadUnloadComplete( toLoad: new[] { - new MaterialToLoadOntoPallet() + new MaterialToLoadOntoFace() { - LoadStation = 111, - Elapsed = TimeSpan.FromMinutes(11122), - Faces = ImmutableList.Create( - new MaterialToLoadOntoFace() - { - FaceNum = 22, - Process = mat2.Process, - Path = null, - MaterialIDs = ImmutableList.Create(mat2.MaterialID, mat15.MaterialID), - ActiveOperationTime = TimeSpan.FromSeconds(111), - } - ), + FaceNum = 22, + Process = mat2.Process, + Path = null, + MaterialIDs = [mat2.MaterialID, mat15.MaterialID], + ActiveOperationTime = TimeSpan.FromSeconds(111), }, - new MaterialToLoadOntoPallet() + new MaterialToLoadOntoFace() { - LoadStation = 222, - Elapsed = TimeSpan.FromMinutes(22211), - Faces = ImmutableList.Create( - new MaterialToLoadOntoFace() - { - FaceNum = matLoc2Face1.Face, - Process = matLoc2Face1.Process, - Path = 33, - MaterialIDs = ImmutableList.Create(matLoc2Face1.MaterialID), - ActiveOperationTime = TimeSpan.FromSeconds(2222), - }, - new MaterialToLoadOntoFace() - { - FaceNum = matLoc2Face2.Face, - Process = matLoc2Face2.Process, - Path = 44, - MaterialIDs = ImmutableList.Create(matLoc2Face2.MaterialID), - ActiveOperationTime = TimeSpan.FromSeconds(3333), - } - ), + FaceNum = matLoc2Face1.Face, + Process = matLoc2Face1.Process, + Path = 33, + MaterialIDs = [matLoc2Face1.MaterialID], + ActiveOperationTime = TimeSpan.FromSeconds(222), + }, + new MaterialToLoadOntoFace() + { + FaceNum = matLoc2Face2.Face, + Process = matLoc2Face2.Process, + Path = 44, + MaterialIDs = [matLoc2Face2.MaterialID], + ActiveOperationTime = TimeSpan.FromSeconds(333), }, }, + toUnload: null, + lulNum: 111, + totalElapsed: TimeSpan.FromMinutes(4000), pallet: 1234, - timeUTC: start.AddHours(3) + timeUTC: start.AddHours(3), + externalQueues: null ); loadEndActualCycle .Should() .BeEquivalentTo( new[] { + new LogEntry() + { + Counter = -1, + Material = [], + Pallet = 1234, + LogType = LogType.PalletCycle, + LocationName = "PalletCycle", + LocationNum = 1, + Program = "PalletCycle", + StartOfCycle = false, + EndTimeUTC = start.AddHours(3), + Result = "PalletCycle", + ElapsedTime = TimeSpan.FromMinutes(-1), + ActiveOperationTime = TimeSpan.Zero, + }, new LogEntry( -1, new LogMaterial[] { mat2, mat15 }, @@ -475,9 +480,9 @@ public void AddLog() 111, "LOAD", false, - start.AddHours(3), + start.AddHours(3).AddSeconds(1), "LOAD", - TimeSpan.FromMinutes(11122), + TimeSpan.FromMinutes(111 * 4000 / (111 + 222 + 333)), TimeSpan.FromSeconds(111) ), new LogEntry( @@ -486,27 +491,27 @@ public void AddLog() 1234, LogType.LoadUnloadCycle, "L/U", - 222, + 111, "LOAD", false, - start.AddHours(3), + start.AddHours(3).AddSeconds(1), "LOAD", - TimeSpan.FromMinutes(22211), - TimeSpan.FromSeconds(2222) + TimeSpan.FromMinutes(222 * 4000 / (111 + 222 + 333)), + TimeSpan.FromSeconds(222) ), new LogEntry( -1, new LogMaterial[] { matLoc2Face2 with { Path = 44 } }, - 1234, + 111, LogType.LoadUnloadCycle, "L/U", 222, "LOAD", false, - start.AddHours(3), + start.AddHours(3).AddSeconds(1), "LOAD", - TimeSpan.FromMinutes(22211), - TimeSpan.FromSeconds(3333) + TimeSpan.FromMinutes(333 * 4000 / (111 + 222 + 333)), + TimeSpan.FromSeconds(333) ), }, options => options.ComparingByMembers().Excluding(x => x.Counter) @@ -736,13 +741,25 @@ public void AddLog() ); logs.Add(unloadStartActualCycle); - var unloadEndActualCycle = _jobLog.RecordUnloadEnd( - mats: new[] { mat2, mat19 }.Select(EventLogMaterial.FromLogMat), + var unloadEndActualCycle = _jobLog.RecordLoadUnloadComplete( + toLoad: null, + toUnload: + [ + new MaterialToUnloadFromFace() + { + MaterialIDToQueue = ImmutableDictionary + .Empty.Add(mat2.MaterialID, null) + .Add(mat19.MaterialID, null), + FaceNum = mat2.Face, + Process = mat2.Process, + ActiveOperationTime = TimeSpan.FromSeconds(55), + }, + ], pallet: 3, lulNum: 14, timeUTC: start.AddHours(7), - elapsed: TimeSpan.FromMinutes(152), - active: TimeSpan.FromMinutes(55) + totalElapsed: TimeSpan.FromMinutes(152), + externalQueues: null ); unloadEndActualCycle .Should() @@ -763,11 +780,26 @@ public void AddLog() TimeSpan.FromMinutes(152), TimeSpan.FromMinutes(55) ), + new LogEntry() + { + Counter = -1, + Material = [], + Pallet = 3, + LogType = LogType.PalletCycle, + LocationName = "PalletCycle", + LocationNum = 1, + Program = "PalletCycle", + StartOfCycle = false, + EndTimeUTC = start.AddHours(7), + Result = "PalletCycle", + ElapsedTime = TimeSpan.FromMinutes(-1), + ActiveOperationTime = TimeSpan.Zero, + }, }, options => options.ComparingByMembers() ); - logs.Add(unloadEndActualCycle.First()); - logsForMat2.Add(unloadEndActualCycle.First()); + logs.AddRange(unloadEndActualCycle); + logsForMat2.Add(unloadEndActualCycle.Last()); // ----- check loading of logs ----- @@ -1059,38 +1091,37 @@ public void LookupByPallet() DateTime pal1InitialTime = DateTime.UtcNow.AddHours(-4); // *********** Add load cycle on pal1 - pal1Initial.Add( - _jobLog.RecordLoadStart( - mats: new[] { mat1, mat2 }.Select(EventLogMaterial.FromLogMat), - pallet: 1, - lulNum: 2, - timeUTC: pal1InitialTime - ) - ); //end of route + // load start won't be on the cycle created by RecordLoadUnloadComplete + var loadStart = _jobLog.RecordLoadStart( + mats: new[] { mat1, mat2 }.Select(EventLogMaterial.FromLogMat), + pallet: 1, + lulNum: 2, + timeUTC: pal1InitialTime + ); pal1Initial.AddRange( - _jobLog.RecordLoadEnd( - toLoad: - [ - new MaterialToLoadOntoPallet() - { - LoadStation = 2, - Faces = - [ - new MaterialToLoadOntoFace() - { - MaterialIDs = [mat1.MaterialID, mat2.MaterialID], - Process = mat1.Process, - Path = mat1.Path, - FaceNum = mat1.Face, - ActiveOperationTime = TimeSpan.FromSeconds(22), - }, - ], - }, - ], - pallet: 1, - timeUTC: pal1InitialTime.AddMinutes(5) - ) + _jobLog + .RecordLoadUnloadComplete( + toLoad: + [ + new MaterialToLoadOntoFace() + { + MaterialIDs = [mat1.MaterialID, mat2.MaterialID], + Process = mat1.Process, + Path = mat1.Path, + FaceNum = mat1.Face, + ActiveOperationTime = TimeSpan.FromSeconds(22), + }, + ], + toUnload: null, + pallet: 1, + lulNum: 2, + totalElapsed: TimeSpan.FromMinutes(10), + timeUTC: pal1InitialTime.AddMinutes(5), + externalQueues: null + ) + .Where(e => e.LogType != LogType.PalletCycle) ); + Assert.Equal(pal1InitialTime.AddMinutes(5), _jobLog.LastPalletCycleTime(1)); // *********** Add machine cycle on pal1 pal1Initial.Add( @@ -1133,28 +1164,40 @@ public void LookupByPallet() ); _jobLog.CurrentPalletLog(2).Should().BeEmpty(); - _jobLog.CompletePalletCycle(1, pal1InitialTime.AddMinutes(25), ""); - - pal1Initial.Add( - new LogEntry( - 0, - new LogMaterial[] { }, - 1, - LogType.PalletCycle, - "Pallet Cycle", - 1, - "", - false, - pal1InitialTime.AddMinutes(25), - "PalletCycle", - TimeSpan.Zero, - TimeSpan.Zero - ) + var pal1CycleEvt = _jobLog.RecordLoadUnloadComplete( + toLoad: null, + toUnload: null, + lulNum: 2, + pallet: 1, + totalElapsed: TimeSpan.Zero, + timeUTC: pal1InitialTime.AddMinutes(25), + externalQueues: null ); + pal1CycleEvt + .Should() + .BeEquivalentTo( + [ + new LogEntry( + 0, + new LogMaterial[] { }, + 1, + LogType.PalletCycle, + "Pallet Cycle", + 1, + "", + false, + pal1InitialTime.AddMinutes(25), + "PalletCycle", + TimeSpan.Zero, + TimeSpan.Zero + ), + ] + ); + Assert.Equal(pal1InitialTime.AddMinutes(25), _jobLog.LastPalletCycleTime(1)); CheckLog( - pal1Initial, + [.. pal1Initial, loadStart, .. pal1Cycle], _jobLog.GetLogEntries(DateTime.UtcNow.AddHours(-10), DateTime.UtcNow).ToList(), DateTime.UtcNow.AddHours(-50) ); @@ -1162,7 +1205,7 @@ public void LookupByPallet() _jobLog .CurrentPalletLog(1, includeLastPalletCycleEvt: true) .Should() - .BeEquivalentTo(new[] { pal1Initial.Last() }, options => options.Excluding(x => x.Counter)); + .BeEquivalentTo(pal1CycleEvt, options => options.Excluding(x => x.Counter)); _jobLog.CurrentPalletLog(2).Should().BeEmpty(); DateTime pal2CycleTime = DateTime.UtcNow.AddHours(-3); diff --git a/server/test/makino/LogBuilderSpec.cs b/server/test/makino/LogBuilderSpec.cs index ce7200da..b6357bda 100644 --- a/server/test/makino/LogBuilderSpec.cs +++ b/server/test/makino/LogBuilderSpec.cs @@ -50,6 +50,7 @@ public sealed class LogBuilderSpec : IDisposable { private readonly RepositoryConfig _repo; private readonly IMakinoDB _makinoDB; + private readonly FMSSettings _settings; private readonly Fixture _fixture = new(); private readonly List _expectedLog = []; private readonly IReadOnlyDictionary _devices; @@ -62,6 +63,8 @@ public LogBuilderSpec() }; _repo = RepositoryConfig.InitializeMemoryDB(serialSettings); + _settings = new FMSSettings(); + _makinoDB = Substitute.For(); _makinoDB .LoadCurrentInfo(Arg.Any(), Arg.Any()) @@ -466,7 +469,7 @@ public void NoLogOnEmpty() } ); - new LogBuilder(_makinoDB, db).CheckLogs(lastDate, DateTime.UtcNow).Should().BeFalse(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(lastDate, DateTime.UtcNow).Should().BeFalse(); db.MaxLogDate().Should().Be(DateTime.MinValue); } @@ -516,7 +519,7 @@ public void SingleCycle() } ); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() @@ -557,7 +560,7 @@ public void AvoidsDuplicateMachine() } ); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() @@ -579,7 +582,7 @@ public void AvoidsDuplicateMachine() } ); - new LogBuilder(_makinoDB, db).CheckLogs(start.AddMinutes(15 + 11), now).Should().BeFalse(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(start.AddMinutes(15 + 11), now).Should().BeFalse(); db.GetLogEntries(start, now) .Should() @@ -633,7 +636,7 @@ public void AvoidsDuplicateLoad() } ); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() @@ -655,7 +658,7 @@ public void AvoidsDuplicateLoad() } ); - new LogBuilder(_makinoDB, db).CheckLogs(start.AddMinutes(30 + 5), now).Should().BeFalse(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(start.AddMinutes(30 + 5), now).Should().BeFalse(); db.GetLogEntries(start, now) .Should() @@ -729,7 +732,7 @@ public void MultiplePallets() } ); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() .BeEquivalentTo(_expectedLog, options => options.Excluding(x => x.Counter)); @@ -818,7 +821,7 @@ public void LoadAndUnloadSameTime() using var db = _repo.OpenConnection(); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() @@ -904,7 +907,7 @@ public void RecordsCommonValues() .Add("24", "common value 24"), }; - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() @@ -996,7 +999,7 @@ public void SignalsInspection() } ); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() @@ -1087,7 +1090,7 @@ public void MultipleFaces() } ); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() @@ -1146,7 +1149,7 @@ public void SkipsRemachine() using var db = _repo.OpenConnection(); - new LogBuilder(_makinoDB, db).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); + new LogBuilder(_makinoDB, db, _settings).CheckLogs(now.AddDays(-30), now).Should().BeTrue(); db.GetLogEntries(start, now) .Should() diff --git a/server/test/makino/SyncSpec.cs b/server/test/makino/SyncSpec.cs index df39887f..06aee785 100644 --- a/server/test/makino/SyncSpec.cs +++ b/server/test/makino/SyncSpec.cs @@ -75,7 +75,8 @@ public SyncSpec() DownloadOnlyOrders = true, DbConnectionString = "unused db conn str", }, - _makinoDB + _makinoDB, + new FMSSettings() ); _devices = new Dictionary() diff --git a/server/test/mazak/BuildCurrentStatusSpec.cs b/server/test/mazak/BuildCurrentStatusSpec.cs index 2dd12dd3..9818f1b0 100644 --- a/server/test/mazak/BuildCurrentStatusSpec.cs +++ b/server/test/mazak/BuildCurrentStatusSpec.cs @@ -186,6 +186,7 @@ Symlinks not supported on Windows _mazakCfg, allData, machineGroupName: "MC", + null, new DateTime(2018, 7, 19, 20, 42, 3, DateTimeKind.Utc) ); } @@ -244,15 +245,6 @@ public void PendingLoad() jsonSettings ); - _memoryLog.AddPendingLoad( - 1, - "thekey", - 1, - TimeSpan.FromMinutes(1), - TimeSpan.FromMinutes(1), - "foreignid" - ); - var matId = _memoryLog.AllocateMaterialID("aaa-schId1234", "aaa", 2); _memoryLog.RecordAddMaterialToQueue( new EventLogMaterial() @@ -273,6 +265,7 @@ public void PendingLoad() _mazakCfg, allData, machineGroupName: "MC", + palletWithUnprocessedUnloads: 1, new DateTime(2018, 7, 19, 20, 42, 3, DateTimeKind.Utc) ); @@ -361,6 +354,7 @@ public void SignalForQuarantine() _mazakCfg, allData, machineGroupName: "MC", + null, new DateTime(2018, 7, 19, 20, 42, 3, DateTimeKind.Utc) ); } @@ -444,6 +438,7 @@ _mazakCfg with }, allData, machineGroupName: "MC", + null, new DateTime(2018, 7, 19, 20, 42, 3, DateTimeKind.Utc) ); diff --git a/server/test/mazak/QueueSpec.cs b/server/test/mazak/QueueSpec.cs index efa2184a..b3932746 100644 --- a/server/test/mazak/QueueSpec.cs +++ b/server/test/mazak/QueueSpec.cs @@ -2768,142 +2768,6 @@ public void SkipsWhenAtLoad(bool waitAll) } } - [Theory] - [InlineData(true)] - [InlineData(false)] - public void SkipsWhenExistsPendingLoad(bool waitAll) - { - using var _logDB = _repoCfg.OpenConnection(); - var read = new TestMazakData(); - var schRow = AddSchedule( - read, - schId: 10, - unique: "uuuu", - part: "pppp", - numProc: 1, - pri: 10, - plan: 50, - complete: 40 - ); - AddScheduleProcess(schRow, proc: 1, matQty: 0, exeQty: 5); - - var j = new Job() - { - UniqueStr = "uuuu", - PartName = "pppp", - RouteStartUTC = DateTime.MinValue, - RouteEndUTC = DateTime.MinValue, - Archived = false, - Cycles = 0, - Processes = ImmutableList.Create( - new ProcessInfo() - { - Paths = ImmutableList.Create(JobLogTest.EmptyPath with { InputQueue = "thequeue" }), - } - ), - }; - _logDB.AddJobs( - new NewJobs() { Jobs = ImmutableList.Create(j), ScheduleId = "sch015" }, - null, - addAsCopiedToSystem: true - ); - - // put 1 castings in queue - var matId = AddAssigned( - uniq: "uuuu", - part: "pppp", - numProc: 1, - lastProc: 0, - path: 1, - queue: "thequeue" - ); - - //add a pending load - _logDB.AddPendingLoad( - 1, - "pppp:10:1,unused", - load: 5, - elapsed: TimeSpan.FromMinutes(2), - active: TimeSpan.FromMinutes(3), - foreignID: null - ); - - var trans = MazakQueues.CalculateScheduleChanges(_logDB, read.ToData(), waitForAllCastings: waitAll); - trans.Should().BeNull(); - - _logDB.CompletePalletCycle( - pal: 1, - timeUTC: DateTime.UtcNow, - matFromPendingLoads: new Dictionary>() - { - { "pppp:10:1,unused", new EventLogMaterial[] { } }, - }, - additionalLoads: null, - foreignID: null, - generateSerials: false - ); - - _logDB - .GetMaterialInAllQueues() - .Should() - .BeEquivalentTo( - new[] - { - new QueuedMaterial() - { - MaterialID = matId, - Queue = "thequeue", - Position = 0, - Unique = "uuuu", - PartNameOrCasting = "pppp", - NumProcesses = 1, - AddTimeUTC = _now, - NextProcess = 1, - Paths = ImmutableDictionary.Empty.Add(1, 1), - }, - } - ); - - trans = MazakQueues.CalculateScheduleChanges(_logDB, read.ToData(), waitForAllCastings: waitAll); - - if (waitAll) - { - // wait all removes the material - trans.Schedules.Should().BeEmpty(); - _logDB.GetMaterialInAllQueues().Should().BeEmpty(); - } - else - { - // not wait all sets the job - _logDB - .GetMaterialInAllQueues() - .Should() - .BeEquivalentTo( - new[] - { - new QueuedMaterial() - { - MaterialID = matId, - Queue = "thequeue", - Position = 0, - Unique = "uuuu", - PartNameOrCasting = "pppp", - NumProcesses = 1, - AddTimeUTC = _now, - NextProcess = 1, - Paths = ImmutableDictionary.Empty.Add(1, 1), - }, - } - ); - trans.Schedules.Count.Should().Be(1); - trans.Schedules[0].Priority.Should().Be(10); - trans.Schedules[0].Id.Should().Be(10); - trans.Schedules[0].Processes.Count.Should().Be(1); - trans.Schedules[0].Processes[0].ProcessNumber.Should().Be(1); - trans.Schedules[0].Processes[0].ProcessMaterialQuantity.Should().Be(1); - } - } - [Theory] [InlineData(null)] [InlineData("mycasting")] diff --git a/server/test/mazak/SyncSpec.cs b/server/test/mazak/SyncSpec.cs index 4fe94a5c..f68d9f38 100644 --- a/server/test/mazak/SyncSpec.cs +++ b/server/test/mazak/SyncSpec.cs @@ -396,26 +396,24 @@ public void QuarantinesMaterial() var now = DateTime.UtcNow; var mat = db.AllocateMaterialID("uuuu", "pppp", 1); - db.RecordLoadEnd( + db.RecordLoadUnloadComplete( + toLoad: [ - new() + new MaterialToLoadOntoFace() { - LoadStation = 2, - Faces = - [ - new MaterialToLoadOntoFace() - { - MaterialIDs = [mat], - FaceNum = 1, - Process = 1, - Path = 1, - ActiveOperationTime = TimeSpan.FromMinutes(1), - }, - ], + MaterialIDs = [mat], + FaceNum = 1, + Process = 1, + Path = 1, + ActiveOperationTime = TimeSpan.FromMinutes(1), }, ], + toUnload: null, + lulNum: 2, pallet: 4, - timeUTC: now + totalElapsed: TimeSpan.FromMinutes(1), + timeUTC: now, + externalQueues: null ); var allData = new MazakAllDataAndLogs()