<commit_before>// --------------------------------------------------------
// Code generated by Papyrus C++
// --------------------------------------------------------

#define Annotator_AnnotatorLib_Project_BODY

/************************************************************
 Project class body
 ************************************************************/

// include associated header file
#include "AnnotatorLib/Project.h"
#include <AnnotatorLib/Storage/StorageFactory.h>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include "AnnotatorLib/ImageSetFactory.h"
#include "AnnotatorLib/Loader/LoaderFactory.h"
#include "AnnotatorLib/Saver/SaverFactory.h"

// Derived includes directives

namespace AnnotatorLib {

// static attributes (if any)

Project::Project() {}

Project::Project(std::string name, ImageSetType imageSetType,
                 std::string imageSetPath, StorageType storageType,
                 std::string storagePath) {
  this->name = name;
  this->imageSetType = imageSetType;
  this->storageType = storageType;
  this->storagePath = storagePath;
  this->imageSet =
      AnnotatorLib::ImageSetFactory::createImageSet(imageSetType, imageSetPath);
}

Project::~Project() { delete session; }

Session *Project::getSession() const { return session; }

Storage::AbstractStorage *Project::getStorage() const {
  return (AnnotatorLib::Storage::AbstractStorage *)session;
}

std::string Project::getName() const { return name; }

unsigned long Project::updateDuration()
{
  int elapsed_seconds = active ? std::chrono::duration_cast<std::chrono::seconds>(
        std::chrono::system_clock::now() - time_point_start).count() : 0;
  total_duration_sec += elapsed_seconds;
  this->time_point_start = std::chrono::system_clock::now(); //reset
}

unsigned long Project::getDuration()
{
  return updateDuration();
}

ImageSet *Project::getImageSet() const { return imageSet; }

Project *Project::load(std::string path) {
  Project *project = new Project();
  project->path = path;
  project->load();

  return project;
}

/**
 *
 */
void Project::load() {
  QFile file(QString::fromStdString(this->path));

  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    qDebug() << "File could not been opened: "
             << QString::fromStdString(this->path);
    throw std::runtime_error("File could not been opened!");
  }

  QDomDocument doc;
  if (!doc.setContent(&file)) {
    file.close();
    throw std::runtime_error("File is not valide!");
  }
  file.close();

  QDomElement root;

  loadRoot(doc, root, this->name);
  std::string imageSetPath;
  loadImageSet(root, this->imageSetType, imageSetPath);
  this->imageSet = AnnotatorLib::ImageSetFactory::createImageSet(
      this->imageSetType, imageSetPath);

  loadStorage(root, this->storageType, this->storagePath);
  loadProjectStatistics(root);
  loadProjectSettings(root);
  loadSession();
}

void Project::loadImageSet(QDomElement &root, ImageSetType &type,
                           std::string &imageSetPath) {
  QDomElement element = root.firstChildElement("ImageSet");
  type = AnnotatorLib::ImageSetTypeFromString(
      element.attribute("type").toStdString());
  imageSetPath = element.attribute("path").toStdString();
}

void Project::loadStorage(QDomElement &root, StorageType &type,
                          std::string &storagePath) {
  QDomElement element = root.firstChildElement("Storage");
  type = AnnotatorLib::StorageTypeFromString(
      element.attribute("type").toStdString());
  storagePath = element.attribute("path").toStdString();
}

void Project::loadProjectStatistics(QDomElement &root) {
  QDomElement element = root.firstChildElement("Statistics");
  if (!element.isNull())
    this->total_duration_sec = element.attribute("duration").toULong();
}

void Project::loadRoot(QDomDocument &doc, QDomElement &root,
                       std::string &name) {
  root = doc.documentElement();
  name = root.tagName().toStdString();
}

void Project::loadProjectSettings(QDomElement &root)
{
  QDomElement element = root.firstChildElement("Statistics");
  if (!element.isNull())
    this->active = element.attribute("active").toStdString() == "1";
}

void Project::loadSession() {
  AnnotatorLib::Storage::AbstractStorage *storage =
      AnnotatorLib::Storage::StorageFactory::createStorage(this->storageType);
  storage->setPath(this->storagePath);
  storage->open();
  this->session = (Session *)storage;
  this->time_point_start = std::chrono::system_clock::now();
}

void Project::save(Project *project, std::string path) {
  project->path = path;
  project->save();
}

