<commit_before>import RpcApi
import Config
#
# Checks if we need to update statistics data like amount of organisms,
# IPS, best organism parameters and so on. Updates statistics according
# to STAT_UPDATE_PERIOD config.
#
function _updateStat(stamp::Float64)
  local bestOrgs::Array{RpcApi.SimpleOrganism, 1}
  local org::RpcApi.SimpleOrganism
  local json::ASCIIString
  local code::ASCIIString

  if Config.val(:STAT_UPDATE_PERIOD) > 0 && (time() - stamp) > Config.val(:STAT_UPDATE_PERIOD)
    bestOrgs = Manager.getBest(1)
    if length(bestOrgs) > 0
      org  = bestOrgs[1]
      code = string(org.code)
      json = string(
        "{",
        string("\"Probabilities\"       : ", org.mutationProbabilities, ",\n"),
        string("\"Amount of functions\" : ", length(split(code, "function ")) - 2, ",\n"), # minus main function
        string("\"Functions calls\"     : ", length(split(code, "func_")) - 1, ",\n"),
        string("\"Mutations on clone\"  : ", string(org.mutationsOnClone), ",\n"),
        string("\"Mutations period\"    : ", string(org.mutationPeriod), ",\n"),
        string("\"Mutations amount\"    : ", string(org.mutationAmount), ",\n"),
        string("\"Energy\"              : ", string(org.energy), ",\n"),
        string("\"for operators\"       : ", length(split(code, "for i::Int8")) - 1, ",\n"),
        string("\"if operators\"        : ", length(split(code, "if var")) - 1, ",\n"),
        string("\"if operators\"        : ", length(split(code, "Creature.getEnergy")) - 1, ",\n"),
        string("\"Memory reading\"      : ", length(split(code, "haskey(o.mem)")) - 1, ",\n"),
        string("\"Eating\"              : ", length(split(code, "Creature.eat")) - 1, ",\n"),
        string("\"Moving\"              : ", length(split(code, "Creature.step")) - 1, ",\n"),
        string("\"Amount of lines\"     : ", string(org.codeSize), ",\n"),
        string("\"Amount of organisms\" : ", string(length(Manager._data.tasks)), ",\n"),
        string("\"IPS\"                 : ", string(Config.val(:WORLD_IPS)), ",\n"),
        string("\"Generation number\"   : ", string(Manager._data.totalOrganisms), ",\n"),
        string("\"Code\"                : \"", code, "\"\n"),
        "},\n"
      )
      _appendToFile(json, "file.json")
    end
    return time()
  end

  stamp
end

#
# Appends native values to the file.
# @param data String data to save
# @param file File name, we want append to
# @return {Bool} saving result
#
function _appendToFile(data::ASCIIString, file::ASCIIString)
  local io  = null
  local ret = true

  try
    io = open(file, "a") # "a" - means "file append" mode
    write(io, data)
    close(io)
  catch(e)
    warn("ManagerStat._appendToFile(): $e")
    ret = false
  finally
    if io !== null close(io) end
  end

  ret
end
<commit_msg>+ added stat data after night<commit_after>import RpcApi
import Config
#
# Checks if we need to update statistics data like amount of organisms,
# IPS, best organism parameters and so on. Updates statistics according
# to STAT_UPDATE_PERIOD config.
#
function _updateStat(stamp::Float64)
  local bestOrgs::Array{RpcApi.SimpleOrganism, 1}
  local org::RpcApi.SimpleOrganism
  local json::ASCIIString
  local code::ASCIIString

  if Config.val(:STAT_UPDATE_PERIOD) > 0 && (time() - stamp) > Config.val(:STAT_UPDATE_PERIOD)
    bestOrgs = Manager.getBest(1)
    if length(bestOrgs) > 0
      org  = bestOrgs[1]
      code = string(org.code)
      json = string(
        "{",
        string("\"Probabilities\"       : ", org.mutationProbabilities, ",\n"),
        string("\"Amount of functions\" : ", length(split(code, "function ")) - 2, ",\n"), # minus main function
        string("\"Functions calls\"     : ", length(split(code, "func_")) - 1, ",\n"),
        string("\"Mutations on clone\"  : ", string(org.mutationsOnClone), ",\n"),
        string("\"Mutations period\"    : ", string(org.mutationPeriod), ",\n"),
        string("\"Mutations amount\"    : ", string(org.mutationAmount), ",\n"),
        string("\"Energy\"              : ", string(org.energy), ",\n"),
        string("\"for operators\"       : ", length(split(code, "for i::Int8")) - 1, ",\n"),
        string("\"if operators\"        : ", length(split(code, "if var")) - 1, ",\n"),
        string("\"getEnergy\"           : ", length(split(code, "Creature.getEnergy")) - 1, ",\n"),
        string("\"Memory reading\"      : ", length(split(code, "haskey(o.mem)")) - 1, ",\n"),
        string("\"Eating\"              : ", length(split(code, "Creature.eat")) - 1, ",\n"),
        string("\"Moving\"              : ", length(split(code, "Creature.step")) - 1, ",\n"),
        string("\"Amount of lines\"     : ", string(org.codeSize), ",\n"),
        string("\"Amount of organisms\" : ", string(length(Manager._data.tasks)), ",\n"),
        string("\"IPS\"                 : ", string(Config.val(:WORLD_IPS)), ",\n"),
        string("\"Generation number\"   : ", string(Manager._data.totalOrganisms), "\n"),
        "},\n"
      )
      _appendToFile(json, "file.json")
      _appendToFile(string("{\"Code\": \"", code, "\"},\n"), "code.json")
    end
    return time()
  end

  stamp
end

#
# Appends native values to the file.
# @param data String data to save
# @param file File name, we want append to
# @return {Bool} saving result
#
function _appendToFile(data::ASCIIString, file::ASCIIString)
  local io  = null
  local ret = true

  try
    io = open(file, "a") # "a" - means "file append" mode
    write(io, data)
    close(io)
  catch(e)
    warn("ManagerStat._appendToFile(): $e")
    ret = false
  finally
    if io !== null close(io) end
  end

  ret
end

{'fraction_non_alphanumeric': 0.18996987418040048, 'fraction_numerical': 0.005670742512847776, 'mean_word_length': 2.6985583224115333, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 9, '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': '6244335', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1802, 'n_words': 437}