Week 8: More Top Down Design (TDD)
Week 8 Goals
-
Review
-
Top Down Design concepts
-
How to read data from files
-
How to write functions stubs
-
How to implement a design bottom-up
-
How to test functions incrementally
-
Week 8 Code
-
design_getfit.py
: designing a program that helps monitor your weekly steps -
week1.csv
,week2.csv
: sample csv files for the get fit program
Top Down Design
Suppose that we have data on how many steps a person walked per week.
For example in the sample file called week1.csv
we can see that on
Monday, the user walked about twelve thousand steps, on Tuesday they
walked about five thousand steps, and so on for the rest of the week.
$ cat week1.csv Mon,12345 Tue,5671 Wed,10975 Thu,8909 Fri,4655 Sat,11412 Sun,10402
Here’s another sample file, called week2.csv
, that contains another
week of step data.
$ cat week2.csv Mon,18345 Tue,19012 Wed,12567 Thu,9876 Fri,9076 Sat,10132 Sun,6789
Our goal is to design a program that would work as shown below. Notice that it first asks the user for a filename with step data. Then it asks for their step goal. Next it prints a bar chart showing each day of the week as a bar with a cross cutting line representing their goal. Finally it summarizes the total steps for the week, the average steps per day, and provides an encouraging message depending on their results.
$ python3 getfit.py Enter name of file containing step data: week1.csv Enter daily step goal: 10000 | Mon:+++++++++++++++++++++++++++++++++++++++++++ 12345 | Tue:+++++++++++++++++++ 5671 | Wed:++++++++++++++++++++++++++++++++++++++ 10975 | Thu:+++++++++++++++++++++++++++++++ 8909 | Fri:++++++++++++++++ 4655 | Sat:++++++++++++++++++++++++++++++++++++++++ 11412 | Sun:++++++++++++++++++++++++++++++++++++ 10402 | Total steps for week 64369 Average steps per day 9195 Good work! You reached your goal 4 days this week.
Here’s another sample run. Notice that the program requires the user to enter a step goal that is at least 1000 and no more than 20000.
$ python3 getfit.py Enter name of file containing step data: week2.csv Enter daily step goal: 100 Choose a goal between 1000 and 20000 Enter daily step goal: 25000 Choose a goal between 1000 and 20000 Enter daily step goal: 6000 | Mon:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 18345 | Tue:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 19012 | Wed:++++++++++++++++++++++++++++++++++++++++++++ 12567 | Thu:++++++++++++++++++++++++++++++++++ 9876 | Fri:+++++++++++++++++++++++++++++++ 9076 | Sat:+++++++++++++++++++++++++++++++++++ 10132 | Sun:+++++++++++++++++++++++ 6789 | Total steps for week 85797 Average steps per day 12256 You reached your goal every day this week! Perhaps it's time to up your goal.
Notice that the ending message changed from the previous sample run, and that it depends on how many days they achieved their goal.
Begin building your top-down design in the file design_getfit.py
.