<commit_before>//
//  TimerFormatter.swift
//  GoldenTiler
//
//  Created by <NAME> on 10/6/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

class TimerFormatter: NSFormatter {

  enum Unit {
    case Nanosecond, Microsecond, Millisecond, Second
  }

  /// Returns timer string for the provided value in nanoseconds
  override func stringForObjectValue(obj: AnyObject) -> String? {
    guard let obj = obj as? Timer else {
      return nil
    }

    return stringFromTimer(obj, unit: .Nanosecond)
  }

  /// Returns timer string for the provided value and unit
  func stringFromTimer(timer: Timer, unit: Unit) -> String? {
    switch unit {
    case .Nanosecond:
      return String.localizedStringWithFormat(TimerLocalizable.UnitNanosecond, timer.nanoseconds)
    case .Microsecond:
      return String.localizedStringWithFormat(TimerLocalizable.UnitMicrosecond, timer.microseconds)
    case .Millisecond:
      return String.localizedStringWithFormat(TimerLocalizable.UnitMillisecond, timer.milliseconds)
    case .Second:
      return String.localizedStringWithFormat(TimerLocalizable.UnitSecond, timer.seconds)
    }
  }

  /// This method is not supported for TimerFormatter class
  override func getObjectValue(obj: AutoreleasingUnsafeMutablePointer<AnyObject?>, forString string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>) -> Bool {
    return false
  }
<commit_msg>Add best guess formatter function<commit_after>//
//  TimerFormatter.swift
//  GoldenTiler
//
//  Created by <NAME> on 10/6/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

class TimerFormatter: NSFormatter {

  enum Unit {
    case Nanosecond, Microsecond, Millisecond, Second
  }

  /// Returns timer string for the provided value in nanoseconds
  override func stringForObjectValue(obj: AnyObject) -> String? {
    guard let obj = obj as? Timer else {
      return nil
    }

    return stringFromTimer(obj, unit: .Nanosecond)
  }

  /// Returns timer string for the provided value and unit
  func stringFromTimer(timer: Timer, unit: Unit) -> String? {
    switch unit {
    case .Nanosecond:
      return String.localizedStringWithFormat(TimerLocalizable.UnitNanosecond, timer.nanoseconds)
    case .Microsecond:
      return String.localizedStringWithFormat(TimerLocalizable.UnitMicrosecond, timer.microseconds)
    case .Millisecond:
      return String.localizedStringWithFormat(TimerLocalizable.UnitMillisecond, timer.milliseconds)
    case .Second:
      return String.localizedStringWithFormat(TimerLocalizable.UnitSecond, timer.seconds)
    }
  }

  /// Returns timer string with the best human readable unit
  func stringFromTimer(timer: Timer) -> String? {
    if timer.seconds >= 1.0 {
      return stringFromTimer(timer, unit: .Second)
    }
    else if timer.milliseconds >= 1.0 {
      return stringFromTimer(timer, unit: .Millisecond)
    }
    else if timer.microseconds >= 1.0 {
      return stringFromTimer(timer, unit: .Microsecond)
    }

    return stringFromTimer(timer, unit: .Nanosecond)
  }

  /// This method is not supported for TimerFormatter class
  override func getObjectValue(obj: AutoreleasingUnsafeMutablePointer<AnyObject?>, forString string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>) -> Bool {
    return false
  }

{'fraction_non_alphanumeric': 0.08733233979135618, 'fraction_numerical': 0.007153502235469449, 'mean_word_length': 3.700280112044818, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '7043348', 'n_tokens_mistral': 1000, 'n_tokens_neox': 920, 'n_words': 268}