detect_anomalies.R 564 B

12345678910111213141516171819
  1. tryCatch({
  2. library(AnomalyDetection)
  3. args <- commandArgs(trailingOnly = TRUE)
  4. con <- textConnection(args[2])
  5. data <- read.csv(con, stringsAsFactors = FALSE)
  6. data$timestamp <- as.POSIXct(data$timestamp)
  7. if (identical(args[1], "ts")) {
  8. res <- AnomalyDetectionTs(data, direction = "both", alpha = 0.05, max_anoms = 0.2)
  9. } else {
  10. res <- AnomalyDetectionVec(data$count, direction = "both", alpha = 0.05, max_anoms = 0.2, period = length(data$count) / 2 - 1)
  11. }
  12. write.csv(res$anoms)
  13. }, error = function (e) {
  14. write.csv(geterrmessage())
  15. })