<commit_before>/** @jsx React.DOM */

//= require react
//= require reqwest
//= require chartjs
//= require underscore

(function () {
  'use strict';

  var StatManager;
  StatManager = React.createClass(new StatManagerConfig());

  var LoadButton;
  LoadButton = React.createClass(new LoadButtonConfig());

  React.renderComponent(
    (
      /* jshint ignore: start */
      <StatManager />
      /* jshint ignore: end */
    ),
    window.document.getElementById('example')
  );

  function StatManagerConfig() {
    return {
      getInitialState: getInitialState,
      componentDidMount: componentDidMount,
      handleStatsLoad: handleStatsLoad,
      render: render
    };

    function getInitialState() {
      return { stats: {} };
    }

    function componentDidMount() {
      reqwest({
        url: 'who-to-blame/footprints',
        method: 'get',
        success: this.handleStatsLoad
      });
    }

    function handleStatsLoad(stats) {
      console.log(stats);
      this.setState({ stats: stats });

      var colors = [
        {
          color: '#F7464A',
          highlight: '#FF5A5E'
        },
        {
          color: '#46BFBD',
          highlight: '#5AD3D1'
        },
        {
          color: '#FDB45C',
          highlight: '#FFC870'
        }
      ];

      var colorIndex = 0;
      var chartData = _.map(stats.rb, function (numLines, author) {
        var colorOptions = colors[colorIndex];
        colorIndex = (colorIndex + 1) % colors.length;

        return _.extend({
          value: numLines,
          label: author
        }, colorOptions);
      });

      var ctx = window.document.getElementById('myChart').getContext('2d');
      new Chart(ctx).Doughnut(chartData);
    }

    function render() {
      return (
        /* jshint ignore: start */
        <div>
          <LoadButton onDataLoad={this.handleStatsLoad} />
          <div>{JSON.stringify(this.state.stats)}</div>
          <canvas id="myChart" width="400" height="400"></canvas>
        </div>
        /* jshint ignore: end */
      );
    }
  }

  function LoadButtonConfig() {
    var buttonText = {
      default: 'Load Data',
      loading: 'Loading...'
    };

    return {
      getInitialState: getInitialState,
      loadData: loadData,
      render: render
    };

    function getInitialState() {
      return { loading: false };
    }

    function loadData() {
      if (this.state.loading) {
        alert('Already loading data');
        return;
      }

      var result = window.confirm('Are you sure you want to load data?');
      if (result) {
        this.setState({ loading: true });

        var today = new Date();
        var request_data = {
          year: today.getFullYear(),
          month: today.getMonth() + 1,
          day: today.getDate(),
          num_steps: 3,
          step: 7
        };

        reqwest({
          url: 'who-to-blame/footprints',
          method: 'post',
          data: request_data,
          success: function (data) {
            this.props.onDataLoad(data);
            this.setState({ loading: false });
          }.bind(this),
          error: function () {
            this.setState({ loading: false });
          }.bind(this),
        });
      }
    }

    function render() {
      return (
        /* jshint ignore: start */
        <button onClick={this.loadData}>
          {this.state.loading ? 'Loading...' : 'Load Data'}
        </button>
        /* jshint ignore: end */
      );
    }<commit_msg>Fixing jshint<commit_after>/** @jsx React.DOM */

//= require react
//= require reqwest
//= require chartjs
//= require underscore

(function () {
  'use strict';

  var StatManager;
  StatManager = React.createClass(new StatManagerConfig());

  var LoadButton;
  LoadButton = React.createClass(new LoadButtonConfig());

  React.renderComponent(
    (
      /* jshint ignore: start */
      <StatManager />
      /* jshint ignore: end */
    ),
    window.document.getElementById('example')
  );

  function StatManagerConfig() {
    /* jshint validthis: true */
    return {
      getInitialState: getInitialState,
      componentDidMount: componentDidMount,
      handleStatsLoad: handleStatsLoad,
      render: render
    };

    function getInitialState() {
      return { stats: {} };
    }

    function componentDidMount() {
      reqwest({
        url: 'who-to-blame/footprints',
        method: 'get',
        success: this.handleStatsLoad
      });
    }

    function handleStatsLoad(stats) {
      this.setState({ stats: stats });

      var colors = [
        {
          color: '#F7464A',
          highlight: '#FF5A5E'
        },
        {
          color: '#46BFBD',
          highlight: '#5AD3D1'
        },
        {
          color: '#FDB45C',
          highlight: '#FFC870'
        }
      ];

      var colorIndex = 0;
      var chartData = _.map(stats.rb, function (numLines, author) {
        var colorOptions = colors[colorIndex];
        colorIndex = (colorIndex + 1) % colors.length;

        return _.extend({
          value: numLines,
          label: author
        }, colorOptions);
      });

      var ctx = window.document.getElementById('myChart').getContext('2d');
      new Chart(ctx).Doughnut(chartData);
    }

    function render() {
      return (
        /* jshint ignore: start */
        <div>
          <LoadButton onDataLoad={this.handleStatsLoad} />
          <div>{JSON.stringify(this.state.stats)}</div>
          <canvas id="myChart" width="400" height="400"></canvas>
        </div>
        /* jshint ignore: end */
      );
    }
  }

  function LoadButtonConfig() {
    /* jshint validthis: true */
    return {
      getInitialState: getInitialState,
      loadData: loadData,
      render: render
    };

    function getInitialState() {
      return { loading: false };
    }

    function loadData() {
      if (this.state.loading) {
        window.alert('Already loading data');
        return;
      }

      var result = window.confirm('Are you sure you want to load data?');
      if (result) {
        this.setState({ loading: true });

        var today = new Date();
        var requestData = {
          /* jshint camelcase: false */
          year: today.getFullYear(),
          month: today.getMonth() + 1,
          day: today.getDate(),
          num_steps: 3,
          step: 7
          /* jshint camelcase: true */
        };

        reqwest({
          url: 'who-to-blame/footprints',
          method: 'post',
          data: requestData,
          success: function (data) {
            this.props.onDataLoad(data);
            this.setState({ loading: false });
          }.bind(this),
          error: function () {
            this.setState({ loading: false });
          }.bind(this)
        });
      }
    }

    function render() {
      return (
        /* jshint ignore: start */
        <button onClick={this.loadData}>
          {this.state.loading ? 'Loading...' : 'Load Data'}
        </button>
        /* jshint ignore: end */
      );
    }
{'fraction_non_alphanumeric': 0.13375071143995446, 'fraction_numerical': 0.00796812749003984, 'mean_word_length': 1.8104758096761295, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '7055080', 'n_tokens_mistral': 2073, 'n_tokens_neox': 2008, 'n_words': 447}