Computer Science 217
Assignment #2
To input and visualize data; to use conditional statements; to
translate a calculation into code.
- This is an individual assignment. What you submit must be your own
work, although you may discuss the problem in general terms
with other people. You should definitely not be showing other people
your code, and generally speaking, it is not a good idea to talk about
the assignment when you're sitting in front of the computer.
- Sources of algorithms and code, if any, must be properly cited.
Remember that plagiarism regulations apply to code too.
You can put citations into comments in your Python code.
- If you have any questions about what you can and can't safely do,
feel free to email me.
- Per course policy, late assignments are not accepted.
Write a program that reads a temperature data file from the standard
input and plots its data using the turtle. The plot you'll be making
is a simple heat map showing what days in the month had zero/above-zero
temperatures (red), and which days had below-zero temperatures (blue).
Your program will be run by typing
python3 as2.py < datafile
which will make standard input become the data file instead of
the keyboard as it was in the last lab assignment. Important:
if you use a greater than sign by mistake, your data file will
be erased.
Data files and example plots, all from measurements at the
Calgary International Airport:
Your TA will be testing your programs using these files
as well as others you have not seen. Additional test
files the TAs use will conform to the data file format given, however.
The file format used for temperature data is as follows:
- The first line is the month in human-readable format.
- The second line is the month's number (1-12).
- The third line is the year.
- The fourth line is the number of temperatures that follow.
- Fifth and later lines are the temperatures.
You may assume that there is one temperature reading in the file
for each day in the given month.
- Make a directory to keep your files for this assignment in.
- Take notes as you go along, so you can remember what you've
tried already and what did and didn't work.
- Break the task down into small pieces.
- Use an incremental approach. This may mean trying
out things on the Python
command line as you go, before putting them in your program.
It may also mean running your program after each little
addition, to ensure that it's doing what you expect it to.
- Don't name your program
turtle.py, or Python will try to
import your program and not the turtle graphics module when you
say import turtle.
- Input is not coming from a human, so there's no need to print
a prompt with
input.
- Putting
input at the end of your turtle drawing won't
work as it did in Assignment 1, because the standard input
has been redirected. Instead, call time.sleep to delay
long enough for you (and the TA) to see your handiwork.
- You may find
math.floor useful.
- The modulo (
%) operator gives you the reminder from a
division. As a side effect, it can keep a variable's value
constrained within a range of values if used correctly - this
will be shown in class.
To hand the assignment in, send one email to your TA containing:
- Your student ID.
- Your Python source code file.
You are responsible for getting your assignment to your TA on time;
keep in mind that email can take a few minutes to deliver! To be safe,
you should CC yourself a copy of the email too.
You cannot be given a grade above zero if:
- You do not submit the required two items.
- You do not have a program in a .py file - you cannot turn in a solution that only
uses the Python command line.
- Your code does not run on the CPSC machines using Python 3.
- Your program does not plot based on data from an input data file.
- You do not cite the source of the weekday determination algorithm
(assuming you have implemented it).
Your assignment will be given a grade as follows:
- 1/10 - comments used in code to identify what parts of program are doing
(e.g., ``# calculate day of week'', ``# determine color'')
- 1/10 - variables defined at top of program for values that may need
adjustment over time (e.g., window width, window height, box size);
these variables should be used as appropriate in the rest of your
program
- 1/10 - plot title rendered correctly, showing month and year from the
input file
- 1/10 - day number rendered inside boxes for days
- 1/10 - all temperature data read correctly from data file
- 1/10 - boxes for days of month drawn in calendar format
- 1/10 - boxes for days of month correctly colored to reflect high
temperature on the day
- 1/10 - boxes for days of month start on the correct weekday for
the given month (i.e., every month doesn't start on Sunday)
and the Gaussian algorithm for weekday determination
is used, as given
here.
- 1/10 - program works correctly for all supplied data files
- 1/10 - program works correctly for TA's extra data files
The temperature data is from the ``historical weather'' area
of the Environment Canada website, i.e., the National Climate
Data and Information Archive,
and is used under the terms of non-commercial reproduction.
Per those terms, I must state that
the data are a `copy of an official work that is
published by the Government of Canada and that the reproduction has
not been produced in affiliation with or with the endorsement of the
Government of Canada.'
John Aycock
2012-01-25