package cz.cuni.mff.d3s.spl.core.data.segment;

import cz.cuni.mff.d3s.spl.core.data.SerieDataSource;

/** Wrapper for creating sliding time slot view on another data source. */
public class SlidingSerieDataSource {

	/**
	 * Create new data source based on existing one as a sliding time slot.
	 * 
	 * The slot (segment) offset specifies a (relative) difference between
	 * current time and end of the window.
	 * 
	 * As an example, the user creates the slot with offset 14 and length 5. And
	 * at time 31 it looks at the data. The samples returned would then
	 * represent data from 12 to 17.
	 * 
	 * @param origin
	 *            Original data source to get data from.
	 * @param slotOffsetSec
	 *            How many seconds to look into the past.
	 * @param slotLengthSec
	 *            Length of the sliding slot in seconds.
	 * @return
	 */
	public static SerieDataSource create(SerieDataSource origin,
			long slotOffsetSec, long slotLengthSec) {
		return null;
	}
}

@@ -94,16 +94,65 @@
 aSource;
+%0Aimport cz.cuni.mff.d3s.spl.core.data.Statistics;
 %0A%0A/** Wr
@@ -1014,12 +1014,1122 @@
 rn n
-ull;
+ew Implementation(origin, slotOffsetSec + slotLengthSec,%0A%09%09%09%09slotOffsetSec);%0A%09%7D%0A%0A%09private static class Implementation implements SerieDataSource %7B%0A%0A%09%09private SerieDataSource origin;%0A%09%09private long startTimeOffsetMillis;%0A%09%09private long endTimeOffsetMillis;%0A%0A%09%09public Implementation(SerieDataSource data, long startOffsetSec,%0A%09%09%09%09long endOffsetSec) %7B%0A%09%09%09origin = data;%0A%09%09%09startTimeOffsetMillis = startOffsetSec * 1000;%0A%09%09%09endTimeOffsetMillis = endOffsetSec * 1000;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public Statistics get() %7B%0A%09%09%09SerieDataSource segment = getMySegment();%0A%09%09%09return segment.get();%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public SerieDataSource getSegment(long startTime, long endTime) %7B%0A%09%09%09throw new UnsupportedOperationException();%0A%09%09%7D%0A%0A%09%09private SerieDataSource getMySegment() %7B%0A%09%09%09long now = System.currentTimeMillis();%0A%09%09%09return origin.getSegment(now - startTimeOffsetMillis, now - endTimeOffsetMillis);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public String toString() %7B%0A%09%09%09return String.format(%22Sliding source %5B%25d, %25d, %25d, %25s%5D above %25s%22,%0A%09%09%09%09%09startTimeOffsetMillis, endTimeOffsetMillis, System.currentTimeMillis(),%0A%09%09%09%09%09getMySegment().get(), origin);%0A%09%09%7D
 %0A%09%7D%0A

Implement sliding data source