User:Kithira/Course Pages/CSCI 12/Assignment 2/Group 3/Homework 4

Function 1: Summarizedvalue
This function takes three arguments and returns their summarized value. X represents the acceleration in the x-direction, y represents the acceleration in the y-direction and z is the acceleration in the z-direction. Their summarized value, which is the absolute value of the square root of the sum of their squares minus 1, represents the equivalent acceleration in 3-dimensions.

Function 2: Filter
Filter takes two arguments: a list and an integer which represents the order of a potential spike in the list. If the difference between the element j and the element j-1 is greater than a certain limit, the function assigns to the element j the value of the element j-1.

Main Program
This set of instructions reads the file where data is stored. The first 100 lines are skipped. This set of instructions goes through every row in the data file, splits x, y, and z from every row, computes their summarized value and stores it in a list. After computing summarized values for every 1/40th of a second, we add up every 40 consecutive values to get one summarized value for every second. The goal behind this is to compress the original data file. First 0 is assigned to variables sum and m. The while loop runs as long as m is less than the length of the list of summarized values we created earlier. For every iteration, the mth value in list is added to sum, and 1 is added to m. When m reaches a multiple of 40, sum is added to listsummarizedvalue before being set back equal to zero to store the sum of the next 40 values, and so on until m is greater then the length of list. For the first 40 values for example, m starts out as 0 and the program starts adding the mth item to sum. When m is equal to 39, the 39th value is added up to sum, which means that (39-0+1)=40 values have been added to sum. After item 39 is added to sum, m becomes equal to 40 which satisfies the condition m % 40 == 0. At that moment, sum is appended to listsummarized and then is set back equal to zero and the program goes back to the while loop, with m starting out as 40. This second subloop stops when m is equal to 79, and so on. This loop works like the one explained above. As long as m is less than the length of listsummarizedvalue, the mth value of listsummarizedvalue is added to the variable sum. Whenever we have 60 values ( m is a multiple of 60), sum divided by 60 (average activity per minute) is added to a new list, averageminute. Now all that's left for us to do is computing classific, the value that would allow us to classify our test subject. To do this we create a loop that goes through averageminute and add up all the values contained in it. We compare classific to 7500 and 22500. If classific is less than 7500, our subject is sedentary. If classific is between 7500 and 22500, our test subject is moderate. If classific is greater than 22500, then our subject is vigorous.