OruxMaps
Visit the new forum: <a href="http://www.oruxmaps.com/foro">OruxMaps</a>

Join the forum, it's quick and easy

OruxMaps
Visit the new forum: <a href="http://www.oruxmaps.com/foro">OruxMaps</a>
OruxMaps
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Script to convert recorded Heartrate Data for Sporttracks (Updated)

2 posters

Go down

Script to convert recorded Heartrate Data for Sporttracks (Updated) Empty Script to convert recorded Heartrate Data for Sporttracks (Updated)

Post  BerniPi Mon Jul 25, 2011 7:45 pm

In my Holidays I had some problems with the gps reception and returned from my workouts with nice Heartrate statistics, but without gps trackpoints. I searched a way to import the heartrate data track to an activitiy in Sporttracks.
It can be imported with the "Edit Data Tracks" dialog. So i wrote a VBScript to convert the Heartrate Data generated by Oruxmaps to the csv format that Sporttracks need.

The Script is in early stage and not really userfriendly, but it works. Save the code in a file called "OruxHR2CSV.vbs" (the .vbs is the important thing) and place it in the same folder as your gpx files. Then start the Command Prompt (cmd.exe) and execute the script with the filename as argument (for example: OruxHR2CSV.vbs test.gpx). The Script creates a csv file called like the gpx in the same folder.

Hope it works for you, maybe i can improve it further.


I'm a noob in programming, so I look forward for your suggestions.

Code:

Set WshShell = Wscript.CreateObject("WScript.Shell")
Set Arg       = Wscript.Arguments
Set FSO      = CreateObject("Scripting.FileSystemObject")
Set net      = Wscript.createObject("Wscript.network")

Dim gpxsrc, scriptpath, start, ende, data, erste, r, Text, action

if Arg.count < 1 Then
msgbox "Place the Script in the folder of your gpx files and execute the Script with the filename as argument."
WScript.Quit
End if

gpxsrc = Arg.item(0)

if InStr(1, gpxsrc,".gpx") = 0 Then
msgbox "The Sourcefile has to be a gpx file!"
WScript.Quit
End if

scriptpath = FSO.getparentfoldername(Wscript.ScriptFullName)


Lesen(scriptpath&"\"&gpxsrc)
start = InStr(1, Text, "<om:bpm")+68
ende = InStr(start, Text, "</om:bpm>")

if ende-start < 1 Then
msgbox "The Sourcefile contains no heartrate data created by oruxmaps."
WScript.Quit
End if

data = Split(Mid(Text, start, ende - start), "Z")

ReDim Preserve erg(Ubound(data)+2)

'erste Zeile
erste = Replace(Split(data(0)," ")(1),"T"," ")

erg(0) = "Seconds;Value"
erg(1) = "0"&";"&Split(data(0)," ")(0)

for r=1 to Ubound(data)-1
 erg(r+1) = DateDiff("s",erste,Replace(Split(data(r)," ")(1),"T"," "))&";"&Right(Split(data(r)," ")(0),Len(Split(data(r)," ")(0))-1)
Next

Schreiben(Join(erg, VbCrLF))

msgbox "Converted "&scriptpath&"\"&gpxsrc&" to "&scriptpath&Replace(gpxsrc,".gpx","")&".csv. Script finished successfully."

'-------------------------------------------------------------------------------
Sub Schreiben (WText)
'-------------------------------------------------------------------------------
Set File = fso.OpenTextFile(scriptpath&"\"&Replace(gpxsrc,".gpx","")&".csv", 2, True)
File.Write(WText)
File.Close
End Sub


'-------------------------------------------------------------------------------
Sub Lesen (Datei)
'-------------------------------------------------------------------------------
Dim FileNow, a, b
Set a = fso.GetFile(Datei)
b = a.Size
Set f = fso.OpenTextFile(Datei, 1, True)
Text = f.Read(b)
f.Close
End Sub

UPDATE: Only worked in main directories (C:\, D:\, ...)
UPDATE2: Fixed the Script and added some error handling.


Last edited by BerniPi on Mon Mar 26, 2012 7:04 am; edited 6 times in total (Reason for editing : PostIt (orux))

BerniPi

Cantidad de envíos : 26
Fecha de inscripción : 2011-05-24
Localización : Austria

Back to top Go down

Script to convert recorded Heartrate Data for Sporttracks (Updated) Empty Re: Script to convert recorded Heartrate Data for Sporttracks (Updated)

Post  orux Tue Jul 26, 2011 5:06 pm

TheAbalone wrote:In my Holidays I had some problems with the gps reception and returned with nice Heartrate statistics, but without gps trackpoints. I searched a way to import the heartrate data track to an activitiy. It can be imported with the "Edit Data Tracks" dialog. So i wrote a VBScript to convert the Heartrate Data generated by Oruxmaps to the csv format that Sporttracks need.

The Script is in early stage and not really userfriendly, but it works. Save the code in a file called "OruxHR2CSV.vbs" (the .vbs is the important thing) and place it in the same folder as your gpx files. Then start the Command Prompt (cmd.exe) and execute the script with the filename as argument (for example: OruxHR2CSV.vbs test.gpx). The Script creates a csv file called like the gpx in the same folder.

Hope it works for you, maybe i can improve it further.


I'm a noob in programming, so I see forward to your suggestions.


Thanks, TheAbalone;

Interesting...

orux
orux
orux

Cantidad de envíos : 3946
Fecha de inscripción : 2009-07-06

Back to top Go down

Script to convert recorded Heartrate Data for Sporttracks (Updated) Empty Re: Script to convert recorded Heartrate Data for Sporttracks (Updated)

Post  BerniPi Tue Jul 26, 2011 8:28 pm

Thank YOU orux, for this great app and all the work you put into it. This Script adds also the possibility to use Oruxmaps to track Indooractivities. I know, it's kind of strange to use a GPS-tracking-map app indoors, but who cares Laughing

theabalone

BerniPi

Cantidad de envíos : 26
Fecha de inscripción : 2011-05-24
Localización : Austria

Back to top Go down

Script to convert recorded Heartrate Data for Sporttracks (Updated) Empty Re: Script to convert recorded Heartrate Data for Sporttracks (Updated)

Post  BerniPi Mon Mar 19, 2012 12:36 pm

Updated the Script. Should work now Embarassed , although nobody complained yet Laughing

BerniPi

Cantidad de envíos : 26
Fecha de inscripción : 2011-05-24
Localización : Austria

Back to top Go down

Script to convert recorded Heartrate Data for Sporttracks (Updated) Empty Re: Script to convert recorded Heartrate Data for Sporttracks (Updated)

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum