<commit_before>/* eslint-disable */

/* ----------------------------------------------------------
 * @TODO: ^ Enable linting by removing `eslint-disable`! ^
 * ----------------------------------------------------------
 * Linting is disabled in this file. Remove this line and
 * clean this file up according to our coding standards next
 * time it is touched.
 */

import Chart from 'chart.js';
import $ from 'jquery';
import setting from '../utilities/Setting';

/*
 * Number formatter so we can display the goal as a number with commas.
 */
var numberWithCommas = function (num) {
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};

/*
 * Calculates the number of days between two dates.
 */
var dateDiff = function(date1, date2) {
  var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
  var firstDate = date1;
  var secondDate = date2;
  return Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));
};

/*
 * Creates an array of days between the start and end date.
 */
var getDays = function(startDate, endDate) {
  Date.prototype.addDays = function(days) {
    var d = new Date(this.valueOf());
    d.setDate(d.getDate() + days);
    return d;
  };

  var dateArray = [];
  var currentDate = startDate;

  while (currentDate <= endDate) {
    dateArray.push( new Date (currentDate) );
    currentDate = currentDate.addDays(1);
  }

  return dateArray;
};

/*
 * Creates an array of four dates between (and including) the start date and the end date.
 */
var getFourDates = function(startDate, endDate) {
  var numDays = dateDiff(startDate, endDate);
  var interval = Math.floor(numDays / 3);

  var date1 = new Date();
  date1.setDate(startDate.getDate() + interval);

  var date2 = new Date();
  date2.setDate(startDate.getDate() + (interval * 2));

  return [startDate, date1, date2, endDate];
};

/*
 * Creates an array of user friendly date labels from an array of timestamps
 */
var createDateLabels = function(dates) {
  var dateLabels = [];
  var monthNames = ["Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sept", "Oct","Nov", "Dec"];

  dates.forEach(function(date, key) {
    date = new Date(date);
    var month = date.getMonth();
    var day = date.getDate();

    dateLabels[key] = monthNames[month] + " " + day;
  });

  return dateLabels;
};

/*
 * This function builds out an array of quantities for every label on the graph.
 * We need a value for every date, even if it is null.
 */
var createQuantityArray = function(dates, dateLabels, quantities) {
  // Create quantities array.
  var values = [];

  dateLabels.forEach(function(value, key) {
    var index = dates.indexOf(value);

    // If we have a quantity for this date,
    // add it to the array in the correct position.
    // Otherwise, make it null.
    if (index > -1) {
      values[key] = quantities[index];
    }
    else {
      values[key] = null;
    }
  });

  return values;
};

/*<commit_msg>add checks for null values<commit_after>/* eslint-disable */

/* ----------------------------------------------------------
 * @TODO: ^ Enable linting by removing `eslint-disable`! ^
 * ----------------------------------------------------------
 * Linting is disabled in this file. Remove this line and
 * clean this file up according to our coding standards next
 * time it is touched.
 */

import Chart from 'chart.js';
import $ from 'jquery';
import setting from '../utilities/Setting';

/*
 * Number formatter so we can display the goal as a number with commas.
 */
var numberWithCommas = function (num) {
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};

/*
 * Calculates the number of days between two dates.
 */
var dateDiff = function(date1, date2) {
  var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
  var firstDate = date1;
  var secondDate = date2;
  return Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));
};

/*
 * Creates an array of days between the start and end date.
 */
var getDays = function(startDate, endDate) {
  Date.prototype.addDays = function(days) {
    var d = new Date(this.valueOf());
    d.setDate(d.getDate() + days);
    return d;
  };

  var dateArray = [];
  var currentDate = startDate;

  while (currentDate <= endDate) {
    dateArray.push( new Date (currentDate) );
    currentDate = currentDate.addDays(1);
  }

  return dateArray;
};

/*
 * Creates an array of four dates between (and including) the start date and the end date.
 */
var getFourDates = function(startDate, endDate) {
  var numDays = dateDiff(startDate, endDate);
  var interval = Math.floor(numDays / 3);

  var date1 = new Date();
  date1.setDate(startDate.getDate() + interval);

  var date2 = new Date();
  date2.setDate(startDate.getDate() + (interval * 2));

  return [startDate, date1, date2, endDate];
};

/*
 * Creates an array of user friendly date labels from an array of timestamps
 */
var createDateLabels = function(dates) {
  var dateLabels = [];
  var monthNames = ["Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sept", "Oct","Nov", "Dec"];

  if (dates) {
    dates.forEach(function(date, key) {
      date = new Date(date);
      var month = date.getMonth();
      var day = date.getDate();

      dateLabels[key] = monthNames[month] + " " + day;
    });
  }

  return dateLabels;
};

/*
 * This function builds out an array of quantities for every label on the graph.
 * We need a value for every date, even if it is null.
 */
var createQuantityArray = function(dates, dateLabels, quantities) {
  // Create quantities array.
  var values = [];

  if (dateLabels) {
    dateLabels.forEach(function(value, key) {
      var index = dates.indexOf(value);

      // If we have a quantity for this date,
      // add it to the array in the correct position.
      // Otherwise, make it null.
      if (index > -1) {
        values[key] = quantities[index];
      }
      else {
        values[key] = null;
      }
    });
  }

  return values;
};

/*
{'fraction_non_alphanumeric': 0.17497490799598528, 'fraction_numerical': 0.008364001338240215, 'mean_word_length': 2.74858934169279, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '982442', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1805, 'n_words': 594}