Skip to content

Instantly share code, notes, and snippets.

@dzhibas
Created August 8, 2013 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzhibas/6184425 to your computer and use it in GitHub Desktop.
Save dzhibas/6184425 to your computer and use it in GitHub Desktop.
checks acelometer measurements and says if device is in free-fall
from datetime import datetime
from math import sqrt
import csv
f = open("train.csv", "rb")
r = csv.reader(f)
header = r.next()
print(header)
loop = 0
for l in r:
try:
if l[1] == '0' and l[2] == '0' and l[3] == '0':
# ignore
continue
x = float(l[1])
y = float(l[2])
z = float(l[3])
except ValueError:
print("error in converting line: ", l)
v = sqrt(x**2 + y**2 + z**2)
if v <= 0.05:
print("Device is in free-fall", l)
loop += 1
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment