<commit_before>var config = require('dot-file-config')('.pw3-npm');

module.exports = (function() {
  var _ = require('lodash');
  var moment = require('moment');

  var data = config.data.progress = config.data.progress || {};

  var result = {};

  result.findProgressEntry = (show) => {
    var progressEntry = data[show.imdb];

    if (!progressEntry) {
      progressEntry = data[show.imdb] = {
        title: show.title,
        imdb: show.imdb,
        episodes: []
      };
    }

    return progressEntry;
  };

  result.findEpisodeEntry = (progressEntry, episode) => {
    return _.find(progressEntry.episodes, (progressEpisode) => {
      return episode.season === progressEpisode.season && episode.episode === progressEpisode.episode;
    });
  };

  result.findLatestEpisode = (media) => {
    var showEntry = result.findProgressEntry(media);
    return _.last(_.sortByAll(showEntry.episodes, ['season', 'episode']));
  };

  result.isEpisodeChecked = (episode) => {
    var progressEntry = data[episode.showImdb];
    if (!progressEntry) {
      return false;
    }

    var episodeEntry = result.findEpisodeEntry(progressEntry, episode);
    return episodeEntry && episodeEntry.checked;
  };

  var now = moment();

  result.getStats = (show, episodes, noColors = false) => {
    var chalk = require('chalk');
    var watched = 0;
    var unwatched = 0;
    var unaired = 0;

    _.each(episodes, (episode) => {
      if (result.isEpisodeChecked(episode)) {
        watched++;
      } else if (episode._date.isValid() && episode._date.isBefore(now)) {
        unwatched++;
      } else {
        unaired++;
      }
    });

    var colorString = (string, fn) => noColors ? string : fn(string);

    if (watched === episodes.length) {
      return 'watched: all';
    } else {
      // var s1 = '';
      var s1 = watched > 0 ? `watched: ${watched} episodes` : '';
      var s2 = unwatched > 0 ? colorString(`unwatched: ${unwatched} episodes`, chalk.red) : '';
      var s3 = unaired > 0 ? colorString(`unaired: ${unaired} episodes`, chalk.gray) : '';

      return _.filter([s1, s2, s3], (s) => s.length > 0).join(', '); // @TODO: plurals
    }
  };

  // wip
  result.getSeasonsStats = (show, seasons) => {
    var watchedSeasons = 0;
    var unwatchedSeasons = 0;
    var watched = 0;
    var unwatched = 0;

    _.each(seasons, (season) => {
      watched = 0;
      unwatched = 0;

      _.each(season.episodes, (episode) => {
        if (result.isEpisodeChecked(episode)) {
          watched++;
        } else {
          unwatched++;
        }
      });

      if (watched === season.episodes.length) {
        watchedSeasons++;
      } else {
        unwatchedSeasons++;
      }
    });

    var watchedString = (watchedSeasons > 0) ? `${watchedSeasons} seasons` : `0 seasons`;
    var unwatchedString = (unwatchedSeasons === 1) ? `${unwatched} episodes` : `${unwatchedSeasons} seasons`;

    return `watched: ${watchedString}, unwatched: ${unwatchedString}`; // @TODO: plurals
  };

  return result;
})();
<commit_msg>change order of statistics in progress<commit_after>var config = require('dot-file-config')('.pw3-npm');

module.exports = (function() {
  var _ = require('lodash');
  var moment = require('moment');

  var data = config.data.progress = config.data.progress || {};

  var result = {};

  result.findProgressEntry = (show) => {
    var progressEntry = data[show.imdb];

    if (!progressEntry) {
      progressEntry = data[show.imdb] = {
        title: show.title,
        imdb: show.imdb,
        episodes: []
      };
    }

    return progressEntry;
  };

  result.findEpisodeEntry = (progressEntry, episode) => {
    return _.find(progressEntry.episodes, (progressEpisode) => {
      return episode.season === progressEpisode.season && episode.episode === progressEpisode.episode;
    });
  };

  result.findLatestEpisode = (media) => {
    var showEntry = result.findProgressEntry(media);
    return _.last(_.sortByAll(showEntry.episodes, ['season', 'episode']));
  };

  result.isEpisodeChecked = (episode) => {
    var progressEntry = data[episode.showImdb];
    if (!progressEntry) {
      return false;
    }

    var episodeEntry = result.findEpisodeEntry(progressEntry, episode);
    return episodeEntry && episodeEntry.checked;
  };

  var now = moment();

  result.getStats = (show, episodes, noColors = false) => {
    var chalk = require('chalk');
    var watched = 0;
    var unwatched = 0;
    var unaired = 0;

    _.each(episodes, (episode) => {
      if (result.isEpisodeChecked(episode)) {
        watched++;
      } else if (episode._date.isValid() && episode._date.isBefore(now)) {
        unwatched++;
      } else {
        unaired++;
      }
    });

    var colorString = (string, fn) => noColors ? string : fn(string);

    if (watched === episodes.length) {
      return 'watched: all';
    } else {
      // var s1 = '';
      var s1 = watched > 0 ? `watched: ${watched} episodes` : '';
      var s2 = unwatched > 0 ? colorString(`unwatched: ${unwatched} episodes`, chalk.red) : '';
      var s3 = unaired > 0 ? colorString(`unaired: ${unaired} episodes`, chalk.gray) : '';

      return _.filter([s2, s3, s1], (s) => s.length > 0).join(', '); // @TODO: plurals
    }
  };

  // wip
  result.getSeasonsStats = (show, seasons) => {
    var watchedSeasons = 0;
    var unwatchedSeasons = 0;
    var watched = 0;
    var unwatched = 0;

    _.each(seasons, (season) => {
      watched = 0;
      unwatched = 0;

      _.each(season.episodes, (episode) => {
        if (result.isEpisodeChecked(episode)) {
          watched++;
        } else {
          unwatched++;
        }
      });

      if (watched === season.episodes.length) {
        watchedSeasons++;
      } else {
        unwatchedSeasons++;
      }
    });

    var watchedString = (watchedSeasons > 0) ? `${watchedSeasons} seasons` : `0 seasons`;
    var unwatchedString = (unwatchedSeasons === 1) ? `${unwatched} episodes` : `${unwatchedSeasons} seasons`;

    return `watched: ${watchedString}, unwatched: ${unwatchedString}`; // @TODO: plurals
  };

  return result;
})();

{'fraction_non_alphanumeric': 0.16047158997871294, 'fraction_numerical': 0.007859832978549206, 'mean_word_length': 2.6928657799274487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2465685', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1965, 'n_words': 421}