Jump to content

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

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 137.165.8.45 (talk) at 22:37, 22 January 2013 (Code:: edited phrasing). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Final Project by: Christopher Chandler, Ashley Kim, Marina Chaves Caldieraro

Code:

from math import sqrt, pow
def summarize(x, y, z):
    sumT = 0
    for i in range(40):
        sumT = sumT + abs(sqrt(pow(x,2)+pow(y,2)+pow(z,2))-1.0)
    return sumT

This code represents the function Summarize, which summarizes each input using |(sqrt (x^2 + y^2 + z^2)-1|. Then, these values are summarized for i in range(40), which gives a value for 1 second.

def getData(file):
    infile = open(file)
    for i in range(100):
        line = infile.readline()
    total = 0
    for i in range(10080):
        lis = 0
        for i in range(60):
            """avg all values over min"""
            line = infile.readline()
            row = line.split(",")
            res = summarize(float(row[1]), float(row[2]), float(row[3]))
            if res > 5.0:
                res = 0
            lis = lis + res
        ave = lis/60.0
        total = total + ave
    return total
print getData("/usr/local/share/cs12/Test1.csv")

The second part of code is responsible for averaging the values over a minute then adding all the minutes to find a total result that determines the intensity classification. The filter we used deletes any value above 5.0 per minute. We determined this boundary value based off of the plot of the original summarized data over 10 hours. The range of 24192000 represents the total seconds in a week. Finally, we determined that our test subject was a moderately active person.