Commit 4edaf66e authored by pandersson's avatar pandersson
Browse files

Adds ground truth to output, and cleans up a bit

parent 0985971f
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 07:38:10 2020
@author: frida
"""
import numpy as np
import sys
from get_data import get_data
#%%
def main():
freq = 100 # Assume data was collected at 100 Hz
still = 3
walk = 15
# Get mean of accelerometer x,y,z data
acc, ground_truth = get_data(sys.argv[1], 'ACC')
# Check minimum and maximum value over time interval. Determine activity during time interval based on difference between these
time_interval = 2 # s
for i in np.arange(0, len(acc)//freq - time_interval, time_interval):
acc_one_sec = acc[i * freq:(i + time_interval) * freq]
xMin = min(acc_one_sec)
xMax = max(acc_one_sec)
if xMax - xMin < still: # Some limit for still
print("At time: {}-{}, the person is - Still ({})".format(i, i + time_interval, ground_truth[int((2 * i + time_interval) * freq / 2.0)]))
elif xMax - xMin < walk: # Some limit for walk
print("At time: {}-{}, the person is - Walking ({})".format(i, i + time_interval, ground_truth[int((2 * i + time_interval) * freq / 2.0)]))
else:
print("At time: {}-{}, the person is - Running ({})".format(i, i + time_interval, ground_truth[int((2 * i + time_interval) * freq / 2.0)]))
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -7,12 +7,11 @@ import sys
import numpy as np
def main():
person = sys.argv[1] # Frida or Momina
visualization = sys.argv[2] # ACC or GYR
person = sys.argv[1] # Frida, Matthias or Momina
data_type = sys.argv[2] # ACC or GYR
verbose = True if len(sys.argv) > 3 else False
data_path = '../Data_' + person + '/'
data_paths = (glob.glob(data_path + '/*.txt'))
data_x = []
......@@ -21,13 +20,15 @@ def main():
all_nbr_measurements = []
# Read each file in person's directory
for path in data_paths:
nbr_measurements = 0
with open(path, 'r') as f:
# Retrieve data of type data_type, and store the activity and the number of measurements
for l in f:
l = l.split('\t')
if visualization == l[1]:
if data_type == 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
......@@ -40,9 +41,10 @@ def main():
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))
# Plot x, y, z, and the mean of those, together with delimeters for the different files
cumulative_all_nbr_measurements = np.cumsum(all_nbr_measurements)
plt.figure(figsize=(24, 9))
plt.suptitle(visualization + ' data visualization')
plt.suptitle(data_type + ' data visualization')
plt.subplot(411)
plt.plot(data_x)
for nbr in cumulative_all_nbr_measurements:
......
......@@ -6,75 +6,48 @@ 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
def get_data(person, data_type):
freq = 100
data_path = '../Data_' + person + '/'
data_paths = (glob.glob(data_path + '/*.txt'))
data_x = []
data_y = []
data_z = []
data_GT = []
all_nbr_measurements = []
# Read each txt file in the folder
for path in data_paths:
nbr_measurements = 0
with open(path, 'r') as f:
print("Reading file {}: ".format(path))
# Retrieve data of type data_type, and store the activity and the number of measurements
for l in f:
l = l.split('\t')
if visualization == l[1]:
if data_type == 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
path_str_lower_case = path.lower()
if 'running' in path_str_lower_case:
data_GT.append('Running')
elif 'walking' in path_str_lower_case:
data_GT.append('Walking')
else:
data_GT.append('Still')
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)
# Compute mean of x, y and z components of the data
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()
return data_mean, data_GT
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 07:38:10 2020
@author: frida
"""
import numpy as np
from data_visualization_copy import get_data
#%%
x = 1
freq = 100 # Hz ?
time_interval = 1 # s
xMin = np.inf
xMax = -np.inf
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("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