Skip to content

Commit

Permalink
server: initial stab at reworking workorders
Browse files Browse the repository at this point in the history
wuzzeb committed Jul 17, 2024
1 parent f3a0b77 commit e29a055
Showing 12 changed files with 398 additions and 257 deletions.
2 changes: 0 additions & 2 deletions server/lib/BlackMaple.MachineFramework/api/CellStatus.cs
Original file line number Diff line number Diff line change
@@ -101,8 +101,6 @@ public record RecentHistoricData : HistoricData
public string? MostRecentSimulationId { get; init; }

public ImmutableList<SimulatedDayUsage>? MostRecentSimDayUsage { get; init; }

public string? MostRecentSimDayUsageWarning { get; init; }
}

public record PlannedSchedule
28 changes: 23 additions & 5 deletions server/lib/BlackMaple.MachineFramework/api/NewJobs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2023, John Lenz
/* Copyright (c) 2024, John Lenz
All rights reserved.
@@ -72,19 +72,37 @@ public record SimulatedDayUsage
public required double Usage { get; init; }
}

public record SimulationResults
{
public required string ScheduleId { get; init; }
public required ImmutableList<Job> Jobs { get; init; }
public ImmutableDictionary<string, int>? NewExtraParts { get; init; }
public required ImmutableList<SimulatedStationUtilization> SimStations { get; init; }
public ImmutableList<SimulatedStationUtilization>? SimStationsForExecutionOfCurrentStatus { get; init; }
public ImmutableList<SimulatedDayUsage>? SimDayUsage { get; init; }
public ImmutableList<WorkorderSimFilled>? SimWorkordersFilled { get; init; }
public ImmutableList<string>? AllocationWarning { get; init; }
public byte[]? DebugMessage { get; init; }
}

// NewJobs is SimulationResults plus workorders and programs and so conceptually should be derived
// from SimulationResults, but a few fields are renamed because of backwards compatibility with
// older APIs
public record NewJobs
{
public required string ScheduleId { get; init; }

public required ImmutableList<MachineFramework.Job> Jobs { get; init; }
public required ImmutableList<Job> Jobs { get; init; }

public ImmutableDictionary<string, int>? ExtraParts { get; init; }

public ImmutableList<SimulatedStationUtilization>? StationUse { get; init; }

public ImmutableList<SimulatedDayUsage>? SimDayUsage { get; init; }
public ImmutableList<SimulatedStationUtilization>? StationUseForCurrentStatus { get; init; }

public string? SimDayUsageWarning { get; init; }
public ImmutableList<SimulatedDayUsage>? SimDayUsage { get; init; }

public ImmutableDictionary<string, int>? ExtraParts { get; init; }
public ImmutableList<WorkorderSimFilled>? SimWorkordersFilled { get; init; }

public ImmutableList<Workorder>? CurrentUnfilledWorkorders { get; init; }

14 changes: 9 additions & 5 deletions server/lib/BlackMaple.MachineFramework/api/Workorders.cs
Original file line number Diff line number Diff line change
@@ -51,14 +51,18 @@ public record Workorder

public required int Priority { get; init; }

public DateOnly? SimulatedStart { get; init; }

public DateOnly? SimulatedFilled { get; init; }

///<summary>If given, this value overrides the programs to run for this specific workorder.</summary>
public ImmutableList<ProgramForJobStep>? Programs { get; init; }
}

public record WorkorderSimFilled
{
public required string WorkorderId { get; init; }
public required string Part { get; init; }
public DateOnly? Started { get; init; }
public DateOnly? Filled { get; init; }
}

public record WorkorderComment
{
public required string Comment { get; init; }
@@ -96,11 +100,11 @@ public record ActiveWorkorder

public required int Priority { get; init; }

// active data
public DateOnly? SimulatedStart { get; init; }

public DateOnly? SimulatedFilled { get; init; }

// active data
public required int CompletedQuantity { get; init; }

public ImmutableList<WorkorderComment>? Comments { get; init; }
Original file line number Diff line number Diff line change
@@ -35,6 +35,8 @@ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
using System.Collections.Generic;
using System.Collections.Immutable;

#nullable enable

namespace BlackMaple.MachineFramework
{
public interface IMachineControl
@@ -83,23 +85,28 @@ public interface IPrintLabelForMaterial

public interface ICalculateInstructionPath
{
public string InstructionPath(
public string? InstructionPath(
string part,
int? process,
string type,
long? materialID,
string operatorName,
string? operatorName,
int pallet
);
}

public interface IParseBarcode
{
public ScannedMaterial ParseBarcode(string barcode, Uri httpReferer);
public ScannedMaterial? ParseBarcode(string barcode, Uri httpReferer);
}

public interface ICheckLicense
{
public DateTime? LicenseExpires();
}

public interface IProgramContentForJobs
{
public ImmutableList<NewProgramContent>? ProgramsForJobs(IEnumerable<Job> jobs);
}
}
35 changes: 11 additions & 24 deletions server/lib/BlackMaple.MachineFramework/db/EventLog.cs
Original file line number Diff line number Diff line change
@@ -769,40 +769,27 @@ public bool CycleExists(DateTime endUTC, int pal, LogType logTy, string locName,
public ImmutableList<ActiveWorkorder> GetActiveWorkorders(string partToFilter = null)
{
using var trans = _connection.BeginTransaction();
using var lastSchIdCmd = _connection.CreateCommand();

lastSchIdCmd.CommandText =
"SELECT MAX(ScheduleId) FROM unfilled_workorders WHERE ScheduleId IS NOT NULL";
var lastWorkSchId = lastSchIdCmd.ExecuteScalar() as string;
var lastJobSchId = LatestJobScheduleId(trans);
var lastSchId = string.IsNullOrEmpty(lastWorkSchId)
? lastJobSchId
: string.IsNullOrEmpty(lastJobSchId)
? lastWorkSchId
: lastWorkSchId.CompareTo(lastJobSchId) > 0
? lastWorkSchId
: lastJobSchId;

if (string.IsNullOrEmpty(lastSchId))
{
return [];
}

// we distinguish between a cell never using workorders at all and return null
// vs a cell that has no workorders currently active where we return an empty list

using (var checkExistingRowCmd = _connection.CreateCommand())
{
checkExistingRowCmd.CommandText = "SELECT EXISTS (SELECT 1 FROM unfilled_workorders LIMIT 1)";
checkExistingRowCmd.CommandText = "SELECT EXISTS (SELECT 1 FROM workorder_cache LIMIT 1)";
if (!Convert.ToBoolean(checkExistingRowCmd.ExecuteScalar()))
{
return null;
}
}

var lastSchId = LatestSimulationScheduleId(trans);
if (string.IsNullOrEmpty(lastSchId))
{
return [];
}

var workQry =
@"
SELECT uw.Workorder, uw.Part, uw.Quantity, uw.DueDate, uw.Priority, uw.SimulatedStartUTC, uw.SimulatedFilledUTC,
SELECT uw.Workorder, uw.Part, uw.Quantity, uw.DueDate, uw.Priority, sw.SimulatedStartDay, sw.SimulatedFilledDay,
(
SELECT COUNT(matdetails.MaterialID)
FROM stations, stations_mat, matdetails
@@ -824,9 +811,9 @@ SELECT COUNT(matdetails.MaterialID)
matdetails.PartName = uw.Part
) AS Completed
FROM unfilled_workorders uw
WHERE uw.ScheduleId = $schid
AND (uw.Archived IS NULL OR uw.Archived != 1)
FROM workorder_cache uw
LEFT OUTER JOIN sim_workorders sw ON sw.ScheduleId = $schid AND uw.Workorder = sw.Workorder AND uw.Part = sw.Part
WHERE uw.Archived = 0
";

if (!string.IsNullOrEmpty(partToFilter))
1 change: 1 addition & 0 deletions server/lib/BlackMaple.MachineFramework/db/IRepository.cs
Original file line number Diff line number Diff line change
@@ -489,6 +489,7 @@ HistoricData LoadJobHistory(
// --------------------------------------------------------------------------------
void AddJobs(NewJobs newJobs, string expectedPreviousScheduleId, bool addAsCopiedToSystem);
void AddPrograms(IEnumerable<NewProgramContent> programs, DateTime startingUtc);
void UpdateCachedWorkorders(IEnumerable<Workorder> workorders);
void ArchiveJob(string UniqueStr);
void ArchiveJobs(
IEnumerable<string> uniqueStrs,
Loading

0 comments on commit e29a055

Please sign in to comment.