예제 #1
0
def buffer_and_predict(t, x, y, z, on_activity_detected):
    global index
    global sensor_data

    sensor_data.append(reorient(x, y, z))
    index += 1
    # make sure we have exactly window_size data points :
    while len(sensor_data) > window_size:
        sensor_data.pop(0)

    if (index >= step_size and len(sensor_data) == window_size):
        activity_recognition_thread = threading.Thread(
            target=predict,
            args=(np.asarray(sensor_data[:]), on_activity_detected))
        activity_recognition_thread.start()
        index = 0
예제 #2
0
import pickle

# Load Data From Disk
print("Loading data...")
sys.stdout.flush()
data_file = os.path.join("data", "final-project-data.csv")
data = np.genfromtxt(data_file, delimiter=",")
print("Loaded {} raw labelled activity data samples.".format(len(data)))
sys.stdout.flush()

# Pre-processing
print("Reorienting accelerometer data...")
sys.stdout.flush()
reset_vars()
reoriented = np.asarray(
    [reorient(data[i, 1], data[i, 2], data[i, 3]) for i in range(len(data))])
reoriented_data_with_timestamps = np.append(data[:, 0:1], reoriented, axis=1)
data = np.append(reoriented_data_with_timestamps, data[:, -1:], axis=1)

# Extract Features & Labels
# you may want to play around with the window and step sizes
window_size = 20
step_size = 20

# sampling rate for the sample data should be about 25 Hz; take a brief window to confirm this
n_samples = 1000
time_elapsed_seconds = (data[n_samples, 0] - data[0, 0]) / 1000
sampling_rate = n_samples / time_elapsed_seconds

feature_names = [
    # 0, 1, 2
예제 #3
0
            for json_string in json_strings:
                try:
                    data = json.loads(json_string)
                except:
                    previous_json = json_string
                    continue
                previous_json = ''  # reset if all were successful
                sensor_type = data['sensor_type']
                if (sensor_type == u"SENSOR_ACCEL"):
                    t = data['data']['t']
                    x = data['data']['x']
                    y = data['data']['y']
                    z = data['data']['z']

                    sensor_data.append(reorient(x, y, z))
                    index += 1
                    # make sure we have exactly window_size data points :
                    while len(sensor_data) > window_size:
                        sensor_data.pop(0)

                    if (index >= step_size
                            and len(sensor_data) == window_size):
                        t = threading.Thread(target=predict,
                                             args=(np.asarray(
                                                 sensor_data[:]), ))
                        t.start()
                        index = 0

            sys.stdout.flush()
        except KeyboardInterrupt:
예제 #4
0
sys.stdout.flush()
data_file = 'final-data-accel.csv'
data = np.genfromtxt(data_file, delimiter=',')
print("Loaded {} raw labelled activity data samples.".format(len(data)))
sys.stdout.flush()

# %%---------------------------------------------------------------------------
#
#		                    Pre-processing
#
# -----------------------------------------------------------------------------

print("Reorienting accelerometer data...")
sys.stdout.flush()
reset_vars()
reoriented = np.asarray([reorient(data[i,1], data[i,2], data[i,3]) for i in range(len(data))])
reoriented_data_with_timestamps = np.append(data[:,0:1],reoriented,axis=1)
data = np.append(reoriented_data_with_timestamps, data[:,-1:], axis=1)


# %%---------------------------------------------------------------------------
#
#		                Extract Features & Labels
#
# -----------------------------------------------------------------------------

# you may want to play around with the window and step sizes
window_size = 10
step_size = 10

# sampling rate for the sample data should be about 25 Hz; take a brief window to confirm this
예제 #5
0
        if len(data) < 13:
            continue

        for i in range(9):
            data[i] = data[i].strip()
            # print(str(i) + " " + data[i])

        timestamp = data[0]
        accel_x = float(data[2])
        accel_y = float(data[3])
        accel_z = float(data[4])
        gyro_x = float(data[6])
        gyro_y = float(data[7])
        gyro_z = float(data[8])

        temp_data = reorient(accel_x, accel_y, accel_z)
        temp_data.append(gyro_x)
        temp_data.append(gyro_y)
        temp_data.append(gyro_z)

        sensor_data.append(temp_data)
        index += 1

        while len(sensor_data) > window_size:
            sensor_data.pop(0)
        if index >= step_size and len(sensor_data) == window_size:
            t = threading.Thread(target=predict,
                                 args=(np.asarray(sensor_data[:]), ))
            t.start()
            index = 0