org.android.activityminer.logic.features
Class FeatureExtractionHelper<T extends Enum<T> & Dimensions>

Package class diagram package FeatureExtractionHelper
java.lang.Object
  extended by org.android.activityminer.logic.features.FeatureExtractionHelper<T>
Type Parameters:
T - the enumeration type for the dimensions
All Implemented Interfaces:
EventObserver<FeatureVector>

public class FeatureExtractionHelper<T extends Enum<T> & Dimensions>
extends Object
implements EventObserver<FeatureVector>


Nested Class Summary
private  class FeatureExtractionHelper.Entry
          Helper class for time stamp lookups
 class FeatureExtractionHelper.ProgressEvent
          The observable progress event (to notify progress on a single sequence processing)
 
Field Summary
private  T accGXId
          Dimension id for gravitation vector x value.
private  T accGYId
          Dimension id for gravitation vector y value.
private  T accGZId
          Dimension id for gravitation vector z value.
private  T accXId
          Dimension id for x acceleration.
private  T accYId
          Dimension id for y acceleration.
private  T accZId
          Dimension id for z acceleration.
private  Context context
          The context.
private  AtomicInteger currentFeatureVectorCount
          The current feature vector count
private  DBManager dbManager
          A reference to the database manager.
private  AbstractFeatureExtractorForDBRecordings<T> featureExtractor
          The feature extractor to use
private  LowPassFilter filter
          The low pass filter for the accelerometer data.
private  GravitationFilter gFilter
          The gravitation filter
private  boolean hasToAdaptToConfiguration
          The flag for configuration based adaption.
private  boolean isUseOwnGravitationFilter
          The gravitation filter usage flag
private  Exception lastException
          last exception reference if one occurs during asynchronous saves
private  ObservableEventSource<FeatureExtractionHelper.ProgressEvent> progressEventSource
          The observable delegator for progress events
private  ConcurrentLinkedQueue<FeatureExtractionHelper.Entry> queueTs2IDMapping
          The queue to store mappings for time stamps and recording identifiers in
private  long sampleRate
          The configured sample rate
private  int sampleRateAdaptionFactor
          The adaption factor for the sample rate is the relation of the configured sample rate to the one used for recordings.
 
Constructor Summary
private FeatureExtractionHelper(DBManager dbManager, Configuration config, AbstractFeatureExtractorForDBRecordings<T> featureExtractor, AbstractFeatureFactory<T> factory, Context context, boolean hasToAdaptToConfiguration)
          Constructor
 
Method Summary
private  SensorObservationCutout<T,Double> adaptToConfiguration(SensorObservationCutout<T,Double> cutOut, Long lastTs)
          Method to apply the configured sample rate and the optional filter to the cut-out window of a recording.
static
<T extends Enum<T> & Dimensions>
FeatureExtractionHelper<T>
createFeatureExtractionHelper(Context context, DBManager dbManager, Configuration config, AbstractFeatureExtractorForDBRecordings<T> featureExtractor, AbstractFeatureFactory<T> factory, boolean hasToAdaptToConfiguration)
          Method to create a feature extraction helper instance.
protected  DBManager getDbManager()
          Getter for the dbManager
 String getErrorNotificationMsg(List<Long> failedIds)
          Getter for the error notification message
protected  Exception getLastException()
          Getter for the last exception
 double getLastExtractionTime()
          Getter for the last extraction time from the feature extractor
 String getResultNotificationMsg(int extractedSampleCount, double avgTimeForFeatureExtraction, double processingTime)
          Getter for the result notification message
 void onDestroy()
          Destruction.
 void onEvent(ObservableEventSource<? extends FeatureVector> eventSource, FeatureVector featureVector)
           
 int process(long sequenceId, EventObserver<FeatureExtractionHelper.ProgressEvent> progressObserver)
          Does process a sequence of continuous recordings.
protected  void setLastException(Exception lastException)
          Setter for the last exception
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

private final LowPassFilter filter
The low pass filter for the accelerometer data.


featureExtractor

private final AbstractFeatureExtractorForDBRecordings<T extends Enum<T> & Dimensions> featureExtractor
The feature extractor to use


progressEventSource

private final ObservableEventSource<FeatureExtractionHelper.ProgressEvent> progressEventSource
The observable delegator for progress events


dbManager

private final DBManager dbManager
A reference to the database manager.


queueTs2IDMapping

private final ConcurrentLinkedQueue<FeatureExtractionHelper.Entry> queueTs2IDMapping
The queue to store mappings for time stamps and recording identifiers in


currentFeatureVectorCount

private final AtomicInteger currentFeatureVectorCount
The current feature vector count


lastException

private Exception lastException
last exception reference if one occurs during asynchronous saves


