Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #linear.r takes raw data time series index associated with some variable 'y' and uses 1 minute interpolation and 15 minute sliding average to format data. User can comment/uncomment code blocks to disable/enable features respectively. Raw data must be located on desktop as cooling.txt, IT.txt, lighting.txt, or losses.txt
- #load packages zoo and chron
- require(zoo)
- require(chron)
- #set working directory
- setwd("/home/knavero/Desktop")
- #read in data text file to create zoo series object
- rawCool = read.zoo("cooling.txt", FUN = as.chron, format = "%m/%d/%Y %H:%M", sep = "\t", aggregate = function(x) tail(x, 1))
- #rawIT = read.zoo("IT.txt", FUN = as.chron, format = "%m/%d/%Y %H:%M", sep = "\t", aggregate = function(x) tail(x, 1))
- #rawLight = read.zoo("lighting.txt", FUN = as.chron, format = "%m/%d/%Y %H:%M", sep = "\t", aggregate = function(x) tail(x, 1))
- #rawLoss = read.zoo("losses.txt", FUN = as.chron, format = "%m/%d/%Y %H:%M", sep = "\t", aggregate = function(x) tail(x, 1))
- #graphical parameters for page layout (nr, nc)
- #par(mfrow = c(4, 1))
- #raw data plots
- #par(mar = c(2, 4, 1, 1))
- #plot(rawCool, ylim = c(0, 2500), type = "o", xlab = "", ylab = "cooling", cex.lab = 1)
- #grid(col = "darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(rawIT, ylim = c(0, 500), type = "o", xlab = "", ylab = "IT", cex.lab = 1)
- #grid(col = "darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(rawLight, ylim = c(0, 11), type = "o", xlab = "", ylab = "lighting", cex.lab = 1)
- #grid(col = "darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(rawLoss, ylim = c(0, 90), type = "o", xlab = "", ylab = "losses", cex.lab = 1)
- #grid(col = "darkgrey")
- #1 minute increment linear interpolation
- oneMin = seq(start(rawCool), end(rawCool), by = times("00:01:00"))
- intCool = na.approx(rawCool, xout = oneMin)
- #oneMin = seq(start(rawIT), end(rawIT), by = times("00:01:00"))
- #intIT = na.approx(rawIT, xout = oneMin)
- #oneMin = seq(start(rawLight), end(rawLight), by = times("00:01:00"))
- #intLight = na.approx(rawLight, xout = oneMin)
- #oneMin = seq(start(rawLoss), end(rawLoss), by = times("00:01:00"))
- #intLoss = na.approx(rawLoss, xout = oneMin)
- #combine = merge(intCool, intIT, intLight, intLoss)
- #intSum = zoo(rowSums(combine), time(combine))
- #1 minute increment linear interpolation plots
- #par(mar = c(2, 4, 1, 1))
- #plot(intCool, ylim = c(0, 2500), type ="o", xlab = "", ylab ="cooling int.", cex.lab = 1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(intIT, ylim = c(0, 500), type ="o", xlab = "", ylab ="IT int.", cex.lab = 1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(intLight, ylim = c(0, 11), type ="o", xlab = "", ylab ="lighting int.", cex.lab = 1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(intLoss, ylim = c(0, 90), type ="o", xlab = "", ylab ="losses int.", cex.lab = 1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(intSum, ylim = c(0, 3000), type ="o", xlab = "", ylab ="sum int.", cex.lab = 1)
- #grid(col ="darkgrey")
- #write linear interpolated data to file
- #write.zoo(intCool, file = "intOutputCooling.txt")
- #write.zoo(intIT, file = "intOutputIT.txt")
- #write.zoo(intLight, file = "intOutputLighting.txt")
- #write.zoo(intLoss, file = "intOutputLosses.txt")
- #write.zoo(intSum, file = "intOutputSum.txt")
- #15 minute rolling average/mean
- avgCool = aggregate(intCool, trunc(time(intCool), times("00:15:00")), mean)
- #avgIT = aggregate(intIT, trunc(time(intIT), times("00:15:00")), mean)
- #avgLight = aggregate(intLight, trunc(time(intLight), times("00:15:00")), mean)
- #avgLoss = aggregate(intLoss, trunc(time(intLoss), times("00:15:00")), mean)
- #avgSum = aggregate(intSum, trunc(time(intSum), times("00:15:00")), mean)
- #15 minute rolling average/mean plot
- #par(mar = c(2, 4, 1, 1))
- #plot(avgCool, ylim =c(0, 2500), type ="o", xlab = "", ylab ="avg cooling", cex.lab =1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(avgIT, ylim =c(0, 500), type ="o", xlab = "", ylab ="avg IT", cex.lab =1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(avgLight, ylim =c(0, 11), type ="o", xlab = "", ylab ="avg lighting", cex.lab =1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(avgLoss, ylim =c(0, 90), type ="o", xlab = "", ylab ="avg losses", cex.lab =1)
- #grid(col ="darkgrey")
- #par(mar = c(2, 4, 1, 1))
- #plot(avgSum, ylim =c(0, 3000), type ="o", xlab = "", ylab ="avg sum", cex.lab =1)
- #grid(col ="darkgrey")
- #write linear interpolated, 15 minute sliding mean to file
- #write.zoo(avgCool, file = "finalOutputCool.txt")
- #write.zoo(avgIT, file = "finalOutputIT.txt")
- #write.zoo(avgLight, file = "finalOutputLight.txt")
- #write.zoo(avgLoss, file = "finalOutputLoss.txt")
- #write.zoo(avgSum, file = "finalOutputSum.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement