The Mayday Application

The Problem

Boats at sea usually report their position once a day via radio to a land-based controller. These reports provide a 'last known position' in case of accident. The position of a boat is expressed as a Latitude (North or South of the Equator) and Longitude (East or West of the Greenwich Meridian). Both Latitude and Longitude are expressed in degrees and minutes. Degrees are whole numbers ranging from +180 to -180 for Longitude and +90 to -90 for Latitude. The minutes must be in the range 00 to 59.9999.

A minute of Latitude (anywhere) corresponds to 1 Nautical mile. Minutes of Longitude are equal to minutes of Latitude at the Equator, but get progressively shorter as the Latitude increases, until they become zero at the poles.

The calculation of the distance between two positions, expressed as Latitude/Logitudes, is complicated by the shape of the earth. For small distances, an adequate approximation is to imagine a straight line between the two points and to calulate the distance using Pythagoras, correcting for the changing length of minutes of Longitude. For longer distances, a calculation which accounts for the curvature of the earth is required.

'Mayday' is the internation signal for distress and indicates that there is a danger to life aboard a boat. If a MayDay is called by one of the boats (the 'target' boat), all nearby boats are required under international maritime law to proceed to its help, but it makes sense to identify the boats nearest to the target's position.

Running the Application

When the application starts, a form is generated containing a drop-down list of the known boats.
With this form, the user can select a target boat from amongst the set of known boats and specify the range in which to search.
When the request is submitted, a second page shows the position of the target boats and the position of all boats with range of the target.

Search for a nearby Boat

Design

Types

We will represent a position as two quantities, a Latitude and a Longitude. Both of these are expressed in degrees and minutes so we will also define a more basic degrees/minutes type. Both will be value types - that is they will behave like primitive data types, which have immutable values.

Both new types will need functions (aka methods or operations) to return calculated (derived) values. So for a degrees/minutes object, we want to convert to Radians (there are 2Pi radians in 360 degrees) since trigonometric functions require input in radians. We also want to display these values in a readable way, as a formatted string.

The LatLong type, containing two degrees/minutes values, will need methods to present the value in a readable string, and more critically, to calculate the distance between one LatLong object and another.

The boat Boat Type will initially contain a name (using the standard String type) and current position (using the LatLong type).

Only one set of Objects will need to be held, the set of known Boats, so just one table is required, a table of boat objects.

3-tier System Architecture

User interaction

User interaction will be provided by HTML pages running on any browser. HTML provides the capability to display information from the database as well as collect user selections and input.

Middle ware

PL/SQL procedures will provide the interface between the User interface and the database of boats. Two procedures will be required.

Database

The database will be implemented in Oracle 9i using the Object extensions.

Implementation

Type definitions

Table definitions

Objects are contained in tables in Oracle (not stored on a heap as in a pure object system). So we need to define a table of boats

Initial configuration

We now need to create some initial objects.

Interfacing procedures

Two PL/SQL procedures are required in the middle layer.

Suppport code

Exercises

Week 1

Week 2

Week 3 Further exercises

Here are some of the exercises which could be undertaken with this basic system. In tutorial we will look see how you might solve these problems, but not necessarily implement them. Look out for opportunities to re-use Types which have already been developed.

Step Function

The StepFunction type and some tests

Reports

Position reports are received each day. We need to keep the history of reports, together with the date and time they were recorded. Each position report will record the date and time, the position and velocity.
Interspersed with the position reports are other reports.

Use cases and sequence diagrams

Update Position

Here is a simple example of implementing the 'Update Boat position' use case. It can be described by a sequence diagram from which the code for each prodedure can be reached and the whole use case executed: Update Position Usecase

The sequence diagram is generated from a text script by a perl program. I intend to put this application on-line in the near future.