trackerproject / trackeR

Infrastructure for Running, Cycling and Swimming Data from GPS-Enabled Tracking Devices
http://cran.r-project.org/package=trackeR
90 stars 7 forks source link

Hi, how to use readDirectory. #3

Closed raffdoc closed 7 years ago

raffdoc commented 7 years ago

Hi, I love idea of plotting my run stats. My questions is how can I use the read directory function to read bunch of text file to singe contender. In that way I can use code provided in your vignette. All the best.

hfrick commented 7 years ago

Hi! The readDirectory() function reads all files in a directory if they are of the formats .db3, .tcx, and (Golden Cheetah's) .json. If you have a bunch of text files (CSVs?) you'd need to read them into R yourself, possibly through read.csv(), and get them in a data.frame of the following structure:

## 'data.frame':    1191 obs. of  9 variables:
##  $ time      : POSIXct, format: "2013-06-08 08:04:42" "2013-06-08 08:04:43" ...
##  $ latitude  : num  51.4 51.4 51.4 51.4 51.4 ...
##  $ longitude : num  1.04 1.04 1.04 1.04 1.04 ...
##  $ altitude  : num  6.2 6.2 6.2 6.2 6.2 ...
##  $ distance  : num  0 1.68 5.28 8.33 14.88 ...
##  $ heart.rate: num  83 84 84 86 89 93 96 98 101 102 ...
##  $ speed     : num  0 0.594 1.416 1.928 2.614 ...
##  $ cadence   : num  NA 54 74 97 97 97 97 98 97 97 ...
##  $ power     : num  NA NA NA NA NA NA NA NA NA NA ...

That data.frame can be turned into a trackeRdata object through the trackeRdata() function and then you can use the trackeR functionality, e.g., for plotting your run stats.

raffdoc commented 7 years ago

I have the following code: runTr1 <- readContainer("/Historical/2017-01-29_1548154117.txt", type = "tcx", timezone = "GMT") plot(runTr1) plotRoute(runTr1, session = 1, zoom = 13, source = "google") leafletRoute(runTr1, session = 1) It works fine. So I think I can use the readDirectory i a similar manner, but can not figure out how I have to point to directly and give other attributes.

jonmcalder commented 7 years ago

As Hannah mentioned previously, readDirectory() will read .tcx files (among others). So if you're using Garmin and/or Strava you can pretty easily download .tcx files for your activities from there and import them that way. As far as I know neither site supports bulk exports for .tcx, but you can look around for 3rd party services that could assist with that (just be careful to whom, and how you give access to data though).

If you're happy to download some activities manually, in the case of Strava you can just add "/export_tcx" to an activity url and that will get you the download. For Garmin, you need to go login to Garmin Connect, open up the activity, click on the settings wheel (top right) and then hit export to TCX.

Does that help or am I missing something?

raffdoc commented 7 years ago

Dear @jonmcalder Thanks for useful tip of downloading. As I mentioned in my previous question, i have files but they have .txt extention, but under the hood they are tcx files. I will try your sugested way. thanks a lot. I think it could be very useful if you are a real life case scenario to your vignette. All the best.

jonmcalder commented 7 years ago

I don't really have experience with these file formats, but .tcx is xml and can be edited in any text editor, so you might find that if your files are really tcx files you can just rename them to .tcx and the file format will be detected/read automatically?

raffdoc commented 7 years ago

That is other option. I will give it a go. Thanks

ikosmidis commented 7 years ago

Hi both. We have plans to further enhance the vignettes. Any ideas are welcome. Please feel free to comment on a sperate thread