<commit_before>import Ember from 'ember';

const CONVERSION_MAP = {
  // Please sort on alphabetic order, thank you!
  'centimeters': {
    'kilometers':    (value) => value / 100000.0,
    'meters':        (value) => value / 100.0,
    'millimeters':   (value) => value * 10.0
  },
  'feet': {
    'teu':           (value) => value / 20.0
  },
  'hours': {
    'milliseconds':  (value) => value * 3600000,
    'minutes':       (value) => value * 60.0,
    'seconds':       (value) => value * 3600.0
  },
  'kilometers': {
    'centimeters':   (value) => value * 100000,
    'meters':        (value) => value * 1000,
    'millimeters':   (value) => value * 1000000
  },
  'kilos': {
    'tons':          (value) => value / 1000.0
  },
  'meters': {
    'centimeters':   (value) => value * 100,
    'kilometers':    (value) => value / 1000,
    'millimeters':   (value) => value * 1000
  },
  'millimeters': {
    'centimeters':   (value) => value / 10.0,
    'kilometers':    (value) => value / 1000000.0,
    'meters':        (value) => value / 1000.0
  },
  'milliseconds': {
    'hours':         (value) => value / 3600000.0,
    'minutes':       (value) => value / 60000.0,
    'seconds':       (value) => value / 1000.0
  },
  'minutes': {
    'hours':         (value) => value / 60.0,
    'milliseconds':  (value) => value * 60000.0,
    'seconds':       (value) => value * 60.0
  },
  'seconds': {
    'milliseconds':  (value) => value * 1000,
    'minutes':       (value) => value / 60,
    'hours':         (value) => value / 3600
  },
  'teu': {
    'feet':          (value) => value * 20.0
  },
  'tons': {
    'kilos':         (value) => value * 1000
  }
};

export default function(value, fromUnit, toUnit) {
  if (value == null) { return value; }
  if (typeof value !== 'number') {
    throw new Ember.Error('Input to conversion function must be a number');
  }

  if (CONVERSION_MAP[fromUnit] && CONVERSION_MAP[fromUnit][toUnit]) {
    return CONVERSION_MAP[fromUnit][toUnit](value);
  } else {
    throw new Ember.Error('Conversion from ' + fromUnit + ' to ' +
                                               toUnit + ' not available');
  }
}<commit_msg>get rid of magic numbers<commit_after>import Ember from 'ember';

const MILLIMETERS = 1;
const CENTIMETERS = 10 * MILLIMETERS;
const METERS      = 100 * CENTIMETERS;
const KILOMETERS  = 1000 * METERS;

const MILLISECONDS = 1;
const SECONDS      = 1000 * MILLISECONDS;
const MINUTES      = 60 * SECONDS;
const HOURS        = 60 * MINUTES;

const KILOS = 1;
const TONS  = 1000 * KILOS;

const FEET = 1;
const TEU  = 20 * FEET;

const CONVERSION_MAP = {
  // Please sort on alphabetic order, thank you!
  'centimeters': {
    'kilometers':    (value) => value * CENTIMETERS / KILOMETERS,
    'meters':        (value) => value * CENTIMETERS / METERS,
    'millimeters':   (value) => value * CENTIMETERS
  },
  'feet': {
    'teu':           (value) => value / TEU
  },
  'hours': {
    'milliseconds':  (value) => value * HOURS,
    'minutes':       (value) => value * HOURS / MINUTES,
    'seconds':       (value) => value * HOURS / SECONDS
  },
  'kilometers': {
    'centimeters':   (value) => value * KILOMETERS / CENTIMETERS,
    'meters':        (value) => value * KILOMETERS / METERS,
    'millimeters':   (value) => value * KILOMETERS
  },
  'kilos': {
    'tons':          (value) => value / TONS
  },
  'meters': {
    'centimeters':   (value) => value * METERS / CENTIMETERS,
    'kilometers':    (value) => value * METERS / KILOMETERS,
    'millimeters':   (value) => value * METERS
  },
  'millimeters': {
    'centimeters':   (value) => value / CENTIMETERS,
    'kilometers':    (value) => value / KILOMETERS,
    'meters':        (value) => value / METERS
  },
  'milliseconds': {
    'hours':         (value) => value / HOURS,
    'minutes':       (value) => value / MINUTES,
    'seconds':       (value) => value / SECONDS
  },
  'minutes': {
    'hours':         (value) => value * MINUTES / HOURS,
    'milliseconds':  (value) => value * MINUTES,
    'seconds':       (value) => value * MINUTES / SECONDS
  },
  'seconds': {
    'milliseconds':  (value) => value * SECONDS,
    'minutes':       (value) => value * SECONDS / MINUTES,
    'hours':         (value) => value * SECONDS / HOURS
  },
  'teu': {
    'feet':          (value) => value * TEU
  },
  'tons': {
    'kilos':         (value) => value * TONS
  }
};

export default function(value, fromUnit, toUnit) {
  if (value == null) { return value; }
  if (typeof value !== 'number') {
    throw new Ember.Error('Input to conversion function must be a number');
  }

  if (CONVERSION_MAP[fromUnit] && CONVERSION_MAP[fromUnit][toUnit]) {
    return CONVERSION_MAP[fromUnit][toUnit](value);
  } else {
    throw new Ember.Error('Conversion from ' + fromUnit + ' to ' +
                                               toUnit + ' not available');
  }
}
{'fraction_non_alphanumeric': 0.17120065453057884, 'fraction_numerical': 0.031908365718960933, 'mean_word_length': 2.270903010033445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6292264', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1699, 'n_words': 412}