derhuerst / vbb-stations-cli

Find and filter VBB stations from the command line.
https://github.com/derhuerst/vbb-stations-cli
ISC License
4 stars 0 forks source link

Get stations closest to current location #1

Closed JayBrown closed 8 years ago

JayBrown commented 8 years ago

Trying to use my location data to get a list of the closest stations, currently like this, but it doesn't work:

LOCATION_DATA=$(/usr/local/bin/LocateMe -l)
LAT=$(echo "$LOCATION_DATA" | /usr/bin/awk '/Latitude: / {print $2}')
LONG=$(echo "$LOCATION_DATA" | /usr/bin/awk '/Longitude: / {print $2}')
/usr/local/bin/vbb-stations --latitude "$LAT" --longitude "$LONG" --format csv | /usr/bin/awk -F"," '{print $2}'

Any hints? ty.

derhuerst commented 8 years ago
LOCATION_DATA=$(/usr/local/bin/LocateMe -l)
LAT=$(echo "$LOCATION_DATA" | /usr/bin/awk '/Latitude: / {print $2}')
LONG=$(echo "$LOCATION_DATA" | /usr/bin/awk '/Longitude: / {print $2}')

For this, I suggest CoreLocationCLI. It has a --format option.

/usr/local/bin/vbb-stations --latitude "$LAT" --longitude "$LONG" --format csv | /usr/bin/awk -F"," '{print $2}'

As vbb-stations is not made for end-users, it only shows exact matches. I guess there's no station with exactly your lat&long.

derhuerst commented 8 years ago

Have a look at how vbb-cli finds stations close to a location.

JayBrown commented 8 years ago

Ah, thank you. So I need to install the vbb-cli. Good to know.

Thank you also for the CoreLocationCLI info. Much appreciated.

derhuerst commented 8 years ago

Ah, thank you. So I need to install the vbb-cli. Good to know.

You don't need to, it was just an example how to find the closest stations.

What do you want to do anyway?

JayBrown commented 8 years ago

Just a script for myself, for private use, running from a BitBar instance in the menu bar – https://github.com/matryer/bitbar … it would be a shell script with some osascript for user input (date/time), station selections etc. (I don't like using the VBB websites for that.) I don't know if it's possible, but I won't know if I don't try. :)

derhuerst commented 8 years ago

Sounds great! Is it open source? I'd love to use it and to contribute!

JayBrown commented 8 years ago

Best to show you what I'm currently using; see test code below (you can just save it as .sh, chmod+x it, and load it in BitBar). I would build on that, more or less, and the optimum would be a full-fledged VBB-script, with automatic departure station lookup based on geolocation, alternatively user-defined departure stations, arrival stations, date & time (either departure or arrival), favorite stations menu (coupled with an sqlite db). You could probably tweak a lot more out of it, including href to map services. The best thing would probably be a real menulet programmed in SWIFT, but I only know shell scripting and a bit of AppleScript. Don't even know js. One problem, though, would be (a) how to make this all happen just from within a simple menu, and (b) how to output the results; you could always do it with an AppleScript window, or you could do it within the menu itself. But that's the far future. :) I would surely appreciate any help, but please be warned, because I'm (a) neither a very good coder nor (b) do I have a lot of time. (This was kinda planned as a side-project in my spare time.) And yes, if anything, it would be open source.

#!/bin/bash

# BitBar test script

# Menu bar title
echo "VBB| dropdown=false"

# MISC
echo "---"
echo "Miscellaneous"
echo "--VBB | terminal=false bash=$0 param1=vbb"

