Lab 5 will be collected from your subversion repository on Monday, October 31, at 5pm.
Update your repositories to download the materials for lab 5. Work in the file lab5/lab5.rkt. It is important that your lab file has exactly this name and location; we will be looking for your work under this name at collection time.
In today's exercise, we will read data from a csv file, calculate simple statistics about it, and generate a visualization of the statistics using Google Image Charts. In doing so, you will have the experience of fitting smaller components together into a larger piece of software.
Candy Preferences
In honor of the coming holiday, we have generated datasets containing the Halloween candy preferences of all the students in CS151. The data is fabricated, so, begging your pardon, we have inevitably got some (perhaps all) of your preferences wrong. We have two separate data files, one for your preferences among chocolate candies, and one for non-chocolate candies. Look in your repositories for two data files: lab5/choc-prefs.csv and lab5/non-choc-prefs.csv. In each file, the data is plain text in comma-separated-value format, known as csv. Open it with a text editor to see what the file looks like (your Mac might want to open it in Excel on your behalf).
The batch-io package contains a variety of routines for reading data from files. In particular, read-csv-file is helpful for this exercise. Look over the batch-io documentation in the DrRacket help system. Include the package with
(require 2htdp/batch-io)
Google Image Charts
One of the many free software services provided by Google is Image Charts, which provides data visualization from URLs. In response to the URL, a custom image is sent to the client over the Internet. Think of Image Chart URLs as a domain-specific language for constructing informational graphics. Well-formed URLs send back attractive charts, while ill-formed ones send nonsensical or blank charts; consequently, debugging Image Charts can be tricky.
For this exercise, you will build a 3-dimensional pie chart. The URL syntax for such charts looks like this:
Note that any spaces in chart data (as in the chart title here, "MLB Teams", and the chart label "New York") need to be written "%20" lest they terminate the URL. The full Google Image Chart Pie Chart documentation is here; peruse it. While getting familiar with Image Charts, you may find the Live Chart Playground helpful.https://chart.googleapis.com/chart?chtt=MLB%20Teams&chs=400x200&cht=p3&chd=t:2,2,1&chl=Chicago|New%20York|Cleveland
Exercise
Your tasks are as follows:
- write code to tally the candy preferences from a csv file,
- write code to construct a 3D pie chart URL from a tally, and
- call bitmap/url (from 2htdp/image) to construct the image from the URL in DrRacket.
You must provide the following function:
;; generate 3d pie chart with given title and path name of csv file
The first argument to csv->chart is the chart title (like MLB Teams in the example above), and the second is the name of the data file from which to read. In the internal details, how exactly you fulfill this assignment is left to your judgment. As rules of thumb, you should expect to write around a half dozen or a dozen functions, and perhaps a few data definitions.
Note: When we grade this lab exercise, we will test it on a csv file you haven't yet seen. Therefore it is critical that no particular candies are hard-coded in your programs. Another way of saying this is, if you were to edit one of the data files so that every instance of Twizzlers were changed to some unrepresented candy (say Life Savers), the code should continue to work without alteration.
Commit early and often! Let's aim for zero svn mishaps this time around.