-
Notifications
You must be signed in to change notification settings - Fork 20
Server
The purpose of the Shuttle Tracker server is to extract the route, stop and shuttle data from the RPI shuttle server, calculate how long it takes for each shuttle to go to each applicable stop and then send this time data to the client applications on the Android and iPhone. To accomplish this task, the extraction and calculation code is written in Java, which saves the arrival time data in a text file. This file is then read in by a PHP program, which will show the time data on Google Maps and also send this data to the client applications.
The Java Application consists of three main classes: ShuttleTrackerServer, JSONExtractor and JSONSender. Upon initializing an instance of the ShuttleTrackerServer class, the JSONExtractor class will get the route and stop information from the RPI server and locally save a copy of that data. A background thread will then get the shuttle data from the server and calculate the approximate time it would take to for each shuttle to get to a particular stop. This time data (ETAs) is then sent to the JSONSender class, which constructs a text file that contains the ETAs as well as the shuttle's current location. This background thread then sleeps for five seconds and then repeats the process.
After JSONExtractor compiled a list of shuttles, each shuttle will then figure out which route it is currently on. The way it does this is by calculating the distance between its current location and every coordinate point for all of the routes. In the case of RPI as of March 27, 2011, the campus has two shuttle routes, an East Route and a West Route, so each shuttle would calculate the straight-line distance between its current location and every coordinate point making up the East and West routes. The shortest distances are then saved in a collection and then compared to each other in order to determine which route the shuttle is closer to, and therefore is currently travelling on. It should be noted that there are times when the two routes might overlap each other, so it has already been determined which route the shuttle is travelling on, it will be assumed that the shuttle is travelling on the West Route (Shuttle.RouteFinder.routeList.get(0) = West Route). The shuttle is considered to be on an overlapped region if the difference between the shortest calculated distances is no greater than .01 miles.
Once the route of the shuttle has been determined, each shuttle would then filter through the list of stops and add the ones that are on their route to their own stop list. Following this, each shuttle will then calculate the distance between its current location to every route point until it reaches the stop. This end case is determined by comparing the currently viewed route point and the closest route point to the stop. If they are the same, then the distance to the stop has been determined, if they are not the same, then the distance between the shuttle (or the previous route point, if the current iteration is greater than 0) and that route point is calculated and added to a variable that holds the total distance to travel in miles. After calculating the distance to the stop, the value is divided by the average speed of the shuttle (determined by averaging the most recent ten instantaneous speeds) and converted from hours to milliseconds.
##Features to consider
- In order to make the program more robust, use a sortable list instead of a fixed dimension array so that if the campus has more than two routes, these additional routes would be considered by the program.