# VBB query
if [[ "$1" == "vbb" ]] ; then
    DEST_CHOICE=$(/usr/bin/osascript << EOT
tell application "System Events"
    activate
    set theDestinationList to {"S+U Gesundbrunnen Bhf (Berlin)", "S Ostbahnhof (Berlin)", "S+U Berlin Hauptbahnhof", "Other"}
    set theDestination to (choose from list theDestinationList with prompt "Please choose your destination" ¬
    with title "Default Destinations" without multiple selections allowed)
    return the result as string
end tell
theDestination
EOT)
    if [[ "$DEST_CHOICE" == "" ]] ; then
        /usr/bin/osascript -e 'display notification with title "VBB Schedule" subtitle "'"$ACCOUNT"' has canceled"' &> /dev/null
        exit
    fi
    if [[ "$DEST_CHOICE" == "Other" ]] ; then
        DEST_ENTRY=$(/usr/bin/osascript << EOT
tell application "System Events"
    activate
    set theLogoPath to ".VolumeIcon.icns"
    set theDestination to text returned of (display dialog "Please enter your destination" ¬
        default answer "" ¬
        with title "User-Defined Destination" ¬
        with icon file theLogoPath ¬
        giving up after 120)
end tell
theDestination
EOT)
        if [[ "$DEST_ENTRY" == "" ]] ; then
            /usr/bin/osascript -e 'display notification with title "VBB Schedule" subtitle "'"$ACCOUNT"' has canceled"' &> /dev/null
            exit
        else
            USER_CHOICE="true"
        fi
    fi
    if [[ "$USER_CHOICE" == "true" ]] ; then
        VBB_DEST="$DEST_ENTRY"
        DEFAULT_TIME="15:00"
    else
        if [[ "$DEST_CHOICE" == "S+U Gesundbrunnen Bhf (Berlin)" ]] ; then
            DEFAULT_TIME="18:20"
        elif [[ "$DEST_CHOICE" == "S Ostbahnhof (Berlin)" ]] ; then
            DEFAULT_TIME="14:20"
        elif [[ "$DEST_CHOICE" == "S+U Berlin Hauptbahnhof" ]] ; then
            DEFAULT_TIME="18:20"
        fi
        VBB_DEST="$DEST_CHOICE"
    fi
    SELECTED_ARRIVAL=$(/usr/bin/osascript << EOT
tell application "System Events"
    activate
    set theLogoPath to ".VolumeIcon.icns"
    set {theDay, theArrivalTime} to {button returned, text returned} of (display dialog "Please enter your arrival time" ¬
        buttons {"Cancel", "Tomorrow", "Today"} ¬
        default button 3 ¬
        default answer "$DEFAULT_TIME" ¬
        with title "Destination: $VBB_DEST" ¬
        with icon file theLogoPath ¬
        giving up after 120)
end tell
theDay & "@@@" & theArrivalTime
EOT)
    if [[ "$SELECTED_ARRIVAL" == "" ]] ; then
        /usr/bin/osascript -e 'display notification with title "VBB Schedule" subtitle "'"$ACCOUNT"' has canceled"' &> /dev/null
        exit
    fi
    if [[ "$SELECTED_ARRIVAL" == "Tomorrow@@@" ]] || [[ "$SELECTED_ARRIVAL" == "Today@@@" ]] || [[ "$SELECTED_ARRIVAL" == "@@@" ]] ; then
        /usr/bin/osascript -e 'display notification "Input error!" with title "VBB Schedule" subtitle "'"$ACCOUNT"' has canceled"' &> /dev/null
        exit
    fi
    SELECTED_DAY=$(echo "$SELECTED_ARRIVAL" | /usr/bin/awk -F@@@ '{print $1}')
    if [[ "$SELECTED_DAY" == "Tomorrow" ]] ; then
        ARRIVAL_DATE=$(date -v +1d +"%d.%m.%Y")
    elif [[ "$SELECTED_DAY" == "Today" ]] ; then
        ARRIVAL_DATE=$(date +"%d.%m.%Y")
    else
        /usr/bin/osascript -e 'display notification "Internal error!" with title "VBB Schedule" subtitle "'"$ACCOUNT"' has canceled"' &> /dev/null
        exit
    fi
    ARRIVAL_TIME=$(echo "$SELECTED_ARRIVAL" | /usr/bin/awk -F@@@ '{print $2}')
    VBB_DEPARTURE="U Schönleinstr. (Berlin)"
    VBB_URL="http://fahrinfo.bvg.de/Fahrinfo/bin/query.bin/en?pk_campaign=BVG.de_Eingabe&from="$VBB_DEPARTURE"&to="$VBB_DEST"&date="$ARRIVAL_DATE"&time="$ARRIVAL_TIME"&timesel=arrive&lang=en&start=1"
    open -a "Safari" "$VBB_URL"
    exit
