org.android.activityminer.logic.timeseries
Class GenericObservableCutoutCreator<D extends Enum<D> & Dimensions,T>

Package class diagram package GenericObservableCutoutCreator
java.lang.Object
  extended by java.lang.Thread
      extended by de.unikassel.android.sdcframework.util.AbstractWorkerThread
          extended by de.unikassel.android.sdcframework.util.AbstractEventDispatcherImpl<SensorObservation<D,T>,SensorObservationCutout<D,T>>
              extended by org.android.activityminer.logic.timeseries.GenericObservableCutoutCreator<D,T>
Type Parameters:
D - the enumeration type for the dimensions of the sensor observations
T - the data type for time series data
All Implemented Interfaces:
EventDispatcher<SensorObservation<D,T>,SensorObservationCutout<D,T>>, ObservableEventSource<SensorObservationCutout<D,T>>, ObserverRegistration<SensorObservationCutout<D,T>>, WorkerThread, Runnable, ActivatableComponent
Direct Known Subclasses:
ObservableAccCutoutCreator, ObservableCutoutCreator

public class GenericObservableCutoutCreator<D extends Enum<D> & Dimensions,T>
extends AbstractEventDispatcherImpl<SensorObservation<D,T>,SensorObservationCutout<D,T>>
implements ActivatableComponent

The generic observable cut-out creator is a worker thread, which does asynchronously extract fixed size cut-out from cached sensor observations. The sensor observations are received by observing an ObservableEventSource for SensorObservation< D, T > and will be stored in the queue first. This queue is processed by a thread for cut-out extraction.

The position of the current cutOut for extraction may overlap by a configurable size with the previous one, but not more than 50%.

This component must be attached to a source of sensor observations, which does implement the ObservableEventSource interface for the type SensorObservation< D, T >. To attach the sensor observations source, use the attachSensorObservationSource(ObservableEventSource) method. The corresponding method to detach from a sample source is detachSensorObservationSource(ObservableEventSource)

This component is observable for the resulting windows. To register for cutOut observation implement the EventObserver interface for the SensorObservationCutout and register this observer to the event source of this component (accessible by the AbstractEventDispatcherImpl.getEventSource() method}).

IMPORTANT: If you use this component, do not forget to call the AbstractWorkerThread.doTerminate() method to finally kill this thread when done.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  ActivatableComponent activationDelegation
          activatable component implementation to delegate to
private  Context context
          The context.
private  SensorObservationCutout<D,T> current
          The current cutOut.
private  AtomicLong currentCutOutLength
          The current cut-out length in ms.
private  long currentFrameEndTime
          The current cut-out end time.
private  SensorObservationCutout<D,T> last
          Reference to the last unfinished cutOut.
private  SensorObservationCutout<D,T> next
          The next cutOut.
private  long nextFrameStartTime
          The next cut-out start time.
private  AtomicInteger observationCount
          The total received observation count while active.
private  com.google.common.util.concurrent.AtomicDouble overlap
          The overlap size in percent (0-1).
private  AtomicInteger overlapSize
          The overlap size in milliseconds of continuous cut-outs.
private  AtomicLong startTs
          The start time stamp for sample rate calculation
private  AtomicLong stopTs
          The stop time stamp for sample rate calculation
private  AtomicLong windowSize
          The size of the cut-outs (count of sensor observations ) to extract.
 
Fields inherited from class de.unikassel.android.sdcframework.util.AbstractEventDispatcherImpl
collector
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
GenericObservableCutoutCreator(long windowSize, int overlap, Context context)
          Constructor
 
Method Summary
 void attachSensorObservationSource(ObservableEventSource<SensorObservation<D,T>> sensorObservationSource)
          Method to attach a source for sensor observations.
 void detachSensorObservationSource(ObservableEventSource<SensorObservation<D,T>> sensorObservationSource)
          Method to detach from a source for sensor observations.
protected  void doWork()
           
 long getAvgSampleUpdateRate()
          Getter for the average rate for received samples
 long getCurrentCutOutDuration()
          Getter for the current cut-out duration (window length)
 SensorObservationCutout<D,T> getLastCutout()
          If the processor is not active, this method will return the unfinished last cut-out with sensor observations.
 int getOverlapSize()
          Getter for the overlap size
 int getQueuedObservationCount()
          Getter for the remaining count of queued and unprocessed sensor observations.
 long getWindowSize()
          Getter for the cutOut size
 boolean isActive()
          Test method for the actiation state.
protected  SensorObservationCutout<D,T> newCutoutInstance()
          Does create a new cut-out instance of the concrete type.
 void nextTimeStamp(long nextTs)
          Method to handle the next incoming time stamp.
protected  void onActivationStateChange(boolean active)
          Handler for activation state changes
 void setActivationState(boolean active)
          Method to set the activation state of the component
 void setOverlap(double overlap)
          Setter for the overlap in percent (0-1)
 void setWindowSize(int windowSize)
          Setter for the cutOut size
 
Methods inherited from class de.unikassel.android.sdcframework.util.AbstractEventDispatcherImpl
doCleanUp, getCollector, getEventSource, hasObservers, notify, registerEventObserver, removeAllObservers, unregisterEventObserver
 
Methods inherited from class de.unikassel.android.sdcframework.util.AbstractWorkerThread
doTerminate, hasTerminated, isLogging, isWorking, logMessage, run, setLogging, start, startWork, stopWork
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.unikassel.android.sdcframework.util.facade.WorkerThread
doTerminate, hasTerminated, isLogging, isWorking, setLogging, startWork, stopWork
 

Field Detail

activationDelegation

private final ActivatableComponent activationDelegation
activatable component implementation to delegate to


windowSize

private final AtomicLong windowSize
The size of the cut-outs (count of sensor observations ) to extract.


overlap

private final com.google.common.util.concurrent.AtomicDouble overlap
The overlap size in percent (0-1).


overlapSize

private final AtomicInteger overlapSize
The overlap size in milliseconds of continuous cut-outs.


current

private SensorObservationCutout<D extends Enum<D> & Dimensions,T> current
The current cutOut.


next

private SensorObservationCutout<D extends Enum<D> & Dimensions,T> next
The next cutOut.


last

private SensorObservationCutout<D extends Enum<D> & Dimensions,T> last
Reference to the last unfinished cutOut.


startTs

private final AtomicLong startTs
The start time stamp for sample rate calculation


stopTs

private final AtomicLong stopTs
The stop time stamp for sample rate calculation


currentCutOutLength

private final AtomicLong currentCutOutLength
The current cut-out length in ms.


observationCount

private AtomicInteger observationCount
The total received observation count while active.


currentFrameEndTime

private long currentFrameEndTime
The current cut-out end time.


nextFrameStartTime

private long nextFrameStartTime
The next cut-out start time.


context

private final Context context
The context.

Constructor Detail

GenericObservableCutoutCreator

public GenericObservableCutoutCreator(long windowSize,
                                      int overlap,
                                      Context context)
                               throws InvalidParameterException
Constructor

Parameters:
windowSize - the length (in milliseconds) of the window to move over the raw time series stream and to create a result type for.
overlap - the percentage of window overlap (in the range of 0 to 100) with the previous one when moved.
context - the context
Throws:
InvalidParameterException
Method Detail

getWindowSize

public final long getWindowSize()
Getter for the cutOut size

Returns:
the cutOut size

setWindowSize

public final void setWindowSize(int windowSize)
Setter for the cutOut size

Parameters:
windowSize - the cutOut size to set

getOverlapSize

public final int getOverlapSize()
Getter for the overlap size

Returns:
the overlap size

setOverlap

public final void setOverlap(double overlap)
Setter for the overlap in percent (0-1)

Parameters:
overlap - the overlap to set

newCutoutInstance

protected SensorObservationCutout<D,T> newCutoutInstance()
Does create a new cut-out instance of the concrete type.

Returns:
a new cut-out instance

onActivationStateChange

protected final void onActivationStateChange(boolean active)
Handler for activation state changes

Parameters:
active - the new activation state

getLastCutout

public final SensorObservationCutout<D,T> getLastCutout()
If the processor is not active, this method will return the unfinished last cut-out with sensor observations.

Returns:
the last not finished frame

setActivationState

public final void setActivationState(boolean active)
Description copied from interface: ActivatableComponent
Method to set the activation state of the component

Specified by:
setActivationState in interface ActivatableComponent
Parameters:
active - the activation sate flag

isActive

public final boolean isActive()
Description copied from interface: ActivatableComponent
Test method for the actiation state.

Specified by:
isActive in interface ActivatableComponent
Returns:
true if active, false otherwise

doWork

protected final void doWork()
Specified by:
doWork in class AbstractWorkerThread

nextTimeStamp

public void nextTimeStamp(long nextTs)
Method to handle the next incoming time stamp. Does swap between current and next cut-out if time window end was reached.

Parameters:
nextTs - the signaled next time stamp

getQueuedObservationCount

public final int getQueuedObservationCount()
Getter for the remaining count of queued and unprocessed sensor observations.

Returns:
the remaining count of unprocessed samples

attachSensorObservationSource

public final void attachSensorObservationSource(ObservableEventSource<SensorObservation<D,T>> sensorObservationSource)
Method to attach a source for sensor observations.

Parameters:
sensorObservationSource - the source for sensor observations to attach to

detachSensorObservationSource

public final void detachSensorObservationSource(ObservableEventSource<SensorObservation<D,T>> sensorObservationSource)
Method to detach from a source for sensor observations.

Parameters:
sensorObservationSource - the source for sensor observations to detach from

getAvgSampleUpdateRate

public final long getAvgSampleUpdateRate()
Getter for the average rate for received samples

Returns:
the rate in milliseconds ( average delay between two observations).

getCurrentCutOutDuration

public long getCurrentCutOutDuration()
Getter for the current cut-out duration (window length)

Returns:
the observation count