Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Showing with 551 additions and 39,450 deletions.
  1. BIN Maps/auto.png
  2. BIN Maps/default.png
  3. BIN Maps/last-month.png
  4. +450 −39,411 allTracks.csv
  5. +64 −17 functions.R
  6. +6 −18 import.R
  7. +31 −4 map.R
View
BIN Maps/auto.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Maps/default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Maps/last-month.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
39,861 allTracks.csv
450 additions, 39,411 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
81 functions.R
@@ -1,18 +1,24 @@
-appendTrack <- function(fileNumbers) {
+appendTrack <- function(filenames) {
+ extensions <- gsub("^.+\\.", "", filenames)
+ fileNumbers <- 1:length(filenames)
for (fileNumber in fileNumbers) {
+ # delete original extension and add new one:
+ newFilename <- paste(sub(paste("\\.", extensions[fileNumber], sep = ""), "", filenames[fileNumber]), ".csv", sep = "")
- newFilename <- paste(sub(paste("\\.", extension, sep = ""), "", gpxFilenames[fileNumber]), ".csv", sep = "") # deletes original extension
-
- gpsbabelCommand <- paste("sudo gpsbabel -t -i ",
- GPSType,
+ if (extensions[fileNumber] != "csv") {
+ gpsbabelCommand <- paste("sudo gpsbabel -t -i ",
+ extensions[fileNumber],
" -f '",
- gpxFilenames[fileNumber],
+ filenames[fileNumber],
"' -o unicsv -F '",
newFilename,
"'",
sep = "")
- system(gpsbabelCommand)
+ system(gpsbabelCommand)
+ } else {
+ newFilename <- filenames[fileNumber]
+ }
# add variables (based on GPS/addvariables.R)
track <- read.csv(newFilename,
@@ -27,15 +33,56 @@ appendTrack <- function(fileNumbers) {
track$Seg <- 1
track$Seg[1] <- NA # keeps map from drawing a line between one ride and the next
- # need code to check whether it should append or not
-
- write.table(track,
- "allTracks.csv",
- append = TRUE,
- quote = FALSE,
- sep = ",",
- row.names = FALSE,
- col.names = FALSE)
+ # check whether it should append or not:
+ if(file.exists("allTracks.csv")) {
+ write.table(track,
+ "allTracks.csv",
+ append = TRUE,
+ quote = FALSE,
+ sep = ",",
+ row.names = FALSE,
+ col.names = FALSE)
+ } else {
+ write.table(track,
+ "allTracks.csv",
+ append = FALSE,
+ quote = FALSE,
+ sep = ",",
+ row.names = FALSE,
+ col.names = TRUE)
+ }
}
-}
+}
+
+mapSpecs <- function(tracks, rangeConst) {
+ meanLon <- mean(allTracks$Longitude,
+ na.rm = TRUE)
+ meanLat <- mean(allTracks$Latitude,
+ na.rm = TRUE)
+ lonHiRange <- quantile(allTracks$Longitude,
+ probs = c(1 - rangeConst),
+ na.rm = TRUE)
+ lonLoRange <- quantile(allTracks$Longitude,
+ probs = c(rangeConst),
+ na.rm = TRUE)
+ lonRange <- lonHiRange - lonLoRange
+ latHiRange <- quantile(allTracks$Latitude,
+ probs = c(1 - rangeConst),
+ na.rm = TRUE)
+ latLoRange <- quantile(allTracks$Latitude,
+ probs = c(rangeConst),
+ na.rm = TRUE)
+ latRange <- latHiRange - latLoRange
+ # lonRange <- range(allTracks$Longitude)[2] - range(allTracks$Longitude)[1]
+ # latRange <- range(allTracks$Latitude)[2] - range(allTracks$Latitude)[1]
+
+ mapWidth <- max(lonRange, latRange)
+ mapZoom <- floor(13 - log2(10 * mapWidth))
+
+ return(data.frame(meanLon, meanLat,
+ lonHiRange, lonLoRange, latHiRange, latLoRange,
+ mapZoom))
+}
+
+
View
24 import.R
@@ -5,24 +5,12 @@
# All rights reserved
#
-# system() # intern = TRUE?
-# file1 <- read.csv(file.choose(),
- # header = TRUE)
+source("functions.R")
+library(tcltk)
+# this means i should be able to remove the loop below:
+# filenames <- lapply(tk_choose.files(caption = "Choose X"), function)
-extension <- readline("What extension do your files have? (Options: gpx, kml, csv)\n")
-# extension <- ".gpx"
-extension <- sub("\\.", "", extension) # cuts the period, so they're standardized
-# if they have .csv, possibly skip straight to mapping
-GPSType <- extension # change once we have more than just .gpx
+filenames <- tk_choose.files(caption = "Choose files")
-# glob2rx(".gpx")
-gpxFilenames <- Sys.glob(paste("Imported Files/*.", extension, sep = ""))
-
-
-
-# there's probably a more efficient way to do this than a loop:
-
-fileNumbers <- 1:length(gpxFilenames)
-
-appendTrack(fileNumbers)
+appendTrack(filenames)
View
35 map.R
@@ -25,8 +25,9 @@ allTracks$Longitude <- ifelse(is.na(allTracks$Seg), NA, allTracks$Longitude)
library(ggmap)
-# create directory "Maps" if it does not exist:
-dir.create("./Maps")
+# let user choose directory to save in:
+library(tcltk)
+mapDir <- tk_choose.dir()
# default map:
mapImageData <- get_map(location = c(lon = meanLon,
@@ -50,7 +51,7 @@ dir.create("./Maps")
colour = "#F8971F", #F8971F F4640D
size = 0.8,
pch = 20)
- dev.copy(png, "Maps/default.png")
+ dev.copy(png, paste(mapDir, "/default.png", sep = ""))
dev.off()
@@ -80,6 +81,32 @@ mapZoom <- floor(13 - log2(10 * mapWidth))
colour = "#F8971F", #F8971F F4640D
size = 0.8,
pch = 20)
- dev.copy(png, "Maps/auto.png")
+ dev.copy(png, paste(mapDir, "/auto.png", sep = ""))
dev.off()
+# last month:
+allTracks$Date <- as.Date(allTracks$Date, "%Y/%m/%d")
+lastMonth <- allTracks[which(allTracks$Date >= Sys.Date() - 30),]
+ mapImageData <- get_map(location = c(lon = mean(c(lonLoRange, lonHiRange)),
+ lat = mean(c(latLoRange, latHiRange))), # maybe use 20th/80th percentile or something instead of min/max
+ zoom = mapZoom,
+ # size = c(500, 500),
+ maptype = c("toner"), #toner, watercolor
+ source = c("stamen"))
+ ggmap(mapImageData,
+ extent = "device", # takes out axis, etc.
+ darken = c(0.6, "white")) + # makes basemap lighter
+ geom_path(aes(x = Longitude,
+ y = Latitude),
+ data = allTracks,
+ colour = "black", #F8971F F4640D
+ size = 1.2,
+ pch = 20) +
+ geom_path(aes(x = Longitude,
+ y = Latitude),
+ data = allTracks,
+ colour = "#F8971F", #F8971F F4640D
+ size = 0.8,
+ pch = 20)
+ dev.copy(png, paste(mapDir, "/last-month.png", sep = ""))
+ dev.off()

No commit comments for this range

Something went wrong with that request. Please try again.