<commit_before>fs = require('fs')
_  = require('underscore')

class EdeIndicatorator
  constructor: (indicatorType, indicatorCode) ->
    indicatorType = indicatorType.toLowerCase()

    @indicatorDefinition = JSON.parse(
      fs.readFileSync("./definitions/#{indicatorType}_indicator_definitions.json", 'UTF8')
    )[indicatorCode]

  indicatorate: (data) ->
    unless data?
      throw new Error("No data to indicatorate")

    valueField = @indicatorDefinition.valueField

    outputRows = []

    for row in data
      value = row[valueField]
      continue unless value?
      text = @calculateIndicatorText(value)
      outputRows.push(_.extend(row, text: text))

    return outputRows

  calculateIndicatorText: (value) ->
    value = parseFloat(value)
    ranges = @indicatorDefinition.ranges

    for range in ranges
      return range.message if value > range.minValue

    return "Error: Value #{value} outside expected range"

module.exports = EdeIndicatorator
<commit_msg>Fix relative path broken by module move<commit_after>fs = require('fs')
_  = require('underscore')

class EdeIndicatorator
  constructor: (indicatorType, indicatorCode) ->
    indicatorType = indicatorType.toLowerCase()

    @indicatorDefinition = JSON.parse(
      fs.readFileSync(
        "#{__dirname}/../definitions/#{indicatorType}_indicator_definitions.json", 'UTF8'
      )
    )[indicatorCode]

  indicatorate: (data) ->
    unless data?
      throw new Error("No data to indicatorate")

    valueField = @indicatorDefinition.valueField

    outputRows = []

    for row in data
      value = row[valueField]
      continue unless value?
      text = @calculateIndicatorText(value)
      outputRows.push(_.extend(row, text: text))

    return outputRows

  calculateIndicatorText: (value) ->
    value = parseFloat(value)
    ranges = @indicatorDefinition.ranges

    for range in ranges
      return range.message if value > range.minValue

    return "Error: Value #{value} outside expected range"

module.exports = EdeIndicatorator

{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.0009852216748768472, 'mean_word_length': 3.5640449438202246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3836692', 'n_tokens_mistral': 583, 'n_tokens_neox': 581, 'n_words': 143}