fi
derhuerst commented 8 years ago

I would build on that, more or less, and the optimum would be a full-fledged VBB-script, with automatic departure station lookup based on geolocation, alternatively user-defined departure stations, arrival stations, date & time (either departure or arrival), favorite stations menu (coupled with an sqlite db).

I think for a small menu bar app, less functionality is appropriate. Something like "just show me the next stations around me with a link to map" or "when do the trains run at all stations which i marked as favorite?".

for a fully fledged app, something like a real GUI app or a command line app with all it's benefits (piping, filtering) seems more appropriate.

But regardless of that, IMO a menu bar app is a great idea! I'd love to contribute to a repository!

Also, have you checked out my telegram bot? It's @public_transport_bot on Telegram.

JayBrown commented 8 years ago

The main reason for me is to determine how to go from A to B at a certain date & time, e.g. I have a meeting tomorrow at a certain place, and I will start at a certain station, so I'll need to input (or select from favorites or from the geolocation menu) the start station or address, the destination station or address, the date, and the arrival time. This could be coupled with Apple Maps, Apple Reminders etc. Determining which trains and buses will be leaving near my current position from which station, is not a priority. It should be one of the functionalities, for sure, but not the main one. But first I have to wait for my API key, anyway, before I can do anything. ;)

PS: what's that with the telegram bot? Tried the URL, but it redirects to tg://resolve?domain=public_transport_bot. Don't know what to do with that, or which app to use.

derhuerst commented 8 years ago

The main reason for me is to determine how to go from A to B at a certain date & time, e.g. I have a meeting tomorrow at a certain place, and I will start at a certain station, so I'll need to input (or select from favorites or from the geolocation menu) the start station or address, the destination station or address, the date, and the arrival time. This could be coupled with Apple Maps, Apple Reminders etc. Determining which trains and buses will be leaving near my current position from which station, is not a priority.

Then use map/roouting services. BVG doesn't have a good routing functionality. I usually just use it for checking departures.

PS: what's that with the telegram bot? Tried the URL, but it redirects to tg://resolve?domain=public_transport_bot. Don't know what to do with that, or which app to use.

Do you have Telegram installed? You can also go to Telegram manually and search for @public_transport_bot.

JayBrown commented 8 years ago

Just checked the telegram bot. Pretty neat! As for the BitBar script, I've got a good idea of how to do it. As soon as I get my API key I'll get started, first only with nearby stations and departures, later with stuff like favorites, user-defined routes, departure dates/times etc.. I'll let you know when I've uploaded the first beta… or alpha. ;)

PS: I've noticed that there are some bugs in the VBB database. One example: When I search for "Breitscheid", I get this list (already awked):

9200031 | Glienicke/Nordbahn, Breitscheidstr.
9220113 | Kleinmachnow, Rudolf-Breitscheid-Str.
9245791 | Luckenwalde, R.-Breitscheid-Str.
9260200 | Großziethen (LDS), Rudolf-Breitscheid-St
9260946 | Schulzendorf (LDS), R.-Breitscheid-Str.
9320042 | Dahlwitz-Hoppegarten, Breitscheidstr.
9320248 | Rüdersdorf, Breitscheidstr.
9340137 | Angermünde, Breitscheidstr.
9435620 | Lübbenau, Rudolf-Breitscheid-Str.

