<commit_before>const bluebird = require('bluebird');
const cheerio = require('cheerio');
const got = require('got');

const models = require('./models');

async function extractStats(username, category) {
  const url = `https://www.senscritique.com/${username}/collection/rating/${category}/all/all/all/all/all/all/all/page-1`;

  const response = await got(url);
  const $ = cheerio.load(response.body);

  return {
    watchlisted: parseInt(
      $('[data-sc-collection-filter="wish"] span span')
        .text()
        .trim()
        .slice(1, -1)
    ),
    rated: parseInt(
      $('[data-sc-collection-filter="rating"] span span')
        .text()
        .trim()
        .slice(1, -1)
    ),
    finished: parseInt(
      $('[data-sc-collection-filter="done"] span span')
        .text()
        .trim()
        .slice(1, -1)
    )
  };
}

module.exports = async function(username, category) {
  const collection = [];

  const stats = await extractStats(username, category);
  const pages = Math.ceil(stats['rated'] / 18);
  const indexes = Array.from({ length: pages }, (v, k) => k + 1);

  const model = models[models.categoryToModels[category]];
  const keys = Object.keys(model);

  return await bluebird
    .map(indexes, async function(index, callback) {
      const url =<commit_msg>fix: replace null value by 0 in stats object<commit_after>const bluebird = require('bluebird');
const cheerio = require('cheerio');
const got = require('got');

const models = require('./models');

async function extractStats(username, category) {
  const url = `https://www.senscritique.com/${username}/collection/rating/${category}/all/all/all/all/all/all/all/page-1`;

  const response = await got(url);
  const $ = cheerio.load(response.body);

  const stats = {
    watchlisted: parseInt(
      $('[data-sc-collection-filter="wish"] span span')
        .text()
        .trim()
        .slice(1, -1)
    ),
    rated: parseInt(
      $('[data-sc-collection-filter="rating"] span span')
        .text()
        .trim()
        .slice(1, -1)
    ),
    finished: parseInt(
      $('[data-sc-collection-filter="done"] span span')
        .text()
        .trim()
        .slice(1, -1)
    )
  };

  for (let key of Object.keys(stats)) {
    if (Object.is(stats[key], NaN)) {
      stats[key] = 0;
    }
  }

  return stats;
}

module.exports = async function(username, category) {
  const collection = [];

  const stats = await extractStats(username, category);
  const pages = Math.ceil(stats['rated'] / 18);
  const indexes = Array.from({ length: pages }, (v, k) => k + 1);

  const model = models[models.categoryToModels[category]];
  const keys = Object.keys(model);

  return await bluebird
    .map(indexes, async function(index, callback) {
      const url =
{'fraction_non_alphanumeric': 0.16702819956616052, 'fraction_numerical': 0.007953723788864787, 'mean_word_length': 2.930397727272727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5781278', 'n_tokens_mistral': 890, 'n_tokens_neox': 872, 'n_words': 205}