<commit_before>module Yeah
module Web
class Ticker
  attr_accessor :rate
  attr_reader :tick_count, :actual_rate

  def initialize(args = {})
    @rate = args.fetch(:rate, DEFAULT_TICKER_RATE)
    @tick_count = 0
    @actual_rate = 0
    @next_actual_rate = 0
  end

  def on_tick(&block)
    # TODO: add to ticks before yielding
    %x{
      var lastTime = (new Date()).getTime(),
          lastMeasureTime = lastTime,
          elapsed = 0,
          interval,
          currentTime;

      var loop = function() {
        interval = 1000.0 / #{@rate};
        currentTime = new Date().getTime();
        elapsed = currentTime - lastTime;

        if (elapsed > interval) {
          #{yield `elapsed`}

          #@tick_count += 1;
          #@next_actual_rate += 1;

          lastTime = currentTime - (elapsed % interval);
        }<commit_msg>fixed web ticker elapsed time<commit_after>module Yeah
module Web
class Ticker
  attr_accessor :rate
  attr_reader :tick_count, :actual_rate

  def initialize(args = {})
    @rate = args.fetch(:rate, DEFAULT_TICKER_RATE)
    @tick_count = 0
    @actual_rate = 0
    @next_actual_rate = 0
  end

  def on_tick(&block)
    # TODO: add to ticks before yielding
    %x{
      var lastTime = (new Date()).getTime(),
          lastMeasureTime = lastTime,
          elapsed = 0,
          interval,
          currentTime;

      var loop = function() {
        interval = 1.0 / #{@rate};
        currentTime = new Date().getTime();
        elapsed = (currentTime - lastTime) / 1000.0;

        if (elapsed > interval) {
          #{yield `elapsed`}

          #@tick_count += 1;
          #@next_actual_rate += 1;

          lastTime = currentTime - (elapsed % interval);
        }
{'fraction_non_alphanumeric': 0.11252900232018562, 'fraction_numerical': 0.013921113689095127, 'mean_word_length': 2.1420765027322406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5799400', 'n_tokens_mistral': 566, 'n_tokens_neox': 528, 'n_words': 139}