What's missing is "Bernau, Breitscheidstraße". I actually have to input "Breitscheidstraße" in full to get the Bernau street in vbb-stations output. I noticed this because I'm changing the user input slightly, namely [Ss]traße | [Ss]trasse | [Ss]tr. all to [Ss]tr … so my script will never send "*straße" to vbb-stations, just "str" or "Str".

I guess it's a VBB bug, not a bug in your CLI, but maybe it might help, if users were able to add wildcards to the --name option, like vbb-stations --name "Breitscheid*"

One more thing: the best format for shell scripting is probably the csv output, but it would be great to have a --delimiter option in order to change the comma , delimiter to something better like @@@. The problem is that with a comma you can't awk -F"," the 5 columns, because the station names often have commas themselves, like "Bernau, Breitscheidstraße". Therefore I'm currently using the "pretty" output, with rev | awk | rev etc. It's still fast, and it works, but it would be faster with a custom-delimiter option in csv-formatted output.

derhuerst commented 8 years ago

Just checked the telegram bot. Pretty neat! As for the BitBar script, I've got a good idea of how to do it. As soon as I get my API key I'll get started, first only with nearby stations and departures, later with stuff like favorites, user-defined routes, departure dates/times etc.. I'll let you know when I've uploaded the first beta… or alpha. ;)

Great! Keep it as open as possible, so others can follow, give feedback and contribute early.

PS: I've noticed that there are some bugs in the VBB database.

To check if there's really bugs, check vbb-gtfs for the raw data. vbb-static is basically the same data in a different structure.

One example: When I search for "Breitscheid", I get this list (already awked):

9200031 | Glienicke/Nordbahn, Breitscheidstr.
9220113 | Kleinmachnow, Rudolf-Breitscheid-Str.
9245791 | Luckenwalde, R.-Breitscheid-Str.
9260200 | Großziethen (LDS), Rudolf-Breitscheid-St
9260946 | Schulzendorf (LDS), R.-Breitscheid-Str.
9320042 | Dahlwitz-Hoppegarten, Breitscheidstr.
9320248 | Rüdersdorf, Breitscheidstr.
9340137 | Angermünde, Breitscheidstr.
9435620 | Lübbenau, Rudolf-Breitscheid-Str.

What's missing is "Bernau, Breitscheidstraße".

For me, it isn't missing.

9200031,"Glienicke/Nordbahn, Breitscheidstr.",52.639266,13.317361,2810
9220113,"Kleinmachnow, Rudolf-Breitscheid-Str.",52.411692,13.203661,168
9245791,"Luckenwalde, R.-Breitscheid-Str.",52.078585,13.143533,110
9260200,"Großziethen (LDS), Rudolf-Breitscheid-Str.",52.414242,13.451843,740
9260946,"Schulzendorf (LDS), R.-Breitscheid-Str.",52.369862,13.607308,950
9320042,"Dahlwitz-Hoppegarten, Breitscheidstr.",52.500733,13.648235,690
9320248,"Rüdersdorf, Breitscheidstr.",52.468628,13.791684,2140
9340137,"Angermünde, Breitscheidstr.",53.013721,13.992778,450
9350009,"Bernau, Breitscheidstraße",52.675371,13.585488,480
9435620,"Lübbenau, Rudolf-Breitscheid-Str.",51.863798,13.9371,90

Have you updated vbb-stations-cli (which uses vbb-stations) to latest? A week ago new data has been released by VBB, with a few fixes.

I actually have to input "Breitscheidstraße" in full to get the Bernau street in vbb-stations output. I noticed this because I'm changing the user input slightly, namely [Ss]traße | [Ss]trasse | [Ss]tr. all to [Ss]tr … so my script will never send "*straße" to vbb-stations, just "str" or "Str".

I run every user input through vbb-tokenize-station. It converts the input correctly:

p('Bernau, Breitscheidstraße')
// [ 'bernau', 'breitscheid', 'strasse' ]
p('Bernau, Breitscheidstr.')
// [ 'bernau', 'breitscheid', 'strasse' ]
p('Bernau, Breitscheid')
// [ 'bernau', 'breitscheid' ]

