Giter Club home page Giter Club logo

kmb-lwb-combined-headway-eta's Introduction

KMB & LWB combined headway ETA

This is an interface for the KMB / LWB ETA API which allows choosing a stop, and shows the ETA of the upcoming 3 departures combined from a set of routes serving the stop.

Features

  • ETA automatically refreshes every 15 seconds.

  • Direct bookmark and load a specified combination of routes at a certain stop.

  • The existing combination is preserved when a route serving the same stop is entered.

    For example, if routes 258D and 259D at Tuen Mun Road Interchange is already chosen, typing 61X into the route selection box will add 61X into the chosen combination with the correct direction automatically selected.

    Limitation: if the newly-added route serves the stop in both directions (e.g. 64K @ Kam Sheung Road Station), or passing through the same stop in the same direction twice (e.g. 54 @ Kam Sheung Road Station), only one of the stop will be automatically added. You can choose the alternatives manually.

  • The existing combination is preserved when another stop with the same combination in the same direction is chosen.

    For example, if you have selected routes 61X, 258, 259D at Beacon Heights, choosing Wong Tai Sin Station from the stop list now will still load the combination of 61X, 258D, 259D, choosing Millennium City from the stop list will load 258D, 259D because 61X do not serve the stop.

    Limitation: if the newly-chosen stop serves the same route in the same direction twice at the exact same pole, e.g. choosing 71S at Kwong Fuk Playground, then choose Tai Po Market Station (TA10-T-1250-0), both stopping of 71S at that same pole will be selected automatically.

Setting up the project

  1. Run npm install to install the dependencies
  2. Run npm run snowpack dev to start a development server at http://localhost:8080
  3. When ready for deployment, run npm run snowpack build to compile the Javascript to be served
  4. Copy all files inside dist folder to the document root of the web server to deploy or run index.html directly in the browser without a web server.

Usage

  1. Enter the route number.
  2. Change the direction and the variant.
  3. Select a stop which you want to get the ETA.
  4. A list of routes appear in the box below which serve the select stop. Select the other routes you want to see at the same time as well. Alternatively you may type in the other routes directly into the box as well.
  5. The ETA appears at the stop, which automatically reloads after 15 seconds.
  6. The URL is appended with a query string. You can bookmark that link such that the ETA of the desired combination is shown directly without selecting again.

Demo

A demo instance is set up.

Issues

  • A proxy server is required to bypass the CORS restriction. The proxy URL is defined in scripts/Common.js. The address provided in the repository is a private proxy server which can only be used to query the KMB mobile API.

Acknowledgement

This project is possible only when given the knowledge of how the mobile API works, which is studied as a final year project by HKU CS student Wong San Yu, with a working Android implementation BusETA by AlvinHKH.

kmb-lwb-combined-headway-eta's People

Contributors

dependabot[bot] avatar miklcct avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kmb-lwb-combined-headway-eta's Issues

Date object would subject to the timezone of the server

I copied the snippet from Eta.js

const time = new Date();
time.setHours(Number(obj.time.split(':')[0]), Number(obj.time.split(':')[1]), 0);
if (time.getTime() - Date.now() < -60 * 60 * 1000 * 2) {
    // the time is less than 2 hours past - assume midnight rollover
    time.setDate(time.getDate() + 1);
}
if (time.getTime() - Date.now() > 60 * 60 * 1000 * 6) {
    // the time is more than 6 hours in the future - assume midnight rollover
    time.setDate(time.getDate() - 1);
}

The time and Date.now() object uses the timezone of the system (I am just using UTC as the system default). However the setHours uses the Hong Kong time (obtained from the API). For my case midnight rollover would always happen.

I don't use date but just notice my date is always off by a day when I check the eta.time string.

All queries will be redirected to proxy server when running in HTTPS server

When running the script in HTTPS server, all queries to search.kmb.hk will be redirected to proxy server. Since the proxy server redirect all traffic to etav3.kmb.hk, queries to proxy server for search.kmb.hk will be failed.

It looks like the issue is due to determination to call proxy server or not is by checking the protocol of the URL:

Common.js
$.get((location.protocol === 'https:' ? Common.PROXY_URL : '') + Common.API_ENDPOINT, query, callback);

Seems map would provide performance boost

Hi, I decided to use your fetcher code for my MMM-HK-KMB project.

In the StopRoute.js there are some forEach. Use map would improve the performance of the code.

I didn't check the side-effect but it seems to me that it works. I also didn't check other code because StopRoute is more critical.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.