Commit 437501aa authored by Frida Heskebeck's avatar Frida Heskebeck
Browse files

Edited the script to predict activity

parent 44ac6b70
# Activity Recognition
import matplotlib.pyplot as plt
import statistics
import glob
import sys
import numpy as np
def get_data(person,visualization):
#person = sys.argv[1] # Frida or Momina
#visualization = sys.argv[2] # ACC or GYR
#verbose = True if len(sys.argv) > 3 else False
verbose= False
freq = 100
data_path = '../Data_' + person + '/'
data_paths = (glob.glob(data_path + '/*.txt'))
data_x = []
data_y = []
data_z = []
all_nbr_measurements = []
for path in data_paths:
nbr_measurements = 0
with open(path, 'r') as f:
for l in f:
l = l.split('\t')
if visualization == l[1]:
data_x.append(float(l[2]))
data_y.append(float(l[3]))
data_z.append(float(l[4][:-1])) # don't include newline
nbr_measurements += 1
if verbose:
print("Mean value x: {:0.3f}".format(statistics.mean(data_x)))
print("Mean value y: {:0.3f}".format(statistics.mean(data_y)))
print("Mean value z: {:0.3f}".format(statistics.mean(data_z)))
all_nbr_measurements.append(nbr_measurements)
print("Mean of means for file {:s}: {:0.3f}".format(path, (statistics.mean(data_x) + statistics.mean(data_y) + statistics.mean(data_z)) / 3))
cumulative_all_nbr_measurements = np.cumsum(all_nbr_measurements)
plt.figure(figsize=(24, 9))
plt.suptitle(visualization + ' data visualization')
plt.subplot(411)
#plt.plot(data_x)
plt.plot(np.array(range(len(data_x)))/freq,data_x)
for nbr in cumulative_all_nbr_measurements:
plt.axvline(nbr/freq, color='r')
plt.ylabel('x')
plt.subplot(412)
#plt.plot(data_y)
plt.plot(np.array(range(len(data_y)))/freq,data_y)
for nbr in cumulative_all_nbr_measurements:
plt.axvline(nbr/freq, color='r')
plt.ylabel('y')
plt.subplot(413)
#plt.plot(data_z)
plt.plot(np.array(range(len(data_z)))/freq,data_z)
for nbr in cumulative_all_nbr_measurements:
plt.axvline(nbr/freq, color='r')
plt.ylabel('z')
plt.subplot(414)
data_mean = (np.asarray(data_x) + np.asarray(data_y) + np.asarray(data_z)) / 3.0
#plt.plot(data_mean)
plt.plot(np.array(range(len(data_mean)))/freq,data_mean)
for nbr in cumulative_all_nbr_measurements:
plt.axvline(nbr/freq, color='r')
plt.ylabel('mean')
plt.show()
return data_mean
#if __name__ == "__main__":
# main()
......@@ -7,11 +7,9 @@ Created on Wed Mar 25 07:38:10 2020
"""
import numpy as np
from data_visualization_copy import get_data
#%%
def get_acc_data(y): # Get the real data here!
x = [1,6,10]
return np.ones(3)*x[np.mod(y,3)]
#%%
......@@ -20,33 +18,29 @@ freq = 100 # Hz ?
time_interval = 1 # s
xMin = np.inf
xMax = -np.inf
still = 15 # Tune these
walk = 25 # Tune these
y=0
while x and y < 10:
xMin = np.inf
xMax = -np.inf
for i in range(time_interval*freq):
try:
acc = get_acc_data(y) # Needs to implement this one
except:
x = 0
break
x = np.sum(np.abs(acc))
if x < xMin:
xMin = x
if x > xMax:
xMax = x
if xMin > -still and xMax < still: # Some limit for still
print("Still")
elif xMin > -walk and xMax < walk: # Some limit for walk
print("Walk")
still = 3 # Tune these
walk = 15 # Tune these
xMin = np.inf
xMax = -np.inf
acc = get_data('Frida','ACC')
#acc = get_data('Momina','ACC')
time_interval = 2
for i in np.arange(0,len(acc)//freq-time_interval,time_interval):
#for i in range(150,180):
acc_one_sec = acc[(i)*freq:(i+time_interval)*freq]
xMin = min(acc_one_sec)
xMax = max(acc_one_sec)
#print(xMax-xMin)
if xMax-xMin < still: # Some limit for still
print("At time: {}-{}, the person is - Still".format(i,i+time_interval))
elif xMax-xMin < walk: # Some limit for walk
print("At time: {}-{}, the person is - Walking".format(i,i+time_interval))
else:
print("Run")
y+=1
print("At time: {}-{}, the person is - Running".format(i,i+time_interval))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment