Search in sources :

Example 1 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalJsonConverterTest method testContainsIDEHost.

/**
 * Tests the format of the returned Json representation, manually setting an
 * IDE host.
 */
@Test
public void testContainsIDEHost() {
    IntervalBase interval = new IDEOpenInterval(new Date());
    ArrayList<WatchDogItem> intervals = createSampleIntervals(interval);
    assertEquals("[{\"it\":\"eo\",\"ts\":1,\"te\":2,\"ss\":\"\"," + pasteWDVAndClient() + "}]", transferer.toJson(intervals));
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) EditorIntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase) IDEOpenInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IDEOpenInterval) Date(java.util.Date) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Example 2 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalPersisterTestSingleInterval method test3CompareIntervalAfterWriteDemonstratesCloseIsNotPersisted.

@Test
public void test3CompareIntervalAfterWriteDemonstratesCloseIsNotPersisted() {
    WatchDogItem savedItem = new ArrayList<>(persister.readItems()).get(0);
    assertTrue(savedItem instanceof IntervalBase);
    IntervalBase savedInterval = (IntervalBase) savedItem;
    assertEquals(interval.getDuration(), savedInterval.getDuration());
    assertEquals(interval.isClosed(), savedInterval.isClosed());
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Example 3 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalStatisticsBase method addIntervals.

private void addIntervals(IDEIntervalManagerBase intervalManager) {
    for (WatchDogItem item : intervalPersister.readItems()) {
        if (item instanceof IntervalBase) {
            IntervalBase interval = (IntervalBase) item;
            interval.setClosed();
            intervals.add(interval);
        }
    }
    intervals.addAll(intervalManager.getOpenIntervals());
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) EditorIntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem)

Example 4 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IDEIntervalManagerBase method closeAllIntervals.

/**
 * Closes all currently open intervals with the supplied closing date.
 */
public void closeAllIntervals(Date closingDate) {
    closeInterval(editorInterval, closingDate);
    ArrayList<IntervalBase> copiedIntervals = new ArrayList<IntervalBase>(intervals);
    Iterator<IntervalBase> iterator = copiedIntervals.listIterator();
    while (iterator.hasNext()) {
        // we need to remove the interval first from the list in order to
        // avoid ConcurrentListModification Exceptions.
        IntervalBase interval = iterator.next();
        iterator.remove();
        closeInterval(interval, closingDate);
    }
    intervals.clear();
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) EditorIntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase) ArrayList(java.util.ArrayList)

Example 5 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalStatisticsBase method filterIntervals.

/**
 * Filters out and removes intervals which are older than 10 hours from
 * Database. Filters intervals for selected time span.
 */
private void filterIntervals() {
    ArrayList<IntervalBase> filteredIntervals = new ArrayList<IntervalBase>();
    ArrayList<WatchDogItem> intervalsToRemove = new ArrayList<WatchDogItem>();
    if (intervals.size() == 0) {
        return;
    }
    mostRecentDate = intervals.get(intervals.size() - 1).getEnd();
    DateTime thresholdDateDatabase = new DateTime(mostRecentDate);
    thresholdDateDatabase = thresholdDateDatabase.minusMinutes(FILTERED_INTERVALS_IN_MINUTES);
    DateTime thresholdDateView = new DateTime(mostRecentDate);
    thresholdDateView = thresholdDateView.minusMinutes(selectedInterval.minutes);
    for (IntervalBase interval : intervals) {
        if (intervalIsOlderThanThreshold(thresholdDateDatabase, interval)) {
            intervalsToRemove.add(interval);
            continue;
        }
        if (!intervalIsOlderThanThreshold(thresholdDateView, interval)) {
            IntervalBase clonedInterval = null;
            try {
                clonedInterval = (IntervalBase) interval.clone();
                adjustIntervalStartAndEndDate(thresholdDateView, interval, clonedInterval);
                filteredIntervals.add(clonedInterval);
            } catch (CloneNotSupportedException exception) {
            // intentionally empty
            }
        }
    }
    oldestDate = filteredIntervals.get(0).getStart();
    intervalPersister.removeItems(intervalsToRemove);
    intervals = filteredIntervals;
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) EditorIntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem)

Aggregations

IntervalBase (nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase)12 WatchDogItem (nl.tudelft.watchdog.core.logic.storage.WatchDogItem)10 Test (org.junit.Test)7 EditorIntervalBase (nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase)6 Date (java.util.Date)5 IDEOpenInterval (nl.tudelft.watchdog.core.logic.interval.intervaltypes.IDEOpenInterval)4 ArrayList (java.util.ArrayList)3 Random (java.util.Random)1 DebugInterval (nl.tudelft.watchdog.core.logic.interval.intervaltypes.DebugInterval)1 JsonTransferer (nl.tudelft.watchdog.core.logic.network.JsonTransferer)1 ServerCommunicationException (nl.tudelft.watchdog.core.logic.network.ServerCommunicationException)1 ServerReturnCodeException (nl.tudelft.watchdog.core.logic.network.ServerReturnCodeException)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1