bf975ec1f5269979d24d19c98f40c90efb49d13c
[jabaws.git] / webservices / compbio / stat / servlet / YearStat.java
1 package compbio.stat.servlet;\r
2 \r
3 import java.io.IOException;\r
4 import java.sql.SQLException;\r
5 import java.sql.Timestamp;\r
6 import java.util.Calendar;\r
7 import java.util.Date;\r
8 import java.util.Map;\r
9 import java.util.TreeMap;\r
10 \r
11 import javax.servlet.RequestDispatcher;\r
12 import javax.servlet.ServletException;\r
13 import javax.servlet.http.HttpServlet;\r
14 import javax.servlet.http.HttpServletRequest;\r
15 import javax.servlet.http.HttpServletResponse;\r
16 \r
17 import compbio.stat.collector.StatDB;\r
18 import compbio.stat.collector.StatProcessor;\r
19 import compbio.ws.client.Services;\r
20 \r
21 public class YearStat extends HttpServlet {\r
22 \r
23         @Override\r
24         protected void doGet(HttpServletRequest req, HttpServletResponse resp)\r
25                         throws ServletException, IOException {\r
26                 // TODO\r
27                 Calendar startTime = Calendar.getInstance();\r
28                 startTime.roll(Calendar.YEAR, false);\r
29                 Timestamp startDate = new Timestamp(startTime.getTimeInMillis());\r
30                 Timestamp stopDate = new Timestamp(new Date().getTime());\r
31                 StatDB statdb = null;\r
32                 try {\r
33                         statdb = new StatDB();\r
34 \r
35                         Map<Services, StatProcessor> stats = new TreeMap<Services, StatProcessor>();\r
36                         for (Services service : Services.values()) {\r
37                                 stats.put(\r
38                                                 service,\r
39                                                 new StatProcessor(statdb.readData(startDate, stopDate,\r
40                                                                 service, null)));\r
41                         }\r
42 \r
43                         Map<Services, StatProcessor> statsCluster = new TreeMap<Services, StatProcessor>();\r
44                         for (Services service : Services.values()) {\r
45                                 statsCluster.put(\r
46                                                 service,\r
47                                                 new StatProcessor(statdb.readData(startDate, stopDate,\r
48                                                                 service, true)));\r
49                         }\r
50 \r
51                         Map<Services, StatProcessor> statsLocal = new TreeMap<Services, StatProcessor>();\r
52                         for (Services service : Services.values()) {\r
53                                 statsLocal.put(\r
54                                                 service,\r
55                                                 new StatProcessor(statdb.readData(startDate, stopDate,\r
56                                                                 service, false)));\r
57                         }\r
58                         req.setAttribute("stat", stats);\r
59                         req.setAttribute("statTotal", Totals.sumStats(stats));\r
60 \r
61                         req.setAttribute("statCluster", statsCluster);\r
62                         req.setAttribute("statLocal", statsLocal);\r
63                         req.setAttribute("startDate", startDate.getTime());\r
64                         req.setAttribute("stopDate", stopDate.getTime());\r
65 \r
66                         RequestDispatcher dispatcher = req\r
67                                         .getRequestDispatcher("statpages/Statistics.jsp");\r
68                         dispatcher.forward(req, resp);\r
69 \r
70                 } catch (SQLException e) {\r
71                         // TODO Auto-generated catch block\r
72                         e.printStackTrace();\r
73                 }\r
74 \r
75         }\r
76 \r
77 }\r