forked from elastic/ml-cpp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report model change annotations via result stream (elastic#1247)
- Loading branch information
1 parent
37b96b4
commit ef1dcff
Showing
44 changed files
with
648 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
#ifndef INCLUDED_ml_api_CAnnotationJsonWriter_h | ||
#define INCLUDED_ml_api_CAnnotationJsonWriter_h | ||
|
||
#include <core/CJsonOutputStreamWrapper.h> | ||
#include <core/CNonCopyable.h> | ||
#include <core/CRapidJsonConcurrentLineWriter.h> | ||
#include <core/CoreTypes.h> | ||
|
||
#include <api/ImportExport.h> | ||
|
||
#include <model/CAnnotation.h> | ||
|
||
#include <rapidjson/document.h> | ||
|
||
#include <iosfwd> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#include <stdint.h> | ||
|
||
namespace ml { | ||
namespace api { | ||
|
||
//! \brief | ||
//! Write annotation result as a JSON document | ||
class API_EXPORT CAnnotationJsonWriter final : private core::CNonCopyable { | ||
public: | ||
//! Constructor that causes to be written to the specified stream | ||
explicit CAnnotationJsonWriter(core::CJsonOutputStreamWrapper& outStream); | ||
|
||
void writeResult(const std::string& jobId, const model::CAnnotation& annotation); | ||
|
||
private: | ||
void populateAnnotationObject(const std::string& jobId, | ||
const model::CAnnotation& annotation, | ||
rapidjson::Value& obj); | ||
|
||
private: | ||
//! JSON line writer | ||
core::CRapidJsonConcurrentLineWriter m_Writer; | ||
}; | ||
} | ||
} | ||
|
||
#endif // INCLUDED_ml_api_CAnnotationJsonWriter_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
#ifndef INCLUDED_ml_model_CAnnotation_h | ||
#define INCLUDED_ml_model_CAnnotation_h | ||
|
||
#include <model/ImportExport.h> | ||
|
||
#include <model/ModelTypes.h> | ||
|
||
#include <string> | ||
|
||
namespace ml { | ||
namespace model { | ||
|
||
//! \brief Data necessary to create an annotation | ||
class MODEL_EXPORT CAnnotation { | ||
public: | ||
CAnnotation() = default; | ||
CAnnotation(core_t::TTime time, | ||
const std::string& annotation, | ||
int detectorIndex, | ||
const std::string& partitionFieldName, | ||
const std::string& partitionFieldValue, | ||
const std::string& overFieldName, | ||
const std::string& overFieldValue, | ||
const std::string& byFieldName, | ||
const std::string& byFieldValue); | ||
core_t::TTime time() const; | ||
const std::string& annotation() const; | ||
const std::string& event() const; | ||
int detectorIndex() const; | ||
const std::string& partitionFieldName() const; | ||
const std::string& partitionFieldValue() const; | ||
const std::string& overFieldName() const; | ||
const std::string& overFieldValue() const; | ||
const std::string& byFieldName() const; | ||
const std::string& byFieldValue() const; | ||
|
||
private: | ||
core_t::TTime m_Time = 0; | ||
std::string m_Annotation; | ||
int m_DetectorIndex = -1; | ||
std::string m_PartitionFieldName; | ||
std::string m_PartitionFieldValue; | ||
std::string m_OverFieldName; | ||
std::string m_OverFieldValue; | ||
std::string m_ByFieldName; | ||
std::string m_ByFieldValue; | ||
}; | ||
} | ||
} | ||
|
||
#endif // INCLUDED_ml_model_CAnnotation_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.