<commit_before>_ = require 'lodash'

class CharacterStats
  constructor: (stats) ->
    for key, val of stats
      @[key] = val
    @calcDerived()

  secSuffixes: [
    'HighSec'
    'LowSec'
    'NullSec'
    'Wormhole'
  ]

  calcTotal: (prefix) ->
    statNames = _.map @secSuffixes, (suffix) -> prefix + suffix
    return _.reduce statNames, ((sum, stat) => sum + @[stat]), 0

  calcDerived: ->
    # fix a few stats
    @iskOut = -(@iskOut)
    # derive some stats
    @averageSessionLength = @characterMinutes / @characterSessionsStarted

    @combatKillsTotal = @calcTotal 'combatKills'
    @combatDeathsTotal = @calcTotal 'combatDeaths'
    @kdRatioTotal = @combatKillsTotal / @combatDeathsTotal

    @kdRatioHigh = @combatKillsHighSec / @combatDeathsHighSec
    @kdRatioLow = @combatKillsLowSec / @combatDeathsLowSec
    @kdRatioNull = @combatKillsNullSec / @combatDeathsNullSec
    @kdRatioWormhole = @combatKillsWormhole / @combatDeathsWormhole

    @travelDistanceWarpedTotal = @calcTotal 'travelDistanceWarped'

    @iskSpentPercent = 100 * (@iskOut / @iskIn)

  metadata:
    daysOfActivity:
      name: "Active Days"
      description: "The number of days in the period with recorded activity"
      tags: ['general']
    characterMinutes:
      name: "Minutes Logged In"
      description: "The number of minutes logged in as this character"
      tags: ['general']
    characterSessionsStarted:
      name: "Logins"<commit_msg>Memoize some functions, add some more totals and percents<commit_after>_ = require 'lodash'

class CharacterStats
  constructor: (stats) ->
    for key, val of stats
      @[key] = val

    @secSuffixes = [
      'HighSec'
      'LowSec'
      'NullSec'
      'Wormhole'
    ]

    @calcDerived()

  total: _.memoize (prefix) ->
    statNames = _.map @secSuffixes, (suffix) -> prefix + suffix
    return _.reduce statNames, ((sum, stat) => sum + @[stat]), 0

  percent: _.memoize (prefix, suffix) ->
    total = @total prefix
    pct = @[prefix + suffix] / total
    return pct
  # resolver
  , (prefix, suffix) -> return "#{prefix}#{suffix}"

  calcDerived: ->
    # fix a few stats
    @iskOut = -(@iskOut)
    # derive some stats
    @averageSessionLength = @characterMinutes / @characterSessionsStarted

    @combatKillsTotal = @total 'combatKills'
    @combatDeathsTotal = @total 'combatDeaths'
    @kdRatioTotal = @combatKillsTotal / @combatDeathsTotal

    @kdRatioHigh = @combatKillsHighSec / @combatDeathsHighSec
    @kdRatioLow = @combatKillsLowSec / @combatDeathsLowSec
    @kdRatioNull = @combatKillsNullSec / @combatDeathsNullSec
    @kdRatioWormhole = @combatKillsWormhole / @combatDeathsWormhole

    @travelDistanceWarpedTotal = @total 'travelDistanceWarped'

    @totalDamageDealt = @combatDamageToPlayersHybridAmount +
                        @combatDamageToPlayersProjectileAmount +
                        @combatDamageToPlayersEnergyAmount +
                        @combatDamageToPlayersMissileAmount +
                        @combatDamageToPlayersBombAmount +
                        @combatDamageToPlayersSmartBombAmount +
                        @combatDamageToPlayersFighterMissileAmount +
                        @combatDamageToPlayersSuperAmount

    @iskSpentPercent = 100 * (@iskOut / @iskIn)

  metadata:
    daysOfActivity:
      name: "Active Days"
      description: "The number of days in the period with recorded activity"
      tags: ['general']
    characterMinutes:
      name: "Minutes Logged In"
      description: "The number of minutes logged in as this character"
      tags: ['general']
    characterSessionsStarted:
      name: "Logins"
{'fraction_non_alphanumeric': 0.0970231532524807, 'fraction_numerical': 0.002205071664829107, 'mean_word_length': 2.9617903930131004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1672801', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1129, 'n_words': 265}