<commit_before>module ConceptTagHelper
  def all_concept_class_stats(activity_session)
    return '' unless activity_session.present?
    # Generate a header for each applicable concept class (activity session has concept tag results for that class)
    concept_tag_results = activity_session.concept_tag_results
    concept_classes = ConceptClass.for_concept_tag_results(concept_tag_results)
    concept_classes.reduce "" do |html, concept_class|
      html += "<h1 class='concept-class'>" + concept_class.name + "</h1>"
      html += stats_for_concept_class(concept_class, concept_tag_results)
    end
  end

  private

  # TODO: These stats should all be pre-calculated and cached
  def stats_for_concept_class(concept_class, concept_tag_results)
    case concept_class.name
      when 'Typing Speed'
        typing_speed_stats(concept_tag_results)
      when 'Grammar Concepts'
        ''
      else
        raise "Cannot display concept class named '#{concept_class.name}'"
    end
  end

  def typing_speed_stats(concept_tag_results)
    # Currently there is only 1 statistic to account for.
    # When there are multiple concept tags for Typing Speed,
    # it would be better to iterate over them to generate the list.
    average_wpm = ConceptClassStats.average_wpm(concept_tag_results)
    "<div class='row'>" +
      "<div class='col-xs-9 col-sm-10 col-xl-10'>Average words per minute</div>" +
      "<div class='col-xs-3 col-sm-2 col-xl-2'>#{average_wpm}</div>" +<commit_msg>Do not explode when trying to display unknown concept class in mouseover<commit_after>module ConceptTagHelper
  def all_concept_class_stats(activity_session)
    return '' unless activity_session.present?
    # Generate a header for each applicable concept class (activity session has concept tag results for that class)
    concept_tag_results = activity_session.concept_tag_results
    concept_classes = ConceptClass.for_concept_tag_results(concept_tag_results)
    concept_classes.reduce "" do |html, concept_class|
      html += stats_for_concept_class(concept_class, concept_tag_results)
    end
  end

  private

  # TODO: These stats should all be pre-calculated and cached
  def stats_for_concept_class(concept_class, concept_tag_results)
    case concept_class.name
      when 'Typing Speed'
        concept_class_header(concept_class) + typing_speed_stats(concept_tag_results)
      when 'Grammar Concepts'
        ''
      else
        ''
    end
  end

  def concept_class_header(concept_class)
    "<h1 class='concept-class'>" + concept_class.name + "</h1>"
  end

  def typing_speed_stats(concept_tag_results)
    # Currently there is only 1 statistic to account for.
    # When there are multiple concept tags for Typing Speed,
    # it would be better to iterate over them to generate the list.
    average_wpm = ConceptClassStats.average_wpm(concept_tag_results)
    "<div class='row'>" +
      "<div class='col-xs-9 col-sm-10 col-xl-10'>Average words per minute</div>" +
      "<div class='col-xs-3 col-sm-2 col-xl-2'>#{average_wpm}</div>" +
{'fraction_non_alphanumeric': 0.08240315167432699, 'fraction_numerical': 0.007222586999343401, 'mean_word_length': 3.9869067103109654, 'pattern_counts': {'":': 0, '<': 17, '<?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': '4491448', 'n_tokens_mistral': 941, 'n_tokens_neox': 892, 'n_words': 250}