Advertisement
Guest User

Backup

a guest
Sep 8th, 2016
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.82 KB | None | 0 0
  1. library(xts)
  2. library(influxdbr)
  3. library(ggplot2)
  4. library(grid)
  5. library(gridExtra)
  6. require(lubridate)
  7. con <- influxdbr::influx_connection(host = "87.190.238.132",
  8.                                     port = 8086,
  9.                                     user = "default",
  10.                                     pass = "password")
  11.    
  12. dat <- read.csv(paste0(getwd(), "/common.csv"))
  13. one.month <- 30 * 24
  14. periods <- c(
  15.     one.month * 18
  16. )
  17. dat <- dat[dat$Power_On_Hours < periods, ]
  18. dat <- dat[dat$site == "dresden2", ]
  19.  
  20. dat$node<- droplevels(dat$node)
  21.  
  22.  
  23. needed.nodes <- levels(dat$node)
  24. df <- df[df$node %in% needed.nodes, ]
  25.  
  26. df$node <- as.factor(df$node)
  27.  
  28. date.collection <- as.Date("16-07-21")
  29.  
  30. for(node in needed.nodes){
  31.     node = needed.nodes[1]
  32.     curr <- dat[dat$node == node, ]
  33.     pow_on_hours <- curr$Power_On_Hours
  34.     power_on_days <- round(pow_on_hours / 24, 0)
  35.    
  36.     dateofreplace <- date.collection
  37.     day(dateofreplace) <- day(dateofreplace) - power_on_days
  38.     monthbefore <- dateofreplace
  39.     month(monthbefore) <- month(monthbefore) - 1
  40.     dateofreplace <- format(dateofreplace, format="%Y-%m-%d")
  41.     monthbefore <- format(monthbefore, format="%Y-%m-%d")
  42.     time.bord <- paste0("time > \'20", monthbefore, "\' AND time < \'20", dateofreplace, "\'")
  43.     where <- paste0("node=\'", node, "\' AND ", time.bord)
  44.     print(where)
  45.     node.data <- influx_select(
  46.         con = con,
  47.         db = "yearly",
  48.         value = "time, value",
  49.         from = "HDDTemp_temp_AVERAGE",
  50.         where = where,
  51.         order_desc = TRUE,
  52.         return_xts = TRUE
  53.     )$HDDTemp_temp_AVERAGE
  54.    
  55.     df <- as.data.frame(node.data)
  56.     df$time = strptime(df$time, format = "%Y-%m-%dT%H:%M:%S")
  57.    
  58.     p <- ggplot(df, aes(x = time, y = value))
  59.     p <- p + geom_line(size = 0.5)
  60.     grid.draw(p)
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement