<commit_before>package ciir.jfoley.chai.time;

/**
 * @author jfoley
 */
public class Debouncer {
  long startTime;
  long delay;
  long lastTime;
  /**
   * @param milliseconds the minimum number of milliseconds between actions.
   */
  public Debouncer(long milliseconds) {
    this.delay = milliseconds;
    this.startTime = System.currentTimeMillis();
    this.lastTime = startTime - delay;
  }
  public Debouncer() {
    this(1000);
  }

  public boolean ready() {
    long now = System.currentTimeMillis();
    if(now - lastTime >= delay) {
      lastTime = now;
      return true;
    }
    return false;
  }

  public RateEstimate estimate(long currentItem, long totalItems) {
    return new RateEstimate(System.currentTimeMillis() - startTime, currentItem, totalItems);
  }

  public String estimate(int count) {
    double timeDelta = System.currentTimeMillis() - startTime;
    double rate = count / timeDelta;
    return String.format("%4.1f items/s", rate * 1000.0);
  }

  public static class RateEstimate {
    /** fraction of job complete */
    private final double fraction;
    /** items/ms */
    private final double rate;
    /** estimated time remaining (ms) */
    private final double remaining;

    public RateEstimate(long timeDelta, long itemsComplete, long totalItems) {
      this.fraction = itemsComplete / (double) totalItems;
      this.rate = itemsComplete / (double) timeDelta;
      this.remaining = (totalItems - itemsComplete) / rate;<commit_msg>Take longs or ints as doubles in estimate<commit_after>package ciir.jfoley.chai.time;

/**
 * @author jfoley
 */
public class Debouncer {
  long startTime;
  long delay;
  long lastTime;
  /**
   * @param milliseconds the minimum number of milliseconds between actions.
   */
  public Debouncer(long milliseconds) {
    this.delay = milliseconds;
    this.startTime = System.currentTimeMillis();
    this.lastTime = startTime - delay;
  }
  public Debouncer() {
    this(1000);
  }

  public boolean ready() {
    long now = System.currentTimeMillis();
    if(now - lastTime >= delay) {
      lastTime = now;
      return true;
    }
    return false;
  }

  public RateEstimate estimate(long currentItem, long totalItems) {
    return new RateEstimate(System.currentTimeMillis() - startTime, currentItem, totalItems);
  }

  public String estimate(double count) {
    double timeDelta = System.currentTimeMillis() - startTime;
    double rate = count / timeDelta;
    return String.format("%4.1f items/s", rate * 1000.0);
  }

  public static class RateEstimate {
    /** fraction of job complete */
    private final double fraction;
    /** items/ms */
    private final double rate;
    /** estimated time remaining (ms) */
    private final double remaining;

    public RateEstimate(long timeDelta, long itemsComplete, long totalItems) {
      this.fraction = itemsComplete / (double) totalItems;
      this.rate = itemsComplete / (double) timeDelta;
      this.remaining = (totalItems - itemsComplete) / rate;
{'fraction_non_alphanumeric': 0.10329890036654449, 'fraction_numerical': 0.007330889703432189, 'mean_word_length': 3.1464088397790055, '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': '4260377', 'n_tokens_mistral': 885, 'n_tokens_neox': 856, 'n_words': 252}