Professional Documents
Culture Documents
CWK 4
CWK 4
Coursework 4 Task
The United States Geological Surveys Earthquake Hazards Program publishes data for recent earthquakes at http://earthquake.usgs.gov/earthquakes/feed/. Data feeds are available in various formats, including CSV (comma-separated values), which we will use here. Your task is to write a program that reads earthquake data from a CSV le obtained via one of these feeds. Your program must do some processing of these data. A full solution will also generate a Google Map of earthquake locations, as shown in Figure 1.
Figure 1: Example of program output (full solution). Your program can be written in either Python or C++, as you prefer. Choose only one of these! Your solution must be object-oriented. It must include a class called Quake, respresenting the details of a single earthquake, and a class called QuakeData, representing an entire earthquake datasetessentially, a collection of Quake objects. Further details are given in the sections that follow. For both languages, there is a basic solution worth 65% of the marks. If you are reasonably condent and are seeking a good mark for this assignment, you should extend the basic solution with the Google Maps feature. This will earn you up to 85% of the marks available. For the very keen seeking a greater challenge, there are various advanced features that can be implemented for the remaining marks.
Preparation
If you havent yet completed the problem sheets on OOP in Python and C++, you are strongly advised to do so before attempting this assignment. Please also read the rest of this coursework specication carefully before you choose the implementation language and begin any coding. Download cwk4.zip from http://bit.ly/comp1551. This archive contains various les that can be used as the basis of your solution, plus some data that can be used to test it and some sample output. It includes a makele that simplies compilation of C++ solutions. This makele can also be used to prepare your Python or C++ code for submission. Note: for the makele to work properly, you must name your les exactly as specied here!
Python
A full Python solution satisfying all of the requirements given below can be written in under 150 lines, including docstrings, comments and whitespace for neat layout. This gure is intended as a rough guide to the scale of the problem; other good solutions might be shorter or longer.
Modify QuakeData so that the CSV data come directly from the USGS data feed, rather than a manually-downloaded CSV le. You will need to change quakeinfo.py so it uses different command line argumentstime period and quake severity, for example (check the feed URLs for how these parameters are specied). The standard library will help here: see http://bit.ly/urlrequest and the examples therein. You may also nd the information at http://bit.ly/iomodule useful (particularly the section on StringIO). Add support to Quake and QuakeData for plotting of earthquake locations using Pythons turtle module. We have provided you with background.gif for use as a background image. Scaling longitudes and latitudes by a factor of 3 will give you x and y coordinates suitable for plotting on top of this background. Add code to quakeinfo.py that generates the plot. When run, your program should produce output looking something like Figure 2.
C++
A full C++ solution, incorporating all of the features discussed below can be written in around 200 lines, including comments and whitespace for neat layout. This gure is intended as a rough guide to the scale of the problem; other good solutions might be shorter or longer.
Reading CSV data using the relatively low-level features of the IOStreams library is tricky, so we have provided you with a string parsing library that can help. You can access this by adding #include "strtk.hpp" to quakes.cpp. Look at csvdemo.cpp for examples of how this library is used with CSV data. A suitable approach would be to repeatedly read a line with getline and parse it using parse_columns, stopping when the latter returns false. Check your work by entering make quakes.o and x any compiler errors. 4. Add a method that returns the size of the dataset. Then add a method that returns a Quake object, given an integer index into the underlying container that holds the Quake objects. 5. Add a method to QuakeData that computes and returns the mean depth of the stored earthquakes. Add another method that computes and returns the mean magnitude. 6. In a le quakeinfo.cpp, write a program that creates a QuakeData object using a lename given as a command line argument. Your program should then display the number of earthquakes contained in the dataset, their mean depth (to two decimal places) and their mean magnitude (to one decimal place).
Submission
Submit your code as a single Zip archive. You can use the supplied makele to create this archive; simply enter make pyzip for Python solutions or make cppzip for C++ solutions. These commands generate a le called submission.zip, which you should submit using the link provided in the VLE. The deadline for submissions is 10 am on Friday 26 April. The standard university penalty of 5% of available marks per day will apply to late work, unless an extension has been arranged due to genuine extenuating circumstances.
Marking
This assignment is worth 25% of your overall module grade. Submissions will be marked out of 40, with the marks breaking down as follows: Aspect Basic Quake class Basic QuakeData class Basic quakeinfo program Correct output of earthquake statistics Implementation of Google Maps feature Generation of a correct map Implementation of advanced features Correct execution of advanced features Coding style and comments Marks 6 10 6 2 6 2 4 2 2