[…] if users were able to add wildcards to the --name option, like vbb-stations --name "Breitscheid*"

I thought about that already and plan to implement it in vbb-find-stations (which tries to find all stations). For vbb-stations-autocomplete (which tries to find a few stations quickly), this would probably be too slow.

One more thing: the best format for shell scripting is probably the csv output, but it would be great to have a --delimiter option in order to change the comma , delimiter to something better like @@@.

You're right!

The problem is that with a comma you can't awk -F"," the 5 columns, because the station names often have commas themselves, like "Bernau, Breitscheidstraße".

Those quotes are a common extension of CSV and proper CSV parsers support this.

awk is probably too basic for this. Check miller.

JayBrown commented 8 years ago

That's strange. I installed it just recently, and according to the package.json, it's the latest version (v0.3.1), and "Bernau, Breitscheidstraße" doesn't pop up, when I run vbb-stations --name "Breitscheid", independent of the output format used. (I don't have vbb-find-stations installed, though; only vbb-stations-cli and vbb-cli, although I can't yet use the latter without the key. Do I need any of your other releases for a shell script?)

derhuerst commented 8 years ago

If you install vbb-stations-cli with NPM, it will install it's dependencies (including vbb-find-stations). Therefore this should not be a problem.

JayBrown commented 8 years ago

Then something went wrong with the installation of vbb-stations-cli, because vbb-find-stations is not part of the cli module on my system (see below.) Only vbb-tokenize-station and vbb-stations are there, and the latter doesn't sport the latest version number either: it's 0.2.1 instead of 0.4.0. (Tokenize is correctly at v0.1.1.) I installed just a couple of days ago, so it should have all the latest data, but apparently hasn't. I'll uninstall and re-install; maybe then it'll work.

