Skip to content

Project Summary and Enhancement Documentation

Amit Das edited this page Aug 28, 2023 · 4 revisions

Project Summary

Earthquake App

The Earthquake App provides users with a way to interactively explore earthquake data around the world. Users can click on specific locations in the map to find earthquakes within a specified radius or use filters to gain insights into historical trends or patterns of earthquake occurences.

Interactive Map Interface (Click Mode)

Important Queries

Queries are sent to the database through clicking events captured on the map. Users can click anywhere on the map to obtain information about nearby earthquake occurences. Users can specify the radius of search between 500 to 1000 miles. For example if a user sets the radius to be 750 miles and clicks the map in a particular location, markers corresponding to the locations of earthquake events that were within 750 miles of the clicked positon will be displayed.

Implementation Details

When the user clicks on the map, the following request is sent to the server

fetch('/coords', {
        method: 'POST',
        body: JSON.stringify({
            latlng: e.latlng,
            sliderValue: sliderValue
        }),
        headers: {
            'Content-Type': 'application/json'
        }
    })

The server handles this request, by parsing the longitude and lattitude value and displaying all earthquakes that are within the specified radius which is represented by the slider_value variable.

latitude = request.json['latlng']['lat']
        longitude = request.json['latlng']['lng']
        slider_value = request.json['sliderValue']

        cursor = mysql.connection.cursor()
        cursor.execute('''
            SELECT event_id, ed.magnitude, city_name, country_name, latitude, longitude, tsunami
            FROM EarthquakeDetails as ed
            JOIN Location as l ON ed.location_id = l.location_id
            JOIN City as c ON l.city_id = c.city_id
            JOIN Country as co ON c.country_id = co.country_id;
        ''')
        
        close_earthquakes = []
        results = cursor.fetchall()
        
        for row in results:
            if distance.distance((latitude, longitude), (row[4], row[5])).miles <= float(slider_value):
                close_earthquakes.append(row)

The actual latitude and longitude are not passed in to the query, instead, I extract all of the earthquakes and the related attributes, and then filter the results to return the earthquakes within the specified search radius.

Possible Use Cases/Scenarios

If I wanted to find all earthquakes within 500 miles of Florida, I can click the map on Florida, and markers will be displayed. Clicking on the marker will show details about the earthquake such as the location and magnitude. Below is a screenshot of such a use case.
earthquake_erd

Exploration Mode (Explore Mode)

Important Queries

Queries are sent to the database using scroll-down menus and text box entries. The user has the option to select a specific continent, month, and year to display earthquakes. The screenshot below shows where the user can specify their search parameters. Users can specify All Months if they want to see all earthquakes reguardless of which month they were recorded in. If no Year parameter is specified, earthquakes from all years are displayed.
earthquake_erd

Implementation Details

Without loss of generality, we consider the case where the user supplies continent, month, and year parameters. When the user hits the Submit button, the following request is sent to the server.

fetch('/query', {
        method: 'POST',
        body: JSON.stringify({
            continent: selectedContinent,
            month: selectedMonth,
            year: selectedYear
        }),
        headers: {
            'Content-Type': 'application/json'
        }
    })

The server then queries the database, with the following SQL query

cursor.execute('''
                    SELECT event_id, magnitude, city_name, country_name, latitude, longitude, tsunami
                    FROM EarthquakeDetails as ed
                    JOIN Location as l ON ed.location_id = l.location_id
                    JOIN City as c ON l.city_id = c.city_id
                    JOIN Country as co ON c.country_id = co.country_id
                    JOIN Continent as con ON co.continent_id = con.continent_id
                    WHERE con.continent_name = %s AND month = %s AND year = %s;
                ''', (continent, month, year))

These results are then sent back to the client in JSON format. On the client side, I add the markers to the map indicating the locations of the queried earthquake events.

Use Cases

The primary use cases here are when we are interested in analyzing trends. For example, we can see how earthquake events in a specific continent have changed over the years. We can also analyze this on a monthly basis. Furthermore, we can compare these patterns across continents. Below I have attached a screenshot of all the earthquakes in South America that occurred in February.
earthquake_erd

Clone this wiki locally