Skip to content

Commit

Permalink
Merge pull request #2 from infoplaza-mobility/development
Browse files Browse the repository at this point in the history
Update to latest version
  • Loading branch information
Arilith authored Dec 4, 2024
2 parents 181806c + b993aa9 commit b4609af
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 46 deletions.
31 changes: 18 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ name: Deploy to Production
on:
push:
branches:
- 'main'

workflow_dispatch:
- main
pull_request:
types:
- closed
branches:
- main

jobs:
# build:
# runs-on: ["self-hosted", "main"]
# steps:
# - name: Run compose script in Deployment repository.
# uses: benc-uk/workflow-dispatch@v1
# with:
# workflow: Deploy Docker Images of R-OV
# repo: R-OV-NL/Deploy
# token: ${{ secrets.SHARED_PAT }}
# ref: main
deploy:
name: Deploy to Production
if: github.event.pull_request.merged == true || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Run compose script in Deployment repository.
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Deploy Docker Images
repo: infoplaza-mobility/Deploy
token: ${{ secrets.SHARED_PAT }}
ref: main
65 changes: 34 additions & 31 deletions src/Models/StopUpdateCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ export class StopUpdateCollection extends Collection<RitInfoStopUpdate> {
* @private
*/
private checkIncreasingTimes() {
// Initialize variables to keep track of the last stop's arrival and departure times
let lastStopArrivalTime: number | undefined = undefined;
let lastStopDepartureTime: number | undefined = undefined;

// Loop through each stop in the collection
for (let i = 0; i < this.length; i++) {
// Get the current stop, as well as the previous and next stops (if they exist)
Expand All @@ -73,32 +69,29 @@ export class StopUpdateCollection extends Collection<RitInfoStopUpdate> {

// Check if the current stop's planned arrival time is increasing
if (currentStop.arrivalTime !== null) {
if (lastStopDepartureTime !== undefined && currentStop.arrivalTime && currentStop.arrivalTime < lastStopDepartureTime) {
if (currentStop.arrivalTime && currentStop.arrivalTime < previousStop.departureTime) {
// If the current stop's planned arrival time is not increasing, log a warning message
// console.warn(`[StopUpdateCollection ${this.tripId}] Non-increasing arrival time detected for stop ${currentStop.stationCode} [${currentStop.sequence}]`, new Date(currentStop.arrivalTime * 1000), new Date(lastStopDepartureTime * 1000))
arrivalTimeIsIncreasing = false;
}

lastStopArrivalTime = currentStop.arrivalTime;
}

// Check if the current stop's planned departure time is increasing
if (currentStop.departureTime !== null) {
if (lastStopDepartureTime !== undefined && currentStop.departureTime && currentStop.departureTime < lastStopDepartureTime) {
if (currentStop.departureTime && currentStop.departureTime < previousStop.departureTime) {

// If the current stop's planned departure time is not increasing, log a warning message
// console.warn(`[StopUpdateCollection ${this.tripId}] Non-increasing departure time detected for stop ${currentStop.stationCode} [${currentStop.sequence}]`, new Date(currentStop.departureTime * 1000), new Date(lastStopDepartureTime * 1000))
departureTimeIsIncreasing = false;
}
// Update the last stop's departure time to the current stop's planned departure time
lastStopDepartureTime = currentStop.departureTime;
}

// If both the arrival and departure times are increasing, we don't need to fix anything
if (arrivalTimeIsIncreasing && departureTimeIsIncreasing) {
continue;
}


// If there is a previous and next stop, we can fix both times
this.fixStopTime(previousStop, currentStop, !arrivalTimeIsIncreasing, !departureTimeIsIncreasing);

Expand Down Expand Up @@ -127,8 +120,6 @@ export class StopUpdateCollection extends Collection<RitInfoStopUpdate> {
* @param fixDeparture Whether the departure time should be fixed
*/
private fixStopTime(previousStop: RitInfoStopUpdate, currentStop: RitInfoStopUpdate, fixArrival: boolean, fixDeparture: boolean) {
// console.info(`[StopUpdateCollection] Fixing stop times for stop ${currentStop.stopId} [${currentStop.sequence}]`)

if(fixArrival)
this.fixArrivalTime(previousStop, currentStop);

Expand All @@ -153,19 +144,34 @@ export class StopUpdateCollection extends Collection<RitInfoStopUpdate> {
// If the current stop has no planned arrival time, we can't fix the arrival time
if (stopToFix.plannedArrivalTime === null) return;

// Calculate the new arrival time by adding the departure delay at the previous stop to the planned arrival time at the current stop
const newArrivalTime = (stopToFix.plannedArrivalTime.getTime() / 1000) + previousStop.departureDelay;
const orignalStopTime = (stopToFix.departureTime - stopToFix.arrivalTime) / 1000;

// If the new arrival time is not increasing, we can't fix the arrival time
if (newArrivalTime < previousStop.departureTime) {
console.error(`[StopUpdateCollection ${this.tripId}] Tried fixing arrival time for stop ${stopToFix.stationCode} [${stopToFix.sequence}], but the new arrival time is not increasing. New arrival time: ${new Date(newArrivalTime * 1000)}`);
}
// Calculate the base new arrival time
let newArrivalTime = (stopToFix.plannedArrivalTime.getTime() / 1000) + previousStop.departureDelay;

// Update the arrival time of the current stop
stopToFix.arrivalTime = newArrivalTime;
// Ensure the arrival time is strictly greater than the previous stop's departure time
newArrivalTime = Math.max(newArrivalTime, previousStop.departureTime + 1);

// Update the arrival delay of the current stop
stopToFix.arrivalTime = newArrivalTime;
stopToFix.arrivalDelay = previousStop.departureDelay;

//We always stay at the station about 60 seconds, so we cannot run in all delay during the stop.
if(orignalStopTime > 60)
stopToFix.departureDelay = stopToFix.arrivalDelay - (orignalStopTime - 60);
//If we weren't planned to stop for longer than a minute, we don't have to adjust the delay.
else
stopToFix.departureDelay = stopToFix.arrivalDelay;

//If there is still a departure delay after the stop, we have to adjust the departure time.
if(stopToFix.departureDelay > 0) {
//The departure time will be the delay + the arrival time.
stopToFix.departureTime = stopToFix.arrivalTime + stopToFix.departureDelay;
}
//If there is no delay, we can just set the departure time to the planned departure time.
else {
stopToFix.departureTime = stopToFix.plannedDepartureTime.getTime() / 1000;
}

}

/**
Expand All @@ -184,21 +190,18 @@ export class StopUpdateCollection extends Collection<RitInfoStopUpdate> {
// If the current stop has no actual arrival time, we can't fix the departure time
if (stopToFix.arrivalTime === null) return;

// Calculate the new departure time by adding the difference between the planned arrival and departure times to the actual arrival time
const newDepartureTime = stopToFix.arrivalTime + ((stopToFix.plannedDepartureTime.getTime() - stopToFix.plannedArrivalTime.getTime()) / 1000);
// Calculate the base new departure time
let newDepartureTime = stopToFix.arrivalTime + ((stopToFix.plannedDepartureTime.getTime() - stopToFix.plannedArrivalTime.getTime()) / 1000);

// If the new departure time is not increasing, we can't fix the departure time
if (newDepartureTime < stopToFix.arrivalTime) {
console.error(`[StopUpdateCollection ${this.tripId}] Tried fixing departure time for stop ${stopToFix.stationCode} [${stopToFix.sequence}], but the new departure time is not increasing. New departure time: ${new Date(newDepartureTime * 1000)}`);
}
// Ensure the departure time is strictly greater than the arrival time
newDepartureTime = Math.max(newDepartureTime, stopToFix.arrivalTime + 1);

// Update the departure time of the current stop
stopToFix.departureTime = newDepartureTime;

// Update the departure delay of the current stop
stopToFix.departureDelay = stopToFix.arrivalDelay;
}



/**
* Finds the last stop that is still served before only cancelled stops happen.
* Updates it so that it does not have a departure time, as it will never depart because it is the last stop now.
Expand Down Expand Up @@ -269,4 +272,4 @@ export class StopUpdateCollection extends Collection<RitInfoStopUpdate> {
return new StopUpdateCollection(withNewIndexes, this.tripId);

}
}
}
2 changes: 1 addition & 1 deletion src/Models/TrainUpdateCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class TrainUpdateCollection extends Collection<FeedEntity> {
//We do this so we can check if this update is there the next iteration as well, if not, we add a new stop time update
//that cancels the trip.
if(trainUpdate.hasCustomTripId && !this.TrainUpdatesWithCustomTripId.find(u => u.trip.tripId == trainUpdate.trip.tripId)) {
console.log(`[TrainUpdateCollection] Adding ${trainUpdate.trip.tripId} to TrainUpdatesWithCustomTripId array.`)
// console.log(`[TrainUpdateCollection] Adding ${trainUpdate.trip.tripId} to TrainUpdatesWithCustomTripId array.`)
this.TrainUpdatesWithCustomTripId.push(trainUpdate);
}

Expand Down
1 change: 1 addition & 0 deletions src/Repositories/InfoplusRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ FROM "InfoPlus-new".ritinfo r
JOIN "InfoPlus-new".stop_information si
ON jpjl."journeyPartNumber" = si."journeyPartNumber" AND
jpjl."operationDate" = si."operationDate" AND
si."stopType" != 'N' AND
("plannedWillStop" = true OR "actualWillStop" = true) AND
(coalesce("plannedDepartureTime", "actualArrivalTime") IS NOT NULL OR
coalesce("plannedArrivalTime", "actualArrivalTime") IS NOT NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/Shared

0 comments on commit b4609af

Please sign in to comment.