├─┬ vbb-stations-cli@0.3.1
│ ├─┬ chalk@1.1.3
│ │ ├── ansi-styles@2.2.1
│ │ ├── escape-string-regexp@1.0.5
│ │ ├─┬ has-ansi@2.0.0
│ │ │ └── ansi-regex@2.0.0
│ │ ├── strip-ansi@3.0.1
│ │ └── supports-color@2.0.0
│ ├─┬ csv-write-stream@1.0.0
│ │ ├─┬ generate-object-property@1.2.0
│ │ │ └── is-property@1.0.2
│ │ └── minimist@1.2.0
│ ├─┬ ndjson@1.4.3
│ │ ├─┬ split2@0.2.1
│ │ │ └── through2@0.6.5
│ │ └─┬ through2@0.6.5
│ │   └─┬ readable-stream@1.0.34
│ │     └── isarray@0.0.1
│ ├─┬ pad-right@0.2.2
│ │ └── repeat-string@1.5.4
│ ├─┬ stream-filter@1.0.0
│ │ └── through@2.3.8
│ ├─┬ through2@2.0.1
│ │ ├─┬ readable-stream@2.0.6
│ │ │ ├── core-util-is@1.0.2
│ │ │ ├── inherits@2.0.1
│ │ │ ├── isarray@1.0.0
│ │ │ ├── process-nextick-args@1.0.6
│ │ │ ├── string_decoder@0.10.31
│ │ │ └── util-deprecate@1.0.2
│ │ └── xtend@4.0.1
│ ├─┬ vbb-stations@0.2.1
│ │ └── stream-sink@1.2.0
│ ├─┬ vbb-tokenize-station@0.1.1
│ │ └── normalize-for-search@1.2.0
│ └─┬ yargs@4.6.0
│   ├── camelcase@2.1.1
│   ├─┬ cliui@3.2.0
│   │ └── wrap-ansi@2.0.0
│   ├── decamelize@1.2.0
│   ├─┬ lodash.assign@4.0.8
│   │ ├── lodash.keys@4.0.6
│   │ └── lodash.rest@4.0.2
│   ├─┬ os-locale@1.4.0
│   │ └─┬ lcid@1.0.0
│   │   └── invert-kv@1.0.0
│   ├─┬ pkg-conf@1.1.2
│   │ ├─┬ find-up@1.1.2
│   │ │ ├── path-exists@2.1.0
│   │ │ └─┬ pinkie-promise@2.0.1
│   │ │   └── pinkie@2.0.4
│   │ ├─┬ load-json-file@1.1.0
│   │ │ ├── graceful-fs@4.1.3
│   │ │ ├─┬ parse-json@2.2.0
│   │ │ │ └─┬ error-ex@1.3.0
│   │ │ │   └── is-arrayish@0.2.1
│   │ │ ├── pify@2.3.0
│   │ │ └─┬ strip-bom@2.0.0
│   │ │   └── is-utf8@0.2.1
│   │ ├── object-assign@4.0.1
│   │ └── symbol@0.2.1
│   ├─┬ read-pkg-up@1.0.1
│   │ └─┬ read-pkg@1.1.0
│   │   ├─┬ normalize-package-data@2.3.5
│   │   │ ├── hosted-git-info@2.1.4
│   │   │ ├─┬ is-builtin-module@1.0.0
│   │   │ │ └── builtin-modules@1.1.1
│   │   │ ├── semver@5.1.0
│   │   │ └─┬ validate-npm-package-license@3.0.1
│   │   │   ├─┬ spdx-correct@1.0.2
│   │   │   │ └── spdx-license-ids@1.2.1
│   │   │   └─┬ spdx-expression-parse@1.0.2
│   │   │     └── spdx-exceptions@1.0.4
│   │   └── path-type@1.1.0
│   ├── require-main-filename@1.0.1
│   ├─┬ string-width@1.0.1
│   │ ├─┬ code-point-at@1.0.0
│   │ │ └── number-is-nan@1.0.0
│   │ └── is-fullwidth-code-point@1.0.0
│   ├── window-size@0.2.0
│   ├── y18n@3.2.1
│   └── yargs-parser@2.4.0
derhuerst commented 8 years ago

I didn't release a new version with updated dependencies yet. Try cding into vbb-stations-cli's directory and do rm -r node_modules/vbb-tokenize-station; npm i vbb-tokenize-statuon@latest.

JayBrown commented 8 years ago

vbb-tokenize-station is correctly at v0.1.1 in both cli modules. (???)

But I would have to do that with some of the others as well:

(1) vbb-stations-cli: vbb-stations 0.2.1 > 0.4.0

(2) vbb-cli: (a) vbb-hafas 0.7.2 > 0.8.1 (b) vbb-stations 0.3.0 > 0.4.0 (c) vbb-stations-autocomplete 0.6.1 > 0.8.0

PS: What about vbb-find-stations? It's not part of any cli module. Or is integrated somewhere?

derhuerst commented 8 years ago

vbb-tokenize-station is correctly at v0.1.1 in both cli modules. (???)

You're right. I confused it with another vbb-… module i had installed locally. What a mess :grin:

I updated vbb-stations to 0.4.0, which should have updated dependencies itself.

JayBrown commented 8 years ago

Thank you for the v0.4.1 update. Installation now worked, but the above problem remains: Breitscheidstr. in Bernau (just an example) still isn't listed when calling "Breitscheid" or "Breitscheidstr.". I wonder what the problem could be.

 ❯ vbb-stations --name "Breitscheid" --format csv
