/**
 * 保存第一步结果信息
 * */

#ifndef SAVESTEPONERESULTENGINE_H
#define SAVESTEPONERESULTENGINE_H

#include "AppCommon.h"
#include "MyYaml.h"
#include "myutils.h"
#include "EngineBase.h"
#include "EngineFactory.h"
#include "json/json.h"

class SaveStepOneResultEngine : public ai_matrix::EngineBase
{
public:
    SaveStepOneResultEngine();
    ~SaveStepOneResultEngine();

    APP_ERROR Init() override;
    APP_ERROR DeInit() override;
    APP_ERROR Process() override;

private:
    void InitParam();
    void DealTrainSpaceInfo(std::shared_ptr<ProcessData> pProcessData, Json::Value &jvStep1Space);
    void DealCenterSpace(std::vector<PartionInfo> &vecParationInfo,
                         std::shared_ptr<ProcessData> pProcessData);                       
    void MakeParationInfo(PartionInfo &parationInfo, std::shared_ptr<ProcessData> pProcessData, Json::Value &jvStep1Space);

    void SplitTrainByNumPro(std::shared_ptr<PartionInfo> &pPartionInfo, std::shared_ptr<ProcessData> &pProcessData);


    std::string strPort0_;
    std::string strPort1_;
    std::string strResultPath_;
    int iSplitSpan_;
    int iSplitSpanPX_;
    ai_matrix::DataSourceConfig dataSourceConfig_;

    uint32_t iPushSpaceFrameId_;
    uint64_t i64TimeStampFirst_;
    std::vector<PartionInfo> vecParationInfo_;
    bool bPushIsEnd_;
    int iDirection_;        //方向

    PartionInfo parationInfoLast_;
    bool bDealCenterFlag_;
    std::map<int, int> mapInvokeModelCnt_;  //调用模型个数，即第一步该数据源调用了几个模型。

    std::map<uint32_t, float> mapNumCenterInfo_;
    std::map<uint32_t, float> mapProCenterInfo_;

    bool bHaveHeadFlag_;
    CalculateInfo headInfo_;

};

ENGINE_REGIST(SaveStepOneResultEngine)

#endif
