clearer names for actions, and infer actions better
[monitor.git] / statistics / rt_data_opentickets.r
1 source("functions.r");
2
3 # system("parse_rt_data.py 3 > rt_data.csv");
4 t <- read.csv('rt_data_2004-2010.csv', sep=',', header=TRUE)
5 t2 <- t[which(t$complete == 1),]
6
7
8 open_tickets <- function (t, from, to, type, fmt="%b")
9 {
10     # find 'type' range of days
11     dates <-seq(as.Date(from), as.Date(to), type)
12     months <- format(dates, fmt)
13     hbreaks<-unclass(as.POSIXct(dates))
14
15     xx<-NULL;
16     yy<-NULL;
17
18     for ( i in seq(1,length(hbreaks)-1) )
19     {
20         # get range from t
21         t_sub <- t[which(t$start > hbreaks[i] & t$lastreply <= hbreaks[i+1]),]
22         tickets <- length(t_sub$start)
23         #if ( nrow(t_sub) > 0 ){
24         #    for ( j in seq(1,nrow(t_sub)) )
25         #    {
26         #        #print(sprintf("id %s, date %s", t_sub[i,'ticket_id'], t_sub[i,'s1']))
27         #        print(sprintf("id %s, date %s", t_sub[j,]$ticket_id, t_sub[j, 's1']))
28         #    }
29         #}
30
31         xx<- c(xx, hbreaks[i])
32         yy<- c(yy, tickets)
33
34     }
35     m<- months[1:length(months)-1]
36     return (rbind(xx,yy,m))
37 }
38
39 ot <- open_tickets(t2, '2004/1/1', '2010/2/28', 'week', "%b%y")
40
41 plot(ot[1,], ot[2,], axes=F)
42 y<- ot[2,]
43 s<-which(y!='0')
44 y<-y[s]
45 y<-as.numeric(y)
46 plot(ot[1,s],y)
47 axis(1, labels=ot[3,], at=ot[1,])
48 axis(2)
49
50 ot <- open_tickets(t2, '2004/1/1', '2010/2/28', 'day', "%b%y")
51 x1<-as.numeric(ot[1,])
52 y1<-as.numeric(ot[2,])
53
54 # remove zero
55 #s<-which(y1!='0')
56 #y1<-y1[s]
57 #x1<-x1[s]
58
59 y1<-as.numeric(y1)
60
61 lines(x1, y1, axes=F, pch='.')
62 axis(1, labels=ot[3,], at=ot[1,])
63 axis(2)
64 #lines(ot[1,], ot[2,])
65 #a<-smooth(as.numeric(y1))
66 #x<-x1
67 #y<-a
68
69 a<-lowess(x1, y1, delta=(60*60*24), f=0.03)
70 x<-a$x
71 y<-a$y
72
73 #y<-rollmedian(y1, 5)
74 #x<-x1[1:length(y)]
75
76 lines(x, y, col='red')
77 lines(x, round(y), col='blue')
78 #lines(x, ceiling(y), col='blue')
79
80 abline_at_date('2005-01-01', 'grey40')
81 abline_at_date('2006-01-01', 'grey40')
82 abline_at_date('2007-01-01', 'grey40')
83 abline_at_date('2008-01-01', 'grey40')
84 abline_at_date('2009-01-01', 'grey40')
85 abline_at_date('2010-01-01', 'grey40')
86