@seedtactics/insight-client 16.4.0

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.
Files changed (298) hide show
  1. package/README.md +37 -0
  2. package/dist/cell-status/buffers.d.ts +36 -0
  3. package/dist/cell-status/buffers.js +127 -0
  4. package/dist/cell-status/current-status.d.ts +30 -0
  5. package/dist/cell-status/current-status.js +200 -0
  6. package/dist/cell-status/estimated-cycle-times.d.ts +41 -0
  7. package/dist/cell-status/estimated-cycle-times.js +257 -0
  8. package/dist/cell-status/inspections.d.ts +55 -0
  9. package/dist/cell-status/inspections.js +213 -0
  10. package/dist/cell-status/loading.d.ts +26 -0
  11. package/dist/cell-status/loading.js +112 -0
  12. package/dist/cell-status/material-details.d.ts +116 -0
  13. package/dist/cell-status/material-details.js +422 -0
  14. package/dist/cell-status/material-summary.d.ts +52 -0
  15. package/dist/cell-status/material-summary.js +312 -0
  16. package/dist/cell-status/names.d.ts +19 -0
  17. package/dist/cell-status/names.js +134 -0
  18. package/dist/cell-status/pallet-cycles.d.ts +24 -0
  19. package/dist/cell-status/pallet-cycles.js +78 -0
  20. package/dist/cell-status/rebookings.d.ts +30 -0
  21. package/dist/cell-status/rebookings.js +139 -0
  22. package/dist/cell-status/scheduled-jobs.d.ts +18 -0
  23. package/dist/cell-status/scheduled-jobs.js +94 -0
  24. package/dist/cell-status/sim-day-usage.d.ts +14 -0
  25. package/dist/cell-status/sim-day-usage.js +54 -0
  26. package/dist/cell-status/sim-production.d.ts +22 -0
  27. package/dist/cell-status/sim-production.js +91 -0
  28. package/dist/cell-status/sim-station-use.d.ts +25 -0
  29. package/dist/cell-status/sim-station-use.js +71 -0
  30. package/dist/cell-status/station-cycles.d.ts +34 -0
  31. package/dist/cell-status/station-cycles.js +145 -0
  32. package/dist/cell-status/tool-replacements.d.ts +44 -0
  33. package/dist/cell-status/tool-replacements.js +155 -0
  34. package/dist/cell-status/tool-usage.d.ts +25 -0
  35. package/dist/cell-status/tool-usage.js +95 -0
  36. package/dist/components/App.d.ts +15 -0
  37. package/dist/components/App.js +549 -0
  38. package/dist/components/AxisAndGrid.d.ts +51 -0
  39. package/dist/components/AxisAndGrid.js +47 -0
  40. package/dist/components/BarcodeScanning.d.ts +6 -0
  41. package/dist/components/BarcodeScanning.js +150 -0
  42. package/dist/components/ChartTooltip.d.ts +28 -0
  43. package/dist/components/ChartTooltip.js +95 -0
  44. package/dist/components/ChooseMode.d.ts +18 -0
  45. package/dist/components/ChooseMode.js +136 -0
  46. package/dist/components/ChooseOperator.d.ts +1 -0
  47. package/dist/components/ChooseOperator.js +93 -0
  48. package/dist/components/ErrorsAndLoading.d.ts +9 -0
  49. package/dist/components/ErrorsAndLoading.js +55 -0
  50. package/dist/components/LoadingIcon.d.ts +1 -0
  51. package/dist/components/LoadingIcon.js +48 -0
  52. package/dist/components/LogEntry.d.ts +16 -0
  53. package/dist/components/LogEntry.js +365 -0
  54. package/dist/components/ManualSerialEntry.d.ts +5 -0
  55. package/dist/components/ManualSerialEntry.js +91 -0
  56. package/dist/components/MonthSelect.d.ts +6 -0
  57. package/dist/components/MonthSelect.js +67 -0
  58. package/dist/components/Navigation.d.ts +23 -0
  59. package/dist/components/Navigation.js +120 -0
  60. package/dist/components/VerboseLogging.d.ts +1 -0
  61. package/dist/components/VerboseLogging.js +47 -0
  62. package/dist/components/analysis/AnalysisSelectToolbar.d.ts +1 -0
  63. package/dist/components/analysis/AnalysisSelectToolbar.js +55 -0
  64. package/dist/components/analysis/BufferChart.d.ts +1 -0
  65. package/dist/components/analysis/BufferChart.js +139 -0
  66. package/dist/components/analysis/CostPerPiece.d.ts +2 -0
  67. package/dist/components/analysis/CostPerPiece.js +175 -0
  68. package/dist/components/analysis/CycleChart.d.ts +42 -0
  69. package/dist/components/analysis/CycleChart.js +281 -0
  70. package/dist/components/analysis/DataTable.d.ts +83 -0
  71. package/dist/components/analysis/DataTable.js +215 -0
  72. package/dist/components/analysis/EfficiencyPage.d.ts +2 -0
  73. package/dist/components/analysis/EfficiencyPage.js +138 -0
  74. package/dist/components/analysis/HeatChart.d.ts +22 -0
  75. package/dist/components/analysis/HeatChart.js +161 -0
  76. package/dist/components/analysis/InspectionDataTable.d.ts +10 -0
  77. package/dist/components/analysis/InspectionDataTable.js +148 -0
  78. package/dist/components/analysis/InspectionSankey.d.ts +12 -0
  79. package/dist/components/analysis/InspectionSankey.js +140 -0
  80. package/dist/components/analysis/PalletCycleCards.d.ts +1 -0
  81. package/dist/components/analysis/PalletCycleCards.js +137 -0
  82. package/dist/components/analysis/PartCycleCards.d.ts +2 -0
  83. package/dist/components/analysis/PartCycleCards.js +331 -0
  84. package/dist/components/analysis/QualityPage.d.ts +1 -0
  85. package/dist/components/analysis/QualityPage.js +49 -0
  86. package/dist/components/analysis/ScheduleHistory.d.ts +3 -0
  87. package/dist/components/analysis/ScheduleHistory.js +108 -0
  88. package/dist/components/analysis/StationDataTable.d.ts +25 -0
  89. package/dist/components/analysis/StationDataTable.js +246 -0
  90. package/dist/components/analysis/ToolReplacements.d.ts +1 -0
  91. package/dist/components/analysis/ToolReplacements.js +370 -0
  92. package/dist/components/operations/AllMaterial.d.ts +5 -0
  93. package/dist/components/operations/AllMaterial.js +267 -0
  94. package/dist/components/operations/ChartRangeEdit.d.ts +4 -0
  95. package/dist/components/operations/ChartRangeEdit.js +148 -0
  96. package/dist/components/operations/CloseoutReport.d.ts +2 -0
  97. package/dist/components/operations/CloseoutReport.js +172 -0
  98. package/dist/components/operations/CompletedParts.d.ts +2 -0
  99. package/dist/components/operations/CompletedParts.js +286 -0
  100. package/dist/components/operations/CurrentWorkorders.d.ts +3 -0
  101. package/dist/components/operations/CurrentWorkorders.js +368 -0
  102. package/dist/components/operations/Dashboard.d.ts +2 -0
  103. package/dist/components/operations/Dashboard.js +90 -0
  104. package/dist/components/operations/OEEChart.d.ts +10 -0
  105. package/dist/components/operations/OEEChart.js +173 -0
  106. package/dist/components/operations/Outliers.d.ts +4 -0
  107. package/dist/components/operations/Outliers.js +69 -0
  108. package/dist/components/operations/ProgramHighlight.d.ts +1 -0
  109. package/dist/components/operations/ProgramHighlight.js +9 -0
  110. package/dist/components/operations/Programs.d.ts +5 -0
  111. package/dist/components/operations/Programs.js +363 -0
  112. package/dist/components/operations/Rebookings.d.ts +1 -0
  113. package/dist/components/operations/Rebookings.js +213 -0
  114. package/dist/components/operations/RecentCycleChart.d.ts +4 -0
  115. package/dist/components/operations/RecentCycleChart.js +240 -0
  116. package/dist/components/operations/RecentProduction.d.ts +2 -0
  117. package/dist/components/operations/RecentProduction.js +213 -0
  118. package/dist/components/operations/RecentSchedules.d.ts +12 -0
  119. package/dist/components/operations/RecentSchedules.js +180 -0
  120. package/dist/components/operations/RecentStationCycles.d.ts +4 -0
  121. package/dist/components/operations/RecentStationCycles.js +159 -0
  122. package/dist/components/operations/ShiftSettings.d.ts +6 -0
  123. package/dist/components/operations/ShiftSettings.js +134 -0
  124. package/dist/components/operations/SimDayUsage.d.ts +1 -0
  125. package/dist/components/operations/SimDayUsage.js +133 -0
  126. package/dist/components/operations/ToolReport.d.ts +3 -0
  127. package/dist/components/operations/ToolReport.js +233 -0
  128. package/dist/components/operations/WorkorderGantt.d.ts +1 -0
  129. package/dist/components/operations/WorkorderGantt.js +124 -0
  130. package/dist/components/quality/QualityMaterial.d.ts +2 -0
  131. package/dist/components/quality/QualityMaterial.js +169 -0
  132. package/dist/components/quality/QualityPaths.d.ts +1 -0
  133. package/dist/components/quality/QualityPaths.js +53 -0
  134. package/dist/components/quality/RecentFailedInspections.d.ts +1 -0
  135. package/dist/components/quality/RecentFailedInspections.js +123 -0
  136. package/dist/components/routes.d.ts +170 -0
  137. package/dist/components/routes.js +301 -0
  138. package/dist/components/station-monitor/BulkRawMaterial.d.ts +11 -0
  139. package/dist/components/station-monitor/BulkRawMaterial.js +251 -0
  140. package/dist/components/station-monitor/Closeout.d.ts +5 -0
  141. package/dist/components/station-monitor/Closeout.js +162 -0
  142. package/dist/components/station-monitor/CustomStationMonitorDialog.d.ts +1 -0
  143. package/dist/components/station-monitor/CustomStationMonitorDialog.js +55 -0
  144. package/dist/components/station-monitor/Inspection.d.ts +8 -0
  145. package/dist/components/station-monitor/Inspection.js +164 -0
  146. package/dist/components/station-monitor/InvalidateCycle.d.ts +33 -0
  147. package/dist/components/station-monitor/InvalidateCycle.js +262 -0
  148. package/dist/components/station-monitor/JobDetails.d.ts +7 -0
  149. package/dist/components/station-monitor/JobDetails.js +108 -0
  150. package/dist/components/station-monitor/LoadStation.d.ts +10 -0
  151. package/dist/components/station-monitor/LoadStation.js +450 -0
  152. package/dist/components/station-monitor/Material.d.ts +77 -0
  153. package/dist/components/station-monitor/Material.js +489 -0
  154. package/dist/components/station-monitor/MoveMaterialArrows.d.ts +11 -0
  155. package/dist/components/station-monitor/MoveMaterialArrows.js +118 -0
  156. package/dist/components/station-monitor/PrintedLabel.d.ts +29 -0
  157. package/dist/components/station-monitor/PrintedLabel.js +166 -0
  158. package/dist/components/station-monitor/QuarantineButton.d.ts +4 -0
  159. package/dist/components/station-monitor/QuarantineButton.js +184 -0
  160. package/dist/components/station-monitor/Queues.d.ts +23 -0
  161. package/dist/components/station-monitor/Queues.js +312 -0
  162. package/dist/components/station-monitor/QueuesAddMaterial.d.ts +30 -0
  163. package/dist/components/station-monitor/QueuesAddMaterial.js +248 -0
  164. package/dist/components/station-monitor/SelectInspType.d.ts +2 -0
  165. package/dist/components/station-monitor/SelectInspType.js +99 -0
  166. package/dist/components/station-monitor/SelectWorkorder.d.ts +4 -0
  167. package/dist/components/station-monitor/SelectWorkorder.js +100 -0
  168. package/dist/components/station-monitor/StationToolbar.d.ts +3 -0
  169. package/dist/components/station-monitor/StationToolbar.js +168 -0
  170. package/dist/components/station-monitor/SystemOverview.d.ts +46 -0
  171. package/dist/components/station-monitor/SystemOverview.js +439 -0
  172. package/dist/components/station-monitor/Whiteboard.d.ts +10 -0
  173. package/dist/components/station-monitor/Whiteboard.js +67 -0
  174. package/dist/data/all-material-bins.d.ts +45 -0
  175. package/dist/data/all-material-bins.js +224 -0
  176. package/dist/data/chart-times.d.ts +20 -0
  177. package/dist/data/chart-times.js +99 -0
  178. package/dist/data/cost-per-piece.d.ts +32 -0
  179. package/dist/data/cost-per-piece.js +183 -0
  180. package/dist/data/current-cycles.d.ts +13 -0
  181. package/dist/data/current-cycles.js +144 -0
  182. package/dist/data/inspection-sankey.d.ts +15 -0
  183. package/dist/data/inspection-sankey.js +147 -0
  184. package/dist/data/move-arrows.d.ts +48 -0
  185. package/dist/data/move-arrows.js +217 -0
  186. package/dist/data/operators.d.ts +2 -0
  187. package/dist/data/operators.js +44 -0
  188. package/dist/data/part-summary.d.ts +17 -0
  189. package/dist/data/part-summary.js +107 -0
  190. package/dist/data/path-lookup.d.ts +13 -0
  191. package/dist/data/path-lookup.js +107 -0
  192. package/dist/data/queue-material.d.ts +46 -0
  193. package/dist/data/queue-material.js +256 -0
  194. package/dist/data/results.bufferchart.d.ts +10 -0
  195. package/dist/data/results.bufferchart.js +90 -0
  196. package/dist/data/results.completed-parts.d.ts +26 -0
  197. package/dist/data/results.completed-parts.js +181 -0
  198. package/dist/data/results.cycles.d.ts +86 -0
  199. package/dist/data/results.cycles.js +454 -0
  200. package/dist/data/results.inspection.d.ts +36 -0
  201. package/dist/data/results.inspection.js +188 -0
  202. package/dist/data/results.oee.d.ts +40 -0
  203. package/dist/data/results.oee.js +330 -0
  204. package/dist/data/results.schedules.d.ts +23 -0
  205. package/dist/data/results.schedules.js +157 -0
  206. package/dist/data/tools-programs.d.ts +78 -0
  207. package/dist/data/tools-programs.js +376 -0
  208. package/dist/index.d.ts +1 -0
  209. package/dist/index.js +60 -0
  210. package/dist/network/api.d.ts +1390 -0
  211. package/dist/network/api.js +4971 -0
  212. package/dist/network/backend-mock.d.ts +11 -0
  213. package/dist/network/backend-mock.js +512 -0
  214. package/dist/network/backend.d.ts +57 -0
  215. package/dist/network/backend.js +77 -0
  216. package/dist/network/load-specific-month.d.ts +13 -0
  217. package/dist/network/load-specific-month.js +77 -0
  218. package/dist/network/server-settings.d.ts +12 -0
  219. package/dist/network/server-settings.js +92 -0
  220. package/dist/network/websocket.d.ts +4 -0
  221. package/dist/network/websocket.js +165 -0
  222. package/dist/renderer.d.ts +8 -0
  223. package/dist/renderer.js +55 -0
  224. package/dist/seedtactics-logo.d.ts +2 -0
  225. package/dist/seedtactics-logo.js +4 -0
  226. package/dist/util/chart-colors.d.ts +1 -0
  227. package/dist/util/chart-colors.js +116 -0
  228. package/dist/util/chart-helpers.d.ts +3 -0
  229. package/dist/util/chart-helpers.js +51 -0
  230. package/dist/util/parseISODuration.d.ts +4 -0
  231. package/dist/util/parseISODuration.js +40 -0
  232. package/docs/client-efficiency.md +355 -0
  233. package/docs/client-engineering.md +54 -0
  234. package/docs/client-launch.md +55 -0
  235. package/docs/client-operations.md +88 -0
  236. package/docs/client-quality.md +74 -0
  237. package/docs/client-sales.md +61 -0
  238. package/docs/client-scanners.md +41 -0
  239. package/docs/client-station-monitor.md +149 -0
  240. package/docs/client-tools-programs.md +74 -0
  241. package/docs/improve-fms.md +141 -0
  242. package/docs/makino.md +40 -0
  243. package/docs/material-quarantine.md +82 -0
  244. package/docs/material-tracking.md +236 -0
  245. package/docs/mazak.md +115 -0
  246. package/docs/niigata.md +228 -0
  247. package/docs/operator-procedures.md +106 -0
  248. package/docs/part-instructions.md +63 -0
  249. package/docs/screenshots/insight-all-material.png +0 -0
  250. package/docs/screenshots/insight-analysis-pallets.png +0 -0
  251. package/docs/screenshots/insight-analysis-part-completed.png +0 -0
  252. package/docs/screenshots/insight-analysis-sankey.png +0 -0
  253. package/docs/screenshots/insight-analysis-station-oee.png +0 -0
  254. package/docs/screenshots/insight-buffer-occupancy.png +0 -0
  255. package/docs/screenshots/insight-choose-analysis-month.png +0 -0
  256. package/docs/screenshots/insight-closeout.png +0 -0
  257. package/docs/screenshots/insight-cost-percentages.png +0 -0
  258. package/docs/screenshots/insight-dashboard.png +0 -0
  259. package/docs/screenshots/insight-event-custom-view.jpg +0 -0
  260. package/docs/screenshots/insight-event-viewer.jpg +0 -0
  261. package/docs/screenshots/insight-inspection.png +0 -0
  262. package/docs/screenshots/insight-load-station-details.png +0 -0
  263. package/docs/screenshots/insight-load-station.png +0 -0
  264. package/docs/screenshots/insight-loadcycle-graph.png +0 -0
  265. package/docs/screenshots/insight-loadstation-small.jpg +0 -0
  266. package/docs/screenshots/insight-machinecycle-graph.png +0 -0
  267. package/docs/screenshots/insight-machinecycle-table.png +0 -0
  268. package/docs/screenshots/insight-machinecycles.png +0 -0
  269. package/docs/screenshots/insight-machinehours.png +0 -0
  270. package/docs/screenshots/insight-machineoutliers.png +0 -0
  271. package/docs/screenshots/insight-monthly-schedules.png +0 -0
  272. package/docs/screenshots/insight-operations-material.png +0 -0
  273. package/docs/screenshots/insight-operations-overview.png +0 -0
  274. package/docs/screenshots/insight-operations-reports.png +0 -0
  275. package/docs/screenshots/insight-part-cost.png +0 -0
  276. package/docs/screenshots/insight-program-report.png +0 -0
  277. package/docs/screenshots/insight-quality-material-details.png +0 -0
  278. package/docs/screenshots/insight-quality-material.png +0 -0
  279. package/docs/screenshots/insight-quality-quarantine.png +0 -0
  280. package/docs/screenshots/insight-quality-sankey.png +0 -0
  281. package/docs/screenshots/insight-quality-similar-paths.png +0 -0
  282. package/docs/screenshots/insight-queue-details.png +0 -0
  283. package/docs/screenshots/insight-queues-jobs-table.png +0 -0
  284. package/docs/screenshots/insight-queues.png +0 -0
  285. package/docs/screenshots/insight-sim-day-usage.png +0 -0
  286. package/docs/screenshots/insight-station-system-overview-buttons.png +0 -0
  287. package/docs/screenshots/insight-station-system-overview.png +0 -0
  288. package/docs/screenshots/insight-system-overview.png +0 -0
  289. package/docs/screenshots/insight-tool-replacements.png +0 -0
  290. package/docs/screenshots/insight-tool-report.png +0 -0
  291. package/docs/screenshots/insight-toolbar-btns.png +0 -0
  292. package/docs/screenshots/insight-workorder-gantt.png +0 -0
  293. package/docs/screenshots/insight-workorders.png +0 -0
  294. package/docs/security.md +131 -0
  295. package/docs/server-config.md +56 -0
  296. package/docs/server-errors.md +44 -0
  297. package/package.json +90 -0
  298. package/src/index.ts +65 -0
