<commit_before>const React = require('react');

const i18nextReact = require('global/i18nextReact');
const MUI = require('app/common/MaterialUI');
const API = require('api');

const WeatherConditions = require('constants/WeatherConditions');
const Compass = require('svg/icon/Compass');
const WeatherIcons = require('svg/icon/Weather');
const EndDistributionGraph = require('svg/EndDistributionGraph');
const DistributionComparisonGraph = require('svg/DistributionComparisonGraph');

const AssessmentArrowTable = require('app/assessments/AssessmentArrowTable');
const Waiting = require('app/common/Waiting');

const AssessmentReport = React.createClass({
  propTypes: {
    // TODO declare a class to validate
    data: React.PropTypes.object,
    onDelete: React.PropTypes.func,
    t: React.PropTypes.func,
    assessmentId: React.PropTypes.number
  },
  getInitialState: function(){
    return {};
  },
  onDelete: function() {
    this.props.onDelete(this.props.assessmentId);
  },
  componentWillReceiveProps: function(nextProps) {
    if(nextProps.open === true){
      var callbacks = {
        context: this,
        success: function(assessment) {
          this.setState(assessment);
        }
      };
      API.assessments.reportById(this.props.assessmentId, callbacks);
    }
  },
  render: function() {
    const t = this.props.t;

    let rounds = <Waiting />;
    if (typeof this.state.rounds !== 'undefined') {
      if(this.state.rounds.length > 0){
        rounds = this.state.rounds.map(
          function(round, roundIndex) {
            round.index = roundIndex;
            var summary = {
              values: {
                averageScore: round.averageScores
              },
              counts: {
                xs: round.xCount,
                tens: round.tenCount
              },
              minAverage: round.minAverage,
              maxAverage: round.maxAverage,
              maxCount: round.maxCount,
              endCount: round.endCount
            };
            return (
              <MUI.GridTile
                key={'aaa-assessmentRound_' + roundIndex}
                style={MUI.styles.GridTile} cols={8} >
                <MUI.GridList cellHeight={'auto'} cols={2} padding={10} >
                  <MUI.GridTile style={MUI.styles.GridTile} cols={1} >
                    <AssessmentArrowTable data={round} />
                  </MUI.GridTile>
                  <MUI.GridTile style={MUI.styles.GridTile} cols={1} >
                    <EndDistributionGraph
                      id={'aaa-assessmentGraph_' + roundIndex}
                      height={'230pt'}
                      data={summary} />
                  </MUI.GridTile>
                </MUI.GridList>
              </MUI.GridTile>
            );
          },
        this);
      } else {
        rounds = (
          <MUI.GridTile
            style={MUI.styles.GridTile} cols={8} >
            {t('assessment:report.noRounds')}
          </MUI.GridTile>
        );
      }
    }

    let comparison = <MUI.GridTile cols={8} ><Waiting /></MUI.GridTile>;
    if(typeof this.state.ringComparison !== 'undefined'){
      comparison = (
        <MUI.GridTile style={MUI.styles.GridTile} cols={4} >
          <DistributionComparisonGraph data={this.state.ringComparison} />
        </MUI.GridTile>
      );
    }

    const CurrentWeather = WeatherIcons[WeatherConditions[this.state.weather]];

    return (
      <MUI.Dialog
          title={ this.state.event ? this.state.event.name :
                  t('assessment:report.title', this.props.data)}
          modal={false}
          actions={[
            <MUI.FloatingActionButton
              mini={true}
              secondary={true}
              style={{margin: '5pt'}}
              onTouchTap={this.onDelete}>
              <MUI.icons.action.delete />
            </MUI.FloatingActionButton>
          ]}
          autoScrollBodyContent={true}
          open={this.props.open}
          onRequestClose={this.props.handleClose} >

        <MUI.GridList cellHeight={'auto'} cols={8} padding={10} >
          <MUI.GridTile style={MUI.styles.GridTile} cols={4} >
            <h4>
              {t('assessment:report.overviewTitle', this.props.data)}
            </h4>
            <p>
              {this.state.targetName ? this.state.targetName : ''}
            </p>
            <p>
              {t('assessment:report.totalPoints', this.props.data)} <br/>
              {t('assessment:report.averagePoints', this.props.data)}
            </p>
            {
              this.state.weather ?
              [
                <h4>
                  {t('assessment:report.weatherTitle', this.props.data)}
                </h4>,
                <table style={{width: '100%'}}>
                  <tbody>
                    <tr>
                      <td width={'1%'} rowSpan={2}>
                        <CurrentWeather
                           height={'48pt'} style={{padding: '5pt'}} />
                      </td>
                      { this.state.windSpeed ?
                        [<td width={'1%'} style={{textAlign: 'right',color:MUI.palette.accent3Color}}>
                          <p>
                            {t('assessment:report.windLabel')}
                          </p>
                        </td>,
                        <td width={'1%'}>
                          <Compass direction={this.state.windDirection} height={'24pt'} />
                        </td>,
                        <td width={'99%'} style={{color:MUI.palette.accent3Color}}>
                          <p>
                            {this.state.windSpeed}
                            {t('assessment:report.windSpeedInfo', this.state)}
                          </p>
                        </td>] : [] }
                    </tr>
                    <tr>
                      { this.state.shootDirection ?
                        [<td width={'1%'} style={{textAlign: 'right',color:MUI.palette.accent3Color}}>
                          <p>
                            {t('assessment:report.targetLabel')}
                          </p>
                        </td>,
                        <td width={'1%'}>
                          <Compass direction={this.state.shootDirection} height={'24pt'} />
                        </td>]
                         : [] }<commit_msg>Fixing multiple calls for report.<commit_after>const React = require('react');

const i18nextReact = require('global/i18nextReact');
const MUI = require('app/common/MaterialUI');
const API = require('api');

const WeatherConditions = require('constants/WeatherConditions');
const Compass = require('svg/icon/Compass');
const WeatherIcons = require('svg/icon/Weather');
const EndDistributionGraph = require('svg/EndDistributionGraph');
const DistributionComparisonGraph = require('svg/DistributionComparisonGraph');

const AssessmentArrowTable = require('app/assessments/AssessmentArrowTable');
const Waiting = require('app/common/Waiting');

const AssessmentReport = React.createClass({
  propTypes: {
    // TODO declare a class to validate
    data: React.PropTypes.object,
    onDelete: React.PropTypes.func,
    t: React.PropTypes.func,
    assessmentId: React.PropTypes.number
  },
  getInitialState: function(){
    return {called:false,assessment:{}};
  },
  onDelete: function() {
    this.props.onDelete(this.props.assessmentId);
  },
  componentWillReceiveProps: function(nextProps) {
    if(nextProps.open === true && !this.state.called){
      var callbacks = {
        context: this,
        success: function(assessment) {
          console.log({assessment:assessment,called:false})
          this.setState({assessment:assessment,called:false});
        }
      };
      API.assessments.reportById(this.props.assessmentId, callbacks);
      this.state.called = true;
      this.setState(this.state);
    }
  },
  render: function() {
    const t = this.props.t;

    let rounds = <Waiting />;
    if (typeof this.state.assessment.rounds !== 'undefined') {
      if(this.state.assessment.rounds.length > 0){
        rounds = this.state.assessment.rounds.map(
          function(round, roundIndex) {
            round.index = roundIndex;
            var summary = {
              values: {
                averageScore: round.averageScores
              },
              counts: {
                xs: round.xCount,
                tens: round.tenCount
              },
              minAverage: round.minAverage,
              maxAverage: round.maxAverage,
              maxCount: round.maxCount,
              endCount: round.endCount
            };
            return (
              <MUI.GridTile
                key={'aaa-assessmentRound_' + roundIndex}
                style={MUI.styles.GridTile} cols={8} >
                <MUI.GridList cellHeight={'auto'} cols={2} padding={10} >
                  <MUI.GridTile style={MUI.styles.GridTile} cols={1} >
                    <AssessmentArrowTable data={round} />
                  </MUI.GridTile>
                  <MUI.GridTile style={MUI.styles.GridTile} cols={1} >
                    <EndDistributionGraph
                      id={'aaa-assessmentGraph_' + roundIndex}
                      height={'230pt'}
                      data={summary} />
                  </MUI.GridTile>
                </MUI.GridList>
              </MUI.GridTile>
            );
          },
        this);
      } else {
        rounds = (
          <MUI.GridTile
            style={MUI.styles.GridTile} cols={8} >
            {t('assessment:report.noRounds')}
          </MUI.GridTile>
        );
      }
    }

    let comparison = <MUI.GridTile cols={8} ><Waiting /></MUI.GridTile>;
    if(typeof this.state.assessment.ringComparison !== 'undefined'){
      comparison = (
        <MUI.GridTile style={MUI.styles.GridTile} cols={4} >
          <DistributionComparisonGraph data={this.state.assessment.ringComparison} />
        </MUI.GridTile>
      );
    }

    const CurrentWeather = WeatherIcons[WeatherConditions[this.state.assessment.weather]];

    return (
      <MUI.Dialog
          title={ this.state.assessment.event ? this.state.assessment.event.name :
                  t('assessment:report.title', this.props.data)}
          modal={false}
          actions={[
            <MUI.FloatingActionButton
              mini={true}
              secondary={true}
              style={{margin: '5pt'}}
              onTouchTap={this.onDelete}>
              <MUI.icons.action.delete />
            </MUI.FloatingActionButton>
          ]}
          autoScrollBodyContent={true}
          open={this.props.open}
          onRequestClose={this.props.handleClose} >

        <MUI.GridList cellHeight={'auto'} cols={8} padding={10} >
          <MUI.GridTile style={MUI.styles.GridTile} cols={4} >
            <h4>
              {t('assessment:report.overviewTitle', this.props.data)}
            </h4>
            <p>
              {this.state.assessment.targetName ? this.state.assessment.targetName : ''}
            </p>
            <p>
              {t('assessment:report.totalPoints', this.props.data)} <br/>
              {t('assessment:report.averagePoints', this.props.data)}
            </p>
            {
              this.state.assessment.weather ?
              [
                <h4>
                  {t('assessment:report.weatherTitle', this.props.data)}
                </h4>,
                <table style={{width: '100%'}}>
                  <tbody>
                    <tr>
                      <td width={'1%'} rowSpan={2}>
                        <CurrentWeather
                           height={'48pt'} style={{padding: '5pt'}} />
                      </td>
                      { this.state.assessment.windSpeed ?
                        [<td width={'1%'} style={{textAlign: 'right',color:MUI.palette.accent3Color}}>
                          <p>
                            {t('assessment:report.windLabel')}
                          </p>
                        </td>,
                        <td width={'1%'}>
                          <Compass direction={this.state.assessment.windDirection} height={'24pt'} />
                        </td>,
                        <td width={'99%'} style={{color:MUI.palette.accent3Color}}>
                          <p>
                            {this.state.assessment.windSpeed}
                            {t('assessment:report.windSpeedInfo', this.state.assessment)}
                          </p>
                        </td>] : [] }
                    </tr>
                    <tr>
                      { this.state.assessment.shootDirection ?
                        [<td width={'1%'} style={{textAlign: 'right',color:MUI.palette.accent3Color}}>
                          <p>
                            {t('assessment:report.targetLabel')}
                          </p>
                        </td>,
                        <td width={'1%'}>
                          <Compass direction={this.state.assessment.shootDirection} height={'24pt'} />
                        </td>]
                         : [] }
{'fraction_non_alphanumeric': 0.13309902200489, 'fraction_numerical': 0.007182151589242054, 'mean_word_length': 1.5118019573978123, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 125, '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': '5818445', 'n_tokens_mistral': 3690, 'n_tokens_neox': 3562, 'n_words': 536}