<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import _ from 'underscore';
import fuzzy from 'fuzzyset.js';
import DiffedResponse from './diffedResponse.jsx';
import { listenToResponsesWithCallback } from '../../actions/responses';
import respWithStatus from '../../libs/responseTools.js';

export class AnswerVisualizer extends Component {
  constructor() {
    super();
    this.state = {
      responses: {},
      loadedResponses: false
    };
  }

  componentWillMount() {
    listenToResponsesWithCallback(
      this.props.params.questionID,
      (data) => {
        this.setState({
          responses: respWithStatus(data),
          loadedResponses: true,
        });
      }
    );
  }

  getHumanCorrectResponses() {
    return _.reject(_.values(_.mapObject(this.state.responses, (r) => {
      return r.statusCode == 0 ? r.text : null;
    })), (r) => { return !r });
  }

  getHumanIncorrectResponses() {
    return _.reject(_.values(_.mapObject(this.state.responses, (r) => {
      return r.statusCode == 1 ? r.text : null;
    })), (r) => { return !r });
  }

  getClosestCorrectResponse(response) {
    return fuzzy(this.getHumanCorrectResponses()).get(response)[0][1];
  }

  renderDiffsBetweenIncorrectResponsesAndNearestCorrectResponse() {
    return this.getHumanIncorrectResponses().map((response) => {
      return(
        <DiffedResponse
          firstResponse={this.getClosestCorrectResponse(response)}
          newResponse={response}
        />
      );
    });
  }

  render() {
    if(this.state.loadedResponses) {
      return (
        <div>
          <div className="card is-fullwidth has-bottom-margin">
            <div className="card-content">
              <h1 className="title is-3">Diffs Between Incorrect Responses and Nearest Correct Response</h1>
              {this.renderDiffsBetweenIncorrectResponsesAndNearestCorrectResponse()}
            </div>
          </div>
          {this.props.children}
        </div>
      )
    } else {
      return <h1>Loading...</h1>;
    }
  }

}<commit_msg>Renders diffs between correct answers and prompt<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import _ from 'underscore';
import fuzzy from 'fuzzyset.js';
import DiffedResponse from './diffedResponse.jsx';
import { listenToResponsesWithCallback } from '../../actions/responses';
import respWithStatus from '../../libs/responseTools.js';

export class AnswerVisualizer extends Component {
  constructor() {
    super();
    this.state = {
      responses: {},
      loadedResponses: false
    };
  }

  componentWillMount() {
    listenToResponsesWithCallback(
      this.props.params.questionID,
      (data) => {
        this.setState({
          responses: respWithStatus(data),
          loadedResponses: true,
        });
      }
    );
  }

  getHumanCorrectResponses() {
    return _.reject(_.values(_.mapObject(this.state.responses, (r) => {
      return r.statusCode == 0 ? r.text : null;
    })), (r) => { return !r });
  }

  getHumanIncorrectResponses() {
    return _.reject(_.values(_.mapObject(this.state.responses, (r) => {
      return r.statusCode == 1 ? r.text : null;
    })), (r) => { return !r });
  }

  getClosestCorrectResponse(response) {
    return fuzzy(this.getHumanCorrectResponses()).get(response)[0][1];
  }

  renderDiffsBetweenIncorrectResponsesAndNearestCorrectResponse() {
    return this.getHumanIncorrectResponses().map((response) => {
      return(
        <DiffedResponse
          firstResponse={this.getClosestCorrectResponse(response)}
          newResponse={response}
        />
      );
    });
  }

  renderDiffsBetweenCorrectResponsesAndPrompt() {
    return this.getHumanCorrectResponses().map((response) => {
      return(
        <DiffedResponse
          firstResponse={this.props.questions.data[this.props.params.questionID].prompt.replace(/\n/g," ").replace(/(<([^>]+)>)/ig," ").replace(/&nbsp;/g, '')}
          newResponse={response}
        />
      );
    });
  }

  render() {
    if(this.state.loadedResponses) {
      return (
        <div>
          <div className="card is-fullwidth has-bottom-margin">
            <div className="card-content">
              <h1 className="title is-3">Diffs Between Incorrect Responses and Nearest Correct Response</h1>
              {this.renderDiffsBetweenIncorrectResponsesAndNearestCorrectResponse()}
            </div>
          </div>
          <div className="card is-fullwidth has-bottom-margin">
            <div className="card-content">
              <h1 className="title is-3">Diffs Between Correct Responses and Prompt</h1>
              {this.renderDiffsBetweenCorrectResponsesAndPrompt()}
            </div>
          </div>
          {this.props.children}
        </div>
      )
    } else {
      return <h1>Loading...</h1>;
    }
  }

}
{'fraction_non_alphanumeric': 0.14119091467157766, 'fraction_numerical': 0.004297114794352364, 'mean_word_length': 2.6342007434944237, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 47, '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': '6706219', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1465, 'n_words': 252}