<commit_before>/*
 * Telefónica Digital - Product Development and Innovation
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
 * All rights reserved.
 */
#ifndef _H_SAMSON_ZOO_NODE_COMITTER
#define _H_SAMSON_ZOO_NODE_COMITTER

#include <list>
#include <string>
#include <vector>

#include "au/containers/SharedPointer.h"
#include "au/containers/Uint64Vector.h"

#include "engine/Engine.h"
#include "engine/Notification.h"
#include "engine/NotificationListener.h"

#include "samson/common/MessagesOperations.h"
#include "samson/common/SamsonSetup.h"
#include "samson/common/Visualitzation.h"
#include "samson/common/gpb_operations.h"
#include "samson/common/samson.pb.h"
#include "samson/worker/CommitCommand.h"
#include "zoo/Connection.h"
#include "zoo/common.h"

namespace au {
const int node_commiter_num_commits_to_save_ = 10;

/**
 * \brief StringCommitRecord is a record-log for StringDataModel class
 */


class StringCommitRecord {
public:

  StringCommitRecord(const std::string& caller
                     , const std::string& commit_command
                     , const std::string& result
                     , double commit_time) {
    caller_ = caller;
    commit_command_ = commit_command;
    result_ = result;
    commit_time_ = commit_time;
  }

  std::string caller() const {
    return caller_;
  }

  std::string commit_command() const {
    return commit_command_;
  }

  std::string result() const {
    return result_;
  }

  double commit_time() const {
    return commit_time_;
  }

private:

  std::string caller_;
  std::string commit_command_;
  std::string result_;
  double commit_time_;
};

/**
 * \brief StringDataModel is a distributed synchronous efficient data-model based on zookeeper where commits are strings
 */

template<class C>     // C is suppoused to be a gpb message class
class StringDataModel : public engine::NotificationListener {
public:

  StringDataModel(zoo::Connection *zoo_connection, const std::string& path) : token_("<PASSWORD>") {
    zoo_connection_ = zoo_connection;
    path_ = path;

    // Create sub-directories for commits and versions
    zoo_connection_->Create(path + "/versions");
    zoo_connection_->Create(path + "/commits");

    version_ = -1;           // No current version
  }

  /*
   * \brief Virtual method to init data model "C c_"
   */

  virtual void Init(au::SharedPointer<C> c) = 0;

  /*
   * \brief Virtual method to perform a commit over data model
   */

  virtual void PerformCommit(au::SharedPointer<C> c
                             , std::string commit_command
                             , int version
                             , au::ErrorManager& error) = 0;<commit_msg>Minor bug in string-base data_model in zoo library<commit_after>/*
 * Telefónica Digital - Product Development and Innovation
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
 * All rights reserved.
 */
#ifndef _H_SAMSON_ZOO_NODE_COMITTER
#define _H_SAMSON_ZOO_NODE_COMITTER

#include <list>
#include <string>
#include <vector>

#include "au/containers/SharedPointer.h"
#include "au/containers/Uint64Vector.h"

#include "engine/Engine.h"
#include "engine/Notification.h"
#include "engine/NotificationListener.h"

#include "samson/common/MessagesOperations.h"
#include "samson/common/SamsonSetup.h"
#include "samson/common/Visualitzation.h"
#include "samson/common/gpb_operations.h"
#include "samson/common/samson.pb.h"
#include "samson/worker/CommitCommand.h"
#include "zoo/Connection.h"
#include "zoo/common.h"

namespace au {
const int node_commiter_num_commits_to_save_ = 10;

/**
 * \brief StringCommitRecord is a record-log for StringDataModel class
 */


class StringCommitRecord {
public:

  StringCommitRecord(const std::string& caller
                     , const std::string& commit_command
                     , const std::string& result
                     , double commit_time) {
    caller_ = caller;
    commit_command_ = commit_command;
    result_ = result;
    commit_time_ = commit_time;
  }

  std::string caller() const {
    return caller_;
  }

  std::string commit_command() const {
    return commit_command_;
  }

  std::string result() const {
    return result_;
  }

  double commit_time() const {
    return commit_time_;
  }

private:

  std::string caller_;
  std::string commit_command_;
  std::string result_;
  double commit_time_;
};

/**
 * \brief StringDataModel is a distributed synchronous efficient data-model based on zookeeper where commits are strings
 */

template<class C>     // C is suppoused to be a gpb message class
class StringDataModel : public engine::NotificationListener {
public:

  StringDataModel(zoo::Connection *zoo_connection, const std::string& path) : token_("Z<PASSWORD>") {
    zoo_connection_ = zoo_connection;
    path_ = path;

    // Create sub-directories for commits and versions
    zoo_connection_->Create(path);
    zoo_connection_->Create(path + "/versions");
    zoo_connection_->Create(path + "/commits");

    version_ = -1;           // No current version
  }

  /*
   * \brief Virtual method to init data model "C c_"
   */

  virtual void Init(au::SharedPointer<C> c) = 0;

  /*
   * \brief Virtual method to perform a commit over data model
   */

  virtual void PerformCommit(au::SharedPointer<C> c
                             , std::string commit_command
                             , int version
                             , au::ErrorManager& error) = 0;
{'fraction_non_alphanumeric': 0.09981390627643377, 'fraction_numerical': 0.0023684655726611404, 'mean_word_length': 3.2933914306463326, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2343348', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1768, 'n_words': 491}