<commit_before>#
# Part of the Manager module for working with backups. It may
# save and load application state into/from the file.
# TODO: describe index based saving format
#
# @author DeadbraiN
#
import Backup
import Creature
import Server
import Client
import Creature
import ManagerTypes

export recover
export backup
#
# This function is used for recovering a manager's data from
# backup file. It means that an application was crashed before
# and now we have to recover it with last correct backup. Works
# in pair with backup() function.
# @param man Manager data type
# @return {Bool} recover status
#
function recover(man::ManagerTypes.ManagerData)
  Helper.info(string("Recovering from backup: ", Backup.lastFile()))
  local data = Backup.load()
  local t::ManagerTypes.OrganismTask
  local curTask::Task = current_task()
  #
  # In case if we haven't recovered from backup file,
  # we have to remove it, because it's broken
  #
  if data === null
    if !_removeNew(man) return false end
    return Backup.lastFile() !== "" ? recover(man) : false
  end

  man.task = curTask
  for t in data.tasks
    t.organism.codeFn = Creature.eval(t.organism.code)
    bindEvents(man, t.organism)
    t.task = Task(() -> Creature.born(t.organism, man.cfg, curTask))
    #
    # We must call yieldto(), because born() function parameters
    # will not be passed into the task and only last organism will
    # be run.
    #
    yieldto(t.task)
  end
  #
  # We don't need to load\create servers and clients every
  # time on load backup. They should be created every time
  # on Manager application starts. So we have to skip loading
  # of man.cons property.
  #
  man.cfg            = data.cfg
  man.world          = data.world
  man.positions      = data.positions
  man.organisms      = data.organisms
  man.tasks          = data.tasks
  man.params         = data.params
  man.organismId     = data.organismId
  man.totalOrganisms = data.totalOrganisms
  man.quiet          = data.quiet
  #
  # We have to remove all event handlers from observers
  # after backup loading, because they may be multiplied
  # on every app running.<commit_msg>* sync<commit_after>#
# Part of the Manager module for working with backups. It may
# save and load application state into/from the file.
# TODO: describe index based saving format
#
# @author DeadbraiN
#
import Backup
import Creature
import Server
import Client
import Creature
import ManagerTypes

export recover
export backup
#
# This function is used for recovering a manager's data from
# backup file. It means that an application was crashed before
# and now we have to recover it with last correct backup. Works
# in pair with backup() function.
# @param man Manager data type
# @return {Bool} recover status
#
function recover(man::ManagerTypes.ManagerData)
  Helper.info(string("Recovering from backup: ", Backup.lastFile()))
  local data = Backup.load()
  local t::ManagerTypes.OrganismTask
  local curTask::Task = current_task()
  #
  # In case if we haven't recovered from backup file,
  # we have to remove it, because it's broken
  #
  if data === null
    if !_removeNew(man) return false end
    return Backup.lastFile() !== "" ? recover(man) : false
  end

  man.task = curTask
  for t in data.tasks
    t.organism.codeFn = Creature.eval(t.organism.code)
    bindEvents(man, t.organism)
    #
    # We must call yieldto(), because born() function parameters
    # will not be passed into the task and only last organism will
    # be run.
    #
    t.task = Task(() -> Creature.born(t.organism, man.cfg, curTask))
    yieldto(t.task)
  end
  #
  # We don't need to load\create servers and clients every
  # time on load backup. They should be created every time
  # on Manager application starts. So we have to skip loading
  # of man.cons property.
  #
  man.cfg            = data.cfg
  man.world          = data.world
  man.positions      = data.positions
  man.organisms      = data.organisms
  man.tasks          = data.tasks
  man.params         = data.params
  man.organismId     = data.organismId
  man.totalOrganisms = data.totalOrganisms
  man.quiet          = data.quiet
  #
  # We have to remove all event handlers from observers
  # after backup loading, because they may be multiplied
  # on every app running.
{'fraction_non_alphanumeric': 0.0828084907860975, 'fraction_numerical': 0.0, 'mean_word_length': 3.1310211946050095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1181436', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1232, 'n_words': 488}