Skip to content

Commit

Permalink
timezone fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dcangst committed Jan 10, 2017
1 parent 269e584 commit 82cec78
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 36 deletions.
10 changes: 8 additions & 2 deletions R/data_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
#' 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
#' @export
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
){
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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

Expand Down
32 changes: 19 additions & 13 deletions R/interactive_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down
25 changes: 10 additions & 15 deletions R/plot_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)) +
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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){
Expand Down
Binary file added data/timeZones.rda
Binary file not shown.
4 changes: 2 additions & 2 deletions man/periodPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/readBatscopeXLSX.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/shiny_batPlots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82cec78

Please sign in to comment.