if (!accessAllowed && coachee==null) {
uid = null;
}
if (uid == null) {
return gson.toJson(new StatusModel(false, "Invalid User ID (null)"));
}
// first use Level and Offset to calculate the desired start and end times
final long startTimeMillis = (long)(LevelOffsetHelper.offsetAtLevelToUnixTime(level, offset) * 1000);
final long endTimeMillis = (long)(LevelOffsetHelper.offsetAtLevelToUnixTime(level, offset + 1) * 1000);
final TimeInterval timeInterval = new SimpleTimeInterval(startTimeMillis, endTimeMillis, TimeUnit.ARBITRARY, TimeZone.getTimeZone("UTC"));
// fetch the photos for this time interval, and for the desired device/channel
final TagFilter tagFilter = TagFilter.create(Tag.parseTagsIntoStrings(tagsStr, Tag.COMMA_DELIMITER), tagFilteringStrategy);
final SortedSet<PhotoService.Photo> photos = photoService.getPhotos(uid, timeInterval, connectorPrettyName, objectTypeName, tagFilter);
// Define the min interval to be 1/20th of the span of the tile. Value is in seconds
final double minInterval = LevelOffsetHelper.levelToDuration(level) / 20.0;
// Now filter the photos using the minInterval as follows:
// * min_interval specifies the minimum number of seconds between images.
// * Always include the first photo, set count to 1
// * When processing a given photo B, compare the time of this photo with the previous included
// photo A. If image B is < min_interval seconds after image A, then increase count field in image
// A and ignore image B. If image B is >= min_interval seconds after image A, then include image
// B with count=1
PhotoItem photoA = null;
final List<PhotoItem> filteredPhotos = new ArrayList<PhotoItem>();
for (final PhotoService.Photo photoB : photos) {
if (photoA == null) {
photoA = new PhotoItem(photoB);
filteredPhotos.add(photoA);
}
else {
// Already have a photoA, compare times to see if we should keep this one
final long photoBStartTimeSecs = photoB.getAbstractPhotoFacetVO().start / 1000;
if (photoBStartTimeSecs > (photoA.begin_d + minInterval)) {
// Enough of a gap between A and B, so keep this one and set to be new A
photoA = new PhotoItem(photoB);
filteredPhotos.add(photoA);
} else {
// Not enough of a gap, increment count on photoA
photoA.incrementCount();
}
}
}
if (LOG_DEBUG.isDebugEnabled()) {
LOG_DEBUG.debug("BodyTrackController.fetchPhotoTile(): num photos filtered from " + photos.size() + " to " + filteredPhotos.size());
}
return gson.toJson(filteredPhotos);
}
catch (Exception e) {
LOG.error("BodyTrackController.fetchPhotoTile(): Exception while trying to fetch photos: ", e);
return gson.toJson(new StatusModel(false, "Access Denied"));
}
}