<commit_before>'use strict';

import React from 'react';
import LinearProgress from 'material-ui/lib/linear-progress';

require('styles//StopWatch.scss');

class StopWatchComponent extends React.Component {

  constructor(props) {
    super(props);

    this.state = {
      completed: 0,
      steps: 0
    };
  }

  componentDidMount() {
    this.timer = setTimeout(() => this.progress(this.state.steps * 2), this.props.watchTimeout);
    this.state.steps = this.getPercentageSteps(this.props.slides.collection[this.props.slides.pointer].timeout);
  }

  componentWillUnmount() {
    clearTimeout(this.timer);
  }

  componentWillReceiveProps(nextProps) {
    if(nextProps.slides.isPlaying && this.props.slides.pointer != nextProps.slides.pointer) {
      clearTimeout(this.timer);
      this.setState({steps: this.getPercentageSteps(nextProps.slides.collection[nextProps.slides.pointer].timeout)});

      this.timer = setTimeout(() => this.progress(this.state.steps * 2), this.props.watchTimeout);
    }
  }

  getPercentageSteps(totalDurationOfSlide) {
    const result = Math.round(1 / totalDurationOfSlide / this.props.watchTimeout * 100);
    return result;
  }

  progress(completed) {
    if (completed > 100) {
      this.setState({completed: 100});
    } else {
      this.setState({completed});
      this.timer = setTimeout(() => this.progress(completed + this.state.steps), this.props.watchTimeout);
    }
  }

  render() {
    return (
      <div className="stopwatch-component">
        <LinearProgress mode="determinate" value={this.state.completed} />
      </div>
    );
  }
}

StopWatchComponent.displayName = 'StopWatchComponent';

StopWatchComponent.propTypes = {
  slides : React.PropTypes.object.isRequired,
  watchTimeout : React.PropTypes.number.isRequired
};

StopWatchComponent.defaultProps = {
  watchTimeout: 250
};

export default StopWatchComponent;
<commit_msg>Fixes the calculation of progress bar steps<commit_after>'use strict';

import React from 'react';
import LinearProgress from 'material-ui/lib/linear-progress';

require('styles//StopWatch.scss');

class StopWatchComponent extends React.Component {

  constructor(props) {
    super(props);

    this.state = {
      completed: 0,
      steps: 0
    };
  }

  componentDidMount() {
    this.timer = setTimeout(() => this.progress(this.state.steps * 2), this.props.watchTimeout);
    this.state.steps = this.getPercentageSteps(this.props.slides.collection[this.props.slides.pointer].timeout);
  }

  componentWillUnmount() {
    clearTimeout(this.timer);
  }

  componentWillReceiveProps(nextProps) {
    if(nextProps.slides.isPlaying && this.props.slides.pointer != nextProps.slides.pointer) {
      clearTimeout(this.timer);
      this.setState({steps: this.getPercentageSteps(nextProps.slides.collection[nextProps.slides.pointer].timeout)});

      this.timer = setTimeout(() => this.progress(this.state.steps * 2), this.props.watchTimeout);
    }
  }

  getPercentageSteps(totalDurationOfSlide) {
    return Math.round(100 / ( totalDurationOfSlide / this.props.watchTimeout) );
  }

  progress(completed) {
    if (completed > 100) {
      this.setState({completed: 100});
    } else {
      this.setState({completed});
      this.timer = setTimeout(() => this.progress(completed + this.state.steps), this.props.watchTimeout);
    }
  }

  render() {
    return (
      <div className="stopwatch-component">
        <LinearProgress mode="determinate" value={this.state.completed} />
      </div>
    );
  }
}

StopWatchComponent.displayName = 'StopWatchComponent';

StopWatchComponent.propTypes = {
  slides : React.PropTypes.object.isRequired,
  watchTimeout : React.PropTypes.number.isRequired
};

StopWatchComponent.defaultProps = {
  watchTimeout: 250
};

export default StopWatchComponent;

{'fraction_non_alphanumeric': 0.13472185605061957, 'fraction_numerical': 0.008700237279198523, 'mean_word_length': 3.83312101910828, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '4537396', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1142, 'n_words': 176}