EXPDPersistenceService extends QueryableImpl implements ExternalDataPersistenceService { public VideoMoment findTimecodeNearDate(String platform, Date date, int millisecTolerance) { List<VideoMoment> tapeTimes = findTimecodesNearDate(platform, date, millisecTolerance); VideoMoment nearestDateTimecode = null; long dtMin = Long.MAX_VALUE; for (VideoMoment tapeTime : tapeTimes) { Date d = tapeTime.getRecordedDate(); long dt = Math.abs(d.getTime() - date.getTime()); if (dt < dtMin) { dtMin = dt; nearestDateTimecode = tapeTime; } } return nearestDateTimecode; } EXPDPersistenceService(); VideoMoment findTimecodeNearDate(String platform, Date date, int millisecTolerance); List<VideoMoment> findTimecodesNearDate(String platform, Date date, int millisecTolerance); VideoMoment interpolateTimecodeByDate(String cameraIdentifier, Date date, int millisecTolerance,
            double frameRate); static final int SAMPLERATE_MILLSEC; }
@Test @Ignore public void findTimecodeByDateTest01() { int millisecTolerance = 1000 * 7; double framerate = 29.97; List<TimecodeBean> beans = new ArrayList<TimecodeBean>(); try { beans.add(new TimecodeBean(new Timecode("04:28:08:03", framerate), dateFormat.parse("2008-05-19T21:03:31Z"), "Ventana")); beans.add(new TimecodeBean(new Timecode("04:31:49:13", framerate), dateFormat.parse("2007-12-20T20:34:08Z"), "Tiburon")); beans.add(new TimecodeBean(new Timecode("01:05:48:24", framerate), dateFormat.parse("2008-04-09T17:16:35Z"), "Ventana")); } catch (ParseException e) { log.error("Failed to generate test data", e); Assert.fail("Failed to generate test data"); } for (TimecodeBean b : beans) { VideoMoment videoMoment = dao.findTimecodeNearDate(b.platform, b.date, millisecTolerance); Timecode tc = new Timecode(videoMoment.getAlternateTimecode(), framerate); double dt = Math.abs(tc.diffFrames(b.timecode)); log.debug("EXPECTED: " + b.timecode + " FOUND: " + tc); Assert.assertTrue("Timecode is wrong. EXPECTED: " + b.timecode + " FOUND: " + tc, dt / framerate * 1000 <= millisecTolerance); } }