com.drismo.logic
Class QualityRater

java.lang.Object
  extended by java.lang.Thread
      extended by com.drismo.logic.QualityRater
All Implemented Interfaces:
FilteredAccelerationListener, java.lang.Runnable

public class QualityRater
extends java.lang.Thread
implements FilteredAccelerationListener

Handles quality rating and distributing updates to all the registered listeners.

See Also:
QualityListener

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  java.util.LinkedList<AccelerationObject> accelerationObjectList
           
private static float CONST_POINTS
          Used to calculate a delta score based on the constant force the vehicle is exposed to, over a short period of time (MAX_LIST_LENGTH_MS).
private  int currentRating
           
private static float DIFF_POINTS
          Used to calculate a delta score based on changes in the force the vehicle is exposed to, over a short period of time (MAX_LIST_LENGTH_MS).
private  boolean isRating
           
private static int MAX_LIST_LENGTH_MS
           
private static float MOTION_THRESHOLD
           
private  java.util.ArrayList<QualityListener> qualityListeners
           
private static float[] THRESHOLD_BAD
           
private static float[] THRESHOLD_UGLY
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
QualityRater()
          Constructs the accelerationObjectList.
 
Method Summary
 float calculateDeltaScore(float outcome, float points)
          This is used to calculate a score relative to the current score and quality.
private  void evaluate()
          Evaluate the new quality rating by adding the sum of each delta score (calculated by evaluating changes and constant force measured by each vector).
 float getDeltaScore(float vector, float badThres, float uglyThres, float points)
          Get delta score based on the current state given.
 void onFilteredAccelerationChange(float[] filteredVectors, float[] RotatedVectors)
          On each entry an AccelerationObject (containing the vectors and timestamp) is added to the accelerationObjectList, and deletes all the objects that are older than MAX_LIST_LENGTH_MS.
 void registerQualityListener(QualityListener listener)
          Adds a quality listener and starts the thread if it is the first listener added to the list.
 void run()
          Evaluates the driving quality and updates all the listeners.
 void unregisterQualityListener(QualityListener listener)
          Removes the specified quality listener and stops the thread if the listener list is empty.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, 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, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_LIST_LENGTH_MS

private static final int MAX_LIST_LENGTH_MS
See Also:
Constant Field Values

DIFF_POINTS

private static final float DIFF_POINTS
Used to calculate a delta score based on changes in the force the vehicle is exposed to, over a short period of time (MAX_LIST_LENGTH_MS).

See Also:
Constant Field Values

CONST_POINTS

private static final float CONST_POINTS
Used to calculate a delta score based on the constant force the vehicle is exposed to, over a short period of time (MAX_LIST_LENGTH_MS).

See Also:
Constant Field Values

THRESHOLD_BAD

private static final float[] THRESHOLD_BAD

THRESHOLD_UGLY

private static final float[] THRESHOLD_UGLY

MOTION_THRESHOLD

private static final float MOTION_THRESHOLD
See Also:
Constant Field Values

currentRating

private int currentRating

qualityListeners

private volatile java.util.ArrayList<QualityListener> qualityListeners

accelerationObjectList

private final java.util.LinkedList<AccelerationObject> accelerationObjectList

isRating

private boolean isRating
Constructor Detail

QualityRater

public QualityRater()
Constructs the accelerationObjectList.

Method Detail

registerQualityListener

public void registerQualityListener(QualityListener listener)
Adds a quality listener and starts the thread if it is the first listener added to the list.

Parameters:
listener - The listener to add.

unregisterQualityListener

public void unregisterQualityListener(QualityListener listener)
Removes the specified quality listener and stops the thread if the listener list is empty.

Parameters:
listener - The given listener to stopMonitoring.

onFilteredAccelerationChange

public void onFilteredAccelerationChange(float[] filteredVectors,
                                         float[] RotatedVectors)
On each entry an AccelerationObject (containing the vectors and timestamp) is added to the accelerationObjectList, and deletes all the objects that are older than MAX_LIST_LENGTH_MS.

Specified by:
onFilteredAccelerationChange in interface FilteredAccelerationListener
Parameters:
filteredVectors - Not used here.
RotatedVectors - This is added as the vectors in the AccelerationObject
See Also:
AccelerationObject, MAX_LIST_LENGTH_MS

run

public void run()
Evaluates the driving quality and updates all the listeners.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
evaluate(), QualityListener.onQualityUpdate(int)

evaluate

private void evaluate()
Evaluate the new quality rating by adding the sum of each delta score (calculated by evaluating changes and constant force measured by each vector).


getDeltaScore

public float getDeltaScore(float vector,
                           float badThres,
                           float uglyThres,
                           float points)
Get delta score based on the current state given.

Parameters:
vector - Current acceleration vector, can be either Good, the bad or the ugly.
badThres - Threshold relative to the given vector, representing bad sectors.
uglyThres - Threshold relative to the given vector, representing ugly sectors.
points - unit used to calculate the delta currentRating.
Returns:
returns the delta score to update the current score.

calculateDeltaScore

public final float calculateDeltaScore(float outcome,
                                       float points)
This is used to calculate a score relative to the current score and quality.

Parameters:
outcome - this is the outcome of the current driving quality.
points - unit used to calculate the delta score.
Returns:
Returns the new delta score