3#include "boon_metrology.h"
5#include "cring_buffer.h"
12#define MAX_ERROR_STRING 256
18#define MS_NOT_CONFIGURED 0
19#define MS_IS_CONFIGURED 1
20#define MS_TRAINING_IN_PROGRESS 2
21#define MS_READY_TO_USE 3
24#define MAX_USE_CASE_NAME_LENGTH 50
25#define MAX_MODEL_STATUS_STRING_LENGTH 2500
26#define NUM_DHC_RANDOM_SAMPLE 1000
33 explicit CMetrologySample(
const MetrologySample& StructForInit);
34 CMetrologySample& operator=(
const CMetrologySample& rhs);
37class CMetrologyUseCase {
39 CMetrologyUseCase(
const char* UseCaseName);
41 const char* GetErrorMessage() {
return m_ErrorStringBuffer; };
44 void SetErrorMessage(
const char* fmt, ...);
45 bool IsConfigured() {
return m_ModelStatus >= MS_IS_CONFIGURED; }
46 bool IsReadyToUse() {
return m_ModelStatus == MS_READY_TO_USE; }
47 bool TrainingInProgress() {
return m_ModelStatus == MS_TRAINING_IN_PROGRESS; }
48 float GetTrainingProgress();
49 virtual const char* GetStatus();
51 virtual bool Configure(uint64_t NumTrainingSamples);
52 virtual bool Serialize(
const char* VarPath,
const char* ThisVarName,
struct archive* ar,
bool IsLoading);
53 virtual bool PostData(
const CMetrologySample& MS);
57 char m_ErrorStringBuffer[MAX_ERROR_STRING];
58 char m_UseCaseName[MAX_USE_CASE_NAME_LENGTH];
59 char m_ModelStatusString[MAX_MODEL_STATUS_STRING_LENGTH];
61 uint64_t m_PostedSampleCount;
62 uint64_t m_NumTrainingSamples;
66class CPowerQualityMonitoring :
public CMetrologyUseCase {
68 CPowerQualityMonitoring();
69 ~CPowerQualityMonitoring();
70 bool Configure(
struct PowerQualitySettings* PQS);
71 bool PostData(
const CMetrologySample& MS)
override;
72 bool Serialize(
const char* VarPath,
const char* ThisVarName,
struct archive* ar,
bool IsLoading)
override;
73 const char* GetStatus()
override;
74 const char* GetDiagnostics(uint16_t ResultsList);
75 bool GetPowerQualityScore(
float *QualityScore);
78 void Reset()
override;
85class CPVDisaggregation :
public CMetrologyUseCase {
89 bool Configure(
struct PVDisaggregationSettings* PVDS);
90 bool PostData(
const CMetrologySample& MS)
override;
91 bool Serialize(
const char* VarPath,
const char* ThisVarName,
struct archive* ar,
bool IsLoading)
override;
92 const char* GetStatus()
override;
93 const char* GetDiagnostics(uint16_t ResultsList);
96 float GetPVEstimate();
97 const char *GetDisaggregation();
100 void Reset()
override;
101 void ComputeDerivativeStatistics();
102 void InitializeStatistics();
105 CRB::CRingBuffer<float> m_Derivatives;
107 float m_Mean, m_StdDev, m_ZValueThresh, m_RunningSum;
108 uint64_t m_SamplesSinceReset;
117 CStateChange& operator=(
const CStateChange& rhs);
121 char m_LastChangeTOD[MAX_TIMESTAMP_LENGTH];
129class CLoadDisaggregation :
public CMetrologyUseCase {
131 CLoadDisaggregation();
132 ~CLoadDisaggregation();
133 bool Configure(
struct LoadDisaggregationSettings* LDS);
134 bool PostData(
const CMetrologySample& MS,
struct LoadChange *LC);
135 bool Serialize(
const char* VarPath,
const char* ThisVarName,
struct archive* ar,
bool IsLoading)
override;
136 const char* GetStatus()
override;
137 const char* GetDiagnostics(uint16_t ResultsList);
138 const char *GetDisaggregation();
141 void Reset()
override;
142 void GenerateKernel(uint16_t WindowSize);
143 float ConvolveRecentDiffs();
144 bool GetCenterRingBufferPattern(std::vector<float> & Pattern);
147 CRB::CRingBuffer<CMetrologySample> m_RecentMetrologySamples;
148 std::vector<float> m_DetectedPattern;
149 std::vector<float> m_Kernel;
150 bool m_AwaitingThreshCrossing;
151 float m_MaxDetectedConvolution;
154 std::vector<CStateChange> m_StateChange;
155 LoadDisaggregationSettings m_LDS;
170struct DataStatistics {
176class CDynamicHostingCapacity :
public CMetrologyUseCase {
178 CDynamicHostingCapacity();
179 ~CDynamicHostingCapacity();
181 bool Configure(
struct DynamicHostingCapacitySettings* DHS);
182 bool PostData(
const CMetrologySample& MS)
override;
183 bool Serialize(
const char* VarPath,
const char* ThisVarName,
struct archive* ar,
bool IsLoading)
override;
184 const char* GetStatus()
override;
185 const char* GetDiagnostics(uint16_t ResultsList);
187 bool GetVoltageEstimatePQ(
float DeltaP,
float DeltaQ,
float *DeltaVEstimate);
188 bool GetVoltageEstimateP(
float DeltaP,
float *DeltaVEstimate);
191 bool PushBack(
float P,
float Q,
float V);
192 void Reset()
override;
193 uint16_t GetRandomGeometric();
194 bool GenerateDeltaStatsValues(
bool isLinear);
197 CRB::CRingBuffer<CapacityData> m_RandomSampleOne;
198 CRB::CRingBuffer<CapacityData> m_RandomSampleTwo;
200 uint16_t m_geometric_rand_space_one;
201 uint16_t m_geometric_rand_space_two;
206 std::uniform_real_distribution<float> m_Distribution;
209 LeastSquares m_ModelCoefficients;
210 std::vector<DataStatistics> m_Stats;
214struct ArchiveBufferStatus {
222 BoonMetrology(uint16_t SamplesPerSecond);
225 bool ConfigureLoadDisaggregation(
struct LoadDisaggregationSettings* LDS);
226 bool ConfigurePVDisaggregation(
struct PVDisaggregationSettings* PVDS);
227 bool ConfigureDynamicHostingCapacity(
struct DynamicHostingCapacitySettings* DHS);
228 bool ConfigurePowerQualityMonitoring(
struct PowerQualitySettings* PQS);
229 void CopyBoonMetrologyConfiguration(
struct BoonMetrologyConfiguration* BMC);
231 bool IncrementalSerialize(
const char* DirPath,
void* ReadOrWriteCallback,
struct IncrementalArchiveFileStatus* AFS,
232 size_t TransferBufferSize,
void* UserData,
bool IsLoading);
233 bool SerializeBuffer(uint8_t **Buffer,
size_t *BufferLength,
bool IsLoading);
235 bool PostMetrologySample(
const MetrologySample* MS,
struct LoadChange* LC);
237 void ResetPVDisaggregationEstimate();
238 bool GetPVDisaggregationEstimate(
float *PVEstimate);
240 const char *GetDisaggregation();
242 bool GetPowerQualityScore(
float *QualityScore);
244 bool GetVoltageEstimatePQ(
float DeltaP,
float DeltaQ,
float *DeltaVEstimate);
245 bool GetVoltageEstimateP(
float DeltaP,
float *DeltaVEstimate);
247 const char* GetStatus();
248 const char* GetStatusPowerQualityMonitoring();
249 const char* GetStatusDynamicHostingCapacity();
250 const char* GetStatusPVDisaggregation();
251 const char* GetStatusLoadDisaggregation();
253 const char* GetDiagnostics(uint16_t ResultsList);
257 const char *GetErrorMessage();
260 bool Serialize(
struct archive* ar,
bool IsLoading);
265 void SetErrorMessage(
const char* fmt, ...);
266 void SetDefaultMetrologyConfiguration();
267 struct BoonMetrologyConfiguration m_MetrologyConfiguration;
268 char m_ErrorStringBuffer[MAX_ERROR_STRING];
269 char m_ModelStatusString[MAX_MODEL_STATUS_STRING_LENGTH * NUM_USE_CASE];
271 uint16_t m_SamplesPerSecond;
272 CRB::CRingBuffer<CMetrologySample> m_RecentMetrologySamples;
273 CPVDisaggregation* m_PVDisaggregation;
274 CLoadDisaggregation* m_LoadDisaggregation;
275 CPowerQualityMonitoring* m_PQM;
276 CDynamicHostingCapacity* m_DHC;
Initialize values not being used to 0.
Definition boon_metrology.h:218