|
CMSC 330, Spring 2011Organization of Programming LanguagesProject 1Updates:
IntroductionAmong other things, Ruby and similar languages are very useful for writing ad hoc scripts to process and analyze data such as web logs (e.g., to find what pages are the most requested on your web site), operating system logs (e.g., to look for alerts that might signal ongoing problems), network traffic logs (e.g., to detect attacks from remote entities), and so on. In this project, you will write a program that works with airline timetable data to carry out a variety of tasks. The timetable data is stored in a text file in which each line represents the information about one flight. The information is a list of comma-separated values that are, from left to right: the flight number, the departure airport code, the arrival airport code, the departure time, and the arrival time. For example, here are two lines from the sample data file included in the project: 424,IAD,BOS,1221,1350 49,IAD,LAX,1220,1807The first line says that flight 424 leaves from IAD (Dulles Airport, one of the local DC airports) at 12:21pm and arrives in BOS (Boston) at 1:50pm. The second line says that flight 49 leaves from IAD at 12:20pm and arrives at LAX (Los Angeles) at 6:07pm. All times are in 24-hour format, and to keep things simple, they're all expressed in eastern standard time (e.g., flight 49 to LAX actually arrives at 3:07pm local time, since Log Angeles is in the pacific time zone). In this project, you will write one script, schedule.rb, that performs a variety of tasks depending on the the command-line arguments. We will invoke your script as Where timetable-file-name is the name of the file containing the timetable, feature-name is the name of the features, and args... are the arguments needed for that particular feature, if any. The various features that you need to implement are listed below. Getting StartedDownload the following zip archive p1.zip. It should include the following files:
You should do all of your work in schedule.rb. You could use each public_*.rb to run the same public tests as on the submit server. Your outputs will be store in student_outputs. For example: % ruby public_validate.rb test validate on correct-empty PASSED test validate on correct-flights PASSED test validate on correct-small PASSED test validate on wrong-empty-line PASSEDIf you implement the project correctly, you should not see any FAILED in the output of any test scripts. Part 1: Validating the data fileThe first part of this project is to add a feature to your Ruby script to validate that an input file is in fact an airline timetable and not, e.g., the professor's grocery list. We will invoke this feature by running your program as In response, your script should output exactly one line of text and then exit. That line should either contain the three letters yes followed by a newline if the log file is valid, or the two letters no followed by a newline otherwise. A valid timetable contains zero or more lines of text, each of which ends in a newline. (Hint: There are Ruby methods to read in a single line of text at a time.) Each line must contain the following fields from left-to-right, with each field separated from the previous field with a comma and no whitespace. The left-most field has nothing in front of it, and the right-most field is followed only by the newline that ends the line:
Any file whose lines do not conform to these rules is invalid. Part 2: Displaying useful informationThe next part of the project is to implement a range of simple but useful queries on the timetable. For all of these queries, we will only test your program with valid inputs, e.g., the airport names will be in the list given above in the discussion for validation (but there *might* be no flights between two cities) Non-stop flights between citiesImplement a feature nonstop start end that lists all the nonstop flights that originate at airport start and end at airport end. For each such flight, print out one line containing the flight number, start time, and end time, each separated by a tab. The flights should be listed in order from earliest departure time to latest. If two flights depart at the same time, they can be listed in any order. If there are no such flights, print a single line containing none. For example: % ruby schedule.rb flights.csv nonstop SFO BOS 180 0140 0705 226 0900 1438 172 1124 1700 788 1410 1952 892 1640 2225 % ruby schedule.rb flights.csv nonstop SFO ATL none All destinationsImplement a feature destinations start that lists all airports that can be reached from start with a nonstop flight, along with the number of daily nonstop flights to that airport from start (separated with a tab, as above). The airport codes should be listed one per line, in alphabetical order. For example: % ruby schedule.rb flights.csv destinations DCA BOS 15 DEN 1 ORD 15(You can assume there is at least one other airport reachable from start.) BalanceImplement a feature balance that lists all the airports in the timetable along with the difference (number of daily arrivals - number of daily departures), separated again with a tab. Sort the list alphabetically by airport. For example: % cat test.csv 1,ATL,BOS,1234,1235 2,ATL,DEN,1234,1235 3,BOS,ATL,1234,1235 % ruby schedule.rb test.csv balance ATL -1 BOS 0 DEN 1(Here the UNIX command cat is being used to display the contents of test.csv.) The balance for ATL is -1, since there are two flights departing but only one arriving. The balance for BOS is 0 because 1 flight arrives and 1 departs. And the balance for DEN is 1 since 1 flight arrives and none depart. Part 3: Multi-hop flightsSince not all airport pairs have nonstop flights between them, next you will implement a feature connecting start end num-connects that lists itineraries that fly from start and end that use exactly num connections. There will be many such itineraries, of course; rather than display them all, use the following rules to pick the ones to show:
% ruby schedule.rb flights.csv connecting SFO ATL 1 756 0900 1126 DEN 6604 1234 1527 ATL Duration 0627 134 1158 1605 ORD 7560 1705 1858 ATL Duration 0700 830 1428 1838 ORD 566 1945 2141 ATL Duration 0713 158 0138 0540 ORD 7592 0701 0853 ATL Duration 0715 664 0904 1305 ORD 7493 1427 1620 ATL Duration 0716 Part last: Random questions to think aboutThe data file we gave you is (barring typos) the real timetable data for a major airline. For fun, try to answer the following questions using your script (or extending it); there's nothing to turn in for this part.
SubmissionSubmit your schedule.rb file directly to the submit server by clicking on the submit link in the column "web submission".
Next, use the submit dialog to submit your schedule.rb file directly.
Select your file using the "Browse" button, then press the "Submit project!" button. You do not need to put it in a Jar or Zip file. Hints and Tips
Academic IntegrityThe Campus Senate has adopted a policy asking students to include the following statement on each assignment in every course: "I pledge on my honor that I have not given or received any unauthorized assistance on this assignment." Consequently your program is requested to contain this pledge in a comment near the top. Please carefully read the academic honesty section of the course syllabus. Any evidence of impermissible cooperation on projects, use of disallowed materials or resources, or unauthorized use of computer accounts, will be submitted to the Student Honor Council, which could result in an XF for the course, or suspension or expulsion from the University. Be sure you understand what you are and what you are not permitted to do in regards to academic integrity when it comes to project assignments. These policies apply to all students, and the Student Honor Council does not consider lack of knowledge of the policies to be a defense for violating them. Full information is found in the course syllabus---please review it at this time. |