sampleRateAdaptionFactor

private final int sampleRateAdaptionFactor
The adaption factor for the sample rate is the relation of the configured sample rate to the one used for recordings. In fact this parameter denotes the multiplication factor for the recording rate to get the configured sample rate.


context

private Context context
The context.


accXId

private T extends Enum<T> & Dimensions accXId
Dimension id for x acceleration.


accYId

private T extends Enum<T> & Dimensions accYId
Dimension id for y acceleration.


accZId

private T extends Enum<T> & Dimensions accZId
Dimension id for z acceleration.


accGXId

private T extends Enum<T> & Dimensions accGXId
Dimension id for gravitation vector x value.


accGYId

private T extends Enum<T> & Dimensions accGYId
Dimension id for gravitation vector y value.


accGZId

private T extends Enum<T> & Dimensions accGZId
Dimension id for gravitation vector z value.


gFilter

private final GravitationFilter gFilter
The gravitation filter


isUseOwnGravitationFilter

private final boolean isUseOwnGravitationFilter
The gravitation filter usage flag


sampleRate

private final long sampleRate
The configured sample rate


hasToAdaptToConfiguration

private final boolean hasToAdaptToConfiguration
The flag for configuration based adaption.

Constructor Detail

FeatureExtractionHelper

private FeatureExtractionHelper(DBManager dbManager,
                                Configuration config,
                                AbstractFeatureExtractorForDBRecordings<T> featureExtractor,
                                AbstractFeatureFactory<T> factory,
                                Context context,
                                boolean hasToAdaptToConfiguration)
Constructor

Parameters:
dbManager - a reference to the database manager
config - the configuration
featureExtractor - the feature extractor
factory - the feature factory
context - the context
hasToAdaptToConfiguration - flag if adaption is required (can only happen in batch export mode)
Method Detail

getDbManager

protected DBManager getDbManager()
Getter for the dbManager

Returns:
the dbManager

getLastException

protected final Exception getLastException()
Getter for the last exception

Returns:
the last exception

setLastException

protected final void setLastException(Exception lastException)
Setter for the last exception

Parameters:
lastException - the last exception to set

getErrorNotificationMsg

public final String getErrorNotificationMsg(List<Long> failedIds)
Getter for the error notification message

Parameters:
failedIds - a list with failed record id's
Returns:
the error notification message

getResultNotificationMsg

public String getResultNotificationMsg(int extractedSampleCount,
                                       double avgTimeForFeatureExtraction,
                                       double processingTime)
Getter for the result notification message

Parameters:
extractedSampleCount - the count of extracted training samples
avgTimeForFeatureExtraction - the average time for feature extraction in milliseconds
processingTime - the whole processing time in seconds
Returns:
the result notification message

getLastExtractionTime

public final double getLastExtractionTime()
Getter for the last extraction time from the feature extractor

Returns:
the last extraction time from the feature extractor

process

public final int process(long sequenceId,
                         EventObserver<FeatureExtractionHelper.ProgressEvent> progressObserver)
                  throws Exception
Does process a sequence of continuous recordings.

Parameters:
sequenceId - the identifier of the continuous recordings sequence to extract features from
progressObserver - the optional progress observer
Returns:
the count of extracted feature vectors
Throws:
Exception

adaptToConfiguration

private SensorObservationCutout<T,Double> adaptToConfiguration(SensorObservationCutout<T,Double> cutOut,
                                                               Long lastTs)
Method to apply the configured sample rate and the optional filter to the cut-out window of a recording. As recordings are always sampled with the maximum rate the count of sensor observations must be reduced in a appropriate way.

Parameters:
cutOut - the cut-out window
lastTs - time stamp from last
Returns:
the adapted cut-out window

onDestroy

public final void onDestroy()
Destruction.


onEvent

public void onEvent(ObservableEventSource<? extends FeatureVector> eventSource,
                    FeatureVector featureVector)
Specified by:
onEvent in interface EventObserver<FeatureVector>

createFeatureExtractionHelper

public static final <T extends Enum<T> & Dimensions> FeatureExtractionHelper<T> createFeatureExtractionHelper(Context context,
                                                                                                             DBManager dbManager,
                                                                                                             Configuration config,
                                                                                                             AbstractFeatureExtractorForDBRecordings<T> featureExtractor,
                                                                                                             AbstractFeatureFactory<T> factory,
                                                                                                             boolean hasToAdaptToConfiguration)
Method to create a feature extraction helper instance.

Parameters:
context - the application context
dbManager - the database manager
config - the configuration
featureExtractor - the feature extractor
factory - the factory
hasToAdaptToConfiguration - flag if adaption is required (can only happen in batch export mode)
Returns:
the feature extraction helper