Skip to content

Commit e82ff1a

Browse files
committed
code compiles
1 parent ab4f7c5 commit e82ff1a

18 files changed

+244
-229
lines changed

include/model/CBucketGatherer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ class MODEL_EXPORT CBucketGatherer {
132132
using TTimeVec = std::vector<core_t::TTime>;
133133
using TTimeVecCItr = TTimeVec::const_iterator;
134134

135+
struct SBucketGathererInitData {
136+
static SBucketGathererInitData emptyData() {
137+
return {.s_SummaryCountFieldName="", .s_PersonFieldName="", .s_AttributeFieldName="", .s_ValueFieldName="", .s_InfluenceFieldNames={}, .s_StartTime=0, .s_SampleOverrideCount=0};
138+
}
139+
const std::string& s_SummaryCountFieldName;
140+
const std::string& s_PersonFieldName;
141+
const std::string& s_AttributeFieldName;
142+
const std::string& s_ValueFieldName;
143+
const TStrVec& s_InfluenceFieldNames;
144+
core_t::TTime s_StartTime;
145+
unsigned int s_SampleOverrideCount;
146+
};
147+
135148
public:
136149
static const std::string EVENTRATE_BUCKET_GATHERER_TAG;
137150
static const std::string METRIC_BUCKET_GATHERER_TAG;

include/model/CDataGatherer.h

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,30 @@ class MODEL_EXPORT CDataGatherer {
169169
CDataGatherer(model_t::EAnalysisCategory gathererType,
170170
model_t::ESummaryMode summaryMode,
171171
const SModelParams& modelParams,
172-
const std::string& summaryCountFieldName,
172+
// const std::string& summaryCountFieldName,
173173
const std::string& partitionFieldValue,
174-
const std::string& personFieldName,
175-
const std::string& attributeFieldName,
176-
const std::string& valueFieldName,
177-
const TStrVec& influenceFieldNames,
174+
// const std::string& personFieldName,
175+
// const std::string& attributeFieldName,
176+
// const std::string& valueFieldName,
177+
// const TStrVec& influenceFieldNames,
178178
const CSearchKey& key,
179179
const TFeatureVec& features,
180-
core_t::TTime startTime,
181-
int sampleCountOverride);
180+
// core_t::TTime startTime,
181+
// int sampleCountOverride
182+
const CBucketGatherer::SBucketGathererInitData& bucketGathererInitData);
182183

183184
//! Construct from a state document.
184185
CDataGatherer(model_t::EAnalysisCategory gathererType,
185186
model_t::ESummaryMode summaryMode,
186187
const SModelParams& modelParams,
187-
const std::string& summaryCountFieldName,
188+
// const std::string& summaryCountFieldName,
188189
const std::string& partitionFieldValue,
189-
const std::string& personFieldName,
190-
const std::string& attributeFieldName,
191-
const std::string& valueFieldName,
192-
const TStrVec& influenceFieldNames,
190+
// const std::string& personFieldName,
191+
// const std::string& attributeFieldName,
192+
// const std::string& valueFieldName,
193+
// const TStrVec& influenceFieldNames,
193194
const CSearchKey& key,
195+
const CBucketGatherer::SBucketGathererInitData& bucketGathererInitData,
194196
core::CStateRestoreTraverser& traverser);
195197

196198
//! Create a copy that will result in the same persisted state as the
@@ -675,19 +677,21 @@ class MODEL_EXPORT CDataGatherer {
675677

676678
private:
677679
//! Restore state from supplied traverser.
678-
bool acceptRestoreTraverser(const std::string& summaryCountFieldName,
680+
bool acceptRestoreTraverser(/*const std::string& summaryCountFieldName,
679681
const std::string& personFieldName,
680682
const std::string& attributeFieldName,
681683
const std::string& valueFieldName,
682-
const TStrVec& influenceFieldNames,
684+
const TStrVec& influenceFieldNames,*/
685+
const CBucketGatherer::SBucketGathererInitData& bucketGathererInitData,
683686
core::CStateRestoreTraverser& traverser);
684687

685688
//! Restore a bucket gatherer from the supplied traverser.
686-
bool restoreBucketGatherer(const std::string& summaryCountFieldName,
689+
bool restoreBucketGatherer(/*const std::string& summaryCountFieldName,
687690
const std::string& personFieldName,
688691
const std::string& attributeFieldName,
689692
const std::string& valueFieldName,
690-
const TStrVec& influenceFieldNames,
693+
const TStrVec& influenceFieldNames,*/
694+
const CBucketGatherer::SBucketGathererInitData& bucketGathererInitData,
691695
core::CStateRestoreTraverser& traverser);
692696

693697
//! Persist a bucket gatherer by passing information to the supplied
@@ -696,13 +700,7 @@ class MODEL_EXPORT CDataGatherer {
696700

697701
//! Create the bucket specific data gatherer.
698702
void createBucketGatherer(model_t::EAnalysisCategory gathererType,
699-
const std::string& summaryCountFieldName,
700-
const std::string& personFieldName,
701-
const std::string& attributeFieldName,
702-
const std::string& valueFieldName,
703-
const TStrVec& influenceFieldNames,
704-
core_t::TTime startTime,
705-
unsigned int sampleCountOverride);
703+
const CBucketGatherer::SBucketGathererInitData& initData);
706704

707705
private:
708706
//! The type of the bucket gatherer(s) used.

include/model/CEventRateBucketGatherer.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,22 @@ class MODEL_EXPORT CEventRateBucketGatherer final : public CBucketGatherer {
124124
//! \param[in] startTime The start of the time interval for which
125125
//! to gather data.
126126
CEventRateBucketGatherer(CDataGatherer& dataGatherer,
127-
const std::string& summaryCountFieldName,
127+
const CBucketGatherer::SBucketGathererInitData& bucketGathererInitData
128+
/*const std::string& summaryCountFieldName,
128129
const std::string& personFieldName,
129130
const std::string& attributeFieldName,
130131
const std::string& valueFieldName,
131132
const TStrVec& influenceFieldNames,
132-
core_t::TTime startTime);
133+
core_t::TTime startTime*/);
133134

134135
//! Construct from a state document.
135136
CEventRateBucketGatherer(CDataGatherer& dataGatherer,
136-
const std::string& summaryCountFieldName,
137+
const CBucketGatherer::SBucketGathererInitData& bucketGathererInitData,
138+
/*const std::string& summaryCountFieldName,
137139
const std::string& personFieldName,
138140
const std::string& attributeFieldName,
139141
const std::string& valueFieldName,
140-
const TStrVec& influenceFieldNames,
142+
const TStrVec& influenceFieldNames,*/
141143
core::CStateRestoreTraverser& traverser);
142144

143145
//! Create a copy that will result in the same persisted state as the
@@ -444,11 +446,7 @@ class MODEL_EXPORT CEventRateBucketGatherer final : public CBucketGatherer {
444446
void startNewBucket(core_t::TTime time, bool skipUpdates) override;
445447

446448
//! Initialize the field names collection.
447-
void initializeFieldNames(const std::string& personFieldName,
448-
const std::string& attributeFieldName,
449-
const std::string& valueFieldName,
450-
const std::string& summaryCountFieldName,
451-
const TStrVec& influenceFieldNames);
449+
void initializeFieldNames(const CBucketGatherer::SBucketGathererInitData& initData);
452450

453451
//! Initialize the feature data gatherers.
454452
void initializeFeatureData();

include/model/CMetricBucketGatherer.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,11 @@ class MODEL_EXPORT CMetricBucketGatherer final : public CBucketGatherer {
6666
//! \param[in] startTime The start of the time interval for which
6767
//! to gather data.
6868
CMetricBucketGatherer(CDataGatherer& dataGatherer,
69-
const std::string& summaryCountFieldName,
70-
const std::string& personFieldName,
71-
const std::string& attributeFieldName,
72-
const std::string& valueFieldName,
73-
const TStrVec& influenceFieldNames,
74-
core_t::TTime startTime);
69+
const CBucketGatherer::SBucketGathererInitData& initData);
7570

7671
//! Construct from a state document.
7772
CMetricBucketGatherer(CDataGatherer& dataGatherer,
78-
const std::string& summaryCountFieldName,
79-
const std::string& personFieldName,
80-
const std::string& attributeFieldName,
81-
const std::string& valueFieldName,
82-
const TStrVec& influenceFieldNames,
73+
const CBucketGatherer::SBucketGathererInitData& initData,
8374
core::CStateRestoreTraverser& traverser);
8475

8576
//! Create a copy that will result in the same persisted state as the
@@ -266,9 +257,7 @@ class MODEL_EXPORT CMetricBucketGatherer final : public CBucketGatherer {
266257
//! 1) initializeFieldNamesPart1()
267258
//! 2) restore state
268259
//! 3) initializeFieldNamesPart2()
269-
void initializeFieldNamesPart1(const std::string& personFieldName,
270-
const std::string& attributeFieldName,
271-
const TStrVec& influenceFieldNames);
260+
void initializeFieldNamesPart1(const SBucketGathererInitData& initData);
272261

273262
//! Initialize the field names collection.
274263
//! initializeFieldNamesPart1() must be called before this.
@@ -277,8 +266,7 @@ class MODEL_EXPORT CMetricBucketGatherer final : public CBucketGatherer {
277266
//! 1) initializeFieldNamesPart1()
278267
//! 2) restore state
279268
//! 3) initializeFieldNamesPart2()
280-
void initializeFieldNamesPart2(const std::string& valueFieldName,
281-
const std::string& summaryCountFieldName);
269+
void initializeFieldNamesPart2(const SBucketGathererInitData& initData);
282270

283271
//! Initialize the feature data gatherers.
284272
void initializeFeatureData();

include/model/CModelFactory.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <maths/common/COrderings.h>
1818
#include <maths/common/MathsTypes.h>
1919

20+
#include <model/CResourceMonitor.h>
2021
#include <model/ImportExport.h>
2122
#include <model/ModelTypes.h>
2223
#include <model/SModelParams.h>
@@ -104,6 +105,8 @@ class MODEL_EXPORT CModelFactory {
104105
using TStrDetectionRulePr = std::pair<std::string, model::CDetectionRule>;
105106
using TStrDetectionRulePrVec = std::vector<TStrDetectionRulePr>;
106107
using TStrDetectionRulePrVecCRef = std::reference_wrapper<const TStrDetectionRulePrVec>;
108+
using TResourceMonitorCRef = std::reference_wrapper<const CResourceMonitor>;
109+
using TOptionalResourceMonitorCRef = std::optional<TResourceMonitorCRef>;
107110

108111
public:
109112
//! Wrapper around the model initialization data.
@@ -373,6 +376,8 @@ class MODEL_EXPORT CModelFactory {
373376
//! Get the minimum seasonal variance scale, specific to the model
374377
virtual double minimumSeasonalVarianceScale() const = 0;
375378

379+
void resourceMonitor(const TResourceMonitorCRef& resourceMonitor) const;
380+
376381
protected:
377382
using TMultivariatePriorUPtrVec = std::vector<TMultivariatePriorUPtr>;
378383
using TOptionalSearchKey = std::optional<CSearchKey>;
@@ -455,6 +460,8 @@ class MODEL_EXPORT CModelFactory {
455460

456461
//! A cache of influence calculators for collections of features.
457462
mutable TStrFeatureVecPrInfluenceCalculatorCPtrMap m_InfluenceCalculatorCache;
463+
464+
mutable TOptionalResourceMonitorCRef m_ResourceMonitor;
458465
};
459466
}
460467
}

lib/api/CAnomalyJob.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,8 +1610,11 @@ CAnomalyJob::detectorForKey(bool isRestoring,
16101610
<< partition << '\'' << ", time " << time);
16111611
LOG_TRACE(<< "Detector count " << m_Detectors.size());
16121612

1613-
detector = ml::api::CAnomalyJob::makeDetector(
1614-
m_ModelConfig, m_Limits, partition, time, m_ModelConfig.factory(key));
1613+
auto factory = m_ModelConfig.factory(key);
1614+
factory->resourceMonitor(resourceMonitor);
1615+
1616+
detector = ml::api::CAnomalyJob::makeDetector(m_ModelConfig, m_Limits,
1617+
partition, time, factory);
16151618
if (detector == nullptr) {
16161619
// This should never happen as CAnomalyDetectorUtils::makeDetector()
16171620
// contracts to never return NULL

lib/model/CCountingModelFactory.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,26 @@ CCountingModelFactory::makeModel(const SModelInitializationData& initData,
6161

6262
CDataGatherer*
6363
CCountingModelFactory::makeDataGatherer(const SGathererInitializationData& initData) const {
64-
return new CDataGatherer(model_t::E_EventRate, m_SummaryMode, this->modelParams(),
65-
m_SummaryCountFieldName, initData.s_PartitionFieldValue,
66-
m_PersonFieldName, EMPTY_STRING, EMPTY_STRING, {},
67-
this->searchKey(), m_Features, initData.s_StartTime, 0);
64+
CBucketGatherer::SBucketGathererInitData bucketGathererInitData{m_SummaryCountFieldName,
65+
m_PersonFieldName,
66+
EMPTY_STRING,
67+
EMPTY_STRING,
68+
{},
69+
initData.s_StartTime,
70+
0};
71+
return new CDataGatherer(model_t::E_EventRate, m_SummaryMode,
72+
this->modelParams(), initData.s_PartitionFieldValue,
73+
this->searchKey(), m_Features, bucketGathererInitData);
6874
}
6975

7076
CDataGatherer*
7177
CCountingModelFactory::makeDataGatherer(const std::string& partitionFieldValue,
7278
core::CStateRestoreTraverser& traverser) const {
79+
CBucketGatherer::SBucketGathererInitData bucketGathererInitData{
80+
m_SummaryCountFieldName, m_PersonFieldName, EMPTY_STRING, EMPTY_STRING, {}, 0, 0};
7381
return new CDataGatherer(model_t::E_EventRate, m_SummaryMode,
74-
this->modelParams(), m_SummaryCountFieldName,
75-
partitionFieldValue, m_PersonFieldName, EMPTY_STRING,
76-
EMPTY_STRING, {}, this->searchKey(), traverser);
82+
this->modelParams(), partitionFieldValue,
83+
this->searchKey(), bucketGathererInitData, traverser);
7784
}
7885

7986
CCountingModelFactory::TPriorPtr

0 commit comments

Comments
 (0)