id,name,latitude,longitude,weight
9200031,"Glienicke/Nordbahn, Breitscheidstr.",52.63927,13.317366,2260
9220113,"Kleinmachnow, Rudolf-Breitscheid-Str.",52.411696,13.203666,168
9245791,"Luckenwalde, R.-Breitscheid-Str.",52.078589,13.143538,110
9260200,"Großziethen (LDS), Rudolf-Breitscheid-Str.",52.414245,13.451849,740
9260946,"Schulzendorf (LDS), R.-Breitscheid-Str.",52.369865,13.607314,940
9320042,"Dahlwitz-Hoppegarten, Breitscheidstr.",52.500737,13.64824,720
9320248,"Rüdersdorf, Breitscheidstr.",52.468631,13.791689,1830
9340137,"Angermünde, Breitscheidstr.",53.013724,13.992783,450
9435620,"Lübbenau, Rudolf-Breitscheid-Str.",51.863801,13.937106,90

 ❯ vbb-stations --name "Breitscheidstr." --format csv
id,name,latitude,longitude,weight
9200031,"Glienicke/Nordbahn, Breitscheidstr.",52.63927,13.317366,2260
9220113,"Kleinmachnow, Rudolf-Breitscheid-Str.",52.411696,13.203666,168
9245791,"Luckenwalde, R.-Breitscheid-Str.",52.078589,13.143538,110
9260200,"Großziethen (LDS), Rudolf-Breitscheid-Str.",52.414245,13.451849,740
9260946,"Schulzendorf (LDS), R.-Breitscheid-Str.",52.369865,13.607314,940
9320042,"Dahlwitz-Hoppegarten, Breitscheidstr.",52.500737,13.64824,720
9320248,"Rüdersdorf, Breitscheidstr.",52.468631,13.791689,1830
9340137,"Angermünde, Breitscheidstr.",53.013724,13.992783,450
9435620,"Lübbenau, Rudolf-Breitscheid-Str.",51.863801,13.937106,90

 ❯ vbb-stations --name "Breitscheidstraße" --format csv
id,name,latitude,longitude,weight
9350009,"Bernau, Breitscheidstraße",52.675374,13.585494,470
derhuerst commented 8 years ago

I can confirm. However, vbb-tokenize-stations gives me ['breitscheid', 'strasse'] for all of the three queries, so this is not a problem.

derhuerst commented 8 years ago

The problem was again my local setup. To avoid installing my own modules all the time, I symlink their git repos into node_modules. Therefore, I tested vbb-stations-cli with vbb-tokenize-stations at master.

I released vbb-tokenize-stations@0.1.2 now, try installing/updating this for vbb-stations-cli.

derhuerst commented 8 years ago

Also, npm/npm#5082 is really tiring me out.

JayBrown commented 8 years ago

Now "Breitscheid" in Bernau works with vbb-tokenize-stations@0.1.5. Awesome, thank you.

Now back to the original question, namely using vbb-stations-cli (or vbb-cli? see below) to find stations near certain coordinates. Let's say my $COORD variable gets its value from CoreLocationCLI, or (let's use this example) I input an address via sub-routine, and Google's API spits out the relevant coordinates, which go into $COORD, e.g. Potsdamer Platz 3 with COORD=52.5101954,13.3754514, alternatively as $LAT and $LNG.

You said above:

Have a look at how vbb-cli finds stations close to a location.

This is the vbb-cli. So my first question is if it's also possible to find a station near $COORD with vbb-stations-cli, and if yes, how to do it. This example – vbb-stations "(s) => s.latitude > 52.5101954" "(s) => s.longitude > 13.3754514" – doesn't do anything. In the vbb-stations --help output, it also says "vbb" instead of "vbb-stations", so I'm a little confused. Do I use vbb-stations, vbb-dep or vbb-route to look up stations near a certain latitude/longitude?

PS: According to the VBB API team, there will eventually be a location.nearbystops service as part of the API. Will that be included in vbb-stations-cli too?

derhuerst commented 8 years ago

Have a look at how vbb-cli finds stations close to a location.

This is the vbb-cli.

Correct. vbb-cli let's the user select from the stations closest to the current location.

[…] Do I use vbb-stations, vbb-dep or vbb-route to look up stations near a certain latitude/longitude?

