
import traildb.*;

import java.io.FileNotFoundException;

public class Wikipedia {
	public static long SESSION_LIMIT = 30 * 60;
	public static void sessions(TrailDB tdb) {
		TrailDBCursor cursor = tdb.cursorNew();
		long n = tdb.numTrails();
		long totalSessions = 0;
		long totalEvents = 0;

		for (long i = 0; i < n; i++) {
			TrailDBEvent event;
			cursor.getTrail(i);
			event = cursor.next();
			long prevTime = event.timestamp;
			long numSessions = 1;
			long numEvents = 1;
			while ((event = cursor.next()) != null) {
				if (event.timestamp - prevTime > SESSION_LIMIT)
					numSessions++;
				prevTime = event.timestamp;
				numEvents++;
			}
			totalSessions += numSessions;
			totalEvents += numEvents;
		}
		System.out.println("Trails: " + n + "Sessions: " + totalSessions + " Events: " + totalEvents);
	}

	public static void main(String[] args) throws FileNotFoundException {
		TrailDB tdb = new TrailDB("wikipedia-history-small.tdb");
		sessions(tdb);
	}
}
@@ -166,16 +166,76 @@
  tdb) %7B%0A
+%09%09System.out.print(%22Number of events: %22 + tdb.numEvents());%0A
 %09%09TrailD
@@ -264,24 +264,24 @@
 ursorNew();%0A
-
 %09%09long n = t
@@ -403,16 +403,119 @@
  event;%0A
+%09%09%09if (i %25 16384 == 0) %7B%0A%09%09%09%09cursor.getTrail(i);%0A%09%09%09%09System.out.println(cursor.getTrailLength());%0A%09%09%09%7D%0A
 %09%09%09curso
@@ -529,16 +529,17 @@
 ail(i);%0A
+%0A
 %09%09%09event
@@ -556,16 +556,17 @@
 next();%0A
+%0A
 %09%09%09long 
@@ -878,16 +878,16 @@
 ts;%0A%09%09%7D%0A
-
 %09%09System
@@ -917,16 +917,17 @@
  + n + %22
+ 
 Sessions

Update Wikipedia example to test numEvents and getTrailLength