busroot-sdk 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/types.js ADDED
@@ -0,0 +1,796 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WeekDay = exports.UserRole = exports.TIMESERIES_MESSAGE_TYPE = exports.StationWindowViewModelTrimmed = exports.StationWindowViewModel = exports.StationWindowSchema = exports.StationViewModel = exports.StationStatus = exports.StationSchema = exports.SkuViewModel = exports.ScheduleViewModel = exports.STATION_MODULE_VISIBILITY = exports.SCHEDULE_TYPE = exports.ReliabilityData = exports.RagStatus = exports.REASON_TYPE = exports.ProductionViewModel = exports.PlantViewModel = exports.PRODUCTIVE_STATUS_MODE = exports.PRODUCTION_TYPE = exports.PERFORMANCE_MODE_TYPE = exports.OeeViewModel = exports.NominalValue = exports.NOTIFICATION_PREFERENCE = exports.MqttEventType = exports.MessageType = exports.GROUP_TAG_PREFIX = exports.EMAIL_HARNESS_TYPE = exports.DowntimeType = exports.DowntimeFilterState = exports.DowntimeEventType = exports.DOWNTIME_DETECTION_MODE = exports.CycleTimeAnalysis = exports.CursorType = exports.AuthType = exports.AggregatedStationWindowsByStation = exports.AccountViewModel = exports.AccountSchema = exports.AccountRole = exports.ALERT_ISSUE_TYPE = exports.ShiftPatternViewModel = exports.ShiftViewModel = exports.ShiftPatternSchema = exports.ShiftSchema = exports.OeeStop = exports.StationGroupSchema = exports.StationState = exports.TimeIntervals = void 0;
7
+ const zod_1 = require("zod");
8
+ const chroma_js_1 = __importDefault(require("chroma-js"));
9
+ var RagStatus;
10
+ (function (RagStatus) {
11
+ RagStatus["Red"] = "#cc3311";
12
+ RagStatus["Amber"] = "#ee7733";
13
+ RagStatus["Green"] = "#009988";
14
+ RagStatus["Blue"] = "#33bbee";
15
+ RagStatus["NA"] = "#CCCCCC";
16
+ RagStatus["Purple"] = "#8338ec";
17
+ })(RagStatus || (exports.RagStatus = RagStatus = {}));
18
+ exports.TimeIntervals = {
19
+ "1ms": { ms: 1, sec: 0.001, min: 1 / 60000, shorthand: "1ms" },
20
+ "10ms": { ms: 10, sec: 0.01, min: 10 / 60000, shorthand: "10ms" },
21
+ "100ms": { ms: 100, sec: 0.1, min: 100 / 60000, shorthand: "100ms" },
22
+ "1s": { ms: 1000, sec: 1, min: 1 / 60, shorthand: "1s" },
23
+ "2s": { ms: 2000, sec: 2, min: 2 / 60, shorthand: "2s" },
24
+ "5s": { ms: 5000, sec: 5, min: 5 / 60, shorthand: "5s" },
25
+ "10s": { ms: 10000, sec: 10, min: 10 / 60, shorthand: "10s" },
26
+ "30s": { ms: 30000, sec: 30, min: 30 / 60, shorthand: "30s" },
27
+ "1m": { ms: 60000, sec: 60, min: 1, shorthand: "1m" },
28
+ "2m": { ms: 120000, sec: 120, min: 2, shorthand: "2m" },
29
+ "5m": { ms: 300000, sec: 300, min: 5, shorthand: "5m" },
30
+ "10m": { ms: 600000, sec: 600, min: 10, shorthand: "10m" },
31
+ "15m": { ms: 900000, sec: 900, min: 15, shorthand: "15m" },
32
+ "30m": { ms: 1800000, sec: 1800, min: 30, shorthand: "30m" },
33
+ "1h": { ms: 3600000, sec: 3600, min: 60, shorthand: "1h" },
34
+ "2h": { ms: 7200000, sec: 7200, min: 120, shorthand: "2h" },
35
+ "6h": { ms: 21600000, sec: 21600, min: 360, shorthand: "6h" },
36
+ "12h": { ms: 43200000, sec: 43200, min: 720, shorthand: "12h" },
37
+ "1d": { ms: 86400000, sec: 86400, min: 1440, shorthand: "1d" },
38
+ "2d": { ms: 172800000, sec: 172800, min: 2880, shorthand: "2d" },
39
+ "7d": { ms: 604800000, sec: 604800, min: 10080, shorthand: "7d" },
40
+ "30d": { ms: 2592000000, sec: 2592000, min: 43200, shorthand: "30d" },
41
+ "60d": { ms: 5184000000, sec: 5184000, min: 86400, shorthand: "60d" },
42
+ "90d": { ms: 7776000000, sec: 7776000, min: 129600, shorthand: "90d" },
43
+ "180d": { ms: 7776000000 * 2, sec: 7776000 * 2, min: 259200, shorthand: "180d" },
44
+ "1y": { ms: 7776000000 * 4, sec: 7776000 * 4, min: 525600, shorthand: "1y" },
45
+ "2y": { ms: 7776000000 * 8, sec: 7776000 * 8, min: 1051200, shorthand: "2y" },
46
+ "5y": { ms: 7776000000 * 20, sec: 7776000 * 20, min: 2628000, shorthand: "5y" },
47
+ };
48
+ exports.StationState = zod_1.z.object({
49
+ code: zod_1.z.string(),
50
+ label: zod_1.z.string(),
51
+ order: zod_1.z.number(),
52
+ color: zod_1.z.string(),
53
+ });
54
+ const StationStatus = {
55
+ outOfShift: { label: "Out of Shift", colour: (0, chroma_js_1.default)("#DDDDDD") },
56
+ futureOutOfShift: { label: "Out of Shift (Future)", colour: (0, chroma_js_1.default)("#DDDDDD").darken(2) },
57
+ futureInShift: { label: "In Shift (Future)", colour: (0, chroma_js_1.default)("#DDDDDD").darken(1) },
58
+ noSchedule: { label: "No Schedule", colour: (0, chroma_js_1.default)("#ee7733") },
59
+ futureNoSchedule: { label: "Not Scheduled (Future)", colour: (0, chroma_js_1.default)("#ee7733").darken(1) },
60
+ nonProductionSchedule: { label: "Scheduled Non-Production", colour: (0, chroma_js_1.default)("#33bbee") },
61
+ futureNonProductionSchedule: { label: "Scheduled Non-Production (Future)", colour: (0, chroma_js_1.default)("#33bbee").darken(1) },
62
+ productionSchedule: { label: "Scheduled Production", colour: (0, chroma_js_1.default)("#009988") },
63
+ futureProductionSchedule: { label: "Scheduled Production (Future)", colour: (0, chroma_js_1.default)("#009988").darken(1) },
64
+ downtime: { label: "Unplanned Downtime", colour: (0, chroma_js_1.default)("#cc3311") },
65
+ disconnected: { label: "Connection Lost", colour: (0, chroma_js_1.default)("#8338ec") },
66
+ };
67
+ exports.StationStatus = StationStatus;
68
+ var DowntimeType;
69
+ (function (DowntimeType) {
70
+ DowntimeType["Stop"] = "stop";
71
+ DowntimeType["Slow"] = "slow";
72
+ DowntimeType["Manual"] = "manual";
73
+ DowntimeType["StopUtilisation"] = "stop_utilisation";
74
+ DowntimeType["Unknown"] = "unknown";
75
+ })(DowntimeType || (exports.DowntimeType = DowntimeType = {}));
76
+ var DowntimeEventType;
77
+ (function (DowntimeEventType) {
78
+ DowntimeEventType["Acknowledge"] = "acknowledge";
79
+ DowntimeEventType["Estimate"] = "estimate";
80
+ DowntimeEventType["Escalate"] = "escalate";
81
+ DowntimeEventType["Cause"] = "cause";
82
+ DowntimeEventType["Exclude"] = "exclude";
83
+ })(DowntimeEventType || (exports.DowntimeEventType = DowntimeEventType = {}));
84
+ var DowntimeFilterState;
85
+ (function (DowntimeFilterState) {
86
+ DowntimeFilterState["Ongoing"] = "ongoing";
87
+ DowntimeFilterState["NotStartNotified"] = "not_start_notified";
88
+ DowntimeFilterState["NotEndNotified"] = "not_end_notified";
89
+ DowntimeFilterState["EscalatedOnly"] = "Escalated_only";
90
+ DowntimeFilterState["WithinADay"] = "day";
91
+ DowntimeFilterState["WithinAWeek"] = "week";
92
+ DowntimeFilterState["NoCause"] = "no_cause";
93
+ })(DowntimeFilterState || (exports.DowntimeFilterState = DowntimeFilterState = {}));
94
+ const GROUP_TAG_PREFIX = "group";
95
+ exports.GROUP_TAG_PREFIX = GROUP_TAG_PREFIX;
96
+ var MessageType;
97
+ (function (MessageType) {
98
+ MessageType["intouch"] = "intouch";
99
+ MessageType["kepware"] = "iotgateway";
100
+ MessageType["dau"] = "dau";
101
+ })(MessageType || (exports.MessageType = MessageType = {}));
102
+ var PRODUCTION_TYPE;
103
+ (function (PRODUCTION_TYPE) {
104
+ PRODUCTION_TYPE["MANUAL"] = "manual";
105
+ PRODUCTION_TYPE["TIMESERIES"] = "timeseries";
106
+ PRODUCTION_TYPE["FROM_SPEED"] = "from-speed";
107
+ })(PRODUCTION_TYPE || (exports.PRODUCTION_TYPE = PRODUCTION_TYPE = {}));
108
+ var SCHEDULE_TYPE;
109
+ (function (SCHEDULE_TYPE) {
110
+ SCHEDULE_TYPE["NON_PRODUCTION"] = "non_production";
111
+ SCHEDULE_TYPE["PRODUCTION"] = "production";
112
+ })(SCHEDULE_TYPE || (exports.SCHEDULE_TYPE = SCHEDULE_TYPE = {}));
113
+ var UserRole;
114
+ (function (UserRole) {
115
+ UserRole["customer"] = "customer";
116
+ UserRole["oi"] = "oi";
117
+ UserRole["blocked"] = "blocked";
118
+ UserRole["partner"] = "partner";
119
+ })(UserRole || (exports.UserRole = UserRole = {}));
120
+ var AccountRole;
121
+ (function (AccountRole) {
122
+ AccountRole["member"] = "member";
123
+ AccountRole["admin"] = "admin";
124
+ AccountRole["blocked"] = "blocked";
125
+ })(AccountRole || (exports.AccountRole = AccountRole = {}));
126
+ var AuthType;
127
+ (function (AuthType) {
128
+ AuthType["ui"] = "ui";
129
+ AuthType["api"] = "api";
130
+ })(AuthType || (exports.AuthType = AuthType = {}));
131
+ var WeekDay;
132
+ (function (WeekDay) {
133
+ WeekDay["Monday"] = "1";
134
+ WeekDay["Tuesday"] = "2";
135
+ WeekDay["Wednesday"] = "3";
136
+ WeekDay["Thursday"] = "4";
137
+ WeekDay["Friday"] = "5";
138
+ WeekDay["Saturday"] = "6";
139
+ WeekDay["Sunday"] = "7";
140
+ })(WeekDay || (exports.WeekDay = WeekDay = {}));
141
+ var NOTIFICATION_PREFERENCE;
142
+ (function (NOTIFICATION_PREFERENCE) {
143
+ NOTIFICATION_PREFERENCE["NONE"] = "none";
144
+ NOTIFICATION_PREFERENCE["ALL"] = "all_issues";
145
+ NOTIFICATION_PREFERENCE["DOWNTIME_SUMMARY"] = "downtime_summary";
146
+ })(NOTIFICATION_PREFERENCE || (exports.NOTIFICATION_PREFERENCE = NOTIFICATION_PREFERENCE = {}));
147
+ var DOWNTIME_DETECTION_MODE;
148
+ (function (DOWNTIME_DETECTION_MODE) {
149
+ DOWNTIME_DETECTION_MODE["OFF"] = "off";
150
+ DOWNTIME_DETECTION_MODE["PRODUCTION_CYCLE_TIME"] = "production";
151
+ DOWNTIME_DETECTION_MODE["UTILISATION"] = "utilisation";
152
+ DOWNTIME_DETECTION_MODE["LINE_SPEED"] = "line_speed";
153
+ })(DOWNTIME_DETECTION_MODE || (exports.DOWNTIME_DETECTION_MODE = DOWNTIME_DETECTION_MODE = {}));
154
+ var PRODUCTIVE_STATUS_MODE;
155
+ (function (PRODUCTIVE_STATUS_MODE) {
156
+ PRODUCTIVE_STATUS_MODE["PRODUCTIVE_SIGNAL"] = "productive_signal";
157
+ PRODUCTIVE_STATUS_MODE["ELECTRICAL_USAGE"] = "electrical_usage";
158
+ PRODUCTIVE_STATUS_MODE["LINE_SPEED"] = "line_speed";
159
+ })(PRODUCTIVE_STATUS_MODE || (exports.PRODUCTIVE_STATUS_MODE = PRODUCTIVE_STATUS_MODE = {}));
160
+ var TIMESERIES_MESSAGE_TYPE;
161
+ (function (TIMESERIES_MESSAGE_TYPE) {
162
+ TIMESERIES_MESSAGE_TYPE["BAD_PRODUCTION_COMPLETE"] = "BAD_PRODUCTION_COMPLETE";
163
+ TIMESERIES_MESSAGE_TYPE["BAD_PRODUCTION_COUNT"] = "BAD_PRODUCTION_COUNT";
164
+ TIMESERIES_MESSAGE_TYPE["PRODUCTION_COMPLETE"] = "PRODUCTION_COMPLETE";
165
+ TIMESERIES_MESSAGE_TYPE["PRODUCTION_COUNT"] = "PRODUCTION_COUNT";
166
+ TIMESERIES_MESSAGE_TYPE["PRODUCTIVE"] = "PRODUCTIVE";
167
+ TIMESERIES_MESSAGE_TYPE["LINE_SPEED"] = "LINE_SPEED";
168
+ TIMESERIES_MESSAGE_TYPE["SPEED"] = "SPEED";
169
+ TIMESERIES_MESSAGE_TYPE["ELECTRICAL_KWH"] = "ELECTRICAL_KWH";
170
+ TIMESERIES_MESSAGE_TYPE["ELECTRICAL_KWH_INTERVAL"] = "ELECTRICAL_KWH_INTERVAL";
171
+ TIMESERIES_MESSAGE_TYPE["ELECTRICAL_A"] = "ELECTRICAL_A";
172
+ TIMESERIES_MESSAGE_TYPE["ELECTRICAL_V"] = "ELECTRICAL_V";
173
+ TIMESERIES_MESSAGE_TYPE["ELECTRICAL_HZ"] = "ELECTRICAL_HZ";
174
+ TIMESERIES_MESSAGE_TYPE["ELECTRICAL_KW"] = "ELECTRICAL_KW";
175
+ TIMESERIES_MESSAGE_TYPE["ELECTRICAL_PF"] = "ELECTRICAL_PF";
176
+ TIMESERIES_MESSAGE_TYPE["STATUS_CODE"] = "STATUS_CODE";
177
+ TIMESERIES_MESSAGE_TYPE["RSSI"] = "RSSI";
178
+ })(TIMESERIES_MESSAGE_TYPE || (exports.TIMESERIES_MESSAGE_TYPE = TIMESERIES_MESSAGE_TYPE = {}));
179
+ var CursorType;
180
+ (function (CursorType) {
181
+ CursorType["production"] = "production";
182
+ CursorType["stops"] = "stops";
183
+ CursorType["slowLineSpeed"] = "slow_line_speed";
184
+ CursorType["lastStatusCode"] = "last_status_code";
185
+ CursorType["stationWindows"] = "station_windows";
186
+ })(CursorType || (exports.CursorType = CursorType = {}));
187
+ var ALERT_ISSUE_TYPE;
188
+ (function (ALERT_ISSUE_TYPE) {
189
+ ALERT_ISSUE_TYPE["STOP"] = "stop";
190
+ ALERT_ISSUE_TYPE["RESOLVED"] = "resolved";
191
+ ALERT_ISSUE_TYPE["ESCALATED"] = "escalated";
192
+ })(ALERT_ISSUE_TYPE || (exports.ALERT_ISSUE_TYPE = ALERT_ISSUE_TYPE = {}));
193
+ var STATION_MODULE_VISIBILITY;
194
+ (function (STATION_MODULE_VISIBILITY) {
195
+ STATION_MODULE_VISIBILITY["UTILISATION"] = "utilisation";
196
+ STATION_MODULE_VISIBILITY["ELECTRICAL"] = "electrical";
197
+ STATION_MODULE_VISIBILITY["LINE_SPEED"] = "line_speed";
198
+ })(STATION_MODULE_VISIBILITY || (exports.STATION_MODULE_VISIBILITY = STATION_MODULE_VISIBILITY = {}));
199
+ var EMAIL_HARNESS_TYPE;
200
+ (function (EMAIL_HARNESS_TYPE) {
201
+ EMAIL_HARNESS_TYPE["LOGIN"] = "login";
202
+ EMAIL_HARNESS_TYPE["DOWNTIME_DETECTION"] = "downtime_detection";
203
+ EMAIL_HARNESS_TYPE["DAILY_SUMMARY"] = "daily_summary";
204
+ EMAIL_HARNESS_TYPE["DAILY_SUMMARY_REAL_ACCOUNT"] = "daily_summary_real_account";
205
+ })(EMAIL_HARNESS_TYPE || (exports.EMAIL_HARNESS_TYPE = EMAIL_HARNESS_TYPE = {}));
206
+ const PERFORMANCE_MODE_TYPE = {
207
+ cycleTime: "cycle-time",
208
+ unitsPerMinute: "units-per-minute",
209
+ unitsPerHour: "units-per-hour",
210
+ lineSpeed: "line-speed",
211
+ none: "none",
212
+ };
213
+ exports.PERFORMANCE_MODE_TYPE = PERFORMANCE_MODE_TYPE;
214
+ const REASON_TYPE = {
215
+ downtime: "downtime",
216
+ non_production: "non-production",
217
+ };
218
+ exports.REASON_TYPE = REASON_TYPE;
219
+ const MqttEventType = {
220
+ StationMetricNew: "STATION_METRIC_NEW", // When a new station window is created and saved to DB.
221
+ StationChanged: "STATION_CHANGED", // When a station is added or edited. NOT IMPLEMENTED.
222
+ ScheduleChanged: "SCHEDULE_CHANGED", // When a schedule is added or edited. NOT IMPLEMENTED.
223
+ ScheduleStarted: "SCHEDULE_STARTED", // When a schedule starts (actualStartAt). NOT IMPLEMENTED.
224
+ ScheduleEnded: "SCHEDULE_ENDED", // When a schedule ends (actualEndAt). NOT IMPLEMENTED.
225
+ ProductionNew: "PRODUCTION_NEW", // When new production is added. NOT IMPLEMENTED FOR MANUAL PRODUCTION YET.
226
+ };
227
+ exports.MqttEventType = MqttEventType;
228
+ const StationSchema = zod_1.z.object({
229
+ // Basics
230
+ accountId: zod_1.z.string(),
231
+ code: zod_1.z.string().describe("Code: Assign a Code to the Station, this cannot be changed once set."),
232
+ name: zod_1.z.string().trim().min(1).max(32).describe("Name: Assign a Name to the Station."),
233
+ description: zod_1.z.string().nullish(),
234
+ groupCode: zod_1.z.string().describe("Group: Assign the station to a group of stations."),
235
+ shiftPatternId: zod_1.z.number().int().positive().nullish().describe("Shift Pattern: Select which Shift Pattern the station will follow."),
236
+ moduleVisibility: zod_1.z.array(zod_1.z.nativeEnum(STATION_MODULE_VISIBILITY)).nullish(),
237
+ minimumCycleTime: zod_1.z
238
+ .number()
239
+ .int()
240
+ .gte(0)
241
+ .lte(exports.TimeIntervals["12h"].ms)
242
+ .nullish()
243
+ .describe("Minimum Cycle Time (secs): Set a minimum cycle-time for the station. If more than one signal is received in this period, Busroot will only count one unit. This allows filtering of signals during setup process for example."),
244
+ speedScale: zod_1.z
245
+ .number()
246
+ .gte(-9999)
247
+ .lte(9999)
248
+ .nullish()
249
+ .describe("Speed scale: If the value on the Performance Chart doesn't reflect actual running speed, it can be calibrated by setting this value. For example current value = 20, but actual speed = 10, scale should be set to 0.5."),
250
+ speedOffset: zod_1.z
251
+ .number()
252
+ .gte(-9999)
253
+ .lte(9999)
254
+ .nullish()
255
+ .describe("Speed offset: This can be set to fine tune a Speed value. For example if a Stations speed is showing as 0.5 when stopped, set the value to -0.5."),
256
+ speedToProductionRatio: zod_1.z
257
+ .number()
258
+ .gte(0)
259
+ .lte(99999)
260
+ .nullish()
261
+ .describe("Speed to Production Ratio: A speed value can be converted into a production count. Set the conversion ratio, this can be a decimal if required. (if left blank no production units will be counted)"),
262
+ electricalPowerNominalKw: zod_1.z
263
+ .number()
264
+ .gte(0)
265
+ .nullish()
266
+ .describe("Electrical Power Nominal (kW): The expected power usage in kW during normal operation."),
267
+ // Defaults
268
+ idleCostPerMinute: zod_1.z
269
+ .number()
270
+ .gte(0)
271
+ .lte(99999)
272
+ .nullish()
273
+ .describe("Idle Cost (£/min): Assign a cost per minute for any idle time. This will be used for scheduling losses, planned non-production losses and downtime losses where the SKU does not have a value set."),
274
+ // Downtime Settings
275
+ downtimeDetectionMode: zod_1.z
276
+ .nativeEnum(DOWNTIME_DETECTION_MODE)
277
+ .default(DOWNTIME_DETECTION_MODE.UTILISATION)
278
+ .describe("Downtime Detection Mode: Busroot will report downtime for a station using either Utilisation, Production Cycle data or Line Speed Monitoring. (relevant signals must be connected)"),
279
+ utilisationDowntimeThreshold: zod_1.z
280
+ .preprocess((val) => (val === null ? exports.TimeIntervals["1h"].ms : val), zod_1.z.number().int().gte(0).optional())
281
+ .describe("Utilisation Downtime Threshold (mins): This controls the minimum period before Busroot will register downtime. ie. with a threshold of 10mins, only stops of 10 mins or longer will be recorded."),
282
+ slowDurationThreshold: zod_1.z.number().int().gte(0).nullish(),
283
+ forceAllShiftTimeAsPlannedProduction: zod_1.z.boolean().nullish(),
284
+ // Productive Settings
285
+ productiveStatusMode: zod_1.z
286
+ .nativeEnum(PRODUCTIVE_STATUS_MODE)
287
+ .default(PRODUCTIVE_STATUS_MODE.PRODUCTIVE_SIGNAL)
288
+ .optional()
289
+ .describe("Productive Status Mode: Select one of the following to measure when the station is engaged in a value-adding-activity."),
290
+ electricalUsageStoppedThresholdKw: zod_1.z
291
+ .number()
292
+ .gte(0)
293
+ .nullish()
294
+ .describe("Stopped Threshold (kW): Set the minimum kW consumption that indicates the station active, below this Busroot will regard as downtime."),
295
+ lineSpeedStoppedThreshold: zod_1.z
296
+ .number()
297
+ .gte(0)
298
+ .nullish()
299
+ .describe("Line Speed Stopped Threshold: Set the minimum speed that the indicates the station is running, below this Busroot will regard as downtime."),
300
+ productiveHoldOnTime: zod_1.z
301
+ .number()
302
+ .int()
303
+ .gte(0)
304
+ .lte(exports.TimeIntervals["1d"].ms)
305
+ .nullish()
306
+ .describe("Productive Hold on Time (mins): This controls the length of time a station is considered active after a productive signal. Each time a new signal is received the hold on time will restart."),
307
+ // Flags
308
+ allowInterruptionMode: zod_1.z
309
+ .boolean()
310
+ .default(false)
311
+ .optional()
312
+ .describe("Allow Interruption Mode: Enable the Interruption tool. The tool provides an intuitive way to capture downtime from human-lead manufacturing processes where digital data capture is impossible."),
313
+ allowManualProduction: zod_1.z
314
+ .boolean()
315
+ .default(false)
316
+ .optional()
317
+ .describe("Allow Manual Production: This enables the production entry module on the tablet, allowing operators to count production manually."),
318
+ allowQuickScheduleStart: zod_1.z
319
+ .boolean()
320
+ .default(false)
321
+ .optional()
322
+ .describe("Allow Ad Hoc Schedules: This allows operators with tablets to start new schedules directly from the tablet."),
323
+ allowScheduleCutShort: zod_1.z
324
+ .boolean()
325
+ .default(false)
326
+ .optional()
327
+ .describe("Allow Schedule Cut Short: This enables a button in Schedule Management, to allow a schedule to be ended early. The remaining quantity will be added to a new schedule with the same Work Order Ref."),
328
+ // Current State
329
+ currentOperatorInitials: zod_1.z.string().min(3).max(3).nullish(),
330
+ statusCode: zod_1.z.string().nullish(),
331
+ statusCodeUpdatedAt: zod_1.z.string().nullish(),
332
+ // Performance Mode
333
+ cycleTime: zod_1.z
334
+ .number()
335
+ .int()
336
+ .gt(0)
337
+ .lte(exports.TimeIntervals["12h"].ms)
338
+ .nullish()
339
+ .describe("Cycle Time (secs): Set a standard cycle-time for the station."),
340
+ unitsPerMinute: zod_1.z.number().int().gt(0).nullish().describe("Units Per Minute: Set the expected production rate in units/min."),
341
+ unitsPerHour: zod_1.z.number().int().gt(0).nullish().describe("Units Per Hour: Set the expected production rate in units/hr."),
342
+ lineSpeedTarget: zod_1.z.number().gt(0).lte(99999).nullish().describe("Line Speed Target: Set a target speed for the station."),
343
+ // System info
344
+ createdAt: zod_1.z.string().nullish(),
345
+ updatedAt: zod_1.z.string().nullish(),
346
+ archivedAt: zod_1.z.string().nullish(),
347
+ });
348
+ exports.StationSchema = StationSchema;
349
+ const AccountSchema = zod_1.z.object({
350
+ id: zod_1.z.string(),
351
+ domain: zod_1.z.string(),
352
+ stationCountLimit: zod_1.z.number().nullish(),
353
+ electricalPricePerKwh: zod_1.z.number().nullish(),
354
+ electricalCo2PerKwh: zod_1.z.number().nullish(),
355
+ currency: zod_1.z.string().nullish(),
356
+ enableLostProductionCost: zod_1.z.boolean().nullish(),
357
+ dashboardConfig: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).nullish(),
358
+ redshiftPassword: zod_1.z.string().nullish(),
359
+ uploadTransforms: zod_1.z.string().nullish(),
360
+ defaultAutoEndOnQuantityComplete: zod_1.z.boolean().nullish(),
361
+ appUrls: zod_1.z.string().nullish(),
362
+ createdAt: zod_1.z.string().nullish(),
363
+ updatedAt: zod_1.z.string().nullish(),
364
+ });
365
+ exports.AccountSchema = AccountSchema;
366
+ // OEE Availability = (scheduledProductionMs - downtimeMs) / scheduledProductionMs
367
+ // OEE Performance = (productionTargetCount - (productionTargetCount - (productionGoodCount + productionBadCount)) / productionTargetCount
368
+ // OEE Quality = (productionGoodCount - productionBadCount) / productionGoodCount
369
+ const StationWindowSchema = zod_1.z.object({
370
+ accountId: zod_1.z.string().describe(""),
371
+ stationCode: zod_1.z.string().describe("A code that uniquely identifies this station within this account."),
372
+ windowStartAt: zod_1.z.string().describe("The start time of this window in ISO 8601 format."),
373
+ windowEndAt: zod_1.z.string().describe("The end time of this window in ISO 8601 format."),
374
+ totalMs: zod_1.z.number().describe("The total number milliseconds covered by this window. Shortcut for windowEndAt - windowStartAt."),
375
+ shiftMs: zod_1.z.number().describe("The number of milliseconds that were in shift.").optional(),
376
+ shiftName: zod_1.z.string().describe("The name of the shift at this time.").optional(),
377
+ scheduledProductionMs: zod_1.z.number().describe("The number of milliseconds that were scheduled production.").optional(),
378
+ scheduledNonProductionMs: zod_1.z.number().describe("The number of milliseconds that were scheduled non-production.").optional(),
379
+ productiveMs: zod_1.z.number().describe("The number of milliseconds that the station was in a productive state.").optional(),
380
+ downtimeId: zod_1.z.number().describe("The ID of the current downtime.").optional(),
381
+ downtimeMs: zod_1.z.number().describe("The number of milliseconds that the station was in downtime.").optional(),
382
+ downtimeReasonCode: zod_1.z.string().describe("The reason code assigned to the current downtime.").optional(),
383
+ downtimeSince: zod_1.z.string().describe("The time this downtime started, in ISO 8601 format.").optional(),
384
+ rssiAvg: zod_1.z
385
+ .number()
386
+ .optional()
387
+ .describe("The received signal strength of the wireless device. -70dBm to -80dBm is good. <-90dBm is bad.")
388
+ .optional(),
389
+ productionGoodCount: zod_1.z.number().describe("The number of good quality units produced.").optional(),
390
+ productionBadCount: zod_1.z.number().describe("The number of bad quality units produced.").optional(),
391
+ productionIdealCount: zod_1.z
392
+ .number()
393
+ .optional()
394
+ .describe("The number of production units that should have been produced according to the SKU/part's cycle-time. WITH consideration for downtime.")
395
+ .optional(),
396
+ productionTargetCount: zod_1.z
397
+ .number()
398
+ .describe("The number of production units that should have been produced according to the SKU/part's cycle-time. WITHOUT consideration for downtime.")
399
+ .optional(),
400
+ speed: zod_1.z
401
+ .number()
402
+ .describe("The average line speed. Line speed is an arbitrary value that relates to this station's manufacturing process. i.e. Motor RPM.")
403
+ .optional(),
404
+ errorCode: zod_1.z.string().describe("The error code that was flagged.").optional(),
405
+ scheduleId: zod_1.z.number().describe("The ID of the current schedule.").optional(),
406
+ skuCode: zod_1.z.string().describe("The SKU code taken from the current schedule.").optional(),
407
+ isAlive: zod_1.z
408
+ .boolean()
409
+ .describe("A boolean value indicating if any signal was recieved from this station. Useful for detemining if the device has been disconnected from the network.")
410
+ .optional(),
411
+ electricalVoltsAvg: zod_1.z.number().describe("The average voltage of the electrical supply.").optional(),
412
+ electricalAmpsAvg: zod_1.z.number().describe("The average current draw.").optional(),
413
+ electricalHzAvg: zod_1.z.number().describe("The average frequency of the electrical supply.").optional(),
414
+ electricalPfAvg: zod_1.z.number().describe("The average Power Factor.").optional(),
415
+ electricalKwAvg: zod_1.z.number().describe("The average power used.").optional(),
416
+ electricalKwh: zod_1.z.number().describe("The total energy consumed.").optional(),
417
+ statusCode: zod_1.z.string().describe("").optional(),
418
+ nonProductionReasonCode: zod_1.z.string().describe("The non-production reason code for the current schedule.").optional(),
419
+ skuGroupCode: zod_1.z.string().describe("").optional(),
420
+ electricalCost: zod_1.z.number().describe("The cost of the electricity used.").optional(),
421
+ costCurrency: zod_1.z.string().describe("The currency of any costs.").optional(),
422
+ electricalCo2: zod_1.z.number().describe("The amount of CO2 associated with the electricity used.").optional(),
423
+ workOrderReference: zod_1.z.string().describe("The work order reference of the current schedule.").optional(),
424
+ lostProductionCostNonProduction: zod_1.z.number().describe("The cost of the time lost to scheduled non-production.").optional(),
425
+ lostProductionCostDowntime: zod_1.z.number().describe("The cost of the time lost to downtime.").optional(),
426
+ lostProductionCostSpeed: zod_1.z.number().describe("The cost of the shortfall units lost due to under performance.").optional(),
427
+ lostProductionCostQuality: zod_1.z.number().describe("The cost of the bad quality units produced.").optional(),
428
+ // Performance Mode
429
+ performanceModeFrom: zod_1.z.string().describe("").optional(),
430
+ performanceModeType: zod_1.z.string().describe("").optional(),
431
+ productionGoodValue: zod_1.z.number().describe("The value of the good quality units produced.").optional(),
432
+ productionBadValue: zod_1.z.number().describe("The value of the bad quality units produced.").optional(),
433
+ createdAt: zod_1.z.string().describe("").optional(),
434
+ updatedAt: zod_1.z.string().describe("").optional(),
435
+ });
436
+ exports.StationWindowSchema = StationWindowSchema;
437
+ const ApiKeySchema = zod_1.z.object({
438
+ accountId: zod_1.z.string(),
439
+ key: zod_1.z.string(),
440
+ createdByUserId: zod_1.z.number(),
441
+ expiresAt: zod_1.z.string(),
442
+ createdAt: zod_1.z.string().optional(),
443
+ updatedAt: zod_1.z.string().optional(),
444
+ });
445
+ const AccountViewModel = AccountSchema.merge(zod_1.z.object({
446
+ plants: zod_1.z.array(zod_1.z.any()), // TODO: Add ZodSchema for PlantSchema
447
+ cursors: zod_1.z
448
+ .array(zod_1.z.object({
449
+ type: zod_1.z.string(),
450
+ timestamp: zod_1.z.number(),
451
+ value: zod_1.z.string(),
452
+ valueAgo: zod_1.z.string(),
453
+ }))
454
+ .optional(),
455
+ redshiftConfig: zod_1.z
456
+ .object({
457
+ host: zod_1.z.string(),
458
+ port: zod_1.z.number(),
459
+ username: zod_1.z.string(),
460
+ })
461
+ .optional(),
462
+ }));
463
+ exports.AccountViewModel = AccountViewModel;
464
+ exports.StationGroupSchema = zod_1.z.object({
465
+ code: zod_1.z.string(),
466
+ name: zod_1.z.string(),
467
+ plantCode: zod_1.z.string(),
468
+ accountId: zod_1.z.string(),
469
+ allowScheduleStationFlexibility: zod_1.z.boolean(),
470
+ shiftPatternId: zod_1.z.number().optional(),
471
+ allowQuickScheduleStart: zod_1.z.boolean().optional(),
472
+ createdAt: zod_1.z.string().optional(),
473
+ updatedAt: zod_1.z.string().optional(),
474
+ });
475
+ const PlantViewModel = zod_1.z.object({
476
+ code: zod_1.z.string(),
477
+ name: zod_1.z.string(),
478
+ timezone: zod_1.z.string(),
479
+ now: zod_1.z.string(),
480
+ stationGroups: zod_1.z.array(exports.StationGroupSchema.omit({ accountId: true })),
481
+ dayStartHour: zod_1.z.number(),
482
+ });
483
+ exports.PlantViewModel = PlantViewModel;
484
+ const SkuViewModel = zod_1.z.object({
485
+ code: zod_1.z.string(),
486
+ name: zod_1.z.string(),
487
+ cycleTime: zod_1.z.number().nullish(),
488
+ specifications: zod_1.z.object({ name: zod_1.z.string(), value: zod_1.z.string() }).array().nullish(),
489
+ instructionsUrl: zod_1.z.string().nullish(),
490
+ lineSpeedTarget: zod_1.z.number().nullish(),
491
+ downtimeDurationThresholdMultiplier: zod_1.z.number().nullish(),
492
+ allowUseInQuickSchedule: zod_1.z.boolean().nullish(),
493
+ unitsPerMinute: zod_1.z.number().nullish(),
494
+ unitsPerHour: zod_1.z.number().nullish(),
495
+ batchSize: zod_1.z.number().nullish(),
496
+ value: zod_1.z.number().nullish(),
497
+ minimumCycleTime: zod_1.z.number().nullish(),
498
+ stationCodes: zod_1.z.array(zod_1.z.string()).nullish(),
499
+ stationGroupCodes: zod_1.z.array(zod_1.z.string()).nullish(),
500
+ });
501
+ exports.SkuViewModel = SkuViewModel;
502
+ exports.OeeStop = zod_1.z.object({
503
+ code: zod_1.z.string(),
504
+ description: zod_1.z.string(),
505
+ duration: zod_1.z.number(),
506
+ cost: zod_1.z.number(),
507
+ percent: zod_1.z.number(),
508
+ energy: zod_1.z.number(),
509
+ energyCost: zod_1.z.number(),
510
+ productionQuantity: zod_1.z.number(),
511
+ });
512
+ const OeeViewModel = zod_1.z.object({
513
+ scheduleMs: zod_1.z.number().describe("The number of milliseconds spent on any schedule."), // production and non-production scheduled time combined.
514
+ scheduleLossMs: zod_1.z.number().describe("The number of milliseconds lost to unscheduled time in shift."), // The amount of in shift time not schedule in either way.
515
+ schedulePerc: zod_1.z.number().describe("The ratio of scheduled to unscheduled time."),
516
+ productionScheduleMs: zod_1.z.number().describe("The number of milliseconds spent in a production schedule."), // In simplified OEE, this is shift time minus scheduled non-production time. In full OEE, this would be only scheduled production time.
517
+ productionScheduleLossMs: zod_1.z.number().describe("The number of milliseconds lost to non-production schedules."),
518
+ productionSchedulePerc: zod_1.z.number().describe("The ratio of production to non-production scheduled time."),
519
+ availabilityMs: zod_1.z.number().describe("The number of milliseconds spent running."), // The planned production time minus stop time.
520
+ availabilityLossMs: zod_1.z.number().describe("The number of milliseconds spend stopped."), // The amount of time the station is stopped during planned production time ()
521
+ availabilityPerc: zod_1.z.number().describe("The ratio of running to stopped time aka OEE Availability."),
522
+ performanceMs: zod_1.z
523
+ .number()
524
+ .describe("The number of milliseconds spend producing under ideal circumstances (production count * ideal cycle time)."),
525
+ performanceLossMs: zod_1.z.number().describe("The number of milliseconds lost to under-production vs ideal cycle times."),
526
+ performancePerc: zod_1.z.number().describe("OEE Performance."),
527
+ goodQualityCount: zod_1.z.number().describe("The number of good quality units produced."),
528
+ goodQualityLossCount: zod_1.z.number().describe("The number of bad quality units produced."),
529
+ goodQualityPerc: zod_1.z.number().describe("The ratio of good units to bad units aka OEE Quality."),
530
+ scheduledNonProduction: zod_1.z.array(exports.OeeStop),
531
+ stops: zod_1.z.array(exports.OeeStop),
532
+ oee: zod_1.z.number(),
533
+ });
534
+ exports.OeeViewModel = OeeViewModel;
535
+ const ScheduleViewModel = zod_1.z.object({
536
+ id: zod_1.z.number(),
537
+ stationCode: zod_1.z.string(),
538
+ stationName: zod_1.z.string().optional(),
539
+ accountId: zod_1.z.string(),
540
+ plannedStartAt: zod_1.z.string(),
541
+ plannedStartAtTimestamp: zod_1.z.number(),
542
+ plannedEndAt: zod_1.z.string().optional(),
543
+ plannedEndAtTimestamp: zod_1.z.number().optional(),
544
+ workOrderReference: zod_1.z.string().optional(),
545
+ plannedDuration: zod_1.z.number().optional(),
546
+ plannedQuantity: zod_1.z.number().optional(),
547
+ nonProductionReasonCode: zod_1.z.string().optional(),
548
+ nonProductionReasonDescription: zod_1.z.string().optional(),
549
+ skuCode: zod_1.z.string().optional(),
550
+ skuName: zod_1.z.string().optional(),
551
+ skuValue: zod_1.z.number().optional(),
552
+ batchSize: zod_1.z.number().optional(),
553
+ autoEndOnQuantityComplete: zod_1.z.boolean().optional(),
554
+ cycleTime: zod_1.z.number().optional(),
555
+ unitsPerMinute: zod_1.z.number().optional(),
556
+ unitsPerHour: zod_1.z.number().optional(),
557
+ lineSpeedTarget: zod_1.z.number().optional(),
558
+ effectiveCycleTime: zod_1.z.number().optional(),
559
+ effectiveUnitsPerMinute: zod_1.z.number().optional(),
560
+ effectiveUnitsPerHour: zod_1.z.number().optional(),
561
+ effectiveLineSpeedTarget: zod_1.z.number().optional(),
562
+ normalisedCycleTime: zod_1.z
563
+ .number()
564
+ .optional()
565
+ .describe("The effective performance mode, convered back into a cycle time (aka the time in millis required to make 1 unit."),
566
+ effectiveBatchSize: zod_1.z.number().optional(),
567
+ effectiveMinimumCycleTime: zod_1.z.number().optional(),
568
+ remainingTime: zod_1.z.number().optional(),
569
+ quantityIdeal: zod_1.z.number().optional(),
570
+ quantityIdealDelta: zod_1.z.number().optional(),
571
+ deletedAt: zod_1.z.string().optional(),
572
+ actualStartAt: zod_1.z.string().optional(),
573
+ actualStartAtTimestamp: zod_1.z.number().optional(),
574
+ actualEndAt: zod_1.z.string().optional(),
575
+ actualEndAtTimestamp: zod_1.z.number().optional(),
576
+ idealEndAt: zod_1.z
577
+ .string()
578
+ .optional()
579
+ .describe("The date and time, in ISO format, this schedule should end at according to the start time, cycle time of the SKU and the planned quantity."),
580
+ idealEndAtTimestamp: zod_1.z
581
+ .number()
582
+ .optional()
583
+ .describe("The timestamp this schedule should end at according to the start time, cycle time of the SKU and the planned quantity."),
584
+ idealDurationMs: zod_1.z
585
+ .number()
586
+ .optional()
587
+ .describe("The duration in millis this schedule should take according to the cycle time of the SKU and the planned quantity."),
588
+ quantityGood: zod_1.z.number().optional(),
589
+ quantityBad: zod_1.z.number().optional(),
590
+ quantityTotal: zod_1.z.number().optional(),
591
+ skuGroupCode: zod_1.z.string().optional(),
592
+ skuGroupName: zod_1.z.string().optional(),
593
+ extendShift: zod_1.z.boolean().optional(),
594
+ downtimeDurationThresholdMultiplier: zod_1.z.number().optional(),
595
+ isStarted: zod_1.z.boolean(),
596
+ isEnded: zod_1.z.boolean(),
597
+ status: zod_1.z.enum(["running", "planned", "deleted", "completed"]),
598
+ allowScheduleCutShort: zod_1.z.boolean().optional(),
599
+ performanceModeFrom: zod_1.z.enum(["schedule", "sku", "station", "none"]).optional(),
600
+ logs: zod_1.z.array(zod_1.z.string()).optional(),
601
+ priorityAt: zod_1.z.string().optional(),
602
+ });
603
+ exports.ScheduleViewModel = ScheduleViewModel;
604
+ const StationWindowViewModel = StationWindowSchema.omit({
605
+ skuCode: true,
606
+ skuGroupCode: true,
607
+ nonProductionReasonCode: true,
608
+ downtimeReasonCode: true,
609
+ downtimeId: true,
610
+ errorCode: true,
611
+ scheduleId: true,
612
+ workOrderReference: true,
613
+ shiftName: true,
614
+ })
615
+ .required({ isAlive: true })
616
+ .merge(zod_1.z.object({
617
+ stationName: zod_1.z.string().describe("The name of the station."),
618
+ scheduleIds: zod_1.z.array(zod_1.z.number()).describe("The IDs of the schedules that ran.").optional(),
619
+ workOrderReferences: zod_1.z.array(zod_1.z.string()).describe("The WO refs of the schedules that ran.").optional(),
620
+ errorCodes: zod_1.z.array(zod_1.z.string()).describe("The error codes that were flagged.").optional(),
621
+ downtimeIds: zod_1.z.array(zod_1.z.number()).describe("The IDs of the downtimes that occured.").optional(),
622
+ downtimeReasonCodes: zod_1.z.array(zod_1.z.string()).describe("The reason codes of the downtimes that occured.").optional(),
623
+ nonProductionReasonCodes: zod_1.z
624
+ .array(zod_1.z.string())
625
+ .optional()
626
+ .describe("The reason codes for the non-production schedules that ran.")
627
+ .optional(),
628
+ windowStartAtTimestamp: zod_1.z.number().describe("The start time of this window as a UNIX timestamp."),
629
+ windowEndAtTimestamp: zod_1.z.number().describe("The end time of this window as a UNIX timestamp."),
630
+ isFuture: zod_1.z.boolean().describe("A boolean value indicating if this is a placeholder station window for future time.").optional(),
631
+ skuNames: zod_1.z.array(zod_1.z.string().describe("The name of the SKUs from the current schedule.")).optional(),
632
+ skuCodes: zod_1.z.array(zod_1.z.string()).describe("The code of the SKUs from the schedules that ran.").optional(),
633
+ shiftNames: zod_1.z.array(zod_1.z.string()).describe("The shift names during this time.").optional(),
634
+ skuGroupCodes: zod_1.z.array(zod_1.z.string()).describe("The code of the SKU Groups from the schedules that ran.").optional(),
635
+ lostProductionCostTotal: zod_1.z.number().describe("The total cost of lost production output.").optional(),
636
+ productionTotalCount: zod_1.z.number().describe("The total number of units produced, both good and bad.").optional(),
637
+ productionRatePerHour: zod_1.z.number().describe("The average rate of production in units per hour.").optional(),
638
+ productionRatePerHourIdeal: zod_1.z.number().describe("The ideal rate of production in units per hour.").optional(),
639
+ productionMs: zod_1.z
640
+ .number()
641
+ .describe("The number of milliseconds of actual production achieved (production count * ideal cycle time).")
642
+ .optional(),
643
+ }));
644
+ exports.StationWindowViewModel = StationWindowViewModel;
645
+ exports.ShiftSchema = zod_1.z.object({
646
+ id: zod_1.z.number(),
647
+ name: zod_1.z.string(),
648
+ startHour: zod_1.z.number(),
649
+ duration: zod_1.z.number(),
650
+ accountId: zod_1.z.string(),
651
+ shiftPatternId: zod_1.z.number(),
652
+ weekDay: zod_1.z.string(),
653
+ });
654
+ exports.ShiftPatternSchema = zod_1.z.object({
655
+ accountId: zod_1.z.string(),
656
+ title: zod_1.z.string(),
657
+ id: zod_1.z.number(),
658
+ createdAt: zod_1.z.string().optional(),
659
+ updatedAt: zod_1.z.string().optional(),
660
+ });
661
+ exports.ShiftViewModel = zod_1.z.object({
662
+ shiftId: zod_1.z.number(),
663
+ startHour: zod_1.z.number(),
664
+ duration: zod_1.z.number(),
665
+ shiftName: zod_1.z.string().optional(),
666
+ shiftPatternId: zod_1.z.number(),
667
+ weekDay: zod_1.z.string(),
668
+ });
669
+ exports.ShiftPatternViewModel = exports.ShiftPatternSchema.merge(zod_1.z.object({
670
+ code: zod_1.z.string(),
671
+ duration: zod_1.z.number(),
672
+ startHour: zod_1.z.number(),
673
+ endHour: zod_1.z.number(),
674
+ title: zod_1.z.string(),
675
+ shifts: zod_1.z.array(exports.ShiftViewModel),
676
+ }));
677
+ const StationViewModel = zod_1.z.object({
678
+ code: zod_1.z.string(), // from station table
679
+ name: zod_1.z.string(), // from station table
680
+ description: zod_1.z.string().nullish(),
681
+ groupCode: zod_1.z.string().nullish(), // from station table
682
+ groupName: zod_1.z.string().nullish(), // from join with group table
683
+ allowScheduleStationFlexibility: zod_1.z.boolean().nullish(), // from join with group table
684
+ plantCode: zod_1.z.string(), // from station table
685
+ timezone: zod_1.z.string(), // from join with plant table
686
+ accountId: zod_1.z.string(), // from station table
687
+ currentOperatorInitials: zod_1.z.string().nullish(), // from station table
688
+ cycleTime: zod_1.z.number().nullish(), // from station table
689
+ unitsPerMinute: zod_1.z.number().nullish(),
690
+ unitsPerHour: zod_1.z.number().nullish(),
691
+ lineSpeedTarget: zod_1.z.number().nullish(), // from station table
692
+ allowInterruptionMode: zod_1.z.boolean().nullish(),
693
+ allowManualProduction: zod_1.z.boolean().nullish(),
694
+ downtimeDetectionMode: zod_1.z.nativeEnum(DOWNTIME_DETECTION_MODE), // from station table
695
+ utilisationDowntimeThreshold: zod_1.z.number().nullish(), // from station table
696
+ slowDurationThreshold: zod_1.z.number().nullish(), // from station table
697
+ electricalUsageStoppedThresholdKw: zod_1.z.number().nullish(), // from station table
698
+ allowScheduleCutShort: zod_1.z.boolean().nullish(), // from station table
699
+ productiveStatusMode: zod_1.z.nativeEnum(PRODUCTIVE_STATUS_MODE), // from station table
700
+ lineSpeedStoppedThreshold: zod_1.z.number().nullish(), // from station table
701
+ shiftPatternId: zod_1.z.number().nullish(), // from station table
702
+ productiveHoldOnTime: zod_1.z.number(), // from station table
703
+ minimumCycleTime: zod_1.z.number().nullish(), // from station table
704
+ statusCode: zod_1.z.string().nullish(), // from station table
705
+ statusCodeUpdatedAt: zod_1.z.string().nullish(), // from station table
706
+ electricalPowerNominalKw: zod_1.z.number().nullish(), // from station table
707
+ shiftPattern: exports.ShiftPatternViewModel.optional(),
708
+ shifts: zod_1.z.array(exports.ShiftSchema), // from join with shift table. station.shiftPatternId or if null, stationGroup.shiftPatternId
709
+ currentShift: exports.ShiftSchema.optional(), // the shift calculated to be in now. Null if not in any shift.
710
+ currentStopReasonCode: zod_1.z.string().nullish(), // The reason code for the 'stop' type issue that is ongoing for this station. unknown if no reason given. null if no ongoing 'stop' type issue.
711
+ stoppedSince: zod_1.z.number().nullish(), // The startAt of the ongoing 'stop' type issue. null if no ongoing issue.
712
+ // TODO: Change this to stateCode. It doesn't match our API style to return the entire state object.
713
+ state: exports.StationState,
714
+ idleCostPerMinute: zod_1.z.number().nullish(),
715
+ moduleVisibility: zod_1.z.array(zod_1.z.nativeEnum(STATION_MODULE_VISIBILITY)).nullish(),
716
+ cachedAt: zod_1.z.number().nullish(),
717
+ allowQuickScheduleStart: zod_1.z.boolean().nullish(),
718
+ speedScale: zod_1.z.number().nullish(),
719
+ speedOffset: zod_1.z.number().nullish(),
720
+ speedToProductionRatio: zod_1.z.number().nullish(),
721
+ forceAllShiftTimeAsPlannedProduction: zod_1.z.boolean().nullish(), // This will cause any in shift time to be treated as planned production time for the sake of downtime detection and OEE.
722
+ lastStationWindow: StationWindowViewModel.nullish(),
723
+ });
724
+ exports.StationViewModel = StationViewModel;
725
+ const ProductionViewModel = zod_1.z.object({
726
+ id: zod_1.z.number().optional(),
727
+ stationCode: zod_1.z.string(),
728
+ stationName: zod_1.z.string(),
729
+ skuCode: zod_1.z.string().optional(),
730
+ skuName: zod_1.z.string().optional(),
731
+ skuValue: zod_1.z.number().optional(),
732
+ skuGroupCode: zod_1.z.string().optional(),
733
+ skuGroupName: zod_1.z.string().optional(),
734
+ effectiveCycleTime: zod_1.z.number().optional(),
735
+ workOrderReference: zod_1.z.string().optional(),
736
+ scheduleId: zod_1.z.number().optional(),
737
+ quantityGood: zod_1.z.number(),
738
+ quantityBad: zod_1.z.number(),
739
+ lastUnitAt: zod_1.z.string(),
740
+ lastUnitAtTimestamp: zod_1.z.number(),
741
+ operatorInitials: zod_1.z.string().optional(),
742
+ type: zod_1.z.nativeEnum(PRODUCTION_TYPE).optional(),
743
+ });
744
+ exports.ProductionViewModel = ProductionViewModel;
745
+ const ReliabilityData = zod_1.z.object({
746
+ runningsCount: zod_1.z.number(),
747
+ stopsCount: zod_1.z.number(),
748
+ totalRunningTime: zod_1.z.number(),
749
+ totalStoppedTime: zod_1.z.number(),
750
+ });
751
+ exports.ReliabilityData = ReliabilityData;
752
+ const StationWindowViewModelTrimmed = StationWindowViewModel.omit({
753
+ accountId: true,
754
+ createdAt: true,
755
+ updatedAt: true,
756
+ })
757
+ .partial({ stationCode: true, stationName: true })
758
+ .merge(zod_1.z.object({
759
+ //TODO: Reasons don't have name, they have descriptions. This needs to be updated.
760
+ nonProductionReasonNames: zod_1.z.array(zod_1.z.string()).optional(),
761
+ }));
762
+ exports.StationWindowViewModelTrimmed = StationWindowViewModelTrimmed;
763
+ const CycleTimeAnalysis = zod_1.z.object({
764
+ avg: zod_1.z.number(),
765
+ min: zod_1.z.number(),
766
+ max: zod_1.z.number(),
767
+ quantity: zod_1.z.number(),
768
+ default: zod_1.z.number().optional(),
769
+ stations: zod_1.z
770
+ .object({
771
+ stationCode: zod_1.z.string(),
772
+ stationName: zod_1.z.string(),
773
+ avg: zod_1.z.number(),
774
+ min: zod_1.z.number(),
775
+ max: zod_1.z.number(),
776
+ quantity: zod_1.z.number(),
777
+ })
778
+ .array(),
779
+ });
780
+ exports.CycleTimeAnalysis = CycleTimeAnalysis;
781
+ const NominalValue = zod_1.z.object({
782
+ electricalPowerNominalKw: zod_1.z.number(),
783
+ });
784
+ exports.NominalValue = NominalValue;
785
+ const AggregatedStationWindowsByStation = zod_1.z.object({
786
+ stationCode: zod_1.z.string(),
787
+ stationName: zod_1.z.string(),
788
+ stationGroupCode: zod_1.z.string(),
789
+ stationGroupName: zod_1.z.string(),
790
+ windows: zod_1.z.array(StationWindowViewModelTrimmed),
791
+ reliabilityData: ReliabilityData,
792
+ cycleTimeAnalysis: CycleTimeAnalysis.optional(),
793
+ oee: OeeViewModel,
794
+ nominal: NominalValue,
795
+ });
796
+ exports.AggregatedStationWindowsByStation = AggregatedStationWindowsByStation;