<commit_before>var SourceStats = function () {
};

// Downloads the sourceUrls and returns the results in Remark format
SourceStats.prototype.createSource = function(classJSONUrl) {
  // Download class file
  classfile = this.getFile(classJSONUrl)
  classJSON = JSON.parse(classfile)

  // Set the class title
  document.title = classJSON.classname

  var source = ""

  // Add all modules for the class
  for (var i = 0; i < classJSON.classmodules.length; i++) {
    source += this.getFile(classJSON.classmodules[i]);

    // Files shouldn't have --- at the head or foot
    // It is added automatically here
    if (i + 1 < classJSON.classmodules.length) {
      source += "\n---\n"
    }
  };

  return source
}

SourceStats.prototype.getFile = function(url) {
  var xmlhttp = new XMLHttpRequest();

  xmlhttp.open('GET', url, false);
  xmlhttp.send();

  if (xmlhttp.status != 200) {
    console.log(url + " could not be found and added to source.")
    return ""
  }

  return xmlhttp.responseText;
}

// Outputs timings and stats
SourceStats.prototype.outputStats = function(slideshow, slidesPerHour, hoursPerDay, demoMultiplier, exerciseMultiplier) {
  // Check if the optional parameters are added
  if (typeof hoursPerDay == 'undefined') {
    hoursPerDay = 6.5
  }

  if (typeof demoMultiplier == 'undefined') {
    demoMultiplier = 1
  }

  if (typeof exerciseMultiplier == 'undefined') {
    exerciseMultiplier = 1
  }

  var slides = slideshow.getSlides()

  var chapters = -1;
  var sections = 0;
  var regular = 0;
  var demoMinutes = 0;
  var exerciseMinutes = 0;

  var currentSlides = 0;
  var currentDemoMinutes = 0;
  var currentExerciseMinutes = 0;
  var currentChapterName = ""

  for (var i = 0; i < slides.length; i++) {
    var template = slides[i].properties.template;

    if (template == "chapter") {
      chapters++;

      if (chapters != 0) {
        this.outputChapterTime(regular, demoMinutes, exerciseMinutes, slidesPerHour, chapters, currentChapterName, currentSlides, currentExerciseMinutes, currentDemoMinutes, hoursPerDay)

        currentSlides = 0;
        currentExerciseMinutes = 0;
        currentDemoMinutes = 0;
      }

      currentChapterName = slides[i].properties.name;
    } else if (template == "section") {
      sections++;
    } else if (template == "regular" || template == "code" || template == "image") {
      regular++;
      currentSlides++;
    } else if (template == "demo") {
      var minutes = parseInt(slides[i].properties.minutes) * demoMultiplier
      demoMinutes += minutes;
      currentDemoMinutes += minutes;
    } else if (template == "exercise") {
      var minutes = parseInt(slides[i].properties.minutes) * exerciseMultiplier
      exerciseMinutes += minutes;
      currentExerciseMinutes += minutes;
    }
  }

  this.outputChapterTime(regular, demoMinutes, exerciseMinutes, slidesPerHour, chapters, currentChapterName, currentSlides, currentExerciseMinutes, currentDemoMinutes, hoursPerDay)

  console.log("Overall stats chapters:" + chapters + " sections:" + sections +
   " regular:" + regular + " demos:" + demoMinutes + " exercises:" + exerciseMinutes +
   " slidesPerHour:" + slidesPerHour)
}

SourceStats.prototype.outputChapterTime = function(regular, demoMinutes, exerciseMinutes, slidesPerHour, chapters, currentChapterName, currentSlides, currentExerciseMinutes, currentDemoMinutes, hoursPerDay) {
  var toLog = this.calculateTime(regular, demoMinutes, exerciseMinutes, slidesPerHour, hoursPerDay) + 
    " Chapter " + chapters + " " + currentChapterName +
    " - " + currentSlides + " slides."

  if (currentExerciseMinutes != 0) {
    toLog += " " + currentExerciseMinutes + " minutes of exercises."
  }

  if (currentDemoMinutes != 0) {
    toLog += " " + currentDemoMinutes + " minutes of demos."
  }

  toLog += " Total chapter time: " + ((currentSlides * (60 / slidesPerHour)) + currentExerciseMinutes + currentDemoMinutes).toFixed(0) + " minutes."

  console.log(toLog)
}

