|
|
@ -5,8 +5,6 @@ const network = require("./network.json"); |
|
|
|
|
|
|
|
const server = "http://localhost:4321"; |
|
|
|
|
|
|
|
const stops = Object.keys(network.stops); |
|
|
|
|
|
|
|
const findRoute = (from, to) => { |
|
|
|
const queue = [[from, []]]; |
|
|
|
|
|
|
@ -84,7 +82,7 @@ class Course { |
|
|
|
} |
|
|
|
} else if (this.state === "moving") { |
|
|
|
const index = this.nextPassings.findIndex( |
|
|
|
([stop, ]) => stop === this.arrivalStop |
|
|
|
([stop]) => stop === this.arrivalStop |
|
|
|
); |
|
|
|
|
|
|
|
if (index === -1 || this.nextPassings[index][1] <= now) { |
|
|
@ -99,7 +97,7 @@ class Course { |
|
|
|
// (this.state === 'stopped')
|
|
|
|
// Try moving to the next stop
|
|
|
|
const index = this.nextPassings.findIndex( |
|
|
|
([stop, ]) => stop === this.currentStop |
|
|
|
([stop]) => stop === this.currentStop |
|
|
|
); |
|
|
|
|
|
|
|
if (index !== -1) { |
|
|
@ -123,11 +121,11 @@ class Course { |
|
|
|
let found = false; |
|
|
|
|
|
|
|
for ( |
|
|
|
let index = 0; |
|
|
|
index < this.nextPassings.length; |
|
|
|
++index |
|
|
|
let nextIndex = 0; |
|
|
|
nextIndex < this.nextPassings.length; |
|
|
|
++nextIndex |
|
|
|
) { |
|
|
|
const [stop, arrivalTime] = this.nextPassings[index]; |
|
|
|
const [stop, arrivalTime] = this.nextPassings[nextIndex]; |
|
|
|
|
|
|
|
if (arrivalTime > now) { |
|
|
|
const route = findRoute(this.currentStop, stop); |
|
|
@ -173,7 +171,8 @@ class Course { |
|
|
|
const segment = this.currentSegment; |
|
|
|
const distance = segment.properties.length - this.traveledDistance; |
|
|
|
const duration = this.arrivalTime - Date.now(); |
|
|
|
this.speed = this.computeSpeed(distance, duration); |
|
|
|
|
|
|
|
this.speed = Course.computeSpeed(distance, duration); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
@ -247,7 +246,7 @@ ${this.currentStop} to stop ${stop}. Teleporting to ${stop}`); |
|
|
|
const distance = network.segments[segmentId].properties.length; |
|
|
|
const duration = arrivalTime - Date.now(); |
|
|
|
|
|
|
|
if (this.computeSpeed(distance, duration) === 0) { |
|
|
|
if (Course.computeSpeed(distance, duration) === 0) { |
|
|
|
// Speed would be too low, better wait for some time
|
|
|
|
return; |
|
|
|
} |
|
|
@ -260,7 +259,7 @@ ${this.currentStop} to stop ${stop}. Teleporting to ${stop}`); |
|
|
|
this.speed = 0; |
|
|
|
} |
|
|
|
|
|
|
|
computeSpeed(distance, duration) { |
|
|
|
static computeSpeed(distance, duration) { |
|
|
|
if (duration <= 0) { |
|
|
|
// Late: go to maximum speed
|
|
|
|
return 50 / 3600; |
|
|
|