<commit_before>import React, { PropTypes } from 'react';
import range from 'lodash.range';
import reduce from 'lodash.reduce';
import { DAYS_IN_WEEK, MILLISECONDS_IN_ONE_DAY, MONTH_LABELS } from './constants';

function getBeginningOfDate(date) {
  return new Date(date.getFullYear(), date.getMonth(), date.getDate());
}

class CalendarHeatmap extends React.Component {
  constructor(props) {
    super(props);

    const endOfWeekForEndDate = getBeginningOfDate(this.props.endDate).getTime() + ((DAYS_IN_WEEK - 1) - this.props.endDate.getDay()) * MILLISECONDS_IN_ONE_DAY;

    this.startDate = new Date(endOfWeekForEndDate - (this.props.numDays * MILLISECONDS_IN_ONE_DAY));

    this.valueAttributes = reduce(props.values, (memo, value) => {
      const index = Math.ceil((value.date.getTime() - this.startDate.getTime()) / MILLISECONDS_IN_ONE_DAY);
      memo[index] = {
        value: value,
        className: props.classForValue(value),
        title: props.titleForValue(value),
      };
      return memo;
    }, {});

    this.squareSize = 10;
    this.squareSizeWithGutter = this.squareSize + props.gutterSize;
    this.monthLabelGutterSize = 4;
    this.monthLabelSize = props.showMonthLabels ? (this.squareSize + this.monthLabelGutterSize) : 0;
    this.weekCount = Math.ceil(props.numDays / DAYS_IN_WEEK);
    this.width = this.weekCount * this.squareSizeWithGutter - props.gutterSize;
    this.height = DAYS_IN_WEEK * this.squareSizeWithGutter + this.monthLabelSize - props.gutterSize;
  }

  handleClick(value) {
    if (this.props.onClick) {
      this.props.onClick(value);
    }
  }

  getValueForIndex(index) {
    if (this.valueAttributes[index]) {
      return this.valueAttributes[index].value;
    } else {<commit_msg>Continued WIP on date calculation<commit_after>import React, { PropTypes } from 'react';
import range from 'lodash.range';
import reduce from 'lodash.reduce';
import { DAYS_IN_WEEK, MILLISECONDS_IN_ONE_DAY, MONTH_LABELS } from './constants';

function getBeginningOfDate(date) {
  return new Date(date.getFullYear(), date.getMonth(), date.getDate());
}

class CalendarHeatmap extends React.Component {
  constructor(props) {
    super(props);

    this.startDate = new Date(getBeginningOfDate(props.endDate).getTime() - (props.numDays - 1) * MILLISECONDS_IN_ONE_DAY);  // numDays - 1 because endDate is included
    const emptyDaysAtStart = this.startDate.getDay();
    const emptyDaysAtEnd = (DAYS_IN_WEEK - 1) - props.endDate.getDay();
    const numDaysRoundedToWeek = props.numDays + emptyDaysAtStart + emptyDaysAtEnd;
    this.startDateWithEmptyDaysTime = this.startDate.getTime() - emptyDaysAtStart * MILLISECONDS_IN_ONE_DAY;

    this.valueAttributes = reduce(props.values, (memo, value) => {
      const index = Math.ceil((value.date.getTime() - this.startDateWithEmptyDaysTime) / MILLISECONDS_IN_ONE_DAY);
      memo[index] = {
        value: value,
        className: props.classForValue(value),
        title: props.titleForValue(value),
      };
      return memo;
    }, {});

    this.squareSize = 10;
    this.squareSizeWithGutter = this.squareSize + props.gutterSize;
    this.monthLabelGutterSize = 4;
    this.monthLabelSize = props.showMonthLabels ? (this.squareSize + this.monthLabelGutterSize) : 0;
    this.weekCount = Math.ceil(numDaysRoundedToWeek / DAYS_IN_WEEK);
    this.width = this.weekCount * this.squareSizeWithGutter - props.gutterSize;
    this.height = DAYS_IN_WEEK * this.squareSizeWithGutter + this.monthLabelSize - props.gutterSize;
  }

  handleClick(value) {
    if (this.props.onClick) {
      this.props.onClick(value);
    }
  }

  getValueForIndex(index) {
    if (this.valueAttributes[index]) {
      return this.valueAttributes[index].value;
    } else {
{'fraction_non_alphanumeric': 0.12011771000535046, 'fraction_numerical': 0.0032102728731942215, 'mean_word_length': 3.9588859416445623, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3459311', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1237, 'n_words': 213}