R/getBatInteract.R

Defines functions getBatInteract

Documented in getBatInteract

#' getBatInteract
#'
#' @param filename name of file where pdk-device-battery is stored (txt).
#' @param desiredtz timezone (character) in Europe/London format
#' @return timestamps (POSIX) on which the battery was either being connected or unplugged.
#' @export
getBatInteract = function(filename, desiredtz) {
  bat = data.table::fread(file=filename,sep="\t")
  bat = as.data.frame(bat)
  bat = replaceVarWithSpace(bat)
  bat = addPOSIX(bat, desiredtz)
  plugged = bat$Plugged != "unknown"
  batInteract = which(abs(diff(plugged)) != 0)
  batInteractTimes = bat$Created.Date.POSIX[batInteract]
  # x11() # Create plot to QC event detection
  # plot(bat$Created.Date.POSIX,bat$Level,type="l",ylab="battery level")
  # lines(bat$Created.Date.POSIX[batInteract],bat$Level[batInteract],type="p",col="red",pch=20)
  return(batInteractTimes)
}
wadpac/sleepsight-analytics-pipeline documentation built on Aug. 1, 2020, 10:41 a.m.