Skip to content
Snippets Groups Projects
Commit 42d42eb5 authored by pbac's avatar pbac
Browse files

misc

parent ff56cffe
Branches
No related tags found
No related merge requests found
## Write the experiment to the incluxdb
##library(influxdbr)
library(influxdbr)
## For now we use .csv files
##con <- influx_connection(host="localhost", port=8086)
## connection
con <- influx_connection(host="localhost", port=8086)
##con <- influx_connection(host="vmpbac1.compute.dtu.dk", port=8086)
##influx_ping(con)
......@@ -18,7 +18,7 @@ load_all(as.package("~/g/onlineforecast"))
##
wd <- "../buildingctrl/main/"
source(paste0(wd,"lib/r/read_idtags.R"))
##source(paste0(wd,"lib/r/write_values.R"))
source(paste0(wd,"lib/r/write_values.R"))
## Find the output channels, to be able to check that the channelids are correct
idtags <- read_idtags(wd)
......@@ -33,7 +33,7 @@ i <- grep("^Room_.*spTemperature__northq", idtags$VarName)
## ------------------------------------------------------------------------
## Generate constant experiment
X <- data.frame(t=seq(asp("2019-12-14 16:30"), by=2*60*60, len=18))
X <- data.frame(t=seq(ct("2020-12-18 16:30"), by=2*60*60, len=16))
range(X$t)
## Set RegI and RegP
......@@ -46,9 +46,9 @@ X$HX_VE_spRegI_building_ltech <- 60 #rep(seq(30,by=10,len=6), each=2)
## The set points
set.seed(9387)
val <- c(t(matrix(c(sample(seq(20,42,len=8)), sample(seq(48,65,len=8))), ncol=2)))
X[ ,nmTforwardRC] <- c(rep(5,16),NA,NA)#rep(c(50,20), 6)
X[ ,nmTforwardVE] <- c(val,NA,NA)#sample(seq(20,65,len=17))#c(65,60,55,50,45,40,35,30,25,30,35,40,45,50,55,60,65))#rep(c(50,20), 6)
val <- #c(t(matrix(c(sample(seq(20,42,len=8)), sample(seq(48,65,len=8))), ncol=2)))
X[ ,nmTforwardRC] <- 60#rep(c(50,20), 6)
X[ ,nmTforwardVE] <- 5#c(val)#sample(seq(20,65,len=17))#c(65,60,55,50,45,40,35,30,25,30,35,40,45,50,55,60,65))#rep(c(50,20), 6)
## for(nm in nmRooms){
## X[ ,nm] <- 22
## }
......@@ -56,20 +56,24 @@ X[ ,nmTforwardVE] <- c(val,NA,NA)#sample(seq(20,65,len=17))#c(65,60,55,50,45,40,
## ------------------------------------------------------------------------
## Room set points
## val <- c(t(matrix(c(sample(seq(15,20,len=8)), sample(seq(21,25,len=8))), ncol=2)))
## ## Set it to all rooms
## for(nm in nmRooms){
## X[ ,nm] <- c(val, NA)
## }
tmp <- nrow(X)/2
val <- 10 + 2 * (c(t(matrix(c(1:tmp,tmp:1), ncol=2))) - 1)
#val <- c(t(matrix(c(sample(seq(15,20,len=8)), sample(seq(21,25,len=8))), ncol=2)))
## Set it uniquely to each rooms
set.seed(92387)
for(nm in nmRooms){
X[ ,nm] <- sample(val)
}
## ------------------------------------------------------------------------
plot_ts(X, c("RegP","RegI","spTforward"), legendspace=0.8, plotfun=function(x,y,col){lines(x,y,col=col,type="s")})
plot_ts(X, c("RegP","RegI","spTforward"), plotfun=function(x,y,col){lines(x,y,col=col,type="s")})
plot_ts(X, nmRooms, plotfun=function(x,y,col){lines(x,y,col=col,type="s")})
Xres <- X
#Xres$t[nrow(Xres)] <- asp("2019-12-24")
#Xres$t[nrow(Xres)] <- ct("2019-12-24")
Xres
##plot.ts(Xres, type="s")
......@@ -77,14 +81,19 @@ Xres
## Replace the column names with channelid
it <- which(names(Xres) == "t")
names(Xres)[-it] <- unlist(sapply(names(Xres)[-it], function(nm){ idtags$channelid[idtags$VarName == nm] }))
write.table(Xres, "../buildingctrl/sender/senddata.csv", sep=",", row.names=FALSE)
#write.table(Xres, "../buildingctrl/sender/senddata.csv", sep=",", row.names=FALSE)
## Copy to the server
system("scp ../buildingctrl/sender/senddata.csv pbac@vmpbac1.compute.dtu.dk:~/buildingctrl/sender/")
## Don't write directly in influxdb
##write_values(Xres, idtags, con, colnamesTag="VarName")
#system("scp ../buildingctrl/sender/senddata.csv pbac@vmpbac1.compute.dtu.dk:~/buildingctrl/sender/")
## Write directly in influxdb
tout <- ct(approx(1:nrow(X), X$t, seq(1,nrow(X),by=1/4))$y)
iseq <- 2:ncol(Xres)
Xres2 <- data.frame(t=tout, sapply(iseq, function(i){
approx(Xres$t, Xres[ ,i], tout, "constant")$y
}))
names(Xres2) <- names(Xres)
write_values(Xres2, idtags, con, colnamesTag = "channelid")
## ## ------------------------------------------------------------------------
......
library(rmarkdown)
library(knitr)
render('experiment.Rmd')
purl('experiment.Rmd')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment