<commit_before># This class determines whether a certain value is moving too fast
#
# Too fast is defined as larger than speeding.
#
# We assume that averaging over the last few values gives the best
# value for speed (to allow for slow-changing discrete values, which
# would otherwise spike a lot)
class Factlink.Speedmeter
  constructor: (@options)->

  measure:  =>
    @value = @options.get_measure()
    @time = new Date().getTime()

  evaluate_current_state: =>
    last_time = @time
    last_value = @value
    @measure()
    current_speed = Math.abs((@value - last_value)/(@time-last_time))
    @speed = @smooth_with_last_speed(current_speed)
    @is_fast = @speed > @options.speeding
    @options.on_change(@is_fast)

  # This smoothes the new measurement with the previous measurement
  # this way we prevent that a small period of slow scrolling breaks
  # a long period of fast scrolling, resulting in a sudden highlight
  smooth_with_last_speed: (new_speed) =>
     0.4 * new_speed + 0.6 * @speed # multipliers are semi-arbitrary

  remeasure: =>
    @remeasure_timeout ?= setTimeout =>
      @remeasure_timeout = null
      @evaluate_current_state()
      if @is_fast
        @remeasure()
    , 100

  start_measuring: =>
    return if @remeasure_timeout
    # needed for smoothing, ensures low-latency first measurement
    @speed = @options.speeding
    @measure()
    @remeasure()
<commit_msg>made clear what parameters we need<commit_after># This class determines whether a certain value is moving too fast
class Factlink.Speedmeter
  constructor: (@options)->
    unless @options.on_change
      throw "Method for handling speed changes missing"
    unless @options.is_fast_treshold
      throw "Treshold for when to consider speed fast is missing"
    unless @options.get_measure
      throw "Function to measure with mising"

  measure:  =>
    @value = @options.get_measure()
    @time = new Date().getTime()

  determine_speed: =>
    last_time = @time
    last_value = @value
    @measure()
    current_speed = Math.abs((@value - last_value)/(@time-last_time))
    @speed = @smooth_with_last_speed(current_speed)
    @is_fast = @speed > @options.is_fast_treshold

  # This smoothes the new measurement with the previous measurement
  # this way we prevent that a small period of slow scrolling breaks
  # a long period of fast scrolling, resulting in a sudden highlight
  smooth_with_last_speed: (new_speed) =>
     0.4 * new_speed + 0.6 * @speed # multipliers are semi-arbitrary

  remeasure: =>
    @remeasure_timeout ?= setTimeout =>
      @remeasure_timeout = null
      @evaluate_current_state()
      if @is_fast
        @remeasure()
    , 100

  start_measuring: =>
    return if @remeasure_timeout
    # needed for smoothing, ensures low-latency first measurement
    @speed = @options.speeding
    @measure()
    @remeasure()

{'fraction_non_alphanumeric': 0.08881118881118881, 'fraction_numerical': 0.0048951048951048955, 'mean_word_length': 3.5197472353870456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5821281', 'n_tokens_mistral': 862, 'n_tokens_neox': 819, 'n_words': 274}