X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=statistics%2Ffunctions.r;h=d9e402385d9485528a6023b581fbc529aee9d90b;hb=a403ef9f15068971de470ce7c66c59252b118f39;hp=34115869256166eba331c494d4a6b2e0d0b819a6;hpb=5a40e4f30c45995dcbd06c5f9a7b5f997c4c926c;p=monitor.git diff --git a/statistics/functions.r b/statistics/functions.r index 3411586..d9e4023 100644 --- a/statistics/functions.r +++ b/statistics/functions.r @@ -173,14 +173,15 @@ plot_rt_hist <- function (t, imagename=0) if ( imagename != 0 ) { end_image() } } -year_hist <- function (t, year, from, to, max, type="week", title="Histogram for Tickets in") +year_hist <- function (t, year, from, to, max, type="week", title="Histogram for Tickets in", fmt="%b-%d") { dates <-seq(as.Date(from), as.Date(to), type) - months <- format(dates, "%b-%d") + months <- format(dates, fmt) hbreaks<-unclass(as.POSIXct(dates)) h<-hist(t$start, breaks=hbreaks, plot=FALSE) main<-sprintf(paste(title, "%s: MEAN %s\n"), year, mean(h$counts)) print(main); + print(h$counts); if ( max == 0 ) { max = max(h$counts) } @@ -190,6 +191,7 @@ year_hist <- function (t, year, from, to, max, type="week", title="Histogram for abline(mean(h$counts), 0, col='grey') #qqnorm(h$counts) #qqline(h$counts) + return (h); } year_hist_unique <- function (t, year, from, to, max, type="week", title="Histogram for Tickets in") @@ -395,9 +397,20 @@ add_timestamp <- function (t) return (t); } -abline_at_date <- function (date, col='black', lty=1, format="%Y-%m-%d") +abline_at_date <- function (date, col='black', lty=1, format="%Y-%m-%d", height=0) { ts <-unclass(as.POSIXct(date, format=format, origin="1970-01-01"))[1] - abline(v=ts, col=col, lty=lty) + if ( height == 0 ) + { + abline(v=ts, col=col, lty=lty) + } else { + lines(c(ts,ts),c(0,height), col=col, lty=lty) + } return (ts); } + +tstamp <- function (date, format="%Y-%m-%d") +{ + ts <- unclass(as.POSIXct(date, format=format, origin="1970-01-01"))[1] + return (ts) +}