Disaggregate
Disaggregate Smart Meter data

Signature Class Reference

Class for storing a Device's signature recorded by, for example, a Watts Up plug-in power logger. More...

#include <Signature.h>

Inheritance diagram for Signature:
Collaboration diagram for Signature:

List of all members.

Classes

struct  Spike
 Recording the value and location of a Spike e.g. a Spike in the gradient of a signature. More...

Public Member Functions

Constructors and destructors
 Signature (const std::string &filename, const size_t _samplePeriod, const std::string _deviceName, const size_t _sigID=0, const size_t cropFront=0, const size_t cropBack=0)
 Constructor for opening a CSV file.
virtual ~Signature ()
Getters and setters
const size_t getSamplePeriod () const
const PowerStates_tgetPowerStates ()
const PowerStateSequencegetPowerStateSequence ()
const std::list< SpikegetDeltaSpikes (const size_t LOOK_AHEAD=20) const
 Takes the gradient of this Signature, then merges gradient values with the same sign, then removes transient spikes, then sorts by value.
const double getEnergyConsumption () const
 Determine how many Joules of energy have been consumed.
const size_t getID () const
Graph drawing
void drawHistWithStateBars (const Histogram &hist) const
virtual void drawGraph (const std::string details="") const
Smoothing
void downSample (Array< Sample_t > *output, const size_t newPeriod, const bool verbose=false) const
 Convert from the Signature data to a different sample period.

Static Public Attributes

static const size_t PREPROCESSING_DATA_SMOOTHING = 1

Private Member Functions

Power state processing
void updatePowerStates ()
 Runs through signature data to find power states and stores the resulting power states in powerStates.
PowerStates_t::const_iterator getPowerState (const Sample_t sample) const
const std::string getStateBarsBaseFilename () const
void fillGapsInPowerStates (const Histogram &hist, const bool verbose=false)
 Fill in gaps in the powerStates so that each powerState in the list is nose-to-tail.
Power state sequence processing
void updatePowerStateSequence ()
 Finding out where each 'powerState' starts and ends.
const std::list< SpikegetMergedSpikes () const
 Merge consecutive spikes of the same sign and then remove any spikes under 10 Watts.

Private Attributes

size_t samplePeriod
const size_t sigID
 Each Device can have multiple signatures. A Device's first sig gets a sigID of 0, the next gets a sigID of 1 etc.
PowerStates_t powerStates
PowerStateSequence powerStateSequence

Detailed Description

Class for storing a Device's signature recorded by, for example, a Watts Up plug-in power logger.

Definition at line 23 of file Signature.h.


Constructor & Destructor Documentation

Signature::Signature ( const std::string &  filename,
const size_t  _samplePeriod,
const std::string  _deviceName,
const size_t  _sigID = 0,
const size_t  cropFront = 0,
const size_t  cropBack = 0 
)

Constructor for opening a CSV file.

Parameters:
filenameFilename, including path and suffix.
_samplePeriodSample period. In seconds.
_deviceNameAll signatures are associated with devices
_sigIDEach Device can have multiple signatures. A Device's first sig gets a sigID of 0, the next gets a sigID of 1 etc. Default=0.
cropFrontNumber of elements to crop from the front. Default=0. If 0 then will automatically crop 0s from the front such that there's only a single leading zero left.
cropBackNumber of elements to crop from the back. Default=0. If 0 then will automatically crop 0s from the back such that there's only a single trailing zero left.

Definition at line 29 of file Signature.cpp.

References Array< Sample_t >::copyCrop(), Array< Sample_t >::data, Array< Sample_t >::deviceName, Array< T >::drawGraph(), drawGraph(), Array< Sample_t >::getDelta(), Array< T >::getNumLeadingZeros(), Array< T >::getNumTrailingZeros(), Array< T >::loadData(), Utils::openFile(), powerStateSequence, and PowerStateSequence::setDeviceName().

Here is the call graph for this function:

Signature::~Signature ( ) [virtual]

Definition at line 71 of file Signature.cpp.


Member Function Documentation

void Signature::downSample ( Array< Sample_t > *  output,
const size_t  newPeriod,
const bool  verbose = false 
) const

Convert from the Signature data to a different sample period.

If the original sample period is 1 second and newPeriod = 6, then the returned array will have 1/6th the number of entries and each entry in the downsampled array will be an average of 6 samples from the original array.

Deprecated:
Probably better to use rollingAv().
Returns:
The parameter output is the returned, down sampled array.

Definition at line 480 of file Signature.cpp.

References Array< Sample_t >::data, samplePeriod, Array< T >::setSize(), and Array< Sample_t >::size.

Here is the call graph for this function:

void Signature::drawGraph ( const std::string  details = "") const [virtual]
Parameters:
detailsType of graph e.g. "gradient". NOT device name, which gets added automatically.

Definition at line 75 of file Signature.cpp.

Referenced by Signature().

Here is the caller graph for this function:

void Signature::drawHistWithStateBars ( const Histogram hist) const
Parameters:
histHistogram array.

Definition at line 87 of file Signature.cpp.

References GNUplot::PlotVars::data, Array< Sample_t >::deviceName, Array< T >::dumpToFile(), Histogram::getBaseFilename(), Array< T >::getSmoothedGradOfHistFilename(), Array< T >::getSmoothing(), getStateBarsBaseFilename(), Array< T >::getUpstreamSmoothing(), Array< T >::HIST_GRADIENT_RA_LENGTH, GNUplot::PlotVars::inFilename, GNUplot::PlotVars::outFilename, GNUplot::plot(), Utils::size_t_to_s(), GNUplot::PlotVars::title, GNUplot::PlotVars::xlabel, and GNUplot::PlotVars::ylabel.

