Commit f71be70b authored by Torje Garnes Anderson's avatar Torje Garnes Anderson
Browse files

Upload New File

parent 86b69e47
import csv
import matplotlib.pyplot as plt
x = [] # Every value has a number starting from 0 up to 99
y = [] # Array for the sensor values
y2 = [] # Array for temperature
p = 0 # Counter for pulse beat
i = 0 # Counter for every sensor value
check = False # Set to True if the Beat has reach the right value
with open("csv_file") as csvfile: # Open csv_file
reader = csv.reader(csvfile, delimiter=',') # Reading the csv_file
for row in reader: # Looping through the list from csv_file
x.append(int(row[0])) # Adding the value numbers to array
y.append(float(row[1])) # Adding the sensor values to array
y2.append(float(row[2])) # Adding temperature to array
if y[i] > 0.03: # If sensor value is over this value we start counting this as one beat
if not check: # Executes when check is False
p += 1 # Adding one beat to the counter
check = True # Turning check into False
i += 1 # Adding one to the counter
else: # Check is True and we dont add one beat
i += 1 # Adding one to the counter
check = False # Always starting the loop as False
i += 1 # Always adding one to the counter
#Found on stackoverflow
def moving_average(a, n):
ret = np.cumsum(a, dtype=float)
ret[n:] = ret[n:] - ret[:-n]
return ret[n - 1:] / n
#Found on stackoverflow
def running_median_insort(seq, window_size):
seq = iter(seq)
d = deque()
s = []
result = []
for item in islice(seq, window_size):
insort(s, item)
m = window_size // 2
for item in seq:
old = d.popleft()
del s[bisect_left(s, old)]
insort(s, item)
return result
#Adding the value from pulse and temp arrays in to each y-axe
fig, ax = plt.subplots()
ax.plot(x, y, color="red")
ax.set_xlabel("Antall målinger")
#Code to get different colors on the labels, gathered from
ybox1 = TextArea("Moving median ", textprops=dict(color="purple", size=10, rotation=90, ha='left', va='bottom'))
ybox2 = TextArea("og ", textprops=dict(color="k", size=10, rotation=90, ha='left', va='bottom'))
ybox3 = TextArea("Moving average ", textprops=dict(color="g", size=10, rotation=90, ha='left', va='bottom'))
ybox4 = TextArea(", ", textprops=dict(color="k", size=10, rotation=90, ha='left', va='bottom'))
ybox5 = TextArea("Sensordata", textprops=dict(color="r", size=10, rotation=90, ha='left', va='bottom'))
ybox = VPacker(children=[ybox1, ybox2, ybox3, ybox4, ybox5], align="center", pad=0, sep=5)
anchored_ybox = AnchoredOffsetbox(loc=8, child=ybox, pad=0., frameon=False, bbox_to_anchor=(-0.1, 0),
bbox_transform=ax.transAxes, borderpad=0.)
fig, ax = plt.subplots() # Drawing the main plot
ax.plot(x, y, color="red") # Plotting the arrays for every number and sensor value in red color
ax.set_xlabel("Antall målinger") # Label for number of readingssum
ax.set_ylabel("Sensorverdi", color="red") # Label for sensor value in color red
ax2 = ax.twinx()
ax2.plot(x, y2, color="blue") # Plotting the temperature values in color blue
ax2.set_ylabel("Temperatur", color="blue") # Adding label on the right for temperature in blue
plt.title("Din puls er: " + str(
p * 6)) # Calculate the pulse, we add 6 with the number of beats because we want this in beats per minute # Showing the plot
Supports Markdown
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