summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandom Hacker <random_hacker@xapek.org>2010-08-29 06:21:11 +0200
committerRandom Hacker <random_hacker@xapek.org>2010-08-29 06:21:11 +0200
commit5977f2abbf9cced7fb3db199a985ab7a3777ab4c (patch)
tree933a77e72069288ad376cbf4ab48f60c74e7beec
parent8c78916ff0dcf7d10b6f599e07c8bc345263ea56 (diff)
downloadebus-alt-5977f2abbf9cced7fb3db199a985ab7a3777ab4c.tar.gz
ebus-alt-5977f2abbf9cced7fb3db199a985ab7a3777ab4c.zip
fix NA handling
-rwxr-xr-xtest.r25
1 files changed, 13 insertions, 12 deletions
diff --git a/test.r b/test.r
index 69ab993..4c5bda7 100755
--- a/test.r
+++ b/test.r
@@ -18,10 +18,10 @@ brenner <- dbGetQuery(con,
AND date_trunc('day',timestamp) = date_trunc('day',now())
ORDER BY timestamp desc", sep=""))
-#Brennerstatus auf Brennerstatusänderungen reduzieren
+## Brennerstatus auf Brennerstatusänderungen reduzieren
brenner <- aggregate(brenner$timestamp,
- list(value_string=brenner$value_string),
- min)
+ list(value_string=brenner$value_string),
+ min)
readNumericSensorDay <- function (sensorName) {
d <- dbGetQuery(con,
@@ -30,7 +30,7 @@ readNumericSensorDay <- function (sensorName) {
" 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")
+ d$timestamp <- as.POSIXct(round(d$timestamp, "mins"),tz="GMT")
dm <- aggregate(d$value, list(timestamp=d$timestamp), mean)
names(dm) <- c("time", sensorName)
dm
@@ -38,11 +38,11 @@ readNumericSensorDay <- function (sensorName) {
## 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)
- }
+ 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")
@@ -53,7 +53,7 @@ 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))
+ 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)
@@ -64,14 +64,15 @@ lines(data$time, data$heizkreisregler9.solarDaten.tempKollektor, col="blue")
box()
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)
+ 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)]))
+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('Kollektor', 'Warmwasser', 'Kessel'), fill=c('red', 'orange', 'blue'))