Class SensorDriver

java.lang.Object
  extended by SensorDriver

public class SensorDriver
extends java.lang.Object


Field Summary
static int numSamples
          Total number of samples to take
static int sampleInterval
          Interval between samples (note that there is also other overhead that extends this delay)
 
Constructor Summary
SensorDriver()
           
 
Method Summary
static void displayConditionalStats(java.util.ArrayList<FinchSensor> list)
          Given an ArrayList of FinchSensors, report the statistics for for both the Acceleration Magnitude and for the Z component of Acceleration
static void displayStats(java.util.List<FinchSensor> log, SensorComparator comp)
          For the given sensor channel (as indicated by comp), display: The mean value of this sensor channel the entire sensor sample for the minimum, median and maximum channel values
static void getSamples(finch.Finch myFinch, int num, int interval, java.util.Map<java.lang.Long,FinchSensor> map)
          Take a specified number of FinchSensor samples and place them into a map.
static void main(java.lang.String[] args)
          Create several Maps of FinchSensor objects.
static double mean(java.util.List<FinchSensor> log, SensorComparator comp)
          Compute the mean value of a some sensor value across a set of FinchSensors.
static FinchSensor median(java.util.List<FinchSensor> log)
          Return the sensor sample that is the median value of the key used to sort a set.
static void queryTest(java.util.ArrayList<FinchSensor> list, java.lang.Long[] keys)
          Given an ArrayList of FinchSensors and an array of sample times to query, measure the amount of time (in ms) that is required to query all of the keys.
static void queryTest(java.util.Map<java.lang.Long,FinchSensor> map, java.lang.Long[] keys)
          Given a map and an array of keys, measure the amount of time (in ms) that is required to query all of the keys.
static java.util.TreeMap<java.lang.Integer,java.util.ArrayList<FinchSensor>> reKey(java.util.Map<java.lang.Long,FinchSensor> map)
          Given an existing map that is keyed by sample time (a Long) and stores FinchSensor values, generate a new map in which the same set of values are stored, but are keyed by the left light sensor value (an Integer).
static
<T,E> void
reportSamples(java.util.Map<T,E> map)
          Report a set of samples that have been stored in the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numSamples

public static final int numSamples
Total number of samples to take

See Also:
Constant Field Values

sampleInterval

public static final int sampleInterval
Interval between samples (note that there is also other overhead that extends this delay)

See Also:
Constant Field Values
Constructor Detail

SensorDriver

public SensorDriver()
Method Detail

getSamples

public static void getSamples(finch.Finch myFinch,
                              int num,
                              int interval,
                              java.util.Map<java.lang.Long,FinchSensor> map)
Take a specified number of FinchSensor samples and place them into a map.

Parameters:
myFinch - A reference to a valid Finch object or null
num - Number of samples to take
interval - Interval in ms between samples (note that this does not take into account the time required to take a sample.
map - The map in which to insert the samples. This map is keyed by the time of the sample
Conditions:
PRE - The map already exists
POST - A set of FinchSensor objects are inserted (as values) into the existing map. FinchSensor is keyed with the sample time.

reportSamples

public static <T,E> void reportSamples(java.util.Map<T,E> map)
Report a set of samples that have been stored in the map. The report is generated in key order

Parameters:
map - Some map
Conditions:
PRE - The map already exists
POST - none

queryTest

public static void queryTest(java.util.Map<java.lang.Long,FinchSensor> map,
                             java.lang.Long[] keys)
Given a map and an array of keys, measure the amount of time (in ms) that is required to query all of the keys.

Parameters:
map - A map from sample time (Long) to FinchSensor
keys - An array of keys to access during the test (sample times)
Conditions:
PRE - The map and key array already exist
POST - none

Algorithm:
Start a timer
Loop over the entire set of keys to query and ask the map to retrieve the corresponding value
Stop the timer.


queryTest

public static void queryTest(java.util.ArrayList<FinchSensor> list,
                             java.lang.Long[] keys)
Given an ArrayList of FinchSensors and an array of sample times to query, measure the amount of time (in ms) that is required to query all of the keys.

Parameters:
list - An ArrayList of FinchSensor objects
keys - An array of keys to access during the test (sample times)
Conditions:
PRE - The list and key array already exist
POST - The elements of the list will be reordered
Algorithm:
Start a timer
Sort the list by sample time
Loop over the entire set of keys to query and ask the list to retrieve the corresponding value (using a binary search)
Stop the timer.


reKey

public static java.util.TreeMap<java.lang.Integer,java.util.ArrayList<FinchSensor>> reKey(java.util.Map<java.lang.Long,FinchSensor> map)
Given an existing map that is keyed by sample time (a Long) and stores FinchSensor values, generate a new map in which the same set of values are stored, but are keyed by the left light sensor value (an Integer). Because the left light sensor values are not unique across all values, they do not form a proper set. To account for this, the Value of the new map will be an ArrayList of FinchSenors (as opposed to a single FinchSensor). So: for a given left light value (e.g., 93), there are possibly a number of FinchSensor instances with that value. These FinchSensor objects are placed into an ArrayList, which is keyed by "93"

Parameters:
map - A map from sample times (Long) to a FinchSensor object
Returns:
A map from left light values (Integer) to an ArrayList of FinchSensor objects

mean

public static double mean(java.util.List<FinchSensor> log,
                          SensorComparator comp)
Compute the mean value of a some sensor value across a set of FinchSensors. The particular sensor stream is specified by the SensorComparator

Parameters:
log - A set of FinchSensors
comp - A SensorComparator that specifies the key
Returns:
The mean value of the keys

Algorithm: Return the sum of the channel values divided by the number of samples.


median

public static FinchSensor median(java.util.List<FinchSensor> log)
Return the sensor sample that is the median value of the key used to sort a set.

Parameters:
log - A set of FinchSensors, already sorted by some key
Returns:
The sensor element in the middle of the ordered list (this is the MEDIAN sample)

Algorithm:
The median sample is the middle one given that the set has already been ordered.

Conditions:
PRE - The log must already be instantiated and sorted according to the key
POST - n/a


displayStats

public static void displayStats(java.util.List<FinchSensor> log,
                                SensorComparator comp)
For the given sensor channel (as indicated by comp), display:
The mean value of this sensor channel
the entire sensor sample for the minimum, median and maximum channel values

Parameters:
log - A valid list of Finch sensor samples
comp - The sensor channel on which to organize the list

Algorithm:
1. Sort the elements of log according to comp
2. Report the mean of the sensor value
3. Given the ordering of the sorted list, we can pull out the min, median and max sensor samples by extracting the first, middle and last elements in the list.

Conditions:
PRE - The log must already be instantiated
POST - The order of log has changed so that it is ordered according to the key

displayConditionalStats

public static void displayConditionalStats(java.util.ArrayList<FinchSensor> list)
Given an ArrayList of FinchSensors, report the statistics for for both the Acceleration Magnitude and for the Z component of Acceleration

Parameters:
list - ArrayList of FinchSensor objects over which to compute the statistics
Conditions:
PRE - The ArrayList already exists and contains at least one entry
POST - The ArrayList order is altered

main

public static void main(java.lang.String[] args)
Create several Maps of FinchSensor objects. We are looking to answer several questions:
1. What order relationships do the map induce?
2. What is the relative performance of the various map implementations?
3. How can we use Maps to facilitate the computation of conditional statistics?

Parameters:
args - Are ignored