void Project::save() {
  QFile file(QString::fromStdString(this->path));
<commit_msg>fix typo<commit_after>// --------------------------------------------------------
// Code generated by Papyrus C++
// --------------------------------------------------------

#define Annotator_AnnotatorLib_Project_BODY

/************************************************************
 Project class body
 ************************************************************/

// include associated header file
#include "AnnotatorLib/Project.h"
#include <AnnotatorLib/Storage/StorageFactory.h>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include "AnnotatorLib/ImageSetFactory.h"
#include "AnnotatorLib/Loader/LoaderFactory.h"
#include "AnnotatorLib/Saver/SaverFactory.h"

// Derived includes directives

namespace AnnotatorLib {

// static attributes (if any)

Project::Project() {}

Project::Project(std::string name, ImageSetType imageSetType,
                 std::string imageSetPath, StorageType storageType,
                 std::string storagePath) {
  this->name = name;
  this->imageSetType = imageSetType;
  this->storageType = storageType;
  this->storagePath = storagePath;
  this->imageSet =
      AnnotatorLib::ImageSetFactory::createImageSet(imageSetType, imageSetPath);
}

Project::~Project() { delete session; }

Session *Project::getSession() const { return session; }

Storage::AbstractStorage *Project::getStorage() const {
  return (AnnotatorLib::Storage::AbstractStorage *)session;
}

std::string Project::getName() const { return name; }

unsigned long Project::updateDuration()
{
  int elapsed_seconds = active ? std::chrono::duration_cast<std::chrono::seconds>(
        std::chrono::system_clock::now() - time_point_start).count() : 0;
  total_duration_sec += elapsed_seconds;
  this->time_point_start = std::chrono::system_clock::now(); //reset
}

unsigned long Project::getDuration()
{
  return updateDuration();
}

ImageSet *Project::getImageSet() const { return imageSet; }

Project *Project::load(std::string path) {
  Project *project = new Project();
  project->path = path;
  project->load();

  return project;
}

/**
 *
 */
void Project::load() {
  QFile file(QString::fromStdString(this->path));

  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    qDebug() << "File could not been opened: "
             << QString::fromStdString(this->path);
    throw std::runtime_error("File could not been opened!");
  }

  QDomDocument doc;
  if (!doc.setContent(&file)) {
    file.close();
    throw std::runtime_error("File is not valide!");
  }
  file.close();

  QDomElement root;

  loadRoot(doc, root, this->name);
  std::string imageSetPath;
  loadImageSet(root, this->imageSetType, imageSetPath);
  this->imageSet = AnnotatorLib::ImageSetFactory::createImageSet(
      this->imageSetType, imageSetPath);

  loadStorage(root, this->storageType, this->storagePath);
  loadProjectStatistics(root);
  loadProjectSettings(root);
  loadSession();
}

void Project::loadImageSet(QDomElement &root, ImageSetType &type,
                           std::string &imageSetPath) {
  QDomElement element = root.firstChildElement("ImageSet");
  type = AnnotatorLib::ImageSetTypeFromString(
      element.attribute("type").toStdString());
  imageSetPath = element.attribute("path").toStdString();
}

void Project::loadStorage(QDomElement &root, StorageType &type,
                          std::string &storagePath) {
  QDomElement element = root.firstChildElement("Storage");
  type = AnnotatorLib::StorageTypeFromString(
      element.attribute("type").toStdString());
  storagePath = element.attribute("path").toStdString();
}

void Project::loadProjectStatistics(QDomElement &root) {
  QDomElement element = root.firstChildElement("Statistics");
  if (!element.isNull())
    this->total_duration_sec = element.attribute("duration").toULong();
}

void Project::loadRoot(QDomDocument &doc, QDomElement &root,
                       std::string &name) {
  root = doc.documentElement();
  name = root.tagName().toStdString();
}

void Project::loadProjectSettings(QDomElement &root)
{
  QDomElement element = root.firstChildElement("Settings");
  if (!element.isNull())
    this->active = element.attribute("active").toStdString() == "1";
}

void Project::loadSession() {
  AnnotatorLib::Storage::AbstractStorage *storage =
      AnnotatorLib::Storage::StorageFactory::createStorage(this->storageType);
  storage->setPath(this->storagePath);
  storage->open();
  this->session = (Session *)storage;
  this->time_point_start = std::chrono::system_clock::now();
}

void Project::save(Project *project, std::string path) {
  project->path = path;
  project->save();
}

void Project::save() {
  QFile file(QString::fromStdString(this->path));

{'fraction_non_alphanumeric': 0.18769395398608882, 'fraction_numerical': 0.00042803638309256285, 'mean_word_length': 4.427409988385598, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 67, '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': '3504624', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2682, 'n_words': 511}