<commit_before>'use strict';

const Debug = (new class {
  async backup() {
    const data = { history: await STORE.get('history') };
    for (const type of ['NWL', 'ENABLE', 'CSW']) {
      store = new Store('training', type);
      data[type] = await store.get('data');
    }
    data.settings = JSON.parse(localStorage.getItem('settings'));
    return JSON.stringify(data);
  }

  async restore(data) {
    await STORE.set('history', data.history);
    for (const type of ['NWL', 'ENABLE', 'CSW']) {
      store = new Store('training', type);
      await store.set('data', data[type]);
    }
    localStorage.setItem('settings', JSON.stringify(data.settings));
  }

  async modify(w, fn) {
    const store = new Store('training', SETTINGS.dict);
    const pool = await TrainingPool.create(STATS, SETTINGS.dice, SETTINGS.dict, store, SETTINGS.min);
    const k = Stats.toAnagram(w);

    let found;
    const popped = [];
    for (found = pool.learned.pop(); found && found.k != k; ) popped.push(found);
    if (!found) throw RangeError();

    pool.learned.push(fn(found));
    for (const p of popped) pool.learned.push(p);

    return store.set('data', pool.learned.data);
  }
}());<commit_msg>Fix debug logic<commit_after>'use strict';

const Debug = new (class {
  async backup() {
    const data = { history: await STORE.get('history') };
    for (const type of ['NWL', 'ENABLE', 'CSW']) {
      const store = new Store('training', type);
      data[type] = await store.get('data');
    }
    data.settings = JSON.parse(localStorage.getItem('settings'));
    return JSON.stringify(data);
  }

  async restore(data) {
    await STORE.set('history', data.history);
    for (const type of ['NWL', 'ENABLE', 'CSW']) {
      const store = new Store('training', type);
      await store.set('data', data[type]);
    }
    localStorage.setItem('settings', JSON.stringify(data.settings));
  }

  async modify(w, fn) {
    const store = new Store('training', SETTINGS.dict);
    const pool = await TrainingPool.create(STATS, SETTINGS.dice, SETTINGS.dict, store, SETTINGS.min);
    const k = Stats.toAnagram(w);

    let found;
    const popped = [];
    for (found = pool.learned.pop(); found && found.k !== k; found = pool.learned.pop()) {
      popped.push(found);
    }
    if (!found) throw RangeError();

    pool.learned.push(fn(found));
    for (const p of popped) pool.learned.push(p);

    return store.set('data', pool.learned.data);
  }
})();
{'fraction_non_alphanumeric': 0.1729906160750714, 'fraction_numerical': 0.0, 'mean_word_length': 3.355239786856128, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3774353', 'n_tokens_mistral': 803, 'n_tokens_neox': 793, 'n_words': 198}