The time/date stamps of the ANT+ HR monitor in the GPX files made by Orux have the format "2014-05-21T06:25:28Z". Does the GPX file format allow for recording milliseconds? If so, could you implement that? For accurately recording and processing HR data, milliseconds would be crucial.
Quote from: aag
The time/date stamps of the ANT+ HR monitor in the GPX files made by Orux have the format "2014-05-21T06:25:28Z". Does the GPX file format allow for recording milliseconds? If so, could you implement that? For accurately recording and processing HR data, milliseconds would be crucial.
Ant+ and bt sensors transmits a packet of data at most once a second, so it's useless to know exactly when the data was received, since the HR number orux get is just an average over 1 second calculated by the sensor itself.
Quote from: fabrylama
Ant+ and bt sensors transmits a packet of data at most once a second, so it's useless to know exactly when the data was received, since the HR number orux get is just an average over 1 second calculated by the sensor itself.
Oh really? Because here I am copying an excerpt from yesterday's GPX file, which clearly shows 5 or more ANT+ records per second (from a chest strap) . Hence there is no doubt that >1 packets/sec are received.
I am writing a Python script which does some interesting number-crunching on these data, which I shall be happy to post once it's functional.
99 2014-05-24T11:48:26Z
99 2014-05-24T11:48:26Z
99 2014-05-24T11:48:26Z
99 2014-05-24T11:48:26Z
99 2014-05-24T11:48:27Z
99 2014-05-24T11:48:27Z
99 2014-05-24T11:48:27Z
99 2014-05-24T11:48:28Z
100 2014-05-24T11:48:28Z
100 2014-05-24T11:48:28Z
100 2014-05-24T11:48:28Z
100 2014-05-24T11:48:28Z
100 2014-05-24T11:48:29Z
100 2014-05-24T11:48:29Z
100 2014-05-24T11:48:29Z
100 2014-05-24T11:48:29Z
100 2014-05-24T11:48:30Z
100 2014-05-24T11:48:30Z
100 2014-05-24T11:48:30Z
100 2014-05-24T11:48:30Z
this is a but of a quick hack, but it will extract and plot HR data from the Orux GPX files. I will improve it over time. The final goal is to gain functionality equivalent to PolarPro Trainer (histograms etc), but with the added location data.
import re
from string import Formatter
import time
import datetime
from time import strftime,strptime
from datetime import timedelta
import array
import matplotlib
from numpy import *
import scipy
from pylab import *
#Equations for Determination of Calorie Burn if VO2max is Unknown
#Male: ((-55.0969 + (0.6309 x HR) + (0.1988 x W) + (0.2017 x A))/4.184) x 60 x T
#Female: ((-20.4022 + (0.4472 x HR) - (0.1263 x W) + (0.074 x A))/4.184) x 60 x T
#
#where
#
#HR = Heart rate (in beats/minute)
#W = Weight (in kilograms)
#A = Age (in years)
#T = Exercise duration time (in hours)
#______________________________________________________
def strfdelta(tdelta, fmt):
f = Formatter()
d = {}
l = {'Y': 31536000, 'D': 86400, 'H': 3600, 'M': 60, 'S': 1}
k = map( lambda x: x[1], list(f.parse(fmt)))
rem = int(tdelta.total_seconds())
for i in ('Y', 'D', 'H', 'M', 'S'):
if i in k and i in l.keys():
d[i], rem = divmod(rem, l[i])
return f.format(fmt, **d)
#______________________________________________________
def getSec(s):
l = s.split(':')
return int(l[0]) * 3600 + int(l[1]) * 60 + int(l[2])
#______________________________________________________
# constants
HeartRates = open ("C:\Users\aag\Documents\Python\HeartRates.txt", "w")
gpxLinesList = [line.split(',') for line in open("C:\Users\aag\Documents\Python\test2.gpx")]
a= 0
previousHeartTime = 0
indexMultipleHR =0
indexGpx = 0
indexGpxHr =0
heartRateValue =0
weightAA = 92
birthdayAA = datetime.datetime(1960, 12, 1)
today = datetime.datetime.now()
ageAA = 53 # strfdelta(today - birthdayAA,"{Y}")
heartRateMatrix2D = []
heartRateMatrix3D = []
listHR = []
listHrTimeStamp = []
listHrInterval = []
#______________________________________________________
for eachLine in gpxLinesList:# iterate through each line of the GPX file
indexGpx +=1
matchHrLine = re.match(r"[[].d{1,}sd{4}[-]d{2}[-]d{2}[T]d{2}[:]d{2}[:]d{2}[Z]", str(eachLine))
if matchHrLine: # if finds a line containing heart rate information
indexGpxHr +=1
heartTime = datetime.datetime.strptime(str(matchHrLine.group() [-20:-1]) , '%Y-%m-%dT%H:%M:%S') # extract timestamp
if previousHeartTime == 0 :
oneSec = timedelta(seconds=1)
previousHeartTime = heartTime-oneSec # for the 1st line, assume 1 second lag
heartTimeInterval = int((heartTime - previousHeartTime).total_seconds()) # lag from previous measurememt
matchHeartRate = re.search(r"[[].d{1,}s", str(matchHrLine.group())) # match heart rate
heartRateValue = int(str(matchHeartRate.group()[2:])) # extract heart rate
#print(indexGpx, indexGpxHr, heartTime, heartRateValue, previousHeartTime, heartTimeInterval)
previousHeartTime = heartTime
heartRateLine = [heartRateValue, heartTime, heartTimeInterval]#
heartRateMatrix2D.append(heartRateLine)
#print (heartRateLine)
listHR.append(heartRateValue) # now populate lists
listHrTimeStamp.append(heartTime)
listHrInterval.append(heartTimeInterval)
#print (heartRateMatrix2D)
arrayHR = asarray(listHR)
arrayHrTimeStamp = asarray(listHrTimeStamp)
print (ageAA, arrayHR, min(arrayHR), max(arrayHR), mean(arrayHR), std(arrayHR))
plot(arrayHrTimeStamp,arrayHR)
savefig("C:/Users/aag/Documents/Python/HrOverTime.png",dpi=144)
show()
# use of hist()
# matplotlib.pyplot.hist(x, bins=10, range=None,
# normed=False, weights=None, cumulative=False, bottom=None,
# histtype='bar', align='mid', orientation='vertical', rwidth=None,
# log=False, color=None, label=None, stacked=False, hold=None, **kwargs)
n, bins, patches = hist(arrayHR, 10, normed=1, histtype='stepfilled')
savefig("C:/Users/aag/Documents/Python/HrHistogram.png",dpi=144)
#setp(patches, 'facecolor', 'g', 'alpha', 0.75)
show()