diff options
author | yvesf <yvesf-git@xapek.org> | 2010-08-30 06:42:03 +0200 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2010-08-30 06:42:03 +0200 |
commit | 72fc24b265a40fad3f25baebf3bbe9e021b356c9 (patch) | |
tree | eebec85ad6c97638dc16040a3b2c94d67127bf07 /test.r | |
parent | 4b04486e2914bcd8fe421d5442a6bdf917835692 (diff) | |
download | ebus-alt-72fc24b265a40fad3f25baebf3bbe9e021b356c9.tar.gz ebus-alt-72fc24b265a40fad3f25baebf3bbe9e021b356c9.zip |
use supsmu for all sensors; cleanup
Diffstat (limited to 'test.r')
-rwxr-xr-x | test.r | 64 |
1 files changed, 36 insertions, 28 deletions
@@ -7,8 +7,8 @@ con <- dbConnect(drv, host="10.2.2.22", user="jack", password="jack", dbname="eb ## plot 1 -png(file = "Rplots.png", width=1000, height=800) - +png(file = "Rplots.png", width=1500, height=800) +par(cex=1.25) cat("Starte Abfragen\n") brenner <- dbGetQuery(con, paste("SELECT timestamp as \"time\" @@ -16,6 +16,7 @@ brenner <- dbGetQuery(con, FROM value WHERE sensor_id IN (select id from sensor where name = 'heizkreisregler1.betriebsdatenFeuerungsautomat.betriebszustand') AND timestamp > now() - interval '1 day'", + " AND value_string IS NOT NULL", " ORDER BY timestamp asc", sep="")) ## Brennerstatus auf Brennerstaotusänderungen reduzieren @@ -33,38 +34,43 @@ brenner <- brennerBla readNumericSensorDay <- function (sensorName) { d <- dbGetQuery(con, - paste("SELECT timestamp,COALESCE(value_int,value_float) \"value\"", + paste("SELECT timestamp", + " , COALESCE(value_int,value_float) \"value\"", " FROM value", " WHERE sensor_id IN (select id from sensor where name = '",sensorName,"')", " AND timestamp > now() - interval '1 day'", " ORDER BY timestamp desc", sep="")) d$timestamp <- as.POSIXct(round(d$timestamp, "mins")) - dm <- aggregate(d$value, list(timestamp=d$timestamp), mean) + d <- supsmu(as.vector(d$timestamp), as.vector(d$value)) + names(d) <- c("time", "value") + +# myMean <- function(values) { +# print(mad(values)) +# if (mad(values) > 1) { +# print(paste("Streiche ",length(values), +# " Werte aus",sensorName, +# "mad =", mad(values))) +# values <- values * NA +# } +# mean(values) +# } +# +# dm <- aggregate(d$value, list(time=d$time), myMean) + dm <- d + dm$time <- as.POSIXct(dm$time,origin=nulltime) 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 { - merge(a,list(...)[1],all.x=all.x) - } -} - warmwasser <- readNumericSensorDay("heizkreisregler9.solarDaten.tempWarmwasserSolar") - kessel <- readNumericSensorDay("heizkreisregler10.betriebsdatenRegler1.kesselTemperatur") - kollektor <- readNumericSensorDay("heizkreisregler9.solarDaten.tempKollektor") -names_kollektor <- names(kollektor) -kollektor <- supsmu(kollektor$time,kollektor$heizkreisregler9.solarDaten.tempKollektor) -names(kollektor) <- names_kollektor - aussenTemperatur <- readNumericSensorDay("feuerungsautomat1.betriebsdatenRegler1.aussenTemperatur") + # -- TODO ausreißer als punkte darstellen -data <- mymerge(kollektor, kessel, warmwasser) +data <- Reduce(function(x,y) { merge(x,y,all.x=TRUE) }, list(kollektor, kessel, warmwasser, aussenTemperatur)) + + cat("Plotte\n") plot.new() @@ -73,25 +79,27 @@ plot.window(xlim=c(min(data$time), max(data$time)), 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") -lines(aussenTemperatur$time, aussenTemperatur$heizkreisregler1.datumZeit.aussenTemperatur, col="green") +for (i in c(2:length(data))) { + lines(subset(data,select=c(1,i)), + col=rainbow(length(data)-1)[i-1]) +} box() for (i in c(1:nrow(brenner))) { text(as.numeric(brenner$time[i]), max(data[2:length(data)],na.rm=TRUE)/2, paste("ab hier", brenner$value_string[i]) ,srt=90) } -r <- as.POSIXct(range(data$time)) -s <- round.POSIXt(seq(r[1], r[2], by=60*60),"hour") +rangeX <- as.POSIXct(range(data$time)) +s <- round.POSIXt(seq(rangeX[1], rangeX[2], by=60*60),"hour") axis.POSIXct(1, at=s, format="%H:%M") r <- range(data[2:length(data)], na.rm=TRUE) 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('Kessel', 'Warmwasser', 'Kollektor'), fill=c('red', 'orange', 'blue')) -title("Temperaturen") +legend('topleft', + legend=names(data)[2:length(data)], + fill=rainbow(length(data)-1)) +title(paste("Temperaturen ", rangeX[1], " bis ", rangeX[2])) dev.off() dbDisconnect(con) |