Referenced by updatePowerStates().

Here is the call graph for this function:

Here is the caller graph for this function:

void Signature::fillGapsInPowerStates ( const Histogram hist,
const bool  verbose = false 
) [private]

Fill in gaps in the powerStates so that each powerState in the list is nose-to-tail.

Deprecated:
not actually used.

Definition at line 193 of file Signature.cpp.

References MAX_WATTAGE, and powerStates.

const list< Signature::Spike > Signature::getDeltaSpikes ( const size_t  LOOK_AHEAD = 20) const

Takes the gradient of this Signature, then merges gradient values with the same sign, then removes transient spikes, then sorts by value.

Returns:
a list of gradient Spikes, sorted in descending order of absolute 'value'.
Parameters:
LOOK_AHEADcheck there isn't an opposite-sign spike within this number of samples.

Definition at line 353 of file Signature.cpp.

References Signature::Spike::compareAbsValueDesc(), getMergedSpikes(), and Utils::roughlyEqual().

Referenced by PowerStateGraph::update(), and PowerStateGraph::updateEdges().

Here is the call graph for this function:

Here is the caller graph for this function:

const double Signature::getEnergyConsumption ( ) const

Determine how many Joules of energy have been consumed.

Definition at line 545 of file Signature.cpp.

References Array< Sample_t >::data, samplePeriod, and Array< Sample_t >::size.

Referenced by PowerStateGraph::update().

Here is the caller graph for this function:

const size_t Signature::getID ( ) const

Definition at line 555 of file Signature.cpp.

References sigID.

Referenced by PowerStateGraph::update().

Here is the caller graph for this function:

const list< Signature::Spike > Signature::getMergedSpikes ( ) const [private]

Merge consecutive spikes of the same sign and then remove any spikes under 10 Watts.

Returns:
a list of merged spikes

NOTE: returning a std::list should not be costly because both GCC and MSVC implement Return Value Optimisation, even when optimisation is turned off. http://stackoverflow.com/questions/1092561/is-returning-a-stdlist-costly

Definition at line 405 of file Signature.cpp.

References Signature::Spike::delta, Array< Sample_t >::getDelta(), Signature::Spike::index, Signature::Spike::n, and Array< Sample_t >::size.

Referenced by getDeltaSpikes().

Here is the call graph for this function:

Here is the caller graph for this function:

PowerStates_t::const_iterator Signature::getPowerState ( const Sample_t  sample) const [private]
Returns:
pointer to a 'powerState' within 'powerStates' corresponding to 'sample'. Returns 'powerStates.end()' if 'sample' does not correspond to any 'powerState'.

Definition at line 324 of file Signature.cpp.

References powerStates, and Utils::roundToNearestInt().

Referenced by updatePowerStateSequence().

Here is the call graph for this function:

Here is the caller graph for this function:

const PowerStates_t & Signature::getPowerStates ( )

Definition at line 127 of file Signature.cpp.

References powerStates, and updatePowerStates().

Here is the call graph for this function:

const PowerStateSequence & Signature::getPowerStateSequence ( )

Definition at line 235 of file Signature.cpp.

References powerStateSequence, and updatePowerStateSequence().

Here is the call graph for this function:

const size_t Signature::getSamplePeriod ( ) const

Definition at line 537 of file Signature.cpp.

References samplePeriod.

const string Signature::getStateBarsBaseFilename ( ) const [private]

Definition at line 183 of file Signature.cpp.

References Array< Sample_t >::deviceName.

Referenced by drawHistWithStateBars(), and updatePowerStates().

Here is the caller graph for this function:

void Signature::updatePowerStates ( ) [private]

Runs through signature data to find power states and stores the resulting power states in powerStates.

Prerequisites: signature data must be populated before this function is called.

<

Definition at line 142 of file Signature.cpp.

References DATA_OUTPUT_PATH, Histogram::drawGraph(), Array< T >::drawGraph(), drawHistWithStateBars(), Array< T >::findPeaks(), getStateBarsBaseFilename(), Statistic< T >::numDataPoints, Utils::openFile(), powerStates, PREPROCESSING_DATA_SMOOTHING, Array< Sample_t >::rollingAv(), and Array< Sample_t >::size.

Referenced by getPowerStates().

Here is the call graph for this function:

Here is the caller graph for this function:

void Signature::updatePowerStateSequence ( ) [private]

Finding out where each 'powerState' starts and ends.

This must be called after 'powerStates' has been populated

Definition at line 248 of file Signature.cpp.

References Array< Sample_t >::deviceName, PowerStateSequenceItem::endTime, getPowerState(), PowerStateSequence::plotGraph(), PowerStateSequenceItem::powerState, powerStates, powerStateSequence, PREPROCESSING_DATA_SMOOTHING, Array< Sample_t >::rollingAv(), samplePeriod, and PowerStateSequenceItem::startTime.

Referenced by getPowerStateSequence().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 117 of file Signature.h.

Referenced by updatePowerStates(), and updatePowerStateSequence().

const size_t Signature::sigID [private]

Each Device can have multiple signatures. A Device's first sig gets a sigID of 0, the next gets a sigID of 1 etc.

Definition at line 156 of file Signature.h.

Referenced by getID().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends