<commit_before>'use strict';

function Article (opts) {
  this.author = opts.author;
  this.description = opts.description;
  this.publishedAt = opts.publishedat;
  this.title = opts.title;
  this.url = opts.url;
  this.urlToImage = opts.urltoimage;
  this.category = opts.category;
  this.viewCount = opts.viewcount
}

Article.prototype.toHtml = function() {
  var $newArticle = $('.template').clone();

  $newArticle.removeClass('template');
  $newArticle.addClass('not-template');

  $newArticle.attr('data-category', this.category);
  $newArticle.find('a.img-link').attr('href', this.url);
  $newArticle.find('img').attr('src', this.urlToImage);
  $newArticle.find('img').attr('alt', this.title);
  $newArticle.find('a.article-link').text(this.title);
  $newArticle.find('a.article-link').attr('href', this.url)
  $newArticle.find('section.article-description').text(this.description);
  // $newArticle.find('a.read-more').attr('href', this.url);
  $newArticle.find('span.author').text(this.author);
  $newArticle.find('span.date').text(this.publishedAt);


  if (this.viewCount) {
    var viewCountReadable = numeral(this.viewCount).format('0,0')
    $newArticle.find('span.viewCount').text(viewCountReadable + " views");
  }

  var totalMinutes = parseInt((new Date() - new Date(this.publishedAt))/60/1000);
  var days = Math.floor(totalMinutes/60/24)
  var hours = Math.floor(totalMinutes/60 - (days*24));
  var minutes = Math.floor(totalMinutes - (days*24*60) - (hours*60));

  // $newArticle.find('span.date').html(days + ' days, ' + hours + ' hours, ' + minutes + ' minutes ago.');

  if (hours < 1) {
    $newArticle.find('span.date').html(minutes + 'm');
  } else if (hours >= 1 && days < 1) {
    $newArticle.find('span.date').html(hours + 'h ' + minutes + 'm');
  } else {
    $newArticle.find('span.date').html(days + 'd ' + hours + 'h ' + minutes + 'm');
  }
  return $newArticle;
}

var fetchAll = function(callback) { //useful function to fetch from DB without refreshing the page
  Google.fetchAll(function(){
    Buzzfeed.fetchAll(function(){
      Espn.fetchAll(function(){
        TechCrunch.fetchAll(function(){
          YouTube.fetchAll(function(){
            callback();
          })
        });
      });
    });
  });
}

var articles = [];

var initPage = function(){
  if (Google.articles.length > 0) {
    Google.articles.forEach(function(articleObject) {
      articles.push(new Article(articleObject));
    });
  }
  if (Google.articles.length > 0) {
    Buzzfeed.articles.forEach(function(articleObject) {
      articles.push(new Article(articleObject));
    });
  }
  if (Espn.articles.length > 0) {
    Espn.articles.forEach(function(articleObject) {
      articles.push(new Article(articleObject));<commit_msg>fixed duplication error, by telling fetchAll to clear the articles array on line 71 of pageview.js<commit_after>'use strict';

function Article (opts) {
  this.author = opts.author;
  this.description = opts.description;
  this.publishedAt = opts.publishedat;
  this.title = opts.title;
  this.url = opts.url;
  this.urlToImage = opts.urltoimage;
  this.category = opts.category;
  this.viewCount = opts.viewcount
}

Article.prototype.toHtml = function() {
  var $newArticle = $('.template').clone();

  $newArticle.removeClass('template');
  $newArticle.addClass('not-template');

  $newArticle.attr('data-category', this.category);
  $newArticle.find('a.img-link').attr('href', this.url);
  $newArticle.find('img').attr('src', this.urlToImage);
  $newArticle.find('img').attr('alt', this.title);
  $newArticle.find('a.article-link').text(this.title);
  $newArticle.find('a.article-link').attr('href', this.url)
  $newArticle.find('section.article-description').text(this.description);
  // $newArticle.find('a.read-more').attr('href', this.url);
  $newArticle.find('span.author').text(this.author);
  $newArticle.find('span.date').text(this.publishedAt);


  if (this.viewCount) {
    var viewCountReadable = numeral(this.viewCount).format('0,0')
    $newArticle.find('span.viewCount').text(viewCountReadable + " views");
  }

  var totalMinutes = parseInt((new Date() - new Date(this.publishedAt))/60/1000);
  var days = Math.floor(totalMinutes/60/24)
  var hours = Math.floor(totalMinutes/60 - (days*24));
  var minutes = Math.floor(totalMinutes - (days*24*60) - (hours*60));

  // $newArticle.find('span.date').html(days + ' days, ' + hours + ' hours, ' + minutes + ' minutes ago.');

  if (hours < 1) {
    $newArticle.find('span.date').html(minutes + 'm');
  } else if (hours >= 1 && days < 1) {
    $newArticle.find('span.date').html(hours + 'h ' + minutes + 'm');
  } else {
    $newArticle.find('span.date').html(days + 'd ' + hours + 'h ' + minutes + 'm');
  }
  return $newArticle;
}

var fetchAll = function(callback) { //useful function to fetch from DB without refreshing the page
  Google.fetchAll(function(){
    Buzzfeed.fetchAll(function(){
      Espn.fetchAll(function(){
        TechCrunch.fetchAll(function(){
          YouTube.fetchAll(function(){
            callback();
          })
        });
      });
    });
  });
}

var articles = [];

var initPage = function(){
  articles = [];
  if (Google.articles.length > 0) {
    Google.articles.forEach(function(articleObject) {
      articles.push(new Article(articleObject));
    });
  }
  if (Google.articles.length > 0) {
    Buzzfeed.articles.forEach(function(articleObject) {
      articles.push(new Article(articleObject));
    });
  }
  if (Espn.articles.length > 0) {
    Espn.articles.forEach(function(articleObject) {
      articles.push(new Article(articleObject));
{'fraction_non_alphanumeric': 0.18084345961401, 'fraction_numerical': 0.010364546104360257, 'mean_word_length': 3.8416955017301038, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4090922', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1819, 'n_words': 299}