CECS Home | ANU Home | Search ANU
The Australian National University
ANU College of Engineering and Computer Science
School of Computer Science
Printer Friendly Version of this Document

UniSAFE

COMP2720 — Lab 5 — Week 9 (18th and 19th September 2008)

Processing Web text data, and shifting between media

IMPORTANT

If you are unfamiliar (or need a refresher) with HTML then you should read section 11.1 (five pages) in the text book before you come into lab 5, otherwise you will waste your time when doing part 1 of the lab!

Objectives

Learn how to process Web text data which is stored in a file, and learn that sounds, pictures, text etc. are all just encodings of bits and bytes.

Marks and submission

  • You will get one mark if you attend this lab, and another mark when you show and demonstrate your working to your tutor.

  • Note that we will not give you an attendance mark if you only come to the lab for a short while (e.g. to show us your lab 4 workings)!

  • The mark for your lab workings will only be awarded in the lab. You can show your workings in this lab as well as the following lab 6 in week 10. You will not receive a mark for this lab if you show it to your tutor after the lab in week 10, unless you have a medical certificate (or similar document) stating that you were unable to attend the normal labs.

  • Please do NOT e-mail your lab workings to your tutor — we will NOT mark e-mailed lab workings. You can only get the mark for workings in the labs.

  • Note also that lab 6 in week 10 will be the LAST OPPORTUNITY for you to show (and get marks for) any lab workings. We will not consider any lab workings after lab 6 (unless you have a medical certificate (or similar document) stating that you were unable to attend the normal labs). So if you are one lab behind you better start catching up!

Preliminaries

  1. Once logged onto a computer, create a sub-folder called lab5 in your folder comp2720.

  2. Download the lab-template.txt and save it in your lab5 folder under the name lab-5-diary.txt.
    Please only save your lab diary as simple text file, not in RTF or DOC format (as you will have to include your lab diaries into your portfolio, and we will not be looking at RTF or DOC files when assessing your portfolio).

  3. Open this file lab-5-diary.txt with a text editor, and complete the header with your details. Keep this file open and continue writing down your workings and paste your programs into it.

  4. Now copy the following files into your lab5 folder:


Part 1: Processing Web text data

You should spend around 50 minutes on this part of the lab.

  1. Open the program getWeather.py into the JES editor, read through it and try to understand it, then run it. This program reads in a file bomInternationalObs.htm, a Web page downloaded from the Australian Bureau of Meteorology from the URL:

    http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDY03031.txt

    You should download the latest version of this page and save it under the name bomInternationalObs.htm, then re-run the getWeather program.

  2. You should extend the getWeather so that it extracts and prints the various weather observations for each city (or station) in a nicer (more readable) way.

  3. Now think of a way (or ways) on how you could summarise the global weather observations. For example, you could
    • count and print the number of cities that had a sunny, rainy, windy or snowy day,
    • calculate and print the worldwide average temperature observed,
    • print the worldwide minimum and maximum temperatures (and at which station they were measured),
    • print how much rain fell in the last day,
    • print the average (minimum and maximum) temperatures only for the cities with a sunny, rainy or windy day.
    Your program should print at least three (3) different summaries of the worldwide weather observations.

  4. Now write a new function getWeatherIn(city) based on the getWeather function which only prints the weather observations of the given input city. For example, getWeatherIn("Nandi") should only print the observations from the station Nandi in Fiji.

Part 2: Shifting between media

You should spend around 40 minutes on this part of the lab.

  1. Open the program sinePictureSound.py into the JES editor, read through it and try to understand it. Then run the program in the JES command area (check what the sinePictureSound() function returns, and call the function appropriately). Play the sound, and show the picture returned by the function. Also, visualise the sound in the MediaTools.

  2. Add comments to the program explaining in details what it does.

  3. When looking at the sound in the MediaTools, it is evident that the program does not work correctly — i.e. it doesn't properly create a sinus wave in the sound samples. Think about what the problem could be, and try to correct the program.

  4. Last, modify the program so it produces a triangular shaped sound wave and a corresponding picture (you might want to look at the programs from lab 4). Call this new function triangularPictureSound and save it into a program triangularPictureSound.py.

Part 3: Show your workings to your tutor

You should spend around 10 minutes on this part of the lab.

  • Explain and show to your tutor what you have done in parts 1 and 2 of the lab, and the programs you have developed.

  • Please also show your tutor your lab diary.


Further programming ideas

In each lab we will provide a last section that contains ideas for people who want to dig deeper, who are hooked on Python or media programming. This section is not part of the assessable lab material, but rather provides some more problems for students who love a programming 'challenge'.

  1. In part 1 of this lab, text data is processed and textual output (like summary weather observations) is produced. It would be nice to have a new weather observation Web page with graphical output, like little pictures for sunny, rainy, windy etc. weather conditions, a compass or wind rose for the wind direction, etc. Extend the getWeather.py program so that it writes a HTML file weather.html that graphically displays weather observations.

  2. For part 2 of the lab, write a program that creates a sound and picture of a combination of wave forms (sine, square, saw-tooth, triangle, etc.) in one function. Input parameters for such a function could be a list with the frequencies and amplitudes of the selected wave forms, like:
         createWavesList = ['sine',440, 16000],
                           ['square',550, 8000],
                           ['saw',1200,8000]]
         picture, sound = wavesPictureSound(createWavesList)
         


Last modified: 4/08/2008, 23:48