Maybe I should disambiguate this more. vbb-stations is a module that contains all stations. vbb-stations-cli is the command line interface for that. vbb-cli intends to become a full-blown command line public transport "app". It combines a lot of other vbb-… modules to do that.

So my first question is if it's also possible to find a station near $COORD with vbb-stations-cli, and if yes, how to do it.

Sure. Do you want to get all stations within a certain radius or do you want to get the n closest stations?

This example – vbb-stations "(s) => s.latitude > 52.5101954" "(s) => s.longitude > 13.3754514" – doesn't do anything

It gives me 2844 results. (Not on my local setup, npm install -ged on another machine)

In the vbb-stations --help output, it also says "vbb" instead of "vbb-stations", so I'm a little confused.

Fixed that already, but didn't push yet. There's both a lot of work going on in the vbb-… modules, but also there's lots to do. Sorry about that.

Do I use vbb-stations, vbb-dep or vbb-route to look up stations near a certain latitude/longitude?

vbb-dep and vbb-route belong to vbb-cli, vbb-stations belongs to vbb-stations-cli. In your case, I'd either use vbb-stations-cli similarily to your example or write a custom script.

derhuerst commented 8 years ago

PS: According to the VBB API team, there will eventually be a location.nearbystops service as part of the API.

Yes, they told me that they will – at an unknown point in the future 😩 – enable location.nearbystops. That would be a benefit, since it takes actual walking distance into account (not just distance on the map).

Will that be included in vbb-stations-cli too?

No, vbb-stations-cli is just a command line tool for the static data in vbb-stations.

But I have a commit ready for vbb-hafas (which is used by vbb-cli).

JayBrown commented 8 years ago

This example – vbb-stations "(s) => s.latitude > 52.5101954" "(s) => s.longitude > 13.3754514" – doesn't do anything

It gives me 2844 results. (Not on my local setup, npm install -ged on another machine)

Right, that's my stdout as well. But there should only be a dozen stations or so for Potsdamer Platz. The idea is to input a location's coordinates (or the current coordinates delivered by CoreLocation), either into vbb-stations-cli or into vbb-cli, and by doing so retrieve a list of the nearby stations, i.e. those in walking distance (e.g. with a radius of 1km), not hundreds or thousands of stations reaching as far as Poland. ;)

derhuerst commented 8 years ago

@JayBrown

Well, it works just like in the example we're talking about. It would be something like this:

vbb-stations "(s) => s.latitude > $lat - x" "(s) => s.latitude < $lat + x" "(s) => s.longitude > $long - x" "(s) => s.longitude < $long + x"
JayBrown commented 8 years ago

Thank you. This works great. Though it seems that one shouldn't use the variable x for both lat & long. But for roughly 500m radius (1 km circle) it might be something like x_lat=.004 and x_long=.007 … but I have to try out first, which combination works best.

PS: I will move to the vbb-cli repo for further comments on different topics, if necessary, but first some testing is needed.

JayBrown commented 8 years ago

My ballpark figures were pretty close: for Germany (pythagorean calculation) the values are .0044992351 and .0069988802 for an approx. radius of 500 meters. The weird thing is that according to online information the former is the value for the longitude, the latter for the latitude, but in vbb-stations I have to input them the other way around to get correct results. Could it be possible that you switched around latitude and longitude in your vbb-stations code? But chances are that I'm not fully understanding coordinates calculations. ;)

derhuerst commented 8 years ago

@JayBrown I'm not sure what you mean.

It is common to specify first the latitude (N-S) and then the longitude (E-W). In the static VBB data, it seems to be the same. In vbb-stations, it seems to be correct as well.

derhuerst commented 8 years ago

@JayBrown

I noticed that the installation instructions for VBBar tell users to npm install vbb-cli globally, althoug that wouldn't be necessary. npm install without the --global flag symlinks every executable into node_modules/.bin, so you should be able to call e.g. node_modules/.bin/vbb-dep. This way, you can keep all dependencies locally and the users machine as clean as possible.