<commit_before>React = require 'react'
_ = require 'underscore'
classnames = require 'classnames'

{AnswersTable} = require './answers-table'
ArbitraryHtmlAndMath = require '../html'
FormatsListing = require './formats-listing'

QuestionHtml = React.createClass
  displayName: 'QuestionHtml'
  propTypes:
    html: React.PropTypes.string
    type: React.PropTypes.string
  getDefaultProps: ->
    html: ''
    type: ''
  contextTypes:
    processHtmlAndMath: React.PropTypes.func

  render: ->
    {html, type} = @props
    return null unless html.length > 0

    htmlAndMathProps = _.pick(@context, 'processHtmlAndMath')

    <ArbitraryHtmlAndMath
      {...htmlAndMathProps}
      className="question-#{type}"
      block={true}
      html={html}
    />

Question = React.createClass
  displayName: 'Question'
  propTypes:
    model: React.PropTypes.object.isRequired
    correct_answer_id: React.PropTypes.string
    exercise_uid: React.PropTypes.string
    displayFormats:  React.PropTypes.bool

  childContextTypes:
    processHtmlAndMath: React.PropTypes.func
  getChildContext: ->
    processHtmlAndMath: @props.processHtmlAndMath

  doesArrayHaveProperty: (arrayToCheck, property) ->
    not _.isEmpty(_.compact(_.pluck(arrayToCheck, property)))

  hasAnswerCorrectness: ->
    {correct_answer_id, model} = @props
    {answers} = model

    correct_answer_id or @doesArrayHaveProperty(answers, 'correctness')

  hasSolution: ->
    {model, correct_answer_id} = @props
    {collaborator_solutions} = model

    @hasAnswerCorrectness() and @doesArrayHaveProperty(collaborator_solutions, 'content_html')

  render: ->
    {model, correct_answer_id, exercise_uid, className, questionNumber} = @props
    {stem_html, collaborator_solutions, formats, stimulus_html} = model

    hasCorrectAnswer = !! correct_answer_id
    classes = classnames 'openstax-question', className,
      'has-correct-answer': hasCorrectAnswer

    exerciseUid = <div className="exercise-uid">{exercise_uid}</div> if exercise_uid?

    if @hasSolution()
      solution =
        <div className='detailed-solution'>
          <div className='header'>Detailed solution</div>
          <ArbitraryHtmlAndMath className="solution" block
            html={_.pluck(collaborator_solutions, 'content_html').join('')}
          />
        </div><commit_msg>answer correctness logic was giving false positives<commit_after>React = require 'react'
_ = require 'underscore'
classnames = require 'classnames'

{AnswersTable} = require './answers-table'
ArbitraryHtmlAndMath = require '../html'
FormatsListing = require './formats-listing'

QuestionHtml = React.createClass
  displayName: 'QuestionHtml'
  propTypes:
    html: React.PropTypes.string
    type: React.PropTypes.string
  getDefaultProps: ->
    html: ''
    type: ''
  contextTypes:
    processHtmlAndMath: React.PropTypes.func

  render: ->
    {html, type} = @props
    return null unless html.length > 0

    htmlAndMathProps = _.pick(@context, 'processHtmlAndMath')

    <ArbitraryHtmlAndMath
      {...htmlAndMathProps}
      className="question-#{type}"
      block={true}
      html={html}
    />

Question = React.createClass
  displayName: 'Question'
  propTypes:
    model: React.PropTypes.object.isRequired
    correct_answer_id: React.PropTypes.string
    exercise_uid: React.PropTypes.string
    displayFormats:  React.PropTypes.bool

  childContextTypes:
    processHtmlAndMath: React.PropTypes.func
  getChildContext: ->
    processHtmlAndMath: @props.processHtmlAndMath

  isArrayMissingProperty: (arrayToCheck, property) ->
    not _.isEmpty(_.compact(_.pluck(arrayToCheck, property)))

  hasAnswerCorrectness: ->
    {correct_answer_id, model} = @props
    {answers} = model

    correct_answer_id or @isArrayMissingProperty(answers, 'correctness')

  hasSolution: ->
    {model, correct_answer_id} = @props
    {collaborator_solutions} = model

    @hasAnswerCorrectness() and @isArrayMissingProperty(collborator_solutions, 'content_html')

  render: ->
    {model, correct_answer_id, exercise_uid, className, questionNumber} = @props
    {stem_html, collaborator_solutions, formats, stimulus_html} = model

    hasCorrectAnswer = !! correct_answer_id
    classes = classnames 'openstax-question', className,
      'has-correct-answer': hasCorrectAnswer

    exerciseUid = <div className="exercise-uid">{exercise_uid}</div> if exercise_uid?

    if @hasSolution()
      solution =
        <div className='detailed-solution'>
          <div className='header'>Detailed solution</div>
          <ArbitraryHtmlAndMath className="solution" block
            html={_.pluck(collaborator_solutions, 'content_html').join('')}
          />
        </div>
{'fraction_non_alphanumeric': 0.11210571184995738, 'fraction_numerical': 0.00042625745950554135, 'mean_word_length': 3.8936392075078206, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, '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': '2868547', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1385, 'n_words': 271}