Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
=== Bug Fixes

* Fix restoration of change detectors after seasonality change. (See {ml-pull}1391[#1391].)
* Fix potential SIGSEGV when forecasting. (See {ml-pull}1402[#1402], issue: {ml-issue}1401[#1401].)

== {es} version 7.8.1

Expand Down
27 changes: 13 additions & 14 deletions lib/model/CAnomalyDetector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,14 @@ CAnomalyDetector::getForecastModels(bool persistOnDisk,
return series;
}

TModelDetailsViewUPtr view = m_Model.get()->details();
TModelDetailsViewUPtr view{m_Model.get()->details()};

// The view can be empty, e.g. for the counting model.
if (view.get() == nullptr) {
return series;
}

const CSearchKey& key = m_DataGatherer->searchKey();
const CSearchKey& key{m_DataGatherer->searchKey()};
series.s_ByFieldName = key.byFieldName();
series.s_DetectorIndex = m_DetectorIndex;
series.s_PartitionFieldName = key.partitionFieldName();
Expand All @@ -516,16 +516,15 @@ CAnomalyDetector::getForecastModels(bool persistOnDisk,
if (persistOnDisk) {
CForecastModelPersist::CPersist persister(persistenceFolder);

for (std::size_t pid = 0u, maxPid = m_DataGatherer->numberPeople();
pid < maxPid; ++pid) {
for (std::size_t pid = 0; pid < m_DataGatherer->numberPeople(); ++pid) {
// todo: Add terms filtering here
if (m_DataGatherer->isPersonActive(pid)) {
for (auto feature : view->features()) {
const maths::CModel* model = view->model(feature, pid);
core_t::TTime firstDataTime;
core_t::TTime lastDataTime;
std::tie(firstDataTime, lastDataTime) = view->dataTimeInterval(pid);
const maths::CModel* model{view->model(feature, pid)};
if (model != nullptr && model->isForecastPossible()) {
core_t::TTime firstDataTime;
core_t::TTime lastDataTime;
std::tie(firstDataTime, lastDataTime) = view->dataTimeInterval(pid);
persister.addModel(model, firstDataTime, lastDataTime, feature,
m_DataGatherer->personName(pid));
}
Expand All @@ -535,16 +534,16 @@ CAnomalyDetector::getForecastModels(bool persistOnDisk,

series.s_ToForecastPersisted = persister.finalizePersistAndGetFile();
} else {
for (std::size_t pid = 0u, maxPid = m_DataGatherer->numberPeople();
pid < maxPid; ++pid) {

for (std::size_t pid = 0; pid < m_DataGatherer->numberPeople(); ++pid) {
// todo: Add terms filtering here
if (m_DataGatherer->isPersonActive(pid)) {
for (auto feature : view->features()) {
const maths::CModel* model = view->model(feature, pid);
core_t::TTime firstDataTime;
core_t::TTime lastDataTime;
std::tie(firstDataTime, lastDataTime) = view->dataTimeInterval(pid);
const maths::CModel* model{view->model(feature, pid)};
if (model != nullptr && model->isForecastPossible()) {
core_t::TTime firstDataTime;
core_t::TTime lastDataTime;
std::tie(firstDataTime, lastDataTime) = view->dataTimeInterval(pid);
series.s_ToForecast.emplace_back(
feature, m_DataGatherer->personName(pid),
CForecastDataSink::TMathsModelPtr(model->cloneForForecast()),
Expand Down