use of org.opencastproject.usertracking.api.FootprintList in project opencast by opencast.
the class UserTrackingServiceImpl method getFootprints.
public FootprintList getFootprints(String mediapackageId, String userId) {
EntityManager em = null;
if (!logUser)
userId = null;
try {
em = emf.createEntityManager();
Query q = null;
if (StringUtils.trimToNull(userId) == null) {
q = em.createNamedQuery("findUserActionsByTypeAndMediapackageIdOrderByOutpointDESC");
} else {
q = em.createNamedQuery("findUserActionsByTypeAndMediapackageIdByUserOrderByOutpointDESC");
q.setParameter("userid", userId);
}
q.setParameter("type", FOOTPRINT_KEY);
q.setParameter("mediapackageId", mediapackageId);
@SuppressWarnings("unchecked") Collection<UserAction> userActions = q.getResultList();
int[] resultArray = new int[1];
boolean first = true;
for (UserAction a : userActions) {
if (first) {
// Get one more item than the known outpoint to append a footprint of 0 views at the end of the result set
resultArray = new int[a.getOutpoint() + 1];
first = false;
}
for (int i = a.getInpoint(); i < a.getOutpoint(); i++) {
resultArray[i]++;
}
}
FootprintList list = new FootprintsListImpl();
int current = -1;
int last = -1;
for (int i = 0; i < resultArray.length; i++) {
current = resultArray[i];
if (last != current) {
Footprint footprint = new FootprintImpl();
footprint.setPosition(i);
footprint.setViews(current);
list.add(footprint);
}
last = current;
}
return list;
} finally {
if (em != null && em.isOpen()) {
em.close();
}
}
}
use of org.opencastproject.usertracking.api.FootprintList in project opencast by opencast.
the class UserTrackingServiceImplTest method getFootprintList.
/**
* Gets the footprint list, performs some asserts
* @throws Exception
*/
private FootprintList getFootprintList(String mediapackageId, String userId, int expectedFootprints) {
FootprintList list;
if (StringUtils.trim(userId) == null) {
list = service.getFootprints(mediapackageId, null);
} else {
list = service.getFootprints(mediapackageId, userId);
}
// There's always a 0th footprint, so this should never be zero!
Assert.assertEquals(expectedFootprints, list.getTotal());
Assert.assertEquals(expectedFootprints, list.getFootprints().size());
return list;
}
use of org.opencastproject.usertracking.api.FootprintList in project opencast by opencast.
the class UserTrackingServiceImplTest method testfootprints.
/**
* Test footprint functionality
* @throws Exception
*/
@Test
public void testfootprints() throws Exception {
FootprintList list = getFootprintList("mp", null, 1);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
list = getFootprintList("mp", "me", 1);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
// Create the initial viewer/user event
createAndVerifyUserAction(UserTrackingServiceImpl.FOOTPRINT_KEY, "session123", "mp", "me", "127.0.0.1", 10, 20);
// Sanity checks
Assert.assertEquals(1, service.getViews("mp"));
Assert.assertEquals(0, service.getViews("other"));
// Assert that the correct things are in the correct places.
list = getFootprintList("mp", null, 3);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 20, 0);
list = getFootprintList("mp", "someone else", 1);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
list = getFootprintList("mp", "me", 3);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 20, 0);
// Create a different viewer/user event
createAndVerifyUserAction(UserTrackingServiceImpl.FOOTPRINT_KEY, "session456", "mp", "someone else", "127.0.01", 560, 720);
// Sanity checks
Assert.assertEquals(2, service.getViews("mp"));
Assert.assertEquals(0, service.getViews("other"));
// Assert that the correct things are in the correct places.
list = getFootprintList("mp", null, 5);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 20, 0);
verifyFootprintViewsAndPositions(list, 3, 560, 1);
verifyFootprintViewsAndPositions(list, 4, 720, 0);
list = getFootprintList("mp", "someone else", 3);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 560, 1);
verifyFootprintViewsAndPositions(list, 2, 720, 0);
list = getFootprintList("mp", "me", 3);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 20, 0);
// Update the first viewer/user event
createAndVerifyUserAction(UserTrackingServiceImpl.FOOTPRINT_KEY, "session123", "mp", "me", "127.0.0.1", 20, 30);
// Sanity checks
Assert.assertEquals(2, service.getViews("mp"));
Assert.assertEquals(0, service.getViews("other"));
// Assert that the correct things are in the correct places.
list = getFootprintList("mp", null, 5);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 30, 0);
verifyFootprintViewsAndPositions(list, 3, 560, 1);
verifyFootprintViewsAndPositions(list, 4, 720, 0);
list = getFootprintList("mp", "someone else", 3);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 560, 1);
verifyFootprintViewsAndPositions(list, 2, 720, 0);
list = getFootprintList("mp", "me", 3);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 30, 0);
// Skip the second viewer to a new point in the video
createAndVerifyUserAction(UserTrackingServiceImpl.FOOTPRINT_KEY, "session456", "mp", "someone else", "127.0.01", 950, 960);
// Sanity checks
Assert.assertEquals(2, service.getViews("mp"));
Assert.assertEquals(0, service.getViews("other"));
// Assert that the correct things are in the correct places.
list = getFootprintList("mp", null, 7);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 30, 0);
verifyFootprintViewsAndPositions(list, 3, 560, 1);
verifyFootprintViewsAndPositions(list, 4, 720, 0);
verifyFootprintViewsAndPositions(list, 5, 950, 1);
verifyFootprintViewsAndPositions(list, 6, 960, 0);
list = getFootprintList("mp", "someone else", 5);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 560, 1);
verifyFootprintViewsAndPositions(list, 2, 720, 0);
verifyFootprintViewsAndPositions(list, 3, 950, 1);
verifyFootprintViewsAndPositions(list, 4, 960, 0);
list = getFootprintList("mp", "me", 3);
verifyFootprintViewsAndPositions(list, 0, 0, 0);
verifyFootprintViewsAndPositions(list, 1, 10, 1);
verifyFootprintViewsAndPositions(list, 2, 30, 0);
}
Aggregations