Skip to content

Commit

Permalink
as.character() w/ POSIX -> format().
Browse files Browse the repository at this point in the history
See issue #21.
  • Loading branch information
sashahafner committed Mar 21, 2024
1 parent 3b685b8 commit 3ce8e32
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: monitoR
Type: Package
Title: Acoustic Template Detection in R
Version: 1.1.3
Date: 2023-10-13
Version: 1.1.4
Date: 2024-03-21
Author: Sasha D. Hafner <[email protected]> and Jon Katz <[email protected]>, with code for the Fourier transform from the seewave package (by Jerome Sueur, Thierry Aubin, and Caroline Simonis), and code for the readMP3 function from the tuneR package (by Uwe Ligges). Therese Donovan provided creative direction and database design support.
Maintainer: Sasha D. Hafner <[email protected]>
Maintainer: Sasha D. Hafner <[email protected]>
Depends: tuneR, methods
Imports: graphics, grDevices, stats, utils
Suggests: fftw, parallel, RODBC, knitr
Expand Down
2 changes: 1 addition & 1 deletion R/dbUploadResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dbUploadResult <- function(
pks.L <- rbindf(pks.L)
# convert date.time characters to datetime data type format
date.time <- unlist(lapply(X = pks.L$date.time, FUN = substr, start = 1, stop = 19))
tzone <- unlist(lapply(pks.L$date.time, function(x) as.character(x, format = '%Z')))
tzone <- unlist(lapply(pks.L$date.time, function(x) format(x, format = '%Z')))

# the MySQL query to send the hits to the database
query<- paste("INSERT INTO `tblResult` (`pkResultID`, `fkSurveyID`, `fkTemplateID`, `fkPersonID`, `fldDateTime`, `fldTimeZone`, `fldTime`, `fldScore`, `fldOnAmp`, `fldOffAmp`, `fldHit`, `fldVerified`, `fldAnalysisType`, `fldLikelihood`, `fldPosterior`, `fldCutoffValue`) VALUES ('", paste(NULL, "', '", survey.name, "', '", pks.L$template, "', '", analyst, "', '", date.time, "', '", tzone, "', '", pks.L$time, "', '", pks.L$score, "', '", if(length(pks.L$on.amp) == 0) {''} else pks.L$on.amp, "', '", if(length(pks.L$off.amp) == 0) {''} else pks.L$off.amp, "', '", if(length(pks.L$hit) == 0) {''} else pks.L$hit*1, "', '", if(length(pks.L$true) == 0) {-1} else pks.L$true*1, "', '", analysis.type, "', '', '', '", pks.L$score.cutoff, "')", sep = "", collapse = ", ('"), sep = "")
Expand Down
2 changes: 1 addition & 1 deletion R/dbUploadSurvey.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dbUploadSurvey <- function(
dm <- substr(survey.meta[, 'fldSurveyName'], start = 8, stop = 24)
dm <- as.Date(dm, format = "%Y-%m-%d_%H%M%S")
dm <- as.POSIXct(dm, tz = tz, format = "%Y-%m-%d_%H%M%S %Z")
survey.meta['fldOriginalDateModified'] <- as.character(dm, format = "%Y-%m-%d_%H%M%S %Z")
survey.meta['fldOriginalDateModified'] <- format(dm, format = "%Y-%m-%d_%H%M%S %Z")
} else stop('No "fldOriginalDateModified" in metadata and file name does not have date and time info.')
}
if(!update.query) {
Expand Down
4 changes: 2 additions & 2 deletions R/fileCopyRename.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function(
copy = TRUE # Set to FALSE to rename files without moving
){

if(missing(csv.name) & length(loc.prefix) == 1) csv.name <- paste(loc.prefix, '_', as.character(Sys.time(), format = '%Y-%m-%d'), '.csv', sep = '')
else csv.name <- paste('metadata_', as.character(Sys.time(), format = '%Y-%m-%d'), '.csv', sep = '')
if(missing(csv.name) & length(loc.prefix) == 1) csv.name <- paste(loc.prefix, '_', format(Sys.time(), format = '%Y-%m-%d'), '.csv', sep = '')
else csv.name <- paste('metadata_', format(Sys.time(), format = '%Y-%m-%d'), '.csv', sep = '')

if (all(nchar(loc.prefix) != 6)) stop(paste('loc.prefix must be 6 characters, got', paste0(loc.prefix, collapse = ", ")))

Expand Down
6 changes: 3 additions & 3 deletions R/mp3Subsamp.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mp3Subsamp <- function(

if (length(system(command = "mp3splt -h", intern = TRUE))<10) stop("'mp3splt' not found; download mp3splt at\nhttp://mp3splt.sourceforge.net/mp3splt_page/home.php\n")

if(missing(csv.name)) csv.name <- paste(loc.prefix, '_', as.character(Sys.time(), format = '%Y-%m-%d'), '.csv', sep = '')
if(missing(csv.name)) csv.name <- paste(loc.prefix, '_', format(Sys.time(), format = '%Y-%m-%d'), '.csv', sep = '')

if (nchar(loc.prefix) != 6) {stop(paste('loc.prefix must be 6 characters, got', loc.prefix))}

Expand Down Expand Up @@ -77,8 +77,8 @@ mp3Subsamp.one <- function(
surv.end <- surv.start+duration
# predict the new mdates and file names for each subsurvey
time.remain <- rec.dur-surv.end
new.file.mdates <- as.character(file.mdate-time.remain, format = '%Y-%m-%d %H%M%S %Z')
new.mdates <- as.character(file.mdate-time.remain, format = '%Y-%m-%d_%H%M%S_%Z')
new.file.mdates <- format(file.mdate-time.remain, format = '%Y-%m-%d %H%M%S %Z')
new.mdates <- format(file.mdate-time.remain, format = '%Y-%m-%d_%H%M%S_%Z')
filenames <- paste(loc.prefix, '_', new.mdates, sep = "")
# Format seconds to mm.ss.xx, where xx are hundredths, for mp3splt
surv.start <- lapply(surv.start, function(x) {
Expand Down
4 changes: 2 additions & 2 deletions R/viewSpec.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ function(
t.bin.ticks <- pretty(t.bins, n = 6)
t.bin.ticks <- pretty(t.bins, n = 10, min.n = 5)
if(page.length<5) {
axis(1, at = t.bin.ticks/t.step, labels = as.character(as.POSIXct(t.bin.ticks+start.time, origin = "1960-01-01", tz = "GMT"), format = '%H:%M:%OS2'))
axis(1, at = t.bin.ticks/t.step, labels = format(as.POSIXct(t.bin.ticks+start.time, origin = "1960-01-01", tz = "GMT"), format = '%H:%M:%OS2'))
} else {
axis(1, at = t.bin.ticks/t.step, labels = as.character(as.POSIXct(t.bin.ticks+start.time, origin = "1960-01-01", tz = "GMT"), format = '%H:%M:%S'))
axis(1, at = t.bin.ticks/t.step, labels = format(as.POSIXct(t.bin.ticks+start.time, origin = "1960-01-01", tz = "GMT"), format = '%H:%M:%S'))
}

if(!quiet && channel == 'both') {return(list(t = t.step, f = frq.step, tb = n.t.bins, amp = amp, whicht = which.t.bins, whichf = which.frq.bins, ampR = amp.R))#, tw = t.wave))
Expand Down

0 comments on commit 3ce8e32

Please sign in to comment.