// Calculates the current run time
SourceStats.prototype.calculateTime = function(slides, demo, exercise, slidesPerHour) {
  var totalMinutes = ((slides / slidesPerHour) * 60) + demo + exercise
  var hoursPerDay = 4.0

  var days = Math.ceil(totalMinutes / (60 * hoursPerDay))

  var hours = (totalMinutes - ((days - 1) * hoursPerDay * 60)) / 60

  return "Day " + days + " " + hours.toFixed(2) + " hours"<commit_msg>Fixed hard coding to 4 hours per day.<commit_after>var SourceStats = function () {
};

// Downloads the sourceUrls and returns the results in Remark format
SourceStats.prototype.createSource = function(classJSONUrl) {
  // Download class file
  classfile = this.getFile(classJSONUrl)
  classJSON = JSON.parse(classfile)

  // Set the class title
  document.title = classJSON.classname

  var source = ""

  // Add all modules for the class
  for (var i = 0; i < classJSON.classmodules.length; i++) {
    source += this.getFile(classJSON.classmodules[i]);

    // Files shouldn't have --- at the head or foot
    // It is added automatically here
    if (i + 1 < classJSON.classmodules.length) {
      source += "\n---\n"
    }
  };

  return source
}

SourceStats.prototype.getFile = function(url) {
  var xmlhttp = new XMLHttpRequest();

  xmlhttp.open('GET', url, false);
  xmlhttp.send();

  if (xmlhttp.status != 200) {
    console.log(url + " could not be found and added to source.")
    return ""
  }

  return xmlhttp.responseText;
}

// Outputs timings and stats
SourceStats.prototype.outputStats = function(slideshow, slidesPerHour, hoursPerDay, demoMultiplier, exerciseMultiplier) {
  // Check if the optional parameters are added
  if (typeof hoursPerDay == 'undefined') {
    hoursPerDay = 6.5
  }

  if (typeof demoMultiplier == 'undefined') {
    demoMultiplier = 1
  }

  if (typeof exerciseMultiplier == 'undefined') {
    exerciseMultiplier = 1
  }

  var slides = slideshow.getSlides()

  var chapters = -1;
  var sections = 0;
  var regular = 0;
  var demoMinutes = 0;
  var exerciseMinutes = 0;

  var currentSlides = 0;
  var currentDemoMinutes = 0;
  var currentExerciseMinutes = 0;
  var currentChapterName = ""

  for (var i = 0; i < slides.length; i++) {
    var template = slides[i].properties.template;

    if (template == "chapter") {
      chapters++;

      if (chapters != 0) {
        this.outputChapterTime(regular, demoMinutes, exerciseMinutes, slidesPerHour, chapters, currentChapterName, currentSlides, currentExerciseMinutes, currentDemoMinutes, hoursPerDay)

        currentSlides = 0;
        currentExerciseMinutes = 0;
        currentDemoMinutes = 0;
      }

      currentChapterName = slides[i].properties.name;
    } else if (template == "section") {
      sections++;
    } else if (template == "regular" || template == "code" || template == "image") {
      regular++;
      currentSlides++;
    } else if (template == "demo") {
      var minutes = parseInt(slides[i].properties.minutes) * demoMultiplier
      demoMinutes += minutes;
      currentDemoMinutes += minutes;
    } else if (template == "exercise") {
      var minutes = parseInt(slides[i].properties.minutes) * exerciseMultiplier
      exerciseMinutes += minutes;
      currentExerciseMinutes += minutes;
    }
  }

  this.outputChapterTime(regular, demoMinutes, exerciseMinutes, slidesPerHour, chapters, currentChapterName, currentSlides, currentExerciseMinutes, currentDemoMinutes, hoursPerDay)

  console.log("Overall stats chapters:" + chapters + " sections:" + sections +
   " regular:" + regular + " demos:" + demoMinutes + " exercises:" + exerciseMinutes +
   " slidesPerHour:" + slidesPerHour)
}

SourceStats.prototype.outputChapterTime = function(regular, demoMinutes, exerciseMinutes, slidesPerHour, chapters, currentChapterName, currentSlides, currentExerciseMinutes, currentDemoMinutes, hoursPerDay) {
  var toLog = this.calculateTime(regular, demoMinutes, exerciseMinutes, slidesPerHour, hoursPerDay) + 
    " Chapter " + chapters + " " + currentChapterName +
    " - " + currentSlides + " slides."

  if (currentExerciseMinutes != 0) {
    toLog += " " + currentExerciseMinutes + " minutes of exercises."
  }

  if (currentDemoMinutes != 0) {
    toLog += " " + currentDemoMinutes + " minutes of demos."
  }

  toLog += " Total chapter time: " + ((currentSlides * (60 / slidesPerHour)) + currentExerciseMinutes + currentDemoMinutes).toFixed(0) + " minutes."

  console.log(toLog)
}

// Calculates the current run time
SourceStats.prototype.calculateTime = function(slides, demo, exercise, slidesPerHour, hoursPerDay) {
  var totalMinutes = ((slides / slidesPerHour) * 60) + demo + exercise
  
  var days = Math.ceil(totalMinutes / (60 * hoursPerDay))

  var hours = (totalMinutes - ((days - 1) * hoursPerDay * 60)) / 60

  return "Day " + days + " " + hours.toFixed(2) + " hours"
{'fraction_non_alphanumeric': 0.12009553053565336, 'fraction_numerical': 0.008756965768224724, 'mean_word_length': 3.5873761085028693, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5236608', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2635, 'n_words': 686}