From 82cec786244ff554c4f9229b98675649fe946e57 Mon Sep 17 00:00:00 2001 From: Daniel Angst Date: Tue, 10 Jan 2017 09:58:03 +0100 Subject: [PATCH] timezone fix --- R/data_functions.R | 10 ++++++++-- R/interactive_functions.R | 32 +++++++++++++++++++------------- R/plot_functions.R | 25 ++++++++++--------------- data/timeZones.rda | Bin 0 -> 4776 bytes man/periodPlot.Rd | 4 ++-- man/readBatscopeXLSX.Rd | 6 ++++-- man/shiny_batPlots.Rd | 6 ++++-- 7 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 data/timeZones.rda diff --git a/R/data_functions.R b/R/data_functions.R index f2441ae..8afe812 100644 --- a/R/data_functions.R +++ b/R/data_functions.R @@ -10,6 +10,7 @@ #' relevant quality scores #' @param quality_threshold sequences with species assignment quality below this #' threshold will be discarded. +#' @param time_zone time zone of timestamps #' @param shiny_progress display more progress info for shiny #' @param shiny_progress_n fraction of progres bar for multiple files #' @family data functions @@ -17,8 +18,8 @@ readBatscopeXLSX <- function(path = file.choose(), species_col_name = "AutoClass1", quality_col_name = "AutoClass1Qual", - time_zone = Sys.timezone(), quality_threshold = 0.8, + time_zone = "UTC", shiny_progress = FALSE, shiny_progress_n = 1 ){ @@ -58,6 +59,11 @@ readBatscopeXLSX <- function(path = file.choose(), data_r$temperature <- as.numeric(data_r$temperature) + data_r$ImportDate <- force_tz(data_r$ImportDate, tzone = time_zone) + data_r$SurveyDate <- force_tz(data_r$SurveyDate, tzone = time_zone) + data_r$recDate <- force_tz(data_r$recDate, tzone = time_zone) + data_r$recTime <- force_tz(data_r$recTime, tzone = time_zone) + return(data_r) } @@ -141,7 +147,7 @@ sumBatscopeData <- function( data_binned <- rbind(data_binned_bySpecies, data_binned_allSpecies) - data_binned$bins <- as.POSIXct(data_binned$bins_factor) + data_binned$bins <- as.POSIXct(data_binned$bins_factor, tz = tz(unique(data_r$SurveyDate)[1])) # GPS Koordinaten diff --git a/R/interactive_functions.R b/R/interactive_functions.R index f0cbdc8..3d67f21 100644 --- a/R/interactive_functions.R +++ b/R/interactive_functions.R @@ -7,11 +7,16 @@ #' @family interactive functions #' @export shiny_batPlots <- function( + lat_default = 47.4, + long_default = 8.52, + customCoord_default = FALSE, + time_zone_default = "UTC+1", option.list = list( shiny.launch.browser = TRUE, shiny.maxRequestSize = 100 * 1024 ^ 2, encoding = "UTF-8") ){ + tz_def_n <- which(names(timeZones)=="UTC+1") shinyApp( onStart = function(options = option.list){ options(options) @@ -48,9 +53,10 @@ shiny_batPlots <- function( multiple = TRUE, accept = c(".xlsx", ".xls") ), - selectizeInput( + selectInput( "time_zone", "Zeitzone", - choices = OlsonNames(), selected = "UTC",multiple = FALSE + choices = as.list(timeZones), + selected = timeZones[tz_def_n], multiple = FALSE, selectize = FALSE ), selectizeInput( "project", "Standorte", @@ -199,11 +205,11 @@ shiny_batPlots <- function( tags$h4("GPS-Daten Optionen"), checkboxInput("customCoord", label = "eigene Koordinaten (in Dezimalgrad)", - value = FALSE), + value = customCoord_default), numericInput("lat", label = "Breite", - value = 47.4, step = 0.1), + value = lat_default, step = 0.1), numericInput("long", label = "Länge", - value = 8.52, step = 0.1) + value = long_default, step = 0.1) ), column(4, tags$h4("Generelle Plotoptionen"), @@ -287,16 +293,17 @@ shiny_batPlots <- function( ) #update DateRange + date_range <- force_tz(range(dataInput()$SurveyDate), tzone = "UTC") if (input$tabs == "NightPlot"){ updateDateRangeInput(session, "dates", - start = format(min(dataInput()$SurveyDate), "%Y-%m-%d"), - end = format(min(dataInput()$SurveyDate), "%Y-%m-%d") + start = date_range[1], + end = date_range[1] ) } if (input$tabs == "PeriodPlot"){ updateDateRangeInput(session, "dates", - start = format(min(dataInput()$SurveyDate), "%Y-%m-%d"), - end = format(max(dataInput()$SurveyDate), "%Y-%m-%d") + start = date_range[1], + end = date_range[2] ) } #update yAxis Input @@ -416,7 +423,7 @@ shiny_batPlots <- function( collapse = ":") xlim <- as.POSIXct( c(paste(as.character(input$dates[1]), hhmm1), - paste(as.character(input$dates[2] + 1), hhmm2))) + paste(as.character(input$dates[2] + 1), hhmm2)), tz = input$time_zone) } else { xlim <- NULL } @@ -426,10 +433,10 @@ shiny_batPlots <- function( } else { ylim <- NULL } - plotData <- subset(data_r(), ProjectName %in% input$project) + nightPlot(plotData, - day = input$dates, + day = with_tz(input$dates, tzone = input$time_zone), sel_species = input$species, x_limits = xlim, y_limits = ylim, @@ -475,7 +482,6 @@ shiny_batPlots <- function( x_break_distance = x_breaks, y_break_distance = "2 hour", x_break_label = x_breaks_label, - time_zone = input$time_zone, text_size = input$text_size) }) #shiny_periodPlot diff --git a/R/plot_functions.R b/R/plot_functions.R index 04c32ab..9b13e93 100644 --- a/R/plot_functions.R +++ b/R/plot_functions.R @@ -25,18 +25,13 @@ nightPlot <- function(plotData, plot_T_color = "black", n_ybreaks = 5, text_size = 16){ - - if (is.POSIXct(day) == FALSE){ - day <- as.POSIXct(day, format = "%Y-%m-%d") - } - + time_zone <- tz(unique(plotData$SurveyDate)[1]) if (sel_species[1] == "every"){ - plotData_sub <- subset(plotData, SurveyDate %in% day & species != "all") + plotData_sub <- dplyr::filter(plotData, SurveyDate == day & species != "all") } else { - plotData_sub <- subset(plotData, SurveyDate %in% day & + plotData_sub <- dplyr::filter(plotData, SurveyDate == day & species %in% sel_species) } - if (is.null(x_limits)){ x_limits <- c(min(plotData_sub$sunset) - 0.5 * 3600, max(plotData_sub$sunrise) + 0.5 * 3600) @@ -50,7 +45,6 @@ nightPlot <- function(plotData, str_c(format(day, format = "%d.%m.%Y"), collapse = " - ")) bin_width <- plotData$bin_length[1] * 60 - plotData_sub$t <- "Temperatur [°C]" nightPlot <- ggplot(plotData_sub, @@ -66,7 +60,7 @@ nightPlot <- function(plotData, scale_x_datetime( limits = x_limits, breaks = date_breaks("2 hour"), minor_breaks = date_breaks("1 hour"), - labels = date_format("%H:%M")) + + labels = date_format("%H:%M", tz = time_zone)) + scale_fill_brewer(name = "Spezies", palette = "Set1") + scale_y_continuous(limits = y_limits, breaks = trans_breaks("identity", function(x) x, n = n_ybreaks)) + @@ -117,11 +111,12 @@ periodPlot <- function(plotData, x_limits = NULL, y_limits = NULL, x_break_distance = "1 month", - y_break_distance = "2 hour", + y_break_distance = "1 hour", x_break_label = "%b", - time_zone = Sys.timezone(), text_size = 16){ + time_zone <- tz(unique(plotData$SurveyDate)[1]) + if (is.POSIXct(start_date) == FALSE){ start_date <- as.POSIXct(start_date, format = "%Y-%m-%d", tz = time_zone) } @@ -190,12 +185,12 @@ periodPlot <- function(plotData, facet_wrap(~ProjectName, ncol = 2) + scale_x_datetime(limits = x_limits, breaks = date_breaks(x_break_distance), - labels = date_format(x_break_label)) + + labels = date_format(x_break_label, tz = time_zone)) + scale_y_datetime(limits = y_limits, breaks = date_breaks(y_break_distance), minor_breaks = date_breaks("1 hour"), - labels = date_format("%H:%M")) + - labs(x = "Datum", y = "Uhrzeit [UTC]", title = plottitle) + + labels = date_format("%H:%M", tz = time_zone)) + + labs(x = "Datum", y = str_c("Uhrzeit (", time_zone,")"), title = plottitle) + theme(text = element_text(size = text_size)) if (sel_species[1] != "every" & length(sel_species) == 1){ diff --git a/data/timeZones.rda b/data/timeZones.rda new file mode 100644 index 0000000000000000000000000000000000000000..0a7ef5d41c572e8c79411ceb681160f5e8a79fcf GIT binary patch literal 4776 zcmXw6X;jjQ*LG$sH(X-WGPfvjA#@xUFt-vk1(ys(MWx1xh#YgnZM5BmvN8o%P|Jms zA7&<*qQf|5W=x_{;fN9Wk|`=`=GNZpm;ZClJ?B2>-234<=dS1&>b_rni8kRx2W}!m zW9Qhp^WVRJ|9U|8`{e%b-{19Zn#K>mS=78fqoHA;Yy6|emavwK5t=_}Xl&8Y(D2pJ z_~C$t24vIyVVFfFYy4`q^?<(9frmdGWNA2WJ--z&Km4f?vl;R~&}>*{8lZ!|B|ill z{i-3kbslu#rUnawwKT@D=3*t$tIG)m+B!EiUG;-m zA)3M0oXOfNl^$>AZVOp|d7j9W#m5<(0@)ObbT!n}%{h})4+IJ2dSl-80S zb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