<commit_before>/*
 * Copyright (c) 2014, webvariants GmbH, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 *
 * @author: <NAME> (<EMAIL>)
 */

#ifndef __HEARTBEATCOMPONENT__
#define __HEARTBEATCOMPONENT__

#include <thread>
#include <atomic>
#include "world/BaseComponent.h"

namespace Susi {
    class HeartBeatComponent : public System::BaseComponent {
    protected:
        std::atomic<bool> stopVar;
        std::thread t;
    public:
        HeartBeatComponent( System::ComponentManager * mgr ) :
            System::BaseComponent {mgr},
        stopVar {false} {}

        ~HeartBeatComponent() {
            stop();
            Susi::Logger::info( "stopped HeartBeatComponent" );
        }

        virtual void start() override {
            t = std::move( std::thread {
                [this]() {
                    int count = 0;
                    std::chrono::seconds interval( 1 );
                    while( !this->stopVar.load() ) {
                        ++count %= 300;
                        publish( createEvent( "heartbeat::one" ) );
                        if( count % 5 == 0 ) {
                            publish( createEvent( "heartbeat::five" ) );
                        }
                        if( count % 10 == 0 ) {
                            publish( createEvent( "heartbeat::ten" ) );
                        }
                        if( count % 60 == 0 ) {
                            publish( createEvent( "heartbeat::minute" ) );
                        }
                        if( count % 300 == 0 ) {
                            publish( createEvent( "heartbeat::fiveMinute" ) );
                        }
                        std::this_thread::sleep_for( interval );
                    }
                }
            } );

            Susi::Logger::info( "started HeartBeatComponent" );
        }

        virtual void stop() override {
            stopVar.store( true );
            if( t.joinable() )t.join();
        }
    };
}

#endif // __HEARTBEATCOMPONENT__

<commit_msg>[heartbeat] added additional heartbeat::one event with authlevel 3;<commit_after>/*
 * Copyright (c) 2014, webvariants GmbH, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 *
 * @author: <NAME> (<EMAIL>)
 */

#ifndef __HEARTBEATCOMPONENT__
#define __HEARTBEATCOMPONENT__

#include <thread>
#include <atomic>
#include "world/BaseComponent.h"

namespace Susi {
    class HeartBeatComponent : public System::BaseComponent {
    protected:
        std::atomic<bool> stopVar;
        std::thread t;
    public:
        HeartBeatComponent( System::ComponentManager * mgr ) :
            System::BaseComponent {mgr},
        stopVar {false} {}

        ~HeartBeatComponent() {
            stop();
            Susi::Logger::info( "stopped HeartBeatComponent" );
        }

        virtual void start() override {
            t = std::move( std::thread {
                [this]() {
                    int count = 0;
                    std::chrono::seconds interval( 1 );
                    while( !this->stopVar.load() ) {
                        ++count %= 300;
                        auto evt = createEvent("heartbeat::one");
                        evt->authlevel = 3;
                        publish( std::move(evt) );
                        publish( createEvent( "heartbeat::one" ) );
                        if( count % 5 == 0 ) {
                            publish( createEvent( "heartbeat::five" ) );
                        }
                        if( count % 10 == 0 ) {
                            publish( createEvent( "heartbeat::ten" ) );
                        }
                        if( count % 60 == 0 ) {
                            publish( createEvent( "heartbeat::minute" ) );
                        }
                        if( count % 300 == 0 ) {
                            publish( createEvent( "heartbeat::fiveMinute" ) );
                        }
                        std::this_thread::sleep_for( interval );
                    }
                }
            } );

            Susi::Logger::info( "started HeartBeatComponent" );
        }

        virtual void stop() override {
            stopVar.store( true );
            if( t.joinable() )t.join();
        }
    };
}

#endif // __HEARTBEATCOMPONENT__


{'fraction_non_alphanumeric': 0.11698683358515001, 'fraction_numerical': 0.009497086121303691, 'mean_word_length': 1.3800719054956343, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6711795', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1171, 'n_words': 284}