<commit_before>var util2 = require('util2');
var Emitter = require('emitter');
var Settings = require('settings');
var simply = require('ui/simply');

var Wakeup = function() {
  this.init();
};

Wakeup.prototype.cleanupGracePeriod = 60 * 5;

util2.copy(Emitter.prototype, Wakeup.prototype);

Wakeup.prototype.init = function() {
  this._setRequests = [];
  this._launchCallbacks = [];
  this._loadData();
  this._cleanup();
};

Wakeup.prototype._loadData = function() {
  this.state = Settings._loadData(null, 'wakeup', true) || {};
  this.state.wakeups = this.state.wakeups || {};
};

Wakeup.prototype._saveData = function() {
  Settings._saveData(null, 'wakeup', this.state);
};

Wakeup.prototype._cleanup = function() {
  var id;
  var ids = [];
  for (id in this.state.wakeups) {
    ids.push(id);
  }
  var cleanupTime = Date.now() / 1000 - Wakeup.cleanupGracePeriod;
  var deleted = false;
  for (var i = 0, ii = ids.length; i < ii; ++i) {
    id = ids[i];
    var wakeup = this.state.wakeups[id];
    if (wakeup.params.time < cleanupTime) {
      deleted = true;
      delete this.state.wakeups[id];
    }
  }
  if (deleted) {
    this._saveData();
  }
};

Wakeup.prototype.get = function(id) {
  var wakeup = this.state.wakeups[id];
  if (wakeup) {
    return {
      id: id,
      cookie: wakeup.cookie,
      data: wakeup.data,
      time: wakeup.params.time,
      notifyIfMissed: !!wakeup.params.notifyIfMissed,
    };
  }
};

Wakeup.prototype.each = function(callback) {
  var i = 0;
  for (var id in this.state.wakeups) {
    if (callback(this.get(id), i++) === false) {
      break;
    }<commit_msg>Fix Wakeup get and each to return the id as the right type<commit_after>var util2 = require('util2');
var Emitter = require('emitter');
var Settings = require('settings');
var simply = require('ui/simply');

var Wakeup = function() {
  this.init();
};

Wakeup.prototype.cleanupGracePeriod = 60 * 5;

util2.copy(Emitter.prototype, Wakeup.prototype);

Wakeup.prototype.init = function() {
  this._setRequests = [];
  this._launchCallbacks = [];
  this._loadData();
  this._cleanup();
};

Wakeup.prototype._loadData = function() {
  this.state = Settings._loadData(null, 'wakeup', true) || {};
  this.state.wakeups = this.state.wakeups || {};
};

Wakeup.prototype._saveData = function() {
  Settings._saveData(null, 'wakeup', this.state);
};

Wakeup.prototype._cleanup = function() {
  var id;
  var ids = [];
  for (id in this.state.wakeups) {
    ids.push(id);
  }
  var cleanupTime = Date.now() / 1000 - Wakeup.cleanupGracePeriod;
  var deleted = false;
  for (var i = 0, ii = ids.length; i < ii; ++i) {
    id = ids[i];
    var wakeup = this.state.wakeups[id];
    if (wakeup.params.time < cleanupTime) {
      deleted = true;
      delete this.state.wakeups[id];
    }
  }
  if (deleted) {
    this._saveData();
  }
};

Wakeup.prototype.get = function(id) {
  var wakeup = this.state.wakeups[id];
  if (wakeup) {
    return {
      id: wakeup.id,
      cookie: wakeup.cookie,
      data: wakeup.data,
      time: wakeup.params.time,
      notifyIfMissed: !!wakeup.params.notifyIfMissed,
    };
  }
};

Wakeup.prototype.each = function(callback) {
  var i = 0;
  for (var id in this.state.wakeups) {
    if (callback(this.get(id), i++) === false) {
      break;
    }
{'fraction_non_alphanumeric': 0.16534713763702802, 'fraction_numerical': 0.007308160779537149, 'mean_word_length': 3.2223650385604112, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3708035', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1193, 'n_words': 244}