sgerp-frontend-lib 0.1.4 → 0.2.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 (81) hide show
  1. package/dist/constants/timezones.d.ts +7 -2
  2. package/dist/constants/timezones.d.ts.map +1 -1
  3. package/dist/constants/timezones.js +17 -2
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/locales/locale-server.d.ts +1 -1
  8. package/dist/locales/locale-server.d.ts.map +1 -1
  9. package/dist/locales/locale-server.js +5 -0
  10. package/dist/locales/locale.d.ts +1 -1
  11. package/dist/locales/locale.d.ts.map +1 -1
  12. package/dist/locales/locale.js +6 -2
  13. package/dist/locales/locale_en.d.ts.map +1 -1
  14. package/dist/locales/locale_en.js +236 -1
  15. package/dist/locales/locale_id.d.ts +2 -0
  16. package/dist/locales/locale_id.d.ts.map +1 -0
  17. package/dist/locales/locale_id.js +2473 -0
  18. package/dist/locales/locale_ja.d.ts.map +1 -1
  19. package/dist/locales/locale_ja.js +188 -1
  20. package/dist/locales/locale_ms.d.ts.map +1 -1
  21. package/dist/locales/locale_ms.js +60 -1
  22. package/dist/locales/locale_tl.d.ts +2 -0
  23. package/dist/locales/locale_tl.d.ts.map +1 -0
  24. package/dist/locales/locale_tl.js +1122 -0
  25. package/dist/sgerp/collection.d.ts.map +1 -1
  26. package/dist/sgerp/collection.js +18 -4
  27. package/dist/sgerp/domains.d.ts +16 -2
  28. package/dist/sgerp/domains.d.ts.map +1 -1
  29. package/dist/sgerp/domains.js +47 -1
  30. package/dist/sgerp/hooks/use-selection-state.d.ts +37 -0
  31. package/dist/sgerp/hooks/use-selection-state.d.ts.map +1 -0
  32. package/dist/sgerp/hooks/use-selection-state.js +121 -0
  33. package/dist/sgerp/hooks/use-simulation-data.d.ts +105 -0
  34. package/dist/sgerp/hooks/use-simulation-data.d.ts.map +1 -0
  35. package/dist/sgerp/hooks/use-simulation-data.js +146 -0
  36. package/dist/sgerp/hooks/use-simulation-state.d.ts +80 -0
  37. package/dist/sgerp/hooks/use-simulation-state.d.ts.map +1 -0
  38. package/dist/sgerp/hooks/use-simulation-state.js +161 -0
  39. package/dist/sgerp/index.d.ts +10 -3
  40. package/dist/sgerp/index.d.ts.map +1 -1
  41. package/dist/sgerp/index.js +30 -2
  42. package/dist/sgerp/simulation-logic/fetchUtils.d.ts +18 -0
  43. package/dist/sgerp/simulation-logic/fetchUtils.d.ts.map +1 -1
  44. package/dist/sgerp/simulation-logic/fetchUtils.js +196 -0
  45. package/dist/sgerp/simulation-logic/index.d.ts +7 -2
  46. package/dist/sgerp/simulation-logic/index.d.ts.map +1 -1
  47. package/dist/sgerp/simulation-logic/index.js +18 -1
  48. package/dist/sgerp/simulation-logic/liveUpdates.d.ts +102 -0
  49. package/dist/sgerp/simulation-logic/liveUpdates.d.ts.map +1 -0
  50. package/dist/sgerp/simulation-logic/liveUpdates.js +87 -0
  51. package/dist/sgerp/simulation-logic/prepareSimulationData.d.ts +36 -0
  52. package/dist/sgerp/simulation-logic/prepareSimulationData.d.ts.map +1 -0
  53. package/dist/sgerp/simulation-logic/prepareSimulationData.js +34 -0
  54. package/dist/sgerp/simulation-logic/routeCalculationUtils.d.ts +7 -1
  55. package/dist/sgerp/simulation-logic/routeCalculationUtils.d.ts.map +1 -1
  56. package/dist/sgerp/simulation-logic/routeCalculationUtils.js +81 -0
  57. package/dist/sgerp/simulation-logic/vrpStatsCalculator.d.ts +52 -0
  58. package/dist/sgerp/simulation-logic/vrpStatsCalculator.d.ts.map +1 -0
  59. package/dist/sgerp/simulation-logic/vrpStatsCalculator.js +247 -0
  60. package/dist/sgerp/simulation-logic/vrpStatsUtils.d.ts +17 -0
  61. package/dist/sgerp/simulation-logic/vrpStatsUtils.d.ts.map +1 -0
  62. package/dist/sgerp/simulation-logic/vrpStatsUtils.js +48 -0
  63. package/dist/sgerp/utils/timezone.d.ts +15 -0
  64. package/dist/sgerp/utils/timezone.d.ts.map +1 -0
  65. package/dist/sgerp/utils/timezone.js +19 -0
  66. package/dist/sgerp/vrptoolbox-analyzer.d.ts +39 -0
  67. package/dist/sgerp/vrptoolbox-analyzer.d.ts.map +1 -0
  68. package/dist/sgerp/vrptoolbox-analyzer.js +210 -0
  69. package/dist/vrptoolbox/collection.d.ts +16 -0
  70. package/dist/vrptoolbox/collection.d.ts.map +1 -0
  71. package/dist/vrptoolbox/collection.js +62 -0
  72. package/dist/vrptoolbox/index.d.ts +7 -0
  73. package/dist/vrptoolbox/index.d.ts.map +1 -0
  74. package/dist/vrptoolbox/index.js +24 -0
  75. package/dist/vrptoolbox/types/job.d.ts +46 -0
  76. package/dist/vrptoolbox/types/job.d.ts.map +1 -0
  77. package/dist/vrptoolbox/types/job.js +5 -0
  78. package/dist/vrptoolbox/vrptoolbox-utils.d.ts +133 -0
  79. package/dist/vrptoolbox/vrptoolbox-utils.d.ts.map +1 -0
  80. package/dist/vrptoolbox/vrptoolbox-utils.js +207 -0
  81. package/package.json +9 -4
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Live updates configuration for simulation pages
3
+ * Encapsulates polling intervals and params for vehicle, booking, node, and processor updates
4
+ */
5
+ /**
6
+ * Configuration for simulation live updates
7
+ */
8
+ export interface SimulationLiveUpdatesConfig {
9
+ /**
10
+ * Simulation ID to poll updates for
11
+ */
12
+ simulationId: number | string;
13
+ /**
14
+ * Whether live updates are enabled (typically disabled during initial loading)
15
+ */
16
+ enabled: boolean;
17
+ /**
18
+ * Callback when any collection receives updates
19
+ */
20
+ onUpdate?: (hasUpdates: boolean) => void;
21
+ }
22
+ /**
23
+ * Standard intervals for different collection types
24
+ */
25
+ export declare const LIVE_UPDATE_INTERVALS: {
26
+ readonly VEHICLE: 5000;
27
+ readonly BOOKING: 5000;
28
+ readonly NODE: 5000;
29
+ readonly PROCESSOR: 3000;
30
+ };
31
+ /**
32
+ * Standard parameters for processor live updates
33
+ */
34
+ export declare const PROCESSOR_LIVE_UPDATE_PARAMS: {
35
+ readonly processor_lifecycle_type: "one_shot";
36
+ readonly only_fields: "id,simulation_id,created_at,modified_at,start_time,state,processor_lifecycle_type,username";
37
+ readonly order_by: "-id";
38
+ readonly limit: 100;
39
+ };
40
+ /**
41
+ * Setup configuration for vehicle live updates
42
+ */
43
+ export declare function getVehicleLiveUpdateConfig(config: SimulationLiveUpdatesConfig): {
44
+ enabled: boolean;
45
+ params: {
46
+ simulation_id: string | number;
47
+ };
48
+ interval: 5000;
49
+ onUpdate: ((hasUpdates: boolean) => void) | undefined;
50
+ };
51
+ /**
52
+ * Setup configuration for booking live updates
53
+ */
54
+ export declare function getBookingLiveUpdateConfig(config: SimulationLiveUpdatesConfig): {
55
+ enabled: boolean;
56
+ params: {
57
+ simulation_id: string | number;
58
+ };
59
+ interval: 5000;
60
+ onUpdate: ((hasUpdates: boolean) => void) | undefined;
61
+ };
62
+ /**
63
+ * Setup configuration for node live updates
64
+ */
65
+ export declare function getNodeLiveUpdateConfig(config: SimulationLiveUpdatesConfig): {
66
+ enabled: boolean;
67
+ params: {
68
+ simulation_id: string | number;
69
+ };
70
+ interval: 5000;
71
+ onUpdate: ((hasUpdates: boolean) => void) | undefined;
72
+ };
73
+ /**
74
+ * Setup configuration for processor live updates
75
+ */
76
+ export declare function getProcessorLiveUpdateConfig(config: SimulationLiveUpdatesConfig): {
77
+ enabled: boolean;
78
+ params: {
79
+ processor_lifecycle_type: "one_shot";
80
+ only_fields: "id,simulation_id,created_at,modified_at,start_time,state,processor_lifecycle_type,username";
81
+ order_by: "-id";
82
+ limit: 100;
83
+ simulation_id: string | number;
84
+ };
85
+ interval: 3000;
86
+ onUpdate: ((hasUpdates: boolean) => void) | undefined;
87
+ };
88
+ /**
89
+ * Trigger functions for manual updates
90
+ */
91
+ export interface SimulationLiveUpdateTriggers {
92
+ triggerVehicleUpdate?: () => Promise<void>;
93
+ triggerBookingUpdate?: () => Promise<void>;
94
+ triggerNodeUpdate?: () => Promise<void>;
95
+ triggerProcessorUpdate?: () => Promise<void>;
96
+ }
97
+ /**
98
+ * Trigger all simulation live updates manually
99
+ * Useful after operations like autoplan, import, or bulk edits
100
+ */
101
+ export declare function triggerAllSimulationUpdates(triggers: SimulationLiveUpdateTriggers): Promise<void>;
102
+ //# sourceMappingURL=liveUpdates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liveUpdates.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/simulation-logic/liveUpdates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;CAKxB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;;CAK/B,CAAC;AAEX;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,2BAA2B;;;;;;4BA1BpD,OAAO,KAAK,IAAI;EAiCzC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,2BAA2B;;;;;;4BAtCpD,OAAO,KAAK,IAAI;EA6CzC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,2BAA2B;;;;;;4BAlDjD,OAAO,KAAK,IAAI;EAyDzC;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,2BAA2B;;;;;;;;;;4BA9DtD,OAAO,KAAK,IAAI;EAwEzC;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,oBAAoB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,oBAAoB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,sBAAsB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAED;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,QAAQ,EAAE,4BAA4B,iBAOvF"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * Live updates configuration for simulation pages
4
+ * Encapsulates polling intervals and params for vehicle, booking, node, and processor updates
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PROCESSOR_LIVE_UPDATE_PARAMS = exports.LIVE_UPDATE_INTERVALS = void 0;
8
+ exports.getVehicleLiveUpdateConfig = getVehicleLiveUpdateConfig;
9
+ exports.getBookingLiveUpdateConfig = getBookingLiveUpdateConfig;
10
+ exports.getNodeLiveUpdateConfig = getNodeLiveUpdateConfig;
11
+ exports.getProcessorLiveUpdateConfig = getProcessorLiveUpdateConfig;
12
+ exports.triggerAllSimulationUpdates = triggerAllSimulationUpdates;
13
+ /**
14
+ * Standard intervals for different collection types
15
+ */
16
+ exports.LIVE_UPDATE_INTERVALS = {
17
+ VEHICLE: 5000, // 5 seconds
18
+ BOOKING: 5000, // 5 seconds
19
+ NODE: 5000, // 5 seconds
20
+ PROCESSOR: 3000, // 3 seconds (more frequent to catch state changes quickly)
21
+ };
22
+ /**
23
+ * Standard parameters for processor live updates
24
+ */
25
+ exports.PROCESSOR_LIVE_UPDATE_PARAMS = {
26
+ processor_lifecycle_type: 'one_shot',
27
+ only_fields: 'id,simulation_id,created_at,modified_at,start_time,state,processor_lifecycle_type,username',
28
+ order_by: '-id',
29
+ limit: 100,
30
+ };
31
+ /**
32
+ * Setup configuration for vehicle live updates
33
+ */
34
+ function getVehicleLiveUpdateConfig(config) {
35
+ return {
36
+ enabled: config.enabled,
37
+ params: { simulation_id: config.simulationId },
38
+ interval: exports.LIVE_UPDATE_INTERVALS.VEHICLE,
39
+ onUpdate: config.onUpdate,
40
+ };
41
+ }
42
+ /**
43
+ * Setup configuration for booking live updates
44
+ */
45
+ function getBookingLiveUpdateConfig(config) {
46
+ return {
47
+ enabled: config.enabled,
48
+ params: { simulation_id: config.simulationId },
49
+ interval: exports.LIVE_UPDATE_INTERVALS.BOOKING,
50
+ onUpdate: config.onUpdate,
51
+ };
52
+ }
53
+ /**
54
+ * Setup configuration for node live updates
55
+ */
56
+ function getNodeLiveUpdateConfig(config) {
57
+ return {
58
+ enabled: config.enabled,
59
+ params: { simulation_id: config.simulationId },
60
+ interval: exports.LIVE_UPDATE_INTERVALS.NODE,
61
+ onUpdate: config.onUpdate,
62
+ };
63
+ }
64
+ /**
65
+ * Setup configuration for processor live updates
66
+ */
67
+ function getProcessorLiveUpdateConfig(config) {
68
+ return {
69
+ enabled: config.enabled,
70
+ params: Object.assign({ simulation_id: config.simulationId }, exports.PROCESSOR_LIVE_UPDATE_PARAMS),
71
+ interval: exports.LIVE_UPDATE_INTERVALS.PROCESSOR,
72
+ onUpdate: config.onUpdate,
73
+ };
74
+ }
75
+ /**
76
+ * Trigger all simulation live updates manually
77
+ * Useful after operations like autoplan, import, or bulk edits
78
+ */
79
+ async function triggerAllSimulationUpdates(triggers) {
80
+ var _a, _b, _c, _d;
81
+ await Promise.all([
82
+ (_a = triggers.triggerVehicleUpdate) === null || _a === void 0 ? void 0 : _a.call(triggers),
83
+ (_b = triggers.triggerBookingUpdate) === null || _b === void 0 ? void 0 : _b.call(triggers),
84
+ (_c = triggers.triggerNodeUpdate) === null || _c === void 0 ? void 0 : _c.call(triggers),
85
+ (_d = triggers.triggerProcessorUpdate) === null || _d === void 0 ? void 0 : _d.call(triggers),
86
+ ]);
87
+ }
@@ -0,0 +1,36 @@
1
+ import type { SGERPClient } from '../client';
2
+ import type { Simulation } from '../types/simulation/simulation';
3
+ import type { Booking } from '../types/simulation/booking';
4
+ import type { Vehicle } from '../types/simulation/vehicle';
5
+ import type { Driver } from '../types/simulation/driver';
6
+ import type { Geofence } from '../types/simulation/geofence';
7
+ import type { RouteNode } from '../utils/routeUtils';
8
+ export interface SimulationDataResult {
9
+ vehicles: Vehicle[];
10
+ bookings: Booking[];
11
+ nodes: RouteNode[];
12
+ drivers: Driver[];
13
+ geofences: Geofence[];
14
+ mainGeofence: Geofence | null;
15
+ vehicleRoutes: Map<number, {
16
+ waypoints: any[];
17
+ polyline?: any;
18
+ }>;
19
+ vehicleData: Map<number, {
20
+ assigned_nodes: RouteNode[];
21
+ completed_nodes: RouteNode[];
22
+ assigned_booking_uids: Set<string>;
23
+ completed_booking_uids: Set<string>;
24
+ }>;
25
+ }
26
+ /**
27
+ * Prepare all simulation data: fetch, attach references, generate routes
28
+ * This is a comprehensive function that handles the entire data preparation pipeline
29
+ *
30
+ * @param api - SGERP client instance
31
+ * @param simulationId - Simulation ID to fetch data for
32
+ * @param simulation - Optional simulation object (for fetching main geofence)
33
+ * @returns Complete simulation data with references attached and routes generated
34
+ */
35
+ export declare function prepareSimulationData(api: SGERPClient, simulationId: number | string, simulation?: Simulation | null): Promise<SimulationDataResult>;
36
+ //# sourceMappingURL=prepareSimulationData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareSimulationData.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/simulation-logic/prepareSimulationData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKrD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,YAAY,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,GAAG,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;IACjE,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE;QACvB,cAAc,EAAE,SAAS,EAAE,CAAC;QAC5B,eAAe,EAAE,SAAS,EAAE,CAAC;QAC7B,qBAAqB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QACnC,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;KACrC,CAAC,CAAC;CACJ;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,WAAW,EAChB,YAAY,EAAE,MAAM,GAAG,MAAM,EAC7B,UAAU,GAAE,UAAU,GAAG,IAAW,GACnC,OAAO,CAAC,oBAAoB,CAAC,CAyB/B"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareSimulationData = prepareSimulationData;
4
+ const fetchUtils_1 = require("./fetchUtils");
5
+ const referenceUtils_1 = require("./referenceUtils");
6
+ const routeUtils_1 = require("../utils/routeUtils");
7
+ /**
8
+ * Prepare all simulation data: fetch, attach references, generate routes
9
+ * This is a comprehensive function that handles the entire data preparation pipeline
10
+ *
11
+ * @param api - SGERP client instance
12
+ * @param simulationId - Simulation ID to fetch data for
13
+ * @param simulation - Optional simulation object (for fetching main geofence)
14
+ * @returns Complete simulation data with references attached and routes generated
15
+ */
16
+ async function prepareSimulationData(api, simulationId, simulation = null) {
17
+ // Step 1: Fetch all data
18
+ const { vehicles, bookings, nodes, drivers, geofences, mainGeofence } = await (0, fetchUtils_1.fetchSimulationData)(api, simulationId, simulation);
19
+ // Step 2: Attach references between models
20
+ const { vehicleData } = (0, referenceUtils_1.attachReferences)(bookings, vehicles, nodes);
21
+ // Step 3: Generate vehicle routes from nodes
22
+ const vehicleIds = vehicles.map(v => v.id);
23
+ const vehicleRoutes = (0, routeUtils_1.createVehicleRoutesFromNodes)(nodes, vehicleIds);
24
+ return {
25
+ vehicles,
26
+ bookings,
27
+ nodes: nodes,
28
+ drivers,
29
+ geofences,
30
+ mainGeofence,
31
+ vehicleRoutes,
32
+ vehicleData
33
+ };
34
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Vehicle } from '../types/simulation/vehicle';
2
- import type { RouteNode } from '../utils/routeUtils';
2
+ import type { RouteNode, Waypoint } from '../utils/routeUtils';
3
3
  import { Route } from '../routing';
4
+ import type { Connection } from '../types/config';
4
5
  /**
5
6
  * Calculate OSRM route for a vehicle based on its assigned nodes
6
7
  */
@@ -9,4 +10,9 @@ export declare function calculateVehicleRoute(vehicle: Vehicle, sortedNodes: Rou
9
10
  * Check if a vehicle's route has changed by comparing node IDs
10
11
  */
11
12
  export declare function hasRouteChanged(existingNodes: RouteNode[] | undefined, newNodes: RouteNode[]): boolean;
13
+ /**
14
+ * Recalculate route for a vehicle when waypoints change
15
+ * Handles route calculation and scheduled timestamp updates
16
+ */
17
+ export declare function recalculateVehicleRoute(vehicle: Vehicle, updatedWaypoints: Waypoint[], activeConnection: Connection | null): Promise<Route | null>;
12
18
  //# sourceMappingURL=routeCalculationUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routeCalculationUtils.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/simulation-logic/routeCalculationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAiB,KAAK,EAAE,MAAM,YAAY,CAAC;AAElD;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,SAAS,EAAE,EACxB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAuCvB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,SAAS,EAAE,GAAG,SAAS,EACtC,QAAQ,EAAE,SAAS,EAAE,GACpB,OAAO,CAIT"}
1
+ {"version":3,"file":"routeCalculationUtils.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/simulation-logic/routeCalculationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAiB,KAAK,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,SAAS,EAAE,EACxB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAuCvB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,SAAS,EAAE,GAAG,SAAS,EACtC,QAAQ,EAAE,SAAS,EAAE,GACpB,OAAO,CAIT;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,QAAQ,EAAE,EAC5B,gBAAgB,EAAE,UAAU,GAAG,IAAI,GAClC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAgHvB"}
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateVehicleRoute = calculateVehicleRoute;
4
4
  exports.hasRouteChanged = hasRouteChanged;
5
+ exports.recalculateVehicleRoute = recalculateVehicleRoute;
5
6
  const routing_1 = require("../routing");
7
+ const domains_1 = require("../domains");
6
8
  /**
7
9
  * Calculate OSRM route for a vehicle based on its assigned nodes
8
10
  */
@@ -41,3 +43,82 @@ function hasRouteChanged(existingNodes, newNodes) {
41
43
  const newNodeIds = newNodes.map(n => n.id).join(',');
42
44
  return existingNodeIds !== newNodeIds;
43
45
  }
46
+ /**
47
+ * Recalculate route for a vehicle when waypoints change
48
+ * Handles route calculation and scheduled timestamp updates
49
+ */
50
+ async function recalculateVehicleRoute(vehicle, updatedWaypoints, activeConnection) {
51
+ // console.log('Recalculating route for vehicle', vehicle.id, 'with', updatedWaypoints.length, 'waypoints')
52
+ // Extract all nodes from updated waypoints and flatten
53
+ const updatedNodes = [];
54
+ updatedWaypoints.forEach((waypoint) => {
55
+ waypoint.nodes.forEach((node) => {
56
+ updatedNodes.push(node);
57
+ });
58
+ });
59
+ // Sort nodes by sequence (they should already be in order from waypoints)
60
+ const sortedNodes = updatedNodes.filter((n) => n.lat && n.lon);
61
+ let calculatedRoute = null;
62
+ // Calculate OSRM route if we have enough waypoints
63
+ if (sortedNodes.length >= 2) {
64
+ const coordinates = sortedNodes.map((node) => [node.lat, node.lon]);
65
+ // Get routing engine settings from vehicle or use defaults
66
+ const settings = vehicle.routing_engine_settings || {};
67
+ const routingEngineName = settings.routing_engine_name || "osrm";
68
+ const url = settings.url || "http://mapbox-osrm-proxy";
69
+ const roadNetwork = settings.road_network || "van";
70
+ const key = settings.key || "dmVyeSBzZWNyZXQga2V5";
71
+ const curb = settings.curb !== undefined ? settings.curb : false;
72
+ // Determine backend from active connection
73
+ let defaultBackend = "production"; // default
74
+ if (activeConnection === null || activeConnection === void 0 ? void 0 : activeConnection.baseUrl) {
75
+ defaultBackend = (0, domains_1.detectBackendFromUrl)(activeConnection.baseUrl);
76
+ }
77
+ // Create routing engine with vehicle-specific settings
78
+ const routingEngine = new routing_1.RoutingEngine(routingEngineName, url, roadNetwork, key, defaultBackend, settings.speed ? { speed: settings.speed } : null);
79
+ await new Promise((resolve) => {
80
+ routingEngine.route(coordinates, curb, (result, status, message) => {
81
+ if (status === "ok" && (result === null || result === void 0 ? void 0 : result.osrmRoute)) {
82
+ calculatedRoute = result.osrmRoute;
83
+ // console.log('Route calculated successfully', result.osrmRoute)
84
+ }
85
+ else {
86
+ console.error(`Failed to recalculate route for vehicle ${vehicle.id}:`, message);
87
+ }
88
+ resolve();
89
+ });
90
+ });
91
+ }
92
+ // Recalculate scheduled_ts for all nodes based on route legs
93
+ if (calculatedRoute &&
94
+ calculatedRoute.legs) {
95
+ const route = calculatedRoute;
96
+ if (sortedNodes.length > 0 && sortedNodes[0].scheduled_ts) {
97
+ let cumulativeDurationSeconds = 0;
98
+ const startTime = new Date(sortedNodes[0].scheduled_ts).getTime();
99
+ sortedNodes.forEach((node, index) => {
100
+ if (index === 0) {
101
+ // Keep first node's scheduled_ts as is (it's the starting point)
102
+ return;
103
+ }
104
+ // Add duration from previous leg
105
+ if (route.legs[index - 1]) {
106
+ cumulativeDurationSeconds += route.legs[index - 1].duration || 0;
107
+ }
108
+ // Calculate new scheduled_ts
109
+ const newScheduledTime = new Date(startTime + cumulativeDurationSeconds * 1000);
110
+ node.scheduled_ts = newScheduledTime.toISOString();
111
+ });
112
+ // Update waypoints with new scheduled_ts
113
+ updatedWaypoints.forEach((waypoint) => {
114
+ waypoint.nodes.forEach((waypointNode) => {
115
+ const updatedNode = sortedNodes.find((n) => n.id === waypointNode.id);
116
+ if (updatedNode && updatedNode.scheduled_ts) {
117
+ waypointNode.scheduled_ts = updatedNode.scheduled_ts;
118
+ }
119
+ });
120
+ });
121
+ }
122
+ }
123
+ return calculatedRoute;
124
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * VRPToolbox Statistics Calculator
3
+ * Processes VRP payload and result to calculate fleet statistics, timeline data, and utilization
4
+ */
5
+ export interface ProcessedNode {
6
+ uid?: string;
7
+ lat: number;
8
+ lon: number;
9
+ scheduled_ts: string;
10
+ location_name?: string;
11
+ node_type: string;
12
+ service_time: number;
13
+ travel_time_from_prev: number;
14
+ nodeBreakDuration: number;
15
+ adjustedSlack: number;
16
+ booking_uid?: string;
17
+ slack?: number;
18
+ demand?: Record<string, number>;
19
+ open_time_ts?: string;
20
+ close_time_ts?: string;
21
+ scheduled_cumulative_dist?: number;
22
+ }
23
+ export interface VRPVehicleStats {
24
+ vehicleId: string;
25
+ vehicleName: string;
26
+ timelineWaypoints: ProcessedNode[];
27
+ utilizationData: Array<{
28
+ time: string;
29
+ utilization: number;
30
+ }>;
31
+ color: string;
32
+ totalDistance: string;
33
+ totalTime: string;
34
+ totalSlack: string;
35
+ totalBreakTime: string;
36
+ totalDrivingTime: string;
37
+ }
38
+ export interface FleetStats {
39
+ totalSlack: string;
40
+ totalDistance: string;
41
+ totalDrivingTime: string;
42
+ totalBreakTime: string;
43
+ }
44
+ /**
45
+ * Calculate fleet-wide statistics from processed vehicles
46
+ */
47
+ export declare function calculateFleetStats(vehicles: VRPVehicleStats[]): FleetStats;
48
+ /**
49
+ * Process VRP result and payload to generate vehicle statistics
50
+ */
51
+ export declare function processVRPStatistics(result: any, payload: any): Promise<VRPVehicleStats[]>;
52
+ //# sourceMappingURL=vrpStatsCalculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vrpStatsCalculator.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/simulation-logic/vrpStatsCalculator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,aAAa,EAAE,CAAC;IACnC,eAAe,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;CACxB;AAaD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,UAAU,CAsB3E;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,GAAG,EACX,OAAO,EAAE,GAAG,GACX,OAAO,CAAC,eAAe,EAAE,CAAC,CAsR5B"}