|
Lines 6-16
Link Here
|
| 6 |
import java.io.InputStream; |
6 |
import java.io.InputStream; |
| 7 |
import java.io.PrintStream; |
7 |
import java.io.PrintStream; |
| 8 |
import java.io.PrintWriter; |
8 |
import java.io.PrintWriter; |
|
|
9 |
import java.text.DateFormat; |
| 10 |
import java.text.SimpleDateFormat; |
| 9 |
import java.util.ArrayList; |
11 |
import java.util.ArrayList; |
|
|
12 |
import java.util.Calendar; |
| 10 |
import java.util.Collections; |
13 |
import java.util.Collections; |
|
|
14 |
import java.util.Date; |
| 11 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
|
|
16 |
import java.util.Iterator; |
| 12 |
import java.util.List; |
17 |
import java.util.List; |
| 13 |
import java.util.Map; |
18 |
import java.util.Map; |
|
|
19 |
import java.util.StringTokenizer; |
| 14 |
import java.util.zip.ZipEntry; |
20 |
import java.util.zip.ZipEntry; |
| 15 |
import java.util.zip.ZipFile; |
21 |
import java.util.zip.ZipFile; |
| 16 |
|
22 |
|
|
Lines 21-43
Link Here
|
| 21 |
Map<Integer, Integer> usersNumSelections = new HashMap<Integer, Integer>(); |
27 |
Map<Integer, Integer> usersNumSelections = new HashMap<Integer, Integer>(); |
| 22 |
|
28 |
|
| 23 |
Map<String, Integer> totalNumSelections = new HashMap<String, Integer>(); |
29 |
Map<String, Integer> totalNumSelections = new HashMap<String, Integer>(); |
| 24 |
|
30 |
|
|
|
31 |
Map<String, Integer> totalNumCommands = new HashMap<String, Integer>(); |
| 32 |
|
| 25 |
final static String USAGE_DIRECTORY = MylarUsageUploadServlet.UPLOAD_DIRECTORY; |
33 |
final static String USAGE_DIRECTORY = MylarUsageUploadServlet.UPLOAD_DIRECTORY; |
| 26 |
|
34 |
|
| 27 |
final static String LOGGING_DIRECTORY = "home//study//logging//"; |
35 |
final static String LOGGING_DIRECTORY = "home//study//logging//"; |
| 28 |
|
36 |
|
| 29 |
final static String ERROR_LOGGING_FILE = "MylarUsageAnalysisErrorLog.txt"; |
37 |
final static String ERROR_LOGGING_FILE = "MylarUsageAnalysisErrorLog.txt"; |
| 30 |
|
38 |
|
| 31 |
final static String USAGE_SUMMARY_FILE = "usageSummary.txt"; |
39 |
final static String USAGE_SUMMARY_FILE = "usageSummary.txt"; |
| 32 |
|
40 |
|
| 33 |
int MAX_NUM_VIEWS_TO_REPORT = 10; |
41 |
int MAX_NUM_VIEWS_TO_REPORT = 10; |
| 34 |
|
42 |
|
|
|
43 |
int MAX_NUM_COMMANDS_TO_REPORT = 25; |
| 44 |
|
| 35 |
int totalSelections = 0; |
45 |
int totalSelections = 0; |
| 36 |
|
46 |
|
| 37 |
public static void main(String []args) { |
47 |
int totalCommands = 0; |
|
|
48 |
|
| 49 |
public static void main(String[] args) { |
| 38 |
UsageAnalysis ua = new UsageAnalysis(); |
50 |
UsageAnalysis ua = new UsageAnalysis(); |
| 39 |
ua.analyzeLogs(); |
51 |
ua.analyzeLogs(); |
| 40 |
} |
52 |
} |
|
|
53 |
|
| 41 |
public void analyzeLogs() { |
54 |
public void analyzeLogs() { |
| 42 |
|
55 |
|
| 43 |
try { |
56 |
try { |
|
Lines 50-55
Link Here
|
| 50 |
userID = this.getUserId(currFile); |
63 |
userID = this.getUserId(currFile); |
| 51 |
|
64 |
|
| 52 |
int numSelections = 0; |
65 |
int numSelections = 0; |
|
|
66 |
int numCommands = 0; |
| 53 |
if (usersNumSelections.containsKey(userID)) { |
67 |
if (usersNumSelections.containsKey(userID)) { |
| 54 |
numSelections = usersNumSelections.get(userID); |
68 |
numSelections = usersNumSelections.get(userID); |
| 55 |
} |
69 |
} |
|
Lines 70-76
Link Here
|
| 70 |
String endTag = "</originId>"; |
84 |
String endTag = "</originId>"; |
| 71 |
|
85 |
|
| 72 |
String kindTag = "<kind>"; |
86 |
String kindTag = "<kind>"; |
| 73 |
String matchKind = "selection"; |
87 |
String selectionKind = "selection"; |
|
|
88 |
String commandKind = "command"; |
| 74 |
|
89 |
|
| 75 |
// they should all be zip files, ignore anything that's not |
90 |
// they should all be zip files, ignore anything that's not |
| 76 |
if (currFile.getName().endsWith(".zip")) { |
91 |
if (currFile.getName().endsWith(".zip")) { |
|
Lines 90-96
Link Here
|
| 90 |
int kindIndex = buf.indexOf(kindTag); |
105 |
int kindIndex = buf.indexOf(kindTag); |
| 91 |
kindIndex += kindTag.length(); |
106 |
kindIndex += kindTag.length(); |
| 92 |
|
107 |
|
| 93 |
if (buf.substring(kindIndex, kindIndex + matchKind.length()).equals(matchKind)) { |
108 |
String currKind = buf.substring(kindIndex, kindIndex + selectionKind.length()); |
|
|
109 |
|
| 110 |
if (currKind.contains(selectionKind)) { |
| 94 |
|
111 |
|
| 95 |
numSelections++; |
112 |
numSelections++; |
| 96 |
totalSelections++; |
113 |
totalSelections++; |
|
Lines 109-114
Link Here
|
| 109 |
int totalNumViews = totalNumSelections.get(currOriginId) + 1; |
126 |
int totalNumViews = totalNumSelections.get(currOriginId) + 1; |
| 110 |
totalNumSelections.put(currOriginId, totalNumViews); |
127 |
totalNumSelections.put(currOriginId, totalNumViews); |
| 111 |
|
128 |
|
|
|
129 |
} else if (currKind.contains(commandKind)) { |
| 130 |
numCommands++; |
| 131 |
totalCommands++; |
| 132 |
currOriginId = buf.substring(index, endIndex); |
| 133 |
|
| 134 |
if (!totalNumCommands.containsKey(currOriginId)) { |
| 135 |
totalNumCommands.put(currOriginId, 0); |
| 136 |
} |
| 137 |
|
| 138 |
int currNumCommands = totalNumCommands.get(currOriginId) + 1; |
| 139 |
totalNumCommands.put(currOriginId, currNumCommands); |
| 112 |
} |
140 |
} |
| 113 |
|
141 |
|
| 114 |
buf = buf.substring(endIndex + endTag.length(), buf.length()); |
142 |
buf = buf.substring(endIndex + endTag.length(), buf.length()); |
|
Lines 214-242
Link Here
|
| 214 |
|
242 |
|
| 215 |
PrintStream summaryLogStream = new PrintStream(new FileOutputStream(summaryFile, true)); |
243 |
PrintStream summaryLogStream = new PrintStream(new FileOutputStream(summaryFile, true)); |
| 216 |
|
244 |
|
| 217 |
summaryLogStream.println("Total events: " + totalSelections); |
245 |
summaryLogStream.println("<h2>Mylar Community Usage Statistics</h2>"); |
| 218 |
summaryLogStream.println("Number of unique users: " + userToViewMap.entrySet().size()); |
246 |
summaryLogStream.println("These statistics are updated once per day. They were last updated at " |
| 219 |
summaryLogStream.println(); |
247 |
+ DateFormat.getTimeInstance(DateFormat.DEFAULT).format(Calendar.getInstance().getTime()) + " " |
|
|
248 |
+ new SimpleDateFormat("z").format(Calendar.getInstance().getTime()) + " on " |
| 249 |
+ DateFormat.getDateInstance().format(Calendar.getInstance().getTime()) + "."); |
| 250 |
summaryLogStream.println("<br><br>"); |
| 251 |
|
| 252 |
summaryLogStream.println("<b>Total events: " + (totalSelections + totalCommands) + "</b><br>"); |
| 253 |
summaryLogStream.println("<b>Number of unique users: " + userToViewMap.entrySet().size() + "</b><br><br>"); |
| 254 |
summaryLogStream.println(""); |
| 255 |
|
| 256 |
summaryLogStream.println("<b>" + " " + MAX_NUM_VIEWS_TO_REPORT + " most used views: </b>"); |
| 220 |
|
257 |
|
| 221 |
summaryLogStream.println(MAX_NUM_VIEWS_TO_REPORT + " most used views:"); |
258 |
summaryLogStream.println("<table border=1 rules=rows|columns cellpadding=4>"); |
| 222 |
|
259 |
|
| 223 |
List<String> viewUsage = new ArrayList<String>(); |
260 |
List<String> viewUsage = new ArrayList<String>(); |
| 224 |
for (String view : totalNumSelections.keySet()) { |
261 |
for (String view : totalNumSelections.keySet()) { |
| 225 |
float numSelections = (float) (totalNumSelections.get(view)); |
262 |
float numSelections = (float) (totalNumSelections.get(view)); |
| 226 |
float viewUse = numSelections / totalSelections; |
263 |
float viewUse = numSelections / totalSelections; |
| 227 |
String formattedViewUse = formatAsPercentage(viewUse); |
264 |
String formattedViewUse = formatAsPercentage(viewUse); |
| 228 |
viewUsage.add(formattedViewUse + ": " + view + " (" + totalNumSelections.get(view) + ")"); |
265 |
viewUsage.add(formattedViewUse + "," + view + "," + totalNumSelections.get(view)); |
| 229 |
} |
266 |
} |
| 230 |
Collections.sort(viewUsage, new PercentUsageComparator()); |
267 |
Collections.sort(viewUsage, new PercentUsageComparator()); |
| 231 |
int numViewsToReport = 0; |
268 |
int numViewsToReport = 0; |
| 232 |
for (String viewUsageSummary : viewUsage) { |
269 |
Iterator<String> listIterator = viewUsage.iterator(); |
| 233 |
if (MAX_NUM_VIEWS_TO_REPORT == -1 || numViewsToReport < MAX_NUM_VIEWS_TO_REPORT) { |
270 |
while (listIterator.hasNext() |
|
|
271 |
&& (MAX_NUM_VIEWS_TO_REPORT == -1 || numViewsToReport < MAX_NUM_VIEWS_TO_REPORT)) { |
| 234 |
|
272 |
|
| 235 |
summaryLogStream.println(viewUsageSummary); |
273 |
String[] nextRow = listIterator.next().split(","); |
| 236 |
numViewsToReport++; |
274 |
|
| 237 |
} |
275 |
summaryLogStream.println("<tr>"); |
|
|
276 |
|
| 277 |
summaryLogStream.println("<td>"); |
| 278 |
summaryLogStream.println(nextRow[0]); |
| 279 |
summaryLogStream.println("</td>"); |
| 280 |
|
| 281 |
summaryLogStream.println("<td>"); |
| 282 |
summaryLogStream.println(nextRow[1]); |
| 283 |
summaryLogStream.println("</td>"); |
| 284 |
|
| 285 |
summaryLogStream.println("<td>"); |
| 286 |
summaryLogStream.println(nextRow[2]); |
| 287 |
summaryLogStream.println("</td>"); |
| 288 |
|
| 289 |
summaryLogStream.println("</tr>"); |
| 290 |
numViewsToReport++; |
| 291 |
} |
| 292 |
|
| 293 |
summaryLogStream.println("</table>"); |
| 294 |
summaryLogStream.println("<br><br>"); |
| 295 |
|
| 296 |
summaryLogStream.println("<b>" + " " + MAX_NUM_COMMANDS_TO_REPORT + " most used commands: </b>"); |
| 297 |
|
| 298 |
//Commands |
| 299 |
summaryLogStream.println("<table border=1 rules=rows|columns cellpadding=4>"); |
| 300 |
|
| 301 |
List<String> commandUsage = new ArrayList<String>(); |
| 302 |
for (String cmd : totalNumCommands.keySet()) { |
| 303 |
float numCommands = (float) (totalNumCommands.get(cmd)); |
| 304 |
float commandUse = numCommands / totalCommands; |
| 305 |
String formattedCmdUse = formatAsPercentage(commandUse); |
| 306 |
commandUsage.add(formattedCmdUse + "," + cmd + "," + totalNumCommands.get(cmd)); |
| 307 |
} |
| 308 |
Collections.sort(commandUsage, new PercentUsageComparator()); |
| 309 |
int numCommandsToReport = 0; |
| 310 |
|
| 311 |
Iterator<String> cmdListIterator = commandUsage.iterator(); |
| 312 |
while (cmdListIterator.hasNext() |
| 313 |
&& (MAX_NUM_COMMANDS_TO_REPORT == -1 || numCommandsToReport < MAX_NUM_COMMANDS_TO_REPORT)) { |
| 314 |
|
| 315 |
String[] nextRow = cmdListIterator.next().split(","); |
| 316 |
|
| 317 |
summaryLogStream.println("<tr>"); |
| 318 |
|
| 319 |
summaryLogStream.println("<td>"); |
| 320 |
summaryLogStream.println(nextRow[0]); |
| 321 |
summaryLogStream.println("</td>"); |
| 322 |
|
| 323 |
summaryLogStream.println("<td>"); |
| 324 |
summaryLogStream.println(nextRow[1]); |
| 325 |
summaryLogStream.println("</td>"); |
| 326 |
|
| 327 |
summaryLogStream.println("<td>"); |
| 328 |
summaryLogStream.println(nextRow[2]); |
| 329 |
summaryLogStream.println("</td>"); |
| 330 |
|
| 331 |
summaryLogStream.println("</tr>"); |
| 332 |
numCommandsToReport++; |
| 238 |
} |
333 |
} |
| 239 |
|
334 |
|
|
|
335 |
summaryLogStream.println("</table>"); |
| 336 |
summaryLogStream.close(); |
| 240 |
} catch (IOException e) { |
337 |
} catch (IOException e) { |
| 241 |
logError(e.getMessage()); |
338 |
logError(e.getMessage()); |
| 242 |
} |
339 |
} |