Class sensorDriver

java.lang.Object
  extended by sensorDriver

public class sensorDriver
extends java.lang.Object

The main driver for Lab 4

The responsibilities are:
Read a sequence of sensor samples from the Finch
Compute the mean across the set of samples for some sensor
Find the min, median and max samples for some sensor and report the sample
Repeat for different sensor streams (keys)

Author:
Andrew H. Fagg and Steven Ness

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 displaySensors(java.util.List<FinchSensor> sensors)
          Display the sequence of sensor samples in the given List Algorithm:
- Loop over each sensor in the List and display it
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 Algorithm:
1.
static void main(java.lang.String[] args)
          The main method Algorithm:
1.
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 java.util.List<FinchSensor> ReadSensors(finch.Finch myFinch)
          Read a sequence of samples from the Finch sensors
 
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

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.

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

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)

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

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

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

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

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.

Parameters:
log - A valid list of Finch sensor samples
comp - The sensor channel on which to organize 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

displaySensors

public static void displaySensors(java.util.List<FinchSensor> sensors)
Display the sequence of sensor samples in the given List

Algorithm:
- Loop over each sensor in the List and display it

Parameters:
sensors - A List of sensor samples

ReadSensors

public static java.util.List<FinchSensor> ReadSensors(finch.Finch myFinch)
Read a sequence of samples from the Finch sensors

Parameters:
myFinch - Reference to the finch object
Returns:
A List of FinchSensor samples

main

public static void main(java.lang.String[] args)
The main method Algorithm:
1. Connect to the Finch
2. Take a log of sensor readings
3. Compute statistics over the log
4. Close down connection to the Finch