Groundwork for filtering services based on STP indicator
This commit is contained in:
parent
39dd93edb5
commit
574d232867
@ -16,9 +16,7 @@ async function findByHeadcodeToday(headcode) {
|
|||||||
daysRun: {$in: [shortDay]}
|
daysRun: {$in: [shortDay]}
|
||||||
};
|
};
|
||||||
const queryData = await db.query('timetable', query);
|
const queryData = await db.query('timetable', query);
|
||||||
let trainData = queryData;
|
let trainData = await parseTrains(queryData, now);
|
||||||
// At this point, the returned objects need sorting to ensure the correct object is returned.
|
|
||||||
// C, N, O, P is the order - C being the preferred, then N, then O and finally P.
|
|
||||||
let preparedData = [];
|
let preparedData = [];
|
||||||
for (const trainService in trainData) {
|
for (const trainService in trainData) {
|
||||||
// Search for PIS Code for each service
|
// Search for PIS Code for each service
|
||||||
@ -30,6 +28,12 @@ async function findByHeadcodeToday(headcode) {
|
|||||||
return preparedData;
|
return preparedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
findByHeadcodeToday,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Internal Functions, not to be exported */
|
||||||
|
|
||||||
async function getPublicStops(data) {
|
async function getPublicStops(data) {
|
||||||
let tiplocList = [];
|
let tiplocList = [];
|
||||||
for (const publicStop in data) {
|
for (const publicStop in data) {
|
||||||
@ -40,6 +44,18 @@ async function getPublicStops(data) {
|
|||||||
return tiplocList;
|
return tiplocList;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
async function parseTrains(data, date = new Date() {
|
||||||
findByHeadcodeToday,
|
// Parses an array returned from a db-query and removes any service entries that don't apply to {date}
|
||||||
};
|
// {date} shoule be a datetime object and defaults to now if not provided - as a general rule it should always be provided for clarity
|
||||||
|
|
||||||
|
// At this point, the returned objects need sorting to ensure the correct object is returned.
|
||||||
|
// C, N, O, P is the order - C being the preferred, then N, then O and finally P.
|
||||||
|
// If stpindicator == "C" && trainUid (isSame as N, O or P entry) => DO NOT DISPLAY SERVICE ("C" records do not contain the headcode (signalling_id)) so an additional lookup needs to be performed for the trainUid.
|
||||||
|
// If stpIndicator == "N" && trainUid (isSame as O or P entry) => Display this instead of "O", or "P"
|
||||||
|
// If stpIndicaor == "O" && trainUid (isSame as P entry) => Display this instead of "P"
|
||||||
|
// Obviously, remember that several trains can share a headcode, but the trainUid is unique for each service.
|
||||||
|
// Probably best to loop through each return here and add to a new [], then if another entry supersedes it, overwrite it in the []. Then pass to the below part of the function to process the data for sending.
|
||||||
|
// Maybe break in to a new function parseTrains() which can take in any dbquery array and remove any services that are not meant to be displayed based on the data provided. Maybe have a date as an input so it can be used in the future to fetch trains for a given date in the future - due to database cleaning in db-manager, past dates would need adjustments to how the database is cleaned leaving outdated services available.
|
||||||
|
const parsedDate = data;
|
||||||
|
return parsedData;
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user