Disaggregate
Disaggregate Smart Meter data
|
Class for storing a Device's signature recorded by, for example, a Watts Up plug-in power logger. More...
#include <Signature.h>
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_t & | getPowerStates () |
const PowerStateSequence & | getPowerStateSequence () |
const std::list< Spike > | 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. | |
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< Spike > | getMergedSpikes () 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 |
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.
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.
filename | Filename, including path and suffix. |
_samplePeriod | Sample period. In seconds. |
_deviceName | All signatures are associated with devices |
_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. Default=0. |
cropFront | Number 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. |
cropBack | Number 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().
Signature::~Signature | ( | ) | [virtual] |
Definition at line 71 of file Signature.cpp.
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.
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.
void Signature::drawGraph | ( | const std::string | details = "" | ) | const [virtual] |
details | Type of graph e.g. "gradient". NOT device name, which gets added automatically. |
Definition at line 75 of file Signature.cpp.
Referenced by Signature().
void Signature::drawHistWithStateBars | ( | const Histogram & | hist | ) | const |
hist | Histogram 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().
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.
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.
LOOK_AHEAD | check 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().
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().
const size_t Signature::getID | ( | ) | const |
Definition at line 555 of file Signature.cpp.
References sigID.
Referenced by PowerStateGraph::update().
const list< Signature::Spike > Signature::getMergedSpikes | ( | ) | const [private] |
Merge consecutive spikes of the same sign and then remove any spikes under 10 Watts.
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().
PowerStates_t::const_iterator Signature::getPowerState | ( | const Sample_t | sample | ) | const [private] |
Definition at line 324 of file Signature.cpp.
References powerStates, and Utils::roundToNearestInt().
Referenced by updatePowerStateSequence().
const PowerStates_t & Signature::getPowerStates | ( | ) |
Definition at line 127 of file Signature.cpp.
References powerStates, and updatePowerStates().
const PowerStateSequence & Signature::getPowerStateSequence | ( | ) |
Definition at line 235 of file Signature.cpp.
References powerStateSequence, and updatePowerStateSequence().
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().
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().
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().
PowerStates_t Signature::powerStates [private] |
Definition at line 159 of file Signature.h.
Referenced by fillGapsInPowerStates(), getPowerState(), getPowerStates(), updatePowerStates(), and updatePowerStateSequence().
Definition at line 160 of file Signature.h.
Referenced by getPowerStateSequence(), Signature(), and updatePowerStateSequence().
const size_t Signature::PREPROCESSING_DATA_SMOOTHING = 1 [static] |
Definition at line 117 of file Signature.h.
Referenced by updatePowerStates(), and updatePowerStateSequence().
size_t Signature::samplePeriod [private] |
Definition at line 155 of file Signature.h.
Referenced by downSample(), getEnergyConsumption(), getSamplePeriod(), 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().