Israel Railways Gadget Fetching the response

Fetching the response xml

The gadget receives a full detailed xml from the web service with all the relevant information to show to the user. The xml contains the following:

  • Direct Trains: A detailed list of all the direct trains that connect the origin with the destination in the requested date and time
  • Indirect Trains: (with the different trains the passanger have to take) the same as for directed, but for each of the trains the passanger have to take in his trip.
  • Rates for the requested trip: The different rates for all the passanger types and all the ticket types. The user can see the rates by clicking the "tariffs" link in the tab. To read more about rates, see the [[[israel-railways-gadget-rates |Rates Tab] page.

Now, we start parsing the xml and we insert each trip (either direct or indirect) and we build for each trip a Trip Data Type that contains:

  • Whether is a Direct or Indirect Trip.
  • The departure date.
  • The arrival date.
  • The train type (urban or interurban).
  • An array of the trains inside it (if the trip is direct the array contains a single train).
  • An array of the interchange stations (if the trip is indirect)
  • The platform from which the train departures at the origin station.
  • A function how to display the trip (differs from direct to indirect)

The Train Data Type contains the following:

  • The Origin Station Id
  • The Destination Station Id
  • The departure time
  • The arrival time
  • The departure platform
  • The stop stations of the train (from origin to destination)

The problem is that the data we received from the Web Service was unsorted and we found there irrelevant data (such as trips that departure before others and arrive after them). So we developed an algorithm which sorts and filters the relevant trips. The algorithm pseudocode is the following:

Filter_Trips(trips_array)

1. Sort the trips_array by departure time from the early to the lately.

2. Add the last trip (the late one) to the result array

3. Traverse the trip_array from the last trip to the first one and do:

3.1. If the current trip departures before the last inserted trip in the result array and arrives after it, throw this trip.

3.2. Otherwise, add it to the result array.

4. Reverse the result array and return it.

As can be seen, we filter the trips efficiently by traversing the sorted array only once.

Back to Trips Tab

Back to Development Details

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License