-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from openplannerteam/dev
Release 0.0.2-alpha
- Loading branch information
Showing
41 changed files
with
1,143 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,75 @@ | ||
// @ts-ignore | ||
import { EventEmitter, Listener } from "events"; | ||
import { Container, injectable } from "inversify"; | ||
|
||
/** | ||
* The Context serves as event pass through and holder of the inversify container object. | ||
* Proxies an internal EventEmitter because ´decorate(injectable(), EventEmitter)´ causes | ||
* errors when running tests in Jest | ||
*/ | ||
@injectable() | ||
export default class Context { | ||
// @ts-ignore | ||
export default class Context implements EventEmitter { | ||
private emitter: EventEmitter; | ||
private container: Container; | ||
|
||
constructor() { | ||
this.emitter = new EventEmitter(); | ||
} | ||
|
||
public setContainer(container: Container) { | ||
this.container = container; | ||
} | ||
|
||
public getContainer() { | ||
return this.container; | ||
} | ||
|
||
public addListener(type: string | symbol, listener: Listener): this { | ||
this.emitter.addListener(type, listener); | ||
|
||
return this; | ||
} | ||
|
||
public emit(type: string | symbol, ...args: any[]): boolean { | ||
return this.emitter.emit(type, ...args); | ||
} | ||
|
||
public listenerCount(type: string | symbol): number { | ||
return this.emitter.listenerCount(type); | ||
} | ||
|
||
public listeners(type: string | symbol): Listener[] { | ||
return this.emitter.listeners(type); | ||
} | ||
|
||
public on(type: string | symbol, listener: Listener): this { | ||
this.emitter.on(type, listener); | ||
|
||
return this; | ||
} | ||
|
||
public once(type: string | symbol, listener: Listener): this { | ||
this.emitter.once(type, listener); | ||
|
||
return this; | ||
} | ||
|
||
public removeAllListeners(type?: string | symbol): this { | ||
this.emitter.removeAllListeners(type); | ||
|
||
return this; | ||
} | ||
|
||
public removeListener(type: string | symbol, listener: Listener): this { | ||
this.emitter.removeListener(type, listener); | ||
|
||
return this; | ||
} | ||
|
||
public setMaxListeners(n: number): this { | ||
this.emitter.setMaxListeners(n); | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
enum EventType { | ||
Query = "query", | ||
QueryExponential = "query-exponential", | ||
QueryAbort = "query-abort", | ||
LDFetchGet = "ldfetch-get", | ||
ConnectionScan = "connection-scan", | ||
FinalReachableStops = "final-reachable-stops", | ||
InitialReachableStops = "initial-reachable-stops", | ||
AddedNewTransferProfile = "added-new-transfer-profile", | ||
} | ||
|
||
export default EventType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Catalog from "./Catalog"; | ||
import TravelMode from "./TravelMode"; | ||
|
||
const catalog = new Catalog(); | ||
|
||
catalog.addStopsFetcher("http://openplanner.ilabt.imec.be/delijn/Antwerpen/stops"); | ||
catalog.addStopsFetcher("http://openplanner.ilabt.imec.be/delijn/Limburg/stops"); | ||
catalog.addStopsFetcher("http://openplanner.ilabt.imec.be/delijn/Oost-Vlaanderen/stops"); | ||
catalog.addStopsFetcher("http://openplanner.ilabt.imec.be/delijn/Vlaams-Brabant/stops"); | ||
catalog.addStopsFetcher("http://openplanner.ilabt.imec.be/delijn/West-Vlaanderen/stops"); | ||
|
||
catalog.addConnectionsFetcher("http://openplanner.ilabt.imec.be/delijn/Antwerpen/connections", TravelMode.Bus); | ||
catalog.addConnectionsFetcher("http://openplanner.ilabt.imec.be/delijn/Limburg/connections", TravelMode.Bus); | ||
catalog.addConnectionsFetcher("http://openplanner.ilabt.imec.be/delijn/Oost-Vlaanderen/connections", TravelMode.Bus); | ||
catalog.addConnectionsFetcher("http://openplanner.ilabt.imec.be/delijn/Vlaams-Brabant/connections", TravelMode.Bus); | ||
catalog.addConnectionsFetcher("http://openplanner.ilabt.imec.be/delijn/West-Vlaanderen/connections", TravelMode.Bus); | ||
|
||
export default catalog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Catalog from "./Catalog"; | ||
import TravelMode from "./TravelMode"; | ||
|
||
const catalog = new Catalog(); | ||
catalog.addStopsFetcher("https://irail.be/stations/NMBS"); | ||
catalog.addConnectionsFetcher("https://graph.irail.be/sncb/connections", TravelMode.Train); | ||
|
||
export default catalog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,69 @@ | ||
import EventType from "./EventType"; | ||
import Planner from "./index"; | ||
import IPath from "./interfaces/IPath"; | ||
import Units from "./util/Units"; | ||
|
||
export default async (logResults) => { | ||
|
||
const planner = new Planner(); | ||
|
||
// const roadOnlyResult = await planner.query({ | ||
// roadOnly: true, | ||
// from: "http://irail.be/stations/NMBS/008896008", // Kortrijk | ||
// to: "http://irail.be/stations/NMBS/008892007", // Ghent-Sint-Pieters | ||
// }); | ||
// | ||
// roadOnlyResult.each((path) => { | ||
// if (logResults) { | ||
// console.log(path); | ||
// } | ||
// }); | ||
if (logResults) { | ||
let scannedPages = 0; | ||
let scannedConnections = 0; | ||
|
||
console.time("Public transport planner"); | ||
planner | ||
.on(EventType.Query, (query) => { | ||
console.log("Query", query); | ||
}) | ||
.on(EventType.QueryExponential, (query) => { | ||
const { minimumDepartureTime, maximumArrivalTime } = query; | ||
|
||
console.log("Total scanned pages", scannedPages); | ||
console.log("Total scanned connections", scannedConnections); | ||
console.log("[Subquery]", minimumDepartureTime, maximumArrivalTime, maximumArrivalTime - minimumDepartureTime); | ||
}) | ||
.on(EventType.LDFetchGet, (url, duration) => { | ||
scannedPages++; | ||
console.log(`[GET] ${url} (${duration}ms)`); | ||
}) | ||
.on(EventType.ConnectionScan, (connection) => { | ||
scannedConnections++; | ||
}); | ||
} | ||
|
||
const publicTransportResult = await planner.query({ | ||
publicTransportOnly: true, | ||
// from: "https://data.delijn.be/stops/201657", | ||
// to: "https://data.delijn.be/stops/205910", | ||
// from: "https://data.delijn.be/stops/200455", // Deinze weg op Grammene +456 | ||
// to: "https://data.delijn.be/stops/502481", // Tielt Metaalconstructie Goossens | ||
// from: "https://data.delijn.be/stops/509927", // Tield Rameplein perron 1 | ||
// to: "https://data.delijn.be/stops/200455", // Deinze weg op Grammene +456 | ||
from: "http://irail.be/stations/NMBS/008896925", // Ingelmunster | ||
to: "http://irail.be/stations/NMBS/008892007", // Ghent-Sint-Pieters | ||
minimumDepartureTime: new Date(), | ||
maximumTransferDuration: Units.fromHours(.5), | ||
maximumTransferDuration: Units.fromHours(0.5), | ||
}); | ||
|
||
console.timeEnd("Public transport planner"); | ||
|
||
let i = 0; | ||
return new Promise((resolve, reject) => { | ||
let i = 0; | ||
|
||
publicTransportResult.on("readable", () => { | ||
let path = publicTransportResult.read(); | ||
publicTransportResult.take(3) | ||
.on("data", (path: IPath) => { | ||
++i; | ||
|
||
while (path && i < 5) { | ||
console.log(i++, path); | ||
if (logResults) { | ||
console.log(i); | ||
console.log(JSON.stringify(path, null, " ")); | ||
console.log("\n"); | ||
} | ||
|
||
path = publicTransportResult.read(); | ||
} | ||
if (i === 3) { | ||
resolve(true); | ||
} | ||
}) | ||
.on("end", () => { | ||
resolve(false); | ||
}); | ||
}); | ||
|
||
return true; | ||
}; |
Oops, something went wrong.