<commit_before>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
*/

var round = require('round')

var BILLING_INCREMENT = 15
var MINUTES_PER_HOUR = 60
var MILLISECONDS_PER_MINUTE = MINUTES_PER_HOUR * 1000

// Define LISP-style math functions.
function add(x, y) { return x + y }
function subtract(x, y) { return x - y }
function multiply(x, y) { return x * y }
function divide(x, y) { return x / y }

function dateMatches(year, month, date) {
  return (
    date.getFullYear() === year &&
    // getMonth() is zero-indexed.
    // The month argument is one-indexed.
    add(date.getMonth(), 1) === month) }

function spanAmount(year, month, span) {
  var start = new Date(span.start)
  var end = new Date(span.end)

  // Span is within the relevant month.
  if (dateMatches(year, month, start) &&
      dateMatches(year, month, end)) {
    return round(
      divide(subtract(end, start), MILLISECONDS_PER_MINUTE)) }

  // Span is outside the relevant month.
  else { return 0 } }

function entryAmount(year, month, entry) {

  // Entry gives number of billable hours.
  if ('time' in entry) {
    if (dateMatches(year, month, new Date(entry.date))) {
      return round.down(multiply(entry.time, entry.rate), 1) }
    else { return 0 } }

  // Entry lists spans of billable time.
  else {
    return (
      round.down(
        multiply(
          entry.rate,
          divide(
            // Round billable minutes.
            round(
              entry.spans.reduce(
                function(total, span) {
                  return add(total, spanAmount(year, month, span)) },
                0),
              BILLING_INCREMENT),
            MINUTES_PER_HOUR)),
        1)) } }

module.exports = function(year, month, project) {

  // Bill per a a flat estimate.
  if (project.method === 'estimate') {
    var complete = new Date(project.completed)
    // Was the project completed in the relevant month?
    if (complete && dateMatches(year, month, complete)) {
      return project.estimate }
    else { return 0 } }

  // Bill time on the project.
  else {
    return project.service.reduce(
      function(entryTotal, entry) {<commit_msg>Comment and format<commit_after>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
*/

var round = require('round')

var BILLING_INCREMENT = 15
var MINUTES_PER_HOUR = 60
var MILLISECONDS_PER_MINUTE = MINUTES_PER_HOUR * 1000

// Define LISP-style math functions.
function add(x, y) { return x + y }
function subtract(x, y) { return x - y }
function multiply(x, y) { return x * y }
function divide(x, y) { return x / y }

function dateMatches(year, month, date) {
  return (
    date.getFullYear() === year &&
    // getMonth() is zero-indexed.
    // The month argument is one-indexed.
    add(date.getMonth(), 1) === month) }

function spanAmount(year, month, span) {
  var start = new Date(span.start)
  var end = new Date(span.end)

  // Span is within the relevant month.
  if (dateMatches(year, month, start) &&
      dateMatches(year, month, end)) {
    return round(
      divide(subtract(end, start), MILLISECONDS_PER_MINUTE)) }

  else { return 0 } }

function entryAmount(year, month, entry) {

  // Entry gives number of billable hours.
  if ('time' in entry) {

    // Entry is within the relevant month.
    if (dateMatches(year, month, new Date(entry.date))) {
      return round.down(multiply(entry.time, entry.rate), 1) }

    else { return 0 } }

  // Entry lists spans of billable time.
  else {
    return (
      round.down(
        multiply(
          entry.rate,
          divide(
            // Round billable minutes.
            round(
              // Sum time spans.
              entry.spans.reduce(
                function(total, span) {
                  return add(total, spanAmount(year, month, span)) },
                0),
              BILLING_INCREMENT),
            MINUTES_PER_HOUR)),
        1)) } }

module.exports = function(year, month, project) {

  // Bill per a a flat estimate.
  if (project.method === 'estimate') {
    var complete = new Date(project.completed)

    // Was the project completed in the relevant month?
    if (complete && dateMatches(year, month, complete)) {
      return project.estimate }

    else { return 0 } }

  // Bill time on the project.
  else {
    return project.service.reduce(
      function(entryTotal, entry) {
{'fraction_non_alphanumeric': 0.10817307692307693, 'fraction_numerical': 0.008505917159763314, 'mean_word_length': 2.6497975708502026, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '2506462', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1598, 'n_words': 563}