コード例 #1
0
from sklearn import cross_validation
from sklearn.metrics import confusion_matrix
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
コード例 #2
0
    time_activated = datetime.now()

    print("Time activated: ",
          time_activated.strftime('%H:%M:%S, %A - %d, %m %Y'))

    previous_json = ''

    sensor_data = []
    offset = 1
    mins = 5
    window_size = 25 * 60 * offset * mins  # 5 minutes assuming 25 Hz sampling rate
    step_size = window_size  # no overlap

    index = 0  # to keep track of how many samples we have buffered so far
    reset_vars()  # resets orientation variables

    while True:
        try:
            message = receive_socket.recv(1024).strip().decode('ascii')
            # print("Message")
            # print(message)
            json_strings = message.split("\n")

            json_strings[0] = previous_json + json_strings[0]

            # print("************************************ json_strings *************************************")
            # print(json_strings)
            # print("************************************************************************************** \n")

            for json_string in json_strings: