<commit_before>﻿// Copyright (c) <NAME>. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#pragma once

#include "OutputParser.h"
#include "LuaProgess.h"

namespace worker
{
    class CLuaOutputParser : public IOutputParser
    {
        CLuaProgess luaProgress;
    public:
        IWorkerContext * pWorkerContext;
        CCommandLine *pCommandLine;
        int nProgress;
        int nPreviousProgress;
    public:
        CLuaOutputParser() { }
        virtual ~CLuaOutputParser() { }
    public:
        bool Init(IWorkerContext* pWorkerContext, CCommandLine* pCommandLine)
        {
            this->pWorkerContext = pWorkerContext;
            this->pCommandLine = pCommandLine;
            this->nProgress = 0;
            this->nPreviousProgress = 0;

            if (this->luaProgress.Open(CT2CA(this->pCommandLine->pFormat->szFunction)) == false)
            {
                this->pWorkerContext->Status(this->pCommandLine->nItemId, app::pszDefaulTime, this->pWorkerContext->GetString(0x00110001, app::pszProgresssLoop[0]));
                this->pWorkerContext->Callback(this->pCommandLine->nItemId, -1, true, true);
                return false;
            }

            if (this->luaProgress.Init() == false)
            {
                this->pWorkerContext->Status(this->pCommandLine->nItemId, app::pszDefaulTime, this->pWorkerContext->GetString(0x00110002, app::pszProgresssLoop[1]));
                this->pWorkerContext->Callback(this->pCommandLine->nItemId, -1, true, true);
                return false;
            }

            return true;
        }
        bool Parse(const char *szLine)
        {
            int nRet = (int)this->luaProgress.GetProgress(szLine);
            if (nRet != -1)
            {
                this->nProgress = nRet;
            }

            if (this->nProgress != this->nPreviousProgress)
            {
                nPreviousProgress = nProgress;
                bool bRunning = this->pWorkerContext->Callback(this->pCommandLine->nItemId, nProgress, false);
                return bRunning;
            }
            else
            {
                bool bRunning = this->pWorkerContext->IsRunning();
                return bRunning;
            }

            return true;
        }
    };
}<commit_msg>Update LuaOutputParser.h<commit_after>﻿// Copyright (c) <NAME>. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#pragma once

#include "OutputParser.h"
#include "LuaProgess.h"

namespace worker
{
    class CLuaOutputParser : public IOutputParser
    {
        CLuaProgess luaProgress;
    public:
        IWorkerContext * pWorkerContext;
        CCommandLine *pCommandLine;
        int nProgress;
        int nPreviousProgress;
    public:
        CLuaOutputParser() { }
        virtual ~CLuaOutputParser() { }
    public:
        bool Init(IWorkerContext* pWorkerContext, CCommandLine* pCommandLine)
        {
            this->pWorkerContext = pWorkerContext;
            this->pCommandLine = pCommandLine;
            this->nProgress = 0;
            this->nPreviousProgress = 0;

            if (this->luaProgress.Open(CT2CA(this->pCommandLine->pFormat->szFunction)) == false)
            {
                this->pWorkerContext->Status(this->pCommandLine->nItemId, app::pszDefaulTime, this->pWorkerContext->pConfig->GetString(0x00110001, app::pszProgresssLoop[0]));
                this->pWorkerContext->Callback(this->pCommandLine->nItemId, -1, true, true);
                return false;
            }

            if (this->luaProgress.Init() == false)
            {
                this->pWorkerContext->Status(this->pCommandLine->nItemId, app::pszDefaulTime, this->pWorkerContext->pConfig->GetString(0x00110002, app::pszProgresssLoop[1]));
                this->pWorkerContext->Callback(this->pCommandLine->nItemId, -1, true, true);
                return false;
            }

            return true;
        }
        bool Parse(const char *szLine)
        {
            int nRet = (int)this->luaProgress.GetProgress(szLine);
            if (nRet != -1)
            {
                this->nProgress = nRet;
            }

            if (this->nProgress != this->nPreviousProgress)
            {
                nPreviousProgress = nProgress;
                bool bRunning = this->pWorkerContext->Callback(this->pCommandLine->nItemId, nProgress, false);
                return bRunning;
            }
            else
            {
                bool bRunning = this->pWorkerContext->IsRunning();
                return bRunning;
            }

            return true;
        }
    };
}
{'fraction_non_alphanumeric': 0.10767928918976095, 'fraction_numerical': 0.011000634651999153, 'mean_word_length': 1.9167180752621837, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5422375', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1273, 'n_words': 249}