summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandom Hacker <random_hacker@xapek.org>2010-08-28 17:29:51 +0200
committerRandom Hacker <random_hacker@xapek.org>2010-08-28 17:29:51 +0200
commit41f11ac148ecce2d342514c275691fec76547f6b (patch)
tree3235c6c5fe175e0f0e69fa625112dd4e9c3f553f
parent05859a90d82238880101d9414f7e43f2201cd290 (diff)
downloadebus-alt-41f11ac148ecce2d342514c275691fec76547f6b.tar.gz
ebus-alt-41f11ac148ecce2d342514c275691fec76547f6b.zip
test.r: Rplots
-rwxr-xr-xtest.r78
1 files changed, 67 insertions, 11 deletions
diff --git a/test.r b/test.r
index 166342f..69ab993 100755
--- a/test.r
+++ b/test.r
@@ -1,25 +1,81 @@
#!/usr/bin/Rscript --vanilla
require(RPostgreSQL)
+##nulltime <- strptime("01.01.1970", "%d.%m.%Y")
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, host="10.2.2.22", user="jack", password="jack", dbname="ebus")
-# plot 1
-png(file = "Rplots.png")
-data <- dbGetQuery(con, "select DISTINCT timestamp,value_float from value where sensor_id = 47")
-print(data)
-data$timestamp <- as.POSIXlt(as.character(data$timestamp))
+## plot 1
+png(file = "Rplots.png", width=1000, height=800)
-plot(data$timestamp, data$value_float,type="l",axes=FALSE)
+cat("Starte Abfragen\n")
+brenner <- dbGetQuery(con,
+ paste("SELECT timestamp
+ , value_string
+ FROM value
+ WHERE sensor_id IN (select id from sensor where name = 'heizkreisregler1.betriebsdatenFeuerungsautomat.betriebszustand')
+ AND date_trunc('day',timestamp) = date_trunc('day',now())
+ ORDER BY timestamp desc", sep=""))
-r <- as.POSIXct(range(data$timestamp))
-axis.POSIXct(1, at=seq(r[1], r[2], by="hour"), format="%H")
+#Brennerstatus auf Brennerstatusänderungen reduzieren
+brenner <- aggregate(brenner$timestamp,
+ list(value_string=brenner$value_string),
+ min)
+
+readNumericSensorDay <- function (sensorName) {
+ d <- dbGetQuery(con,
+ paste("SELECT timestamp,COALESCE(value_int,value_float) \"value\"",
+ " FROM value",
+ " WHERE sensor_id IN (select id from sensor where name = '",sensorName,"')",
+ " AND date_trunc('day',timestamp) = date_trunc('day',now()) ",
+ " ORDER BY timestamp desc", sep=""))
+ d$timestamp <- as.POSIXct(round(d$timestamp, "hour"),tz="GMT")
+ dm <- aggregate(d$value, list(timestamp=d$timestamp), mean)
+ names(dm) <- c("time", sensorName)
+ dm
+}
+
+## multi arg version of merge()
+mymerge <- function (a,...,all.x=TRUE) {
+ if ( length(list(...)) > 1) {
+ merge(a,merge(...,all.x=all.x),all.x=all.x)
+ } else {
+ x<-merge(a,list(...)[1],all.x=all.x)
+ }
+}
+
+kollektor <- readNumericSensorDay("heizkreisregler9.solarDaten.tempKollektor")
+warmwasser <- readNumericSensorDay("heizkreisregler9.solarDaten.tempWarmwasserSolar")
+kessel <- readNumericSensorDay("heizkreisregler10.betriebsdatenRegler1.kesselTemperatur")
+data <- mymerge(kollektor, kessel, warmwasser)
+
+cat("Plotte\n")
+plot.new()
+plot.window(xlim=c(min(data$time), max(data$time)),
+ ylim=c(min(data[2:length(data)],na.rm=TRUE)*0.9, max(data[2:length(data)],na.rm=TRUE)*1.1))
+par(lwd=2)
+
+
+lines(data$time, data$heizkreisregler10.betriebsdatenRegler1.kesselTemperatur, col="red")
+lines(data$time, data$heizkreisregler9.solarDaten.tempWarmwasserSolar, col="orange")
+lines(data$time, data$heizkreisregler9.solarDaten.tempKollektor, col="blue")
-title("Temperaturplot")
box()
-print(data)
+for (i in c(1:dim(brenner)[2])) {
+ text(brenner$x[i], max(data[2:length(data)])/2, paste("ab hier", brenner$value_string[i]) ,srt=90)
+}
+
+r <- as.POSIXct(range(data$time),tz="GMT")
+s <- round.POSIXt(seq(r[1], r[2], by=60*60),"hour")
+axis.POSIXct(1, at=s, format="%H:%M")
+
+r <- range(min(data[2:length(data)]), max(data[2:length(data)]))
+s <- seq(r[1], r[2], by=(r[2]-r[1])/8)
+axis(2, at=s, labels=paste(round(s,1),"°C"))
+legend('topleft', legend=c('Kollektor', 'Warmwasser', 'Kessel'), fill=c('red', 'orange', 'blue'))
+title("Temperaturen")
dev.off()
-#dbDisconnect(con)
+dbDisconnect(con)