Source:
public void testCompress() throws Exception { int testNum = 600; long minBucketMillis = CondensedAnomalyTimelinesView.DEFAULT_MIN_BUCKET_UNIT; CondensedAnomalyTimelinesView condensedView = CondensedAnomalyTimelinesView.fromAnomalyTimelinesView(getTestData(testNum)); Assert.assertTrue(condensedView.toJsonString().length() > CondensedAnomalyTimelinesView.DEFAULT_MAX_LENGTH); CondensedAnomalyTimelinesView compressedView = condensedView.compress(); Assert.assertTrue(compressedView.toJsonString().length() < CondensedAnomalyTimelinesView.DEFAULT_MAX_LENGTH); Assert.assertEquals(300, compressedView.timeStamps.size()); Assert.assertEquals(compressedView.bucketMillis.longValue(), 10); DateTime date = new DateTime(2018, 1, 1, 0, 0, 0); for (int i = 0; i < compressedView.getTimeStamps().size(); i++) { Assert.assertEquals(compressedView.getTimeStamps().get(i).longValue(), (date.getMillis() - condensedView.timestampOffset)/minBucketMillis); Assert.assertEquals(compressedView.getCurrentValues().get(i), i * 2 + 0.5, 0.000001); Assert.assertEquals(compressedView.getBaselineValues().get(i), i * 2 + 0.833, 0.000001); date = date.plusMinutes(10); } AnomalyTimelinesView decompressedView = compressedView.toAnomalyTimelinesView(); date = new DateTime(2018, 1, 1, 0, 0, 0); for (int i = 0; i < decompressedView.getBaselineValues().size(); i++) { TimeBucket timeBucket = decompressedView.getTimeBuckets().get(i); Assert.assertEquals(timeBucket.getCurrentStart(), date.getMillis()); Assert.assertEquals(timeBucket.getCurrentEnd(), date.plusMinutes(10).getMillis()); Assert.assertEquals(decompressedView.getCurrentValues().get(i), i * 2 + 0.5, 0.000001); Assert.assertEquals(decompressedView.getBaselineValues().get(i), i * 2 + 0.833, 0.000001); date = date.plusMinutes(10); } }

Target:
public void testCompress() throws Exception { int testNum = 600; long minBucketMillis = CondensedAnomalyTimelinesView.DEFAULT_MIN_BUCKET_UNIT; CondensedAnomalyTimelinesView condensedView = CondensedAnomalyTimelinesView.fromAnomalyTimelinesView(getTestData(testNum)); Assert.assertTrue(condensedView.toJsonString().length() > CondensedAnomalyTimelinesView.DEFAULT_MAX_LENGTH); CondensedAnomalyTimelinesView compressedView = condensedView.compress(); Assert.assertTrue(compressedView.toJsonString().length() < CondensedAnomalyTimelinesView.DEFAULT_MAX_LENGTH); Assert.assertEquals(300, compressedView.timeStamps.size()); Assert.assertEquals(compressedView.bucketMillis.longValue(), 10); DateTime date = new DateTime(2018, 1, 1, 0, 0, 0); for (int i = 0; i < compressedView.getTimeStamps().size(); i++) { Assert.assertEquals(compressedView.getTimeStamps().get(i).longValue(), (date.getMillis() - condensedView.timestampOffset)/minBucketMillis); Assert.assertEquals(compressedView.getCurrentValues().get(i), i * 2 + 0.5); Assert.assertEquals(compressedView.getBaselineValues().get(i), i * 2 + 0.83); date = date.plusMinutes(10); } AnomalyTimelinesView decompressedView = compressedView.toAnomalyTimelinesView(); date = new DateTime(2018, 1, 1, 0, 0, 0); for (int i = 0; i < decompressedView.getBaselineValues().size(); i++) { TimeBucket timeBucket = decompressedView.getTimeBuckets().get(i); Assert.assertEquals(timeBucket.getCurrentStart(), date.getMillis()); Assert.assertEquals(timeBucket.getCurrentEnd(), date.plusMinutes(10).getMillis()); Assert.assertEquals(decompressedView.getCurrentValues().get(i), i * 2 + 0.5); Assert.assertEquals(decompressedView.getBaselineValues().get(i), i * 2 + 0.83); date = date.plusMinutes(10); } }