/[projects]/android/TrainInfoService/WebContent/version.jsp
ViewVC logotype

Contents of /android/TrainInfoService/WebContent/version.jsp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1601 - (show annotations) (download)
Fri Sep 23 10:12:21 2011 UTC (12 years, 7 months ago) by torben
File size: 2466 byte(s)
whoops. when iterating over a map extract the values from the same maps as the keys came from
1 <%@ page import="java.io.*" %>
2 <%@ page import="java.util.*" %>
3 <%@ page import="dk.thoerup.genericjavautils.HttpUtil" %>
4 <%
5 /*
6 cat bin/traininfo-version.sh
7 #!/bin/bash
8
9
10 FILE=/var/log/apache2/access.log
11
12 if [ "$1" != "" ] ; then
13 grep traininfo/version $FILE | grep $1 | awk '{print $8}' | awk -F= '{print $2}' | awk -F\& '{print $1}' | sort | uniq -c
14 else
15 grep traininfo/version $FILE | awk '{print $8}' | awk -F= '{print $2}' | awk -F\& '{print $1}' | sort | uniq -c
16 fi
17 */
18
19 File f = new File("/var/log/apache2/access.log");
20
21 InputStream input = new FileInputStream(f);
22
23 BufferedReader in = new BufferedReader( new InputStreamReader(input) );
24
25 Map<String,Integer> versions = new TreeMap<String,Integer>();
26 Map<String,Integer> phones = new TreeMap<String,Integer>();
27 Map<String,Integer> androids = new TreeMap<String,Integer>();
28
29 String line;
30 while ( (line=in.readLine()) != null) {
31 if (line.indexOf("traininfo/version") == -1)
32 continue;
33 String version = "";
34 String phone = "";
35 String android = "";
36
37 String parts[] = line.split(" ");
38
39 if (parts.length >= 8) {
40 String uri = parts[7];
41 Map<String,String> params = HttpUtil.decodeUri(uri);
42
43 String tmpVer = params.get("version");
44 String tmpPhone = params.get("phone");
45 String tmpAndroid = params.get("android");
46
47 if (tmpVer != null)
48 version = tmpVer;
49 if (tmpPhone != null)
50 phone = tmpPhone;
51 if (tmpAndroid != null)
52 android = tmpAndroid;
53 }
54
55 Integer count = versions.get(version);
56 if (count == null)
57 count = 0;
58 versions.put(version, count+1);
59
60 count = phones.get(phone);
61 if (count == null)
62 count = 0;
63 phones.put(phone, count+1);
64
65 count = androids.get(android);
66 if (count == null)
67 count = 0;
68 androids.put(android, count+1);
69
70 }
71
72 %>
73 <html>
74 <head>
75 <title>Traininfo versions</title>
76 </head>
77 <body>
78 <h2>Versions</h2>
79 <font size='-1'>Counts are extracted from apache access log</font>
80 <table border='0'>
81 <%
82 for (String key : versions.keySet()) {
83 int val = versions.get(key);
84 %>
85 <tr><td><%=key%></td><td align='right'><%= val %></td></tr>
86 <%
87 }
88 %>
89 </table>
90
91 <h2>Phones</h2>
92 <table border='0'>
93 <%
94 for (String key : phones.keySet()) {
95 int val = phones.get(key);
96 %>
97 <tr><td><%=key%></td><td align='right'><%= val %></td></tr>
98 <%
99 }
100 %>
101 </table>
102
103 <h2>Android ver.</h2>
104 <table border='0'>
105 <%
106 for (String key : androids.keySet()) {
107 int val = androids.get(key);
108 %>
109 <tr><td><%=key%></td><td align='right'><%= val %></td></tr>
110 <%
111 }
112 %>
113 </table>
114
115 </body>
116 </html>

  ViewVC Help
Powered by ViewVC 1.1.20