Skip to content

Commit

Permalink
Completed data communicator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dheeraj1998 committed Apr 14, 2019
1 parent debba18 commit 996b548
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

.DS_Store
Data_Analysis_Python/.ipynb_checkpoints/Data Classification-checkpoint.ipynb
4 changes: 2 additions & 2 deletions Data_Analysis_Python/Data Classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
" \n",
"analysis_condition = ListTable()\n",
"\n",
"analysis_condition.append(['Min', 'Max', 'Range', '75%','25%','Median', 'Mean', 'STD', 'Var','Kurtosis','Skewness'])"
"analysis_condition.append(['Min', 'Max', 'Range', '75%', '25%', 'Median', 'Mean', 'STD', 'Var','Kurtosis','Skewness'])"
]
},
{
Expand Down Expand Up @@ -8240,7 +8240,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,
Expand Down
55 changes: 50 additions & 5 deletions Data_Analysis_Python/data_communicator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Importing the required libraries
import numpy as np
import scipy.signal
import serial
import serial.tools.list_ports
import sys
import urllib.request

# Viewing all the available ports
ports = serial.tools.list_ports.comports()
Expand All @@ -11,12 +14,54 @@
print("{}: {} [{}]".format(port, desc, hwid))

# Initialising the COM and BAUD rate
COM = '/dev/cu.usbmodem14201'
COM = '/dev/cu.usbmodem14101'
BAUD = 9600

# Declaring a Serial object
arduino_serial = serial.Serial(COM, BAUD, timeout = .1)

while True:
val = str(arduino_serial.readline().decode().strip('\r\n'))
input_value = input('\n\nPress return to start recording data: ')

# Declaring a Serial object
arduino_serial = serial.Serial(COM, BAUD, timeout = .1)
input_values = []

# Getting the data from serial port and adding it an array
while len(input_values) < 50:
value = str(arduino_serial.readline().decode().strip('\r\n'))

try:
if len(value) > 0 and int(value):
input_values.append(int(value))
except:
continue

print('\nThe recorded values are: ', input_values)

# Filtering of the input values
filtered_values = []

mean_value = np.mean(input_values)
value_25 = np.percentile(input_values, 25)
value_75 = np.percentile(input_values, 75)

for value in input_values:
filtered_values.append(value_75 if value > mean_value else value_25)
print('\nThe filtered values are: ', filtered_values)

# Extraction of the signal parameters
extracted_parameters = [np.amin(filtered_values), np.amax(filtered_values),
np.ptp(filtered_values), np.percentile(filtered_values, 75),
np.percentile(filtered_values, 25), np.median(filtered_values),
np.mean(filtered_values), round(np.std(filtered_values),2),
round(np.var(filtered_values),2), round(scipy.stats.kurtosis(filtered_values),2),
round(scipy.stats.skew(filtered_values),2)]

print('\nThe parameters of this signal are: ', extracted_parameters)

# Calling the web API
web_api_url = "https://pacific-harbor-19774.herokuapp.com/predict?myvar=" + str(extracted_parameters[0]) + "," + str(extracted_parameters[1]) + "," + str(extracted_parameters[2]) + "," + str(extracted_parameters[3]) + "," + str(extracted_parameters[4]) + "," + str(extracted_parameters[5]) + "," + str(extracted_parameters[6]) + "," + str(extracted_parameters[7]) + "," + str(extracted_parameters[8]) + "," + str(extracted_parameters[9]) + "," + str(extracted_parameters[10])

print('\nThe web API URL is: ', web_api_url)
urllib.request.urlopen(web_api_url)

# Closing the Serial connection
arduino_serial.close()

0 comments on commit 996b548

Please sign in to comment.