@tmlmobilidade/controllers 20260519.16.41 → 20260519.1741.30
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/dist/operation/lines/batch.js +21 -21
- package/dist/operation/stops/batch.js +15 -15
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { Logger } from '@tmlmobilidade/logger';
|
|
|
5
5
|
export async function getOperationalLinesBatch(query) {
|
|
6
6
|
//
|
|
7
7
|
//
|
|
8
|
-
// Use Rides as the baseline to fetch distinct
|
|
8
|
+
// Use Rides as the baseline to fetch distinct hashed_pattern_ids matching the query parameters.
|
|
9
9
|
// Rides are the glue between the different entities (Patterns, Lines, Stops, etc...) that compose an Operation,
|
|
10
10
|
// Stream the rides to build the Operation Lines batch on the fly, avoiding loading everything in memory at once.
|
|
11
11
|
const pipeline = [
|
|
@@ -17,12 +17,12 @@ export async function getOperationalLinesBatch(query) {
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
$group: {
|
|
20
|
-
_id: '$
|
|
20
|
+
_id: '$hashed_pattern_id',
|
|
21
21
|
latest_ride: {
|
|
22
22
|
$top: {
|
|
23
23
|
output: {
|
|
24
24
|
agency_id: '$agency_id',
|
|
25
|
-
|
|
25
|
+
hashed_pattern_id: '$hashed_pattern_id',
|
|
26
26
|
operational_date: '$operational_date',
|
|
27
27
|
plan_id: '$plan_id',
|
|
28
28
|
start_time_scheduled: '$start_time_scheduled',
|
|
@@ -46,15 +46,15 @@ export async function getOperationalLinesBatch(query) {
|
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
$lookup: {
|
|
49
|
-
as: '
|
|
49
|
+
as: 'hashed_pattern_doc',
|
|
50
50
|
foreignField: '_id',
|
|
51
|
-
from: '
|
|
52
|
-
localField: '
|
|
51
|
+
from: 'hashed_patterns',
|
|
52
|
+
localField: 'hashed_pattern_id',
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
$unwind: {
|
|
57
|
-
path: '$
|
|
57
|
+
path: '$hashed_pattern_doc',
|
|
58
58
|
preserveNullAndEmptyArrays: true,
|
|
59
59
|
},
|
|
60
60
|
},
|
|
@@ -62,7 +62,7 @@ export async function getOperationalLinesBatch(query) {
|
|
|
62
62
|
$project: {
|
|
63
63
|
_id: 0,
|
|
64
64
|
agency_id: 1,
|
|
65
|
-
|
|
65
|
+
hashed_pattern_doc: 1, // full joined document
|
|
66
66
|
operational_date: 1,
|
|
67
67
|
plan_id: 1,
|
|
68
68
|
start_time_scheduled: 1,
|
|
@@ -77,32 +77,32 @@ export async function getOperationalLinesBatch(query) {
|
|
|
77
77
|
//
|
|
78
78
|
// Setup the final Map to keep track of the Operation Lines,
|
|
79
79
|
// using the line_id as the key to avoid duplicates,
|
|
80
|
-
// since multiple
|
|
80
|
+
// since multiple hashed_pattern_ids can belong to the same line_id.
|
|
81
81
|
const operationalLinesMap = new Map();
|
|
82
82
|
pipelineResult.forEach((item) => {
|
|
83
83
|
// Initialize the line in the map if it doesn't exist yet
|
|
84
|
-
if (!operationalLinesMap.has(item.
|
|
85
|
-
operationalLinesMap.set(item.
|
|
84
|
+
if (!operationalLinesMap.has(item.hashed_pattern_doc.line_id)) {
|
|
85
|
+
operationalLinesMap.set(item.hashed_pattern_doc.line_id, {
|
|
86
86
|
agency_id: item.agency_id,
|
|
87
|
-
|
|
87
|
+
hashed_patterns: [],
|
|
88
88
|
last_operational_date: item.operational_date,
|
|
89
89
|
last_plan_id: item.plan_id,
|
|
90
|
-
line_id: item.
|
|
91
|
-
line_long_name: item.
|
|
92
|
-
line_short_name: item.
|
|
90
|
+
line_id: item.hashed_pattern_doc.line_id,
|
|
91
|
+
line_long_name: item.hashed_pattern_doc.line_long_name,
|
|
92
|
+
line_short_name: item.hashed_pattern_doc.line_short_name,
|
|
93
93
|
pattern_ids: [],
|
|
94
|
-
route_color: item.
|
|
94
|
+
route_color: item.hashed_pattern_doc.route_color,
|
|
95
95
|
route_ids: [],
|
|
96
96
|
stop_ids: [],
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
// Get the saved line from the map
|
|
100
|
-
const savedOperationalLine = operationalLinesMap.get(item.
|
|
100
|
+
const savedOperationalLine = operationalLinesMap.get(item.hashed_pattern_doc.line_id);
|
|
101
101
|
// Update the object with the latest fields
|
|
102
|
-
savedOperationalLine.route_ids = Array.from(new Set([...savedOperationalLine.route_ids, item.
|
|
103
|
-
savedOperationalLine.pattern_ids = Array.from(new Set([...savedOperationalLine.pattern_ids, item.
|
|
104
|
-
savedOperationalLine.stop_ids = Array.from(new Set([...savedOperationalLine.stop_ids, ...(item.
|
|
105
|
-
savedOperationalLine.
|
|
102
|
+
savedOperationalLine.route_ids = Array.from(new Set([...savedOperationalLine.route_ids, item.hashed_pattern_doc.route_id]));
|
|
103
|
+
savedOperationalLine.pattern_ids = Array.from(new Set([...savedOperationalLine.pattern_ids, item.hashed_pattern_doc.pattern_id]));
|
|
104
|
+
savedOperationalLine.stop_ids = Array.from(new Set([...savedOperationalLine.stop_ids, ...(item.hashed_pattern_doc.path.map(stop => stop.stop_id) ?? [])]));
|
|
105
|
+
savedOperationalLine.hashed_patterns.push(item.hashed_pattern_doc);
|
|
106
106
|
});
|
|
107
107
|
//
|
|
108
108
|
// Send the response
|
|
@@ -5,7 +5,7 @@ import { Logger } from '@tmlmobilidade/logger';
|
|
|
5
5
|
export async function getOperationalStopsBatch(query) {
|
|
6
6
|
//
|
|
7
7
|
//
|
|
8
|
-
// Use Rides as the baseline to fetch distinct
|
|
8
|
+
// Use Rides as the baseline to fetch distinct hashed_pattern_ids matching the query parameters.
|
|
9
9
|
// Rides are the glue between the different entities (Patterns, Lines, Stops, etc...) that compose an Operation,
|
|
10
10
|
// Stream the rides to build the Operation Stops batch on the fly, avoiding loading everything in memory at once.
|
|
11
11
|
const pipeline = [
|
|
@@ -17,12 +17,12 @@ export async function getOperationalStopsBatch(query) {
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
$group: {
|
|
20
|
-
_id: '$
|
|
20
|
+
_id: '$hashed_pattern_id',
|
|
21
21
|
latest_ride: {
|
|
22
22
|
$top: {
|
|
23
23
|
output: {
|
|
24
24
|
agency_id: '$agency_id',
|
|
25
|
-
|
|
25
|
+
hashed_pattern_id: '$hashed_pattern_id',
|
|
26
26
|
operational_date: '$operational_date',
|
|
27
27
|
plan_id: '$plan_id',
|
|
28
28
|
start_time_scheduled: '$start_time_scheduled',
|
|
@@ -46,15 +46,15 @@ export async function getOperationalStopsBatch(query) {
|
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
$lookup: {
|
|
49
|
-
as: '
|
|
49
|
+
as: 'hashed_pattern_doc',
|
|
50
50
|
foreignField: '_id',
|
|
51
|
-
from: '
|
|
52
|
-
localField: '
|
|
51
|
+
from: 'hashed_patterns',
|
|
52
|
+
localField: 'hashed_pattern_id',
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
$unwind: {
|
|
57
|
-
path: '$
|
|
57
|
+
path: '$hashed_pattern_doc',
|
|
58
58
|
preserveNullAndEmptyArrays: true,
|
|
59
59
|
},
|
|
60
60
|
},
|
|
@@ -62,7 +62,7 @@ export async function getOperationalStopsBatch(query) {
|
|
|
62
62
|
$project: {
|
|
63
63
|
_id: 0,
|
|
64
64
|
agency_id: 1,
|
|
65
|
-
|
|
65
|
+
hashed_pattern_doc: 1, // full joined document
|
|
66
66
|
operational_date: 1,
|
|
67
67
|
plan_id: 1,
|
|
68
68
|
start_time_scheduled: 1,
|
|
@@ -77,15 +77,15 @@ export async function getOperationalStopsBatch(query) {
|
|
|
77
77
|
//
|
|
78
78
|
// Setup the final Map to keep track of the Operation Stops,
|
|
79
79
|
// using the stop_id as the key to avoid duplicates,
|
|
80
|
-
// since multiple
|
|
80
|
+
// since multiple hashed_pattern_ids can belong to the same stop_id.
|
|
81
81
|
const operationalStopsMap = new Map();
|
|
82
82
|
pipelineResult.forEach((item) => {
|
|
83
|
-
item.
|
|
83
|
+
item.hashed_pattern_doc.path.forEach((waypoint) => {
|
|
84
84
|
// Initialize the stop in the map if it doesn't exist yet
|
|
85
85
|
if (!operationalStopsMap.has(waypoint.stop_id)) {
|
|
86
86
|
operationalStopsMap.set(waypoint.stop_id, {
|
|
87
87
|
agency_ids: [],
|
|
88
|
-
|
|
88
|
+
hashed_patterns: [],
|
|
89
89
|
last_operational_date: item.operational_date,
|
|
90
90
|
last_plan_id: item.plan_id,
|
|
91
91
|
line_ids: [],
|
|
@@ -99,10 +99,10 @@ export async function getOperationalStopsBatch(query) {
|
|
|
99
99
|
const savedOperationalStop = operationalStopsMap.get(waypoint.stop_id);
|
|
100
100
|
// Update the object with the latest fields
|
|
101
101
|
savedOperationalStop.agency_ids = Array.from(new Set([...savedOperationalStop.agency_ids, item.agency_id]));
|
|
102
|
-
savedOperationalStop.line_ids = Array.from(new Set([...savedOperationalStop.line_ids, item.
|
|
103
|
-
savedOperationalStop.route_ids = Array.from(new Set([...savedOperationalStop.route_ids, item.
|
|
104
|
-
savedOperationalStop.pattern_ids = Array.from(new Set([...savedOperationalStop.pattern_ids, item.
|
|
105
|
-
savedOperationalStop.
|
|
102
|
+
savedOperationalStop.line_ids = Array.from(new Set([...savedOperationalStop.line_ids, item.hashed_pattern_doc.line_id]));
|
|
103
|
+
savedOperationalStop.route_ids = Array.from(new Set([...savedOperationalStop.route_ids, item.hashed_pattern_doc.route_id]));
|
|
104
|
+
savedOperationalStop.pattern_ids = Array.from(new Set([...savedOperationalStop.pattern_ids, item.hashed_pattern_doc.pattern_id]));
|
|
105
|
+
savedOperationalStop.hashed_patterns.push(item.hashed_pattern_doc);
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
//
|