Programming Assignment 1 (Fitbit Data Analysis)

Data Transformation and Helper functions

Write a Python program that reads the name of a data file as a command line parameter, opens that file and reads Fitbit data for a particular day stored in the file, and prints the total number of steps taken and the hourly rate at which these steps were taken. A sample input file is shown below and a sample run of the program is also shown with the corresponding output.

Mac-mini:p1-fitbit raj$ more in.dat
# read from file data about one day 
# format: start_time:end_time:#steps
09.30AM:09.45AM:220
11.45AM:12.23PM:300
11.45AM:10.23AM:302
2.45PM:3.23PM:202
3.45PM:3.53PM:90
5.45PM:5.53PM:80
6.45PM:7.23PM:1000
10.45PM:10.53PM:102

Mac-mini:p1-fitbit raj$ python3 Fitbit.py in.dat 
INVALID data: 11.45AM:10.23AM:302

Total steps:  1994
Hourly steps rate:  781 

Mac-mini:p1-fitbit raj$

Some Notes:

  1. To read command line parameters, you can use the folowing code:
    import sys
    
    fname = sys.argv[1]
    
  2. To read data from file, you can use the following code:
    with open(fname) as f:
        data = f.read().splitlines()
    f.close()
    
  3. We shall assume that the input file is well-formed with exactly 3 pieces of data per line: start time, end time, and number of steps. However, some entries may be incorrect in that the end time is "before" start time. If this is the case, you should discard the entry from your calculations.

  4. Here are some functions that can be developed to solve the problem:
    # Reads file and returns a list of lines in string format
    def read_data(fname):
    	pass
    
    # Takes a list of lines as input and returns a new list of lines with the 
    # comment lines (the ones that begin with #) removed.
    def remove_comment_lines(data):
    	pass
    
    # Takes a string such as "09.30aM" and returns #minutes since midnight
    def generate_minutes_since_midnight(s):
    	pass
    
    # Takes string data, such as "09.30AM:09.45AM:220" as input and returns
    # corresponding (stime,etime,steps), e.g. (570, 585, 220), as output.
    def convert_string_to_triple(d):
    	pass
    
    # Takes (stime,etime,steps) as input and returns corresponding String such as
    # "09.30AM:09.45AM:220"
    def convert_triple_to_string(d):
    	pass
    
    # Takes a list of strings such as "09.30AM:09.45AM:220" and returns
    # a list of triples (stime,ntime,steps)
    def extract_data_parts(data):
    	pass
    
    # Takes list of (stime,etime,steps) and returns a new list that does not contain bad data
    def remove_bad_data(data):
    	pass
    
    # Takes a list of (stime,etime,steps) and returns total steps and total minutes
    def compute_stats(data):
    	pass
    
    # The main function that calls the above functions in order and prints final results
    def main():
    	pass
    
    
What to Submit: Fitbit.py