Skip to content

Commit

Permalink
better filters
Browse files Browse the repository at this point in the history
  • Loading branch information
burnoutberni committed Mar 4, 2017
1 parent d45007a commit 3a3d723
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oeffimonitor",
"version": "0.1.1",
"version": "0.1.2",
"description": "Displays an info screen with the next Wiener Linien public transport connections nearby.",
"main": "server/httpd.js",
"directories": {
Expand Down
15 changes: 13 additions & 2 deletions server/httpd.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,21 @@ const flatten = (json, cb) => {
json.data.monitors.map(monitor => {
monitor.lines.map(line => {

// don't add departures on excluded lines
if (settings.exclude_lines && settings.exclude_lines.indexOf(line.name) > -1) {
// filter stuff as defined in settings.filters
if (settings.filters && !!settings.filters.find(filter => {
const keys = Object.keys(filter);
// check if there is a filter with only stop and line defined
if (keys.length === 2 && !!filter.stop && !!filter.line) {
// filter if both stop and line match
return filter.stop.indexOf(monitor.locationStop.properties.title) > -1
&& filter.line.indexOf(line.name) > -1;
}
// else check if there is a filter for the whole line
return keys.length === 1 && keys[0] === 'line' && filter.line.indexOf(line.name) > -1
})) {
return;
}

line.departures.departure.map(departure => {
// calculate most accurate known departure time
let time;
Expand Down
56 changes: 39 additions & 17 deletions server/settings.example.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
// add your API key here
const api_key = 'XXXXXXXXXX';

// define all RBLs of stops you want to display
const api_ids = [
"252","269", // Rathaus 2
"4205","4210", // Rathaus U2
"1346", // Landesgerichtsstraße 43, 44, N43 (stadtauswärts)
"1212", // Schottentor 37, 38, 40, 41, 42 (stadtauswärts)
"1303", // Schottentor 40A (stadtauswärts)
"3701", // Schottentor N38 (stadtauswärts, nur am Wochenende)
"5568", // Schottentor N41 (stadtauswärts)
"17", // Burgtheater/Rathausplatz D, 1, 71, N25, N38, N60, N66 (Richtung Schottentor, Nachtbusse nur wochentags)
"48", // Stadiongasse/Parlament D, 1, 71 (Richtung Volkstheater)
"1401", // Volkstheater 48A (stadtauswärts)
"1440", // Volkstheater 49 (stadtauswärts)
"4909","4908", // Volkstheater U3
"1376", // Auerspergstraße 46 (stadtauswärts)
"5691", // Auerspergstraße N46 (stadtauswärts)
"252", // Rathaus – 2 (Richtung Friedrich-Engels-Platz)
"269", // Rathaus – 2 (Richtung Ottakringer Str./Erdbrustgasse)
"4205", // Rathaus – U2 (Richtung Karlsplatz)
"4210", // Rathaus – U2 (Richtung Seestadt)
"1346", // Landesgerichtsstraße – 43, 44, N43 (stadtauswärts)
"1212", // Schottentor – 37, 38, 40, 41, 42 (stadtauswärts)
"1303", // Schottentor — 40A (stadtauswärts)
"3701", // Schottentor – N38 (stadtauswärts, nur am Wochenende)
"5568", // Schottentor – N41 (stadtauswärts)
"17", // Rathausplatz/Burgtheater – D, 1, 71, N25, N38, N60, N66 (Richtung Schottentor, Nachtbusse nur wochentags)
"48", // Stadiongasse/Parlament – D, 1, 71 (Richtung Volkstheater)
"16", // Stadiongasse/Parlament – D, 1, 2, 71 (Richtung Schottentor)
"1401", // Volkstheater – 48A (stadtauswärts)
"1440", // Volkstheater – 49 (stadtauswärts)
"4908", // Volkstheater – U3 (Richtung Ottakring)
"4909", // Volkstheater – U3 (Richtung Simmering)
"1376", // Auerspergstraße – 46 (stadtauswärts)
"5691", // Auerspergstraße – N46 (stadtauswärts)
];

const api_url = 'http://www.wienerlinien.at/ogd_realtime/monitor' +
'?activateTrafficInfo=stoerunglang' +
`&sender=${api_key}`+
'&rbl=' + api_ids.join("&rbl=");

const exclude_lines = [
'VRT',
// define filters to exclude specific departures from the monitor
// currently you can exclude lines as a whole or only at certain stops
const filters = [
{
line: ['VRT'], // excludes whole line (VRT = tourist line)
},
{
line: ['D', '1', '71'],
stop: ['Rathausplatz/Burgtheater'], // excludes lines only at given stop
},
{
line: ['2'],
stop: ['Stadiongasse/Parlament'],
},
];

// define your current location
const location_coordinate = '16.3509389,48.2103151'

// define OSRM server for routing to stops. Empty string to disable feature
const osrm_api_url = 'http://router.project-osrm.org/route/v1/foot/' + location_coordinate + ';'

module.exports = {
'api_url' : api_url,
'api_key' : api_key,
'api_ids' : api_ids,
'exclude_lines' : exclude_lines,
'filters' : filters,
'api_cache_msec' : 6000, // cache API responses for this many milliseconds; default: 6s
'listen_port' : 8080, // port to listen on
'osrm_api_url' : osrm_api_url
Expand Down

0 comments on commit 3a3d723

Please sign in to comment.