<commit_before>module Concepts

  extend ActiveSupport::Concern
  def all_concept_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_results = activity_session.concept_results.partition{|c| c.metadata['wpm']}
    # concept_results[0] is from sentence writing, [1] from story
    concepts = activity_session.concepts
    organize_by_type(concept_results, concepts)
  end

  private

  def organize_by_type(concept_results, concepts)
    h = Hash.new {|h,k| h[k] = [] }
    concepts.map do |concept|
      concept_results.map do |cr|
        if cr.any?
          type = cr == concept_results[0] ? :sentence : :story
          h[type].push(stats_for_concept(concept, cr, type))
        end<commit_msg>partition results on question UID, as sometimes wpm doesn’t save.<commit_after>module Concepts

  extend ActiveSupport::Concern
  def all_concept_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_results = activity_session.concept_results.partition{|c| c.metadata['questionUid']}
    # concept_results[0] is from sentence writing, [1] from story
    concepts = activity_session.concepts
    organize_by_type(concept_results, concepts)
  end

  private

  def organize_by_type(concept_results, concepts)
    h = Hash.new {|h,k| h[k] = [] }
    concepts.map do |concept|
      concept_results.map do |cr|
        if cr.any?
          type = cr == concept_results[0] ? :sentence : :story
          h[type].push(stats_for_concept(concept, cr, type))
        end
{'fraction_non_alphanumeric': 0.09075342465753425, 'fraction_numerical': 0.003424657534246575, 'mean_word_length': 3.8292011019283745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4987647', 'n_tokens_mistral': 532, 'n_tokens_neox': 507, 'n_words': 142}