Commit 8ccbc33c authored by pandersson's avatar pandersson
Browse files

Adds script for data visualization

parent 8809e4e9
# Activity Recognition
import matplotlib.pyplot as plt
import statistics
import glob
import sys
import numpy as np
def main():
person = sys.argv[1] # Frida or Momina
visualization = 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 = []
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(311)
plt.plot(data_x)
for nbr in cumulative_all_nbr_measurements:
plt.axvline(nbr, color='r')
plt.subplot(312)
plt.plot(data_y)
for nbr in cumulative_all_nbr_measurements:
plt.axvline(nbr, color='r')
plt.subplot(313)
plt.plot(data_z)
for nbr in cumulative_all_nbr_measurements:
plt.axvline(nbr, color='r')
plt.show()
if __name__ == "__main__":
main()
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