@@ -0,0 +1,257 @@
1
+ /* Copyright (c) 2021, John Lenz
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following
13
+ disclaimer in the documentation and/or other materials provided
14
+ with the distribution.
15
+
16
+ * Neither the name of John Lenz, Black Maple Software, SeedTactics,
17
+ nor the names of other contributors may be used to endorse or
18
+ promote products derived from this software without specific
19
+ prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ */
33
+ import { differenceInSeconds } from "date-fns";
34
+ import { LogType } from "../network/api.js";
35
+ import { LazySeq, HashMap, hashValues } from "@seedtactics/immutable-collections";
36
+ import { durationToMinutes } from "../util/parseISODuration.js";
37
+ import { atom } from "jotai";
38
+ export class PartAndStationOperation {
39
+ constructor(part, statGroup, operation) {
40
+ this.part = part;
41
+ this.statGroup = statGroup;
42
+ this.operation = operation;
43
+ }
44
+ static ofLogCycle(c) {
45
+ return new PartAndStationOperation(c.material[0].part, c.loc, c.type === LogType.LoadUnloadCycle && c.material.length > 0
46
+ ? c.result + "-" + c.material[0].proc.toString()
47
+ : c.program);
48
+ }
49
+ static ofPartCycle(c) {
50
+ return new PartAndStationOperation(c.part, c.stationGroup, c.isLabor && c.material.length > 0 ? c.operation + "-" + c.material[0].proc.toString() : c.operation);
51
+ }
52
+ compare(other) {
53
+ let cmp = this.part.localeCompare(other.part);
54
+ if (cmp !== 0)
55
+ return cmp;
56
+ cmp = this.statGroup.localeCompare(other.statGroup);
57
+ if (cmp !== 0)
58
+ return cmp;
59
+ return this.operation.localeCompare(other.operation);
60
+ }
61
+ hash() {
62
+ return hashValues(this.part, this.statGroup, this.operation);
63
+ }
64
+ toString() {
65
+ return `{part: ${this.part}}, statGroup: ${this.statGroup}, operation: ${this.operation}}`;
66
+ }
67
+ }
68
+ const last30EstimatedTimesRW = atom(HashMap.empty());
69
+ export const last30EstimatedCycleTimes = last30EstimatedTimesRW;
70
+ const specificMonthEstimatedTimesRW = atom(HashMap.empty());
71
+ export const specificMonthEstimatedCycleTimes = specificMonthEstimatedTimesRW;
72
+ // Assume: samples come from two distributions:
73
+ // - the program runs without interruption, giving a guassian iid around the cycle time.
74
+ // - the program is interrupted or stopped, which adds a random amount to the program
75
+ // and results in an outlier.
76
+ // - the program doesn't run at all, which results in a random short cycle time.
77
+ // We use median absolute deviation to detect outliers, remove the outliers,
78
+ // then compute average to find cycle time.
79
+ export function isOutlier(s, mins) {
80
+ if (s.medianMinutesForSingleMat === 0) {
81
+ return false;
82
+ }
83
+ if (mins < s.medianMinutesForSingleMat) {
84
+ return (s.medianMinutesForSingleMat - mins) / s.MAD_belowMinutes > 2;
85
+ }
86
+ else {
87
+ return (mins - s.medianMinutesForSingleMat) / s.MAD_aboveMinutes > 2;
88
+ }
89
+ }
90
+ export function isOutlierAbove(s, mins) {
91
+ if (s.medianMinutesForSingleMat === 0) {
92
+ return false;
93
+ }
94
+ if (mins < s.medianMinutesForSingleMat) {
95
+ return false;
96
+ }
97
+ else {
98
+ return (mins - s.medianMinutesForSingleMat) / s.MAD_aboveMinutes > 2;
99
+ }
100
+ }
101
+ function median(vals) {
102
+ const sorted = vals.toMutableArray().sort((a, b) => a - b);
103
+ const cnt = sorted.length;
104
+ if (cnt === 0) {
105
+ return 0;
106
+ }
107
+ const half = Math.floor(sorted.length / 2);
108
+ if (sorted.length % 2 === 0) {
109
+ // average two middle
110
+ return (sorted[half - 1] + sorted[half]) / 2;
111
+ }
112
+ else {
113
+ // return middle
114
+ return sorted[half];
115
+ }
116
+ }
117
+ function estimateCycleTimes(cycles) {
118
+ // compute median
119
+ const medianMinutes = median(LazySeq.of(cycles));
120
+ // absolute deviation from median, but use different values for below and above
121
+ // median. Below is assumed to be from fake cycles and above is from interrupted programs.
122
+ // since we assume gaussian, use consistantcy constant of 1.4826
123
+ let madBelowMinutes = 1.4826 *
124
+ median(LazySeq.of(cycles)
125
+ .filter((x) => x <= medianMinutes)
126
+ .map((x) => medianMinutes - x));
127
+ // clamp at 15 seconds
128
+ if (madBelowMinutes < 0.25) {
129
+ madBelowMinutes = 0.25;
130
+ }
131
+ let madAboveMinutes = 1.4826 *
132
+ median(LazySeq.of(cycles)
133
+ .filter((x) => x >= medianMinutes)
134
+ .map((x) => x - medianMinutes));
135
+ // clamp at 15 seconds
136
+ if (madAboveMinutes < 0.25) {
137
+ madAboveMinutes = 0.25;
138
+ }
139
+ const statCycleTime = {
140
+ medianMinutesForSingleMat: medianMinutes,
141
+ MAD_belowMinutes: madBelowMinutes,
142
+ MAD_aboveMinutes: madAboveMinutes,
143
+ expectedCycleMinutesForSingleMat: 0,
144
+ };
145
+ // filter to only inliers
146
+ const inliers = LazySeq.of(cycles)
147
+ .filter((x) => !isOutlier(statCycleTime, x))
148
+ .toRArray();
149
+ // compute average of inliers
150
+ const expectedCycleMinutesForSingleMat = inliers.reduce((sum, x) => sum + x, 0) / inliers.length;
151
+ return { ...statCycleTime, expectedCycleMinutesForSingleMat };
152
+ }
153
+ export function chunkCyclesWithSimilarEndTime(allCycles, getKey, getTime) {
154
+ return allCycles
155
+ .toLookupOrderedMap(getKey, getTime, (c) => [c], (cs, ds) => cs.concat(ds))
156
+ .toAscLazySeq()
157
+ .map(([k, cycles]) => {
158
+ const ret = [];
159
+ let chunk = [];
160
+ for (const c of cycles.valuesToAscLazySeq().flatMap((cs) => cs)) {
161
+ if (chunk.length === 0) {
162
+ chunk = [c];
163
+ }
164
+ else if (differenceInSeconds(getTime(c), getTime(chunk[chunk.length - 1])) < 10) {
165
+ chunk.push(c);
166
+ }
167
+ else {
168
+ ret.push(chunk);
169
+ chunk = [c];
170
+ }
171
+ }
172
+ if (chunk.length > 0) {
173
+ ret.push(chunk);
174
+ }
175
+ return [k, ret];
176
+ });
177
+ }
178
+ export function splitElapsedTimeAmongChunk(chunk, getElapsedMins, getActiveMins) {
179
+ let totalActiveMins = 0;
180
+ let totalMatCount = 0;
181
+ let allEventsHaveActive = true;
182
+ for (const cycle of chunk) {
183
+ if (getActiveMins(cycle) < 0) {
184
+ allEventsHaveActive = false;
185
+ }
186
+ totalMatCount += cycle.material.length;
187
+ totalActiveMins += getActiveMins(cycle);
188
+ }
189
+ if (allEventsHaveActive && totalActiveMins > 0) {
190
+ //split by active. First multiply by (active/totalActive) ratio to get fraction of elapsed
191
+ //for this cycle, then by material count to get per-material
192
+ return chunk.map((cycle) => ({
193
+ cycle,
194
+ elapsedForSingleMaterialMinutes: (getElapsedMins(cycle) * getActiveMins(cycle)) / totalActiveMins / cycle.material.length,
195
+ }));
196
+ }
197
+ // split equally among all material
198
+ if (totalMatCount > 0) {
199
+ return chunk.map((cycle) => ({
200
+ cycle,
201
+ elapsedForSingleMaterialMinutes: getElapsedMins(cycle) / totalMatCount,
202
+ }));
203
+ }
204
+ // only when no events have material, which should never happen
205
+ return chunk.map((cycle) => ({
206
+ cycle,
207
+ elapsedForSingleMaterialMinutes: getElapsedMins(cycle),
208
+ }));
209
+ }
210
+ // In older versions of FMS Insight, load cycles had a shared elapsed time among all events
211
+ // for the cycle and each event had the total elapsed time for the whole combination of operations.
212
+ // An update to the server changed this so that the server splits the elapsed time among the events.
213
+ // But, for backwards compatibility, detect if we need to split the elpased time in the client too.
214
+ // To detect new vs old, the new version also started adding the material IDs to pallet begin and end events,
215
+ // so if the material appears in a begin/end event that means it does not need to be split.
216
+ export function calcElapsedForCycles(eventLog) {
217
+ const matsInPalEvts = new Set();
218
+ for (const e of eventLog) {
219
+ if (e.type === LogType.PalletCycle && e.material.length > 0) {
220
+ for (const m of e.material) {
221
+ matsInPalEvts.add(m.id);
222
+ }
223
+ }
224
+ }
225
+ return chunkCyclesWithSimilarEndTime(LazySeq.of(eventLog).filter((e) => (e.type === LogType.LoadUnloadCycle || e.type === LogType.MachineCycle) &&
226
+ !e.startofcycle &&
227
+ e.loc !== "" &&
228
+ e.material.length > 0), (c) => c.loc + " #" + c.locnum.toString(), (c) => c.endUTC)
229
+ .flatMap(([_lul, chunks]) => chunks)
230
+ .flatMap((chunk) => {
231
+ // Check if need to split the elapsed
232
+ const chunk0Elapsed = durationToMinutes(chunk[0].elapsed);
233
+ const shouldSplit = chunk.length >= 2 &&
234
+ chunk.every((c) => durationToMinutes(c.elapsed) === chunk0Elapsed &&
235
+ c.material.every((m) => !matsInPalEvts.has(m.id)));
236
+ if (shouldSplit) {
237
+ return splitElapsedTimeAmongChunk(chunk, (c) => durationToMinutes(c.elapsed), (c) => (c.active === "" ? -1 : durationToMinutes(c.active)));
238
+ }
239
+ else {
240
+ return chunk.map((c) => ({
241
+ cycle: c,
242
+ elapsedForSingleMaterialMinutes: c.material.length > 0 ? durationToMinutes(c.elapsed) / c.material.length : 0,
243
+ }));
244
+ }
245
+ });
246
+ }
247
+ function estimateCycleTimesOfParts(cycles) {
248
+ return calcElapsedForCycles(cycles)
249
+ .toLookup((c) => PartAndStationOperation.ofLogCycle(c.cycle), (c) => c.elapsedForSingleMaterialMinutes)
250
+ .mapValues(estimateCycleTimes);
251
+ }
252
+ export const setLast30EstimatedCycleTimes = atom(null, (_, set, log) => {
253
+ set(last30EstimatedTimesRW, (old) => (old.size === 0 ? estimateCycleTimesOfParts(log) : old));
254
+ });
255
+ export const setSpecificMonthEstimatedCycleTimes = atom(null, (_, set, log) => {
256
+ set(specificMonthEstimatedTimesRW, estimateCycleTimesOfParts(log));
257
+ });
@@ -0,0 +1,55 @@
1
+ import { ILogEntry, IMaterialProcessActualPath } from "../network/api.js";
2
+ import { HashMap } from "@seedtactics/immutable-collections";
3
+ import type { ServerEventAndTime } from "./loading.js";
4
+ import { Atom } from "jotai";
5
+ export declare enum InspectionLogResultType {
6
+ Triggered = 0,
7
+ Forced = 1,
8
+ Completed = 2
9
+ }
10
+ export type InspectionLogResult = {
11
+ readonly type: InspectionLogResultType.Triggered;
12
+ readonly actualPath: ReadonlyArray<Readonly<IMaterialProcessActualPath>>;
13
+ readonly toInspect: boolean;
14
+ } | {
15
+ readonly type: InspectionLogResultType.Forced;
16
+ readonly toInspect: boolean;
17
+ } | {
18
+ readonly type: InspectionLogResultType.Completed;
19
+ readonly success: boolean;
20
+ };
21
+ export interface InspectionLogEntry {
22
+ readonly cntr: number;
23
+ readonly time: Date;
24
+ readonly materialID: number;
25
+ readonly serial?: string;
26
+ readonly workorder?: string;
27
+ readonly result: InspectionLogResult;
28
+ readonly part: string;
29
+ readonly inspType: string;
30
+ }
31
+ export type InspectionLogsByCntr = HashMap<number, InspectionLogEntry>;
32
+ export declare class PartAndInspType {
33
+ readonly part: string;
34
+ readonly inspType: string;
35
+ constructor(part: string, inspType: string);
36
+ compare(other: PartAndInspType): number;
37
+ hash(): number;
38
+ toString(): string;
39
+ }
40
+ export type InspectionsByPartAndType = HashMap<PartAndInspType, InspectionLogsByCntr>;
41
+ export declare const last30Inspections: Atom<InspectionsByPartAndType>;
42
+ export declare const specificMonthInspections: Atom<InspectionsByPartAndType>;
43
+ export declare function convertLogToInspections(c: Readonly<ILogEntry>): ReadonlyArray<{
44
+ key: PartAndInspType;
45
+ entry: InspectionLogEntry;
46
+ }>;
47
+ export declare const setLast30Inspections: import("jotai").WritableAtom<null, [log: readonly Readonly<ILogEntry>[]], void> & {
48
+ init: null;
49
+ };
50
+ export declare const updateLast30Inspections: import("jotai").WritableAtom<null, [ServerEventAndTime], void> & {
51
+ init: null;
52
+ };
53
+ export declare const setSpecificMonthInspections: import("jotai").WritableAtom<null, [log: readonly Readonly<ILogEntry>[]], void> & {
54
+ init: null;
55
+ };
@@ -0,0 +1,213 @@
1
+ /* Copyright (c) 2021, John Lenz
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following
13
+ disclaimer in the documentation and/or other materials provided
14
+ with the distribution.
15
+
16
+ * Neither the name of John Lenz, Black Maple Software, SeedTactics,
17
+ nor the names of other contributors may be used to endorse or
18
+ promote products derived from this software without specific
19
+ prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ */
33
+ import { hashValues } from "@seedtactics/immutable-collections";
34
+ import { addDays } from "date-fns";
35
+ import { LogType, MaterialProcessActualPath } from "../network/api.js";
36
+ import { LazySeq, HashMap } from "@seedtactics/immutable-collections";
37
+ import { atom } from "jotai";
38
+ export var InspectionLogResultType;
39
+ (function (InspectionLogResultType) {
40
+ InspectionLogResultType[InspectionLogResultType["Triggered"] = 0] = "Triggered";
41
+ InspectionLogResultType[InspectionLogResultType["Forced"] = 1] = "Forced";
42
+ InspectionLogResultType[InspectionLogResultType["Completed"] = 2] = "Completed";
43
+ })(InspectionLogResultType || (InspectionLogResultType = {}));
44
+ export class PartAndInspType {
45
+ constructor(part, inspType) {
46
+ this.part = part;
47
+ this.inspType = inspType;
48
+ }
49
+ compare(other) {
50
+ const cmp = this.part.localeCompare(other.part);
51
+ if (cmp !== 0) {
52
+ return cmp;
53
+ }
54
+ else {
55
+ return this.inspType.localeCompare(other.inspType);
56
+ }
57
+ }
58
+ hash() {
59
+ return hashValues(this.part, this.inspType);
60
+ }
61
+ toString() {
62
+ return `{part: ${this.part}}, inspType: ${this.inspType}}`;
63
+ }
64
+ }
65
+ const last30InspectionsRW = atom(HashMap.empty());
66
+ export const last30Inspections = last30InspectionsRW;
67
+ const specificMonthInspectionsRW = atom(HashMap.empty());
68
+ export const specificMonthInspections = specificMonthInspectionsRW;
69
+ export function convertLogToInspections(c) {
70
+ if (c.type !== LogType.Inspection &&
71
+ c.type !== LogType.InspectionForce &&
72
+ c.type !== LogType.InspectionResult) {
73
+ return [];
74
+ }
75
+ return c.material.map((m) => {
76
+ if (c.type === LogType.Inspection) {
77
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
78
+ const pathsJson = JSON.parse((c.details || {}).ActualPath || "[]");
79
+ const paths = [];
80
+ for (const pathJson of pathsJson) {
81
+ paths.push(MaterialProcessActualPath.fromJS(pathJson));
82
+ }
83
+ const inspType = (c.details || {}).InspectionType || "";
84
+ let toInspect;
85
+ if (c.result.toLowerCase() === "true" || c.result === "1") {
86
+ toInspect = true;
87
+ }
88
+ else {
89
+ toInspect = false;
90
+ }
91
+ const r = {
92
+ key: new PartAndInspType(m.part, inspType),
93
+ entry: {
94
+ cntr: c.counter,
95
+ time: c.endUTC,
96
+ materialID: m.id,
97
+ serial: m.serial,
98
+ workorder: m.workorder,
99
+ result: {
100
+ type: InspectionLogResultType.Triggered,
101
+ actualPath: paths,
102
+ toInspect,
103
+ },
104
+ part: m.part,
105
+ inspType: inspType,
106
+ },
107
+ };
108
+ return r;
109
+ }
110
+ else if (c.type === LogType.InspectionForce) {
111
+ let forceInspect;
112
+ if (c.result.toLowerCase() === "true" || c.result === "1") {
113
+ forceInspect = true;
114
+ }
115
+ else {
116
+ forceInspect = false;
117
+ }
118
+ const r = {
119
+ key: new PartAndInspType(m.part, c.program),
120
+ entry: {
121
+ cntr: c.counter,
122
+ time: c.endUTC,
123
+ materialID: m.id,
124
+ serial: m.serial,
125
+ workorder: m.workorder,
126
+ result: {
127
+ type: InspectionLogResultType.Forced,
128
+ toInspect: forceInspect,
129
+ },
130
+ part: m.part,
131
+ inspType: c.program,
132
+ },
133
+ };
134
+ return r;
135
+ }
136
+ else {
137
+ // api.LogType.InspectionResult
138
+ let success;
139
+ if (c.result.toLowerCase() === "true" || c.result === "1") {
140
+ success = true;
141
+ }
142
+ else {
143
+ success = false;
144
+ }
145
+ const r = {
146
+ key: new PartAndInspType(m.part, c.program),
147
+ entry: {
148
+ cntr: c.counter,
149
+ time: c.endUTC,
150
+ materialID: m.id,
151
+ serial: m.serial,
152
+ workorder: m.workorder,
153
+ result: { type: InspectionLogResultType.Completed, success },
154
+ part: m.part,
155
+ inspType: c.program,
156
+ },
157
+ };
158
+ return r;
159
+ }
160
+ });
161
+ }
162
+ export const setLast30Inspections = atom(null, (_, set, log) => {
163
+ set(last30InspectionsRW, (oldEntries) => oldEntries.union(LazySeq.of(log)
164
+ .flatMap(convertLogToInspections)
165
+ .toLookupMap((e) => e.key, (e) => e.entry.cntr, (e) => e.entry), (e1, e2) => e1.union(e2)));
166
+ });
167
+ export const updateLast30Inspections = atom(null, (_, set, { evt, now, expire }) => {
168
+ if (evt.logEntry) {
169
+ const log = convertLogToInspections(evt.logEntry);
170
+ if (log.length === 0)
171
+ return;
172
+ set(last30InspectionsRW, (parts) => {
173
+ if (expire) {
174
+ const expireD = addDays(now, -30);
175
+ parts = parts.collectValues((entries) => {
176
+ const newEntries = entries.filter((e) => e.time >= expireD);
177
+ if (newEntries.size === 0) {
178
+ return null;
179
+ }
180
+ else {
181
+ return newEntries;
182
+ }
183
+ });
184
+ }
185
+ return parts.union(LazySeq.of(log).toLookupMap((e) => e.key, (e) => e.entry.cntr, (e) => e.entry), (e1, e2) => e1.union(e2));
186
+ });
187
+ }
188
+ else if (evt.editMaterialInLog) {
189
+ const changedByCntr = evt.editMaterialInLog.editedEvents;
190
+ set(last30InspectionsRW, (parts) => parts.collectValues((entries) => {
191
+ for (const changed of changedByCntr) {
192
+ // inspection logs have only a single material
193
+ const mat = changed?.material[0];
194
+ const old = entries.get(changed.counter);
195
+ if (old !== undefined && mat) {
196
+ const newEntry = {
197
+ ...old,
198
+ materialID: mat.id,
199
+ serial: mat.serial,
200
+ workorder: mat.workorder,
201
+ };
202
+ entries = entries.set(changed.counter, newEntry);
203
+ }
204
+ }
205
+ return entries;
206
+ }));
207
+ }
208
+ });
209
+ export const setSpecificMonthInspections = atom(null, (_, set, log) => {
210
+ set(specificMonthInspectionsRW, LazySeq.of(log)
211
+ .flatMap(convertLogToInspections)
212
+ .toLookupMap((e) => e.key, (e) => e.entry.cntr, (e) => e.entry));
213
+ });
@@ -0,0 +1,26 @@
1
+ import { ICurrentStatus, IHistoricData, ILogEntry, IRecentHistoricData, IServerEvent } from "../network/api.js";
2
+ import { Atom } from "jotai";
3
+ export interface ServerEventAndTime {
4
+ readonly evt: Readonly<IServerEvent>;
5
+ readonly now: Date;
6
+ readonly expire: boolean;
7
+ }
8
+ export declare const lastEventCounter: Atom<number | null>;
9
+ export declare const onServerEvent: import("jotai").WritableAtom<null, [evt: ServerEventAndTime], void> & {
10
+ init: null;
11
+ };
12
+ export declare const onLoadLast30Jobs: import("jotai").WritableAtom<null, [historicData: Readonly<IRecentHistoricData>], void> & {
13
+ init: null;
14
+ };
15
+ export declare const onLoadLast30Log: import("jotai").WritableAtom<null, [log: readonly Readonly<ILogEntry>[]], void> & {
16
+ init: null;
17
+ };
18
+ export declare const onLoadCurrentSt: import("jotai").WritableAtom<null, [curSt: Readonly<ICurrentStatus>], void> & {
19
+ init: null;
20
+ };
21
+ export declare const onLoadSpecificMonthJobs: import("jotai").WritableAtom<null, [historicData: Readonly<IHistoricData>], void> & {
22
+ init: null;
23
+ };
24
+ export declare const onLoadSpecificMonthLog: import("jotai").WritableAtom<null, [log: readonly Readonly<ILogEntry>[]], void> & {
25
+ init: null;
26
+ };
@@ -0,0 +1,112 @@
1
+ /* Copyright (c) 2021, John Lenz
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following
13
+ disclaimer in the documentation and/or other materials provided
14
+ with the distribution.
15
+
16
+ * Neither the name of John Lenz, Black Maple Software, SeedTactics,
17
+ nor the names of other contributors may be used to endorse or
18
+ promote products derived from this software without specific
19
+ prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ */
33
+ import { LazySeq } from "@seedtactics/immutable-collections";
34
+ import * as simProd from "./sim-production.js";
35
+ import * as simUse from "./sim-station-use.js";
36
+ import * as schJobs from "./scheduled-jobs.js";
37
+ import * as buffers from "./buffers.js";
38
+ import * as currentSt from "./current-status.js";
39
+ import * as insp from "./inspections.js";
40
+ import * as mats from "./material-summary.js";
41
+ import * as names from "./names.js";
42
+ import * as estimated from "./estimated-cycle-times.js";
43
+ import * as tool from "./tool-usage.js";
44
+ import * as palCycles from "./pallet-cycles.js";
45
+ import * as statCycles from "./station-cycles.js";
46
+ import * as toolReplace from "./tool-replacements.js";
47
+ import * as simDayUsage from "./sim-day-usage.js";
48
+ import * as rebookings from "./rebookings.js";
49
+ import { atom } from "jotai";
50
+ const lastEventCounterRW = atom(null);
51
+ export const lastEventCounter = lastEventCounterRW;
52
+ export const onServerEvent = atom(null, (_, set, evt) => {
53
+ set(simProd.updateLast30JobProduction, evt);
54
+ set(simUse.updateLast30SimStatUse, evt);
55
+ set(schJobs.updateLast30Jobs, evt);
56
+ set(buffers.updateLast30Buffer, evt);
57
+ set(currentSt.updateCurrentStatus, evt);
58
+ set(mats.updateLast30MatSummary, evt);
59
+ set(insp.updateLast30Inspections, evt);
60
+ set(names.updateNames, evt);
61
+ set(tool.updateLast30ToolUse, evt);
62
+ set(palCycles.updateLast30PalletCycles, evt);
63
+ set(toolReplace.updateLastToolReplacements, evt);
64
+ set(statCycles.updateLast30StationCycles, evt);
65
+ set(rebookings.updateLast30Rebookings, evt);
66
+ set(simDayUsage.updateLatestSimDayUsage, evt);
67
+ if (evt.evt.logEntry) {
68
+ const newCntr = evt.evt.logEntry.counter;
69
+ set(lastEventCounterRW, (old) => (old === null ? old : Math.max(old, newCntr)));
70
+ }
71
+ });
72
+ export const onLoadLast30Jobs = atom(null, (get, set, historicData) => {
73
+ const filtered = schJobs.filterExistingJobs(get(schJobs.last30SchIds), historicData);
74
+ set(simUse.setLast30SimStatUse, filtered);
75
+ set(simProd.setLast30JobProduction, filtered);
76
+ set(schJobs.setLast30Jobs, filtered);
77
+ set(names.setNamesFromLast30Jobs, filtered);
78
+ set(simDayUsage.setLatestSimDayUsage, filtered);
79
+ set(rebookings.setLast30RebookingJobs, filtered);
80
+ });
81
+ export const onLoadLast30Log = atom(null, (_, set, log) => {
82
+ set(estimated.setLast30EstimatedCycleTimes, log);
83
+ set(buffers.setLast30Buffer, log);
84
+ set(insp.setLast30Inspections, log);
85
+ set(mats.setLast30MatSummary, log);
86
+ set(names.setNamesFromLast30Evts, log);
87
+ set(tool.setLast30ToolUse, log);
88
+ set(palCycles.setLast30PalletCycles, log);
89
+ set(toolReplace.setLast30ToolReplacements, log);
90
+ set(statCycles.setLast30StationCycles, log);
91
+ set(rebookings.setLast30Rebookings, log);
92
+ const newCntr = LazySeq.of(log).maxBy((x) => x.counter)?.counter ?? null;
93
+ set(lastEventCounterRW, (oldCntr) => (oldCntr === null ? newCntr : Math.max(oldCntr, newCntr ?? -1)));
94
+ });
95
+ export const onLoadCurrentSt = atom(null, (_, set, curSt) => {
96
+ set(currentSt.setCurrentStatus, curSt);
97
+ set(names.setNamesFromCurrentStatus, curSt);
98
+ });
99
+ export const onLoadSpecificMonthJobs = atom(null, (_, set, historicData) => {
100
+ set(simUse.setSpecificMonthSimStatUse, historicData);
101
+ set(simProd.setSpecificMonthJobProduction, historicData);
102
+ set(schJobs.updateSpecificMonthJobs, historicData);
103
+ });
104
+ export const onLoadSpecificMonthLog = atom(null, (_, set, log) => {
105
+ set(estimated.setSpecificMonthEstimatedCycleTimes, log);
106
+ set(buffers.setSpecificMonthBuffer, log);
107
+ set(insp.setSpecificMonthInspections, log);
108
+ set(mats.setSpecificMonthMatSummary, log);
109
+ set(palCycles.setSpecificMonthPalletCycles, log);
110
+ set(toolReplace.setSpecificMonthToolReplacements, log);
111
+ set(statCycles.setSpecificMonthStationCycles, log);
112
+ });