<commit_before>class StatsController < ApplicationController

  def question_health_index
    question_health_index_helper('lessons', 'datadash')
    render json: :ok
  end

  def diagnostic_question_health_index
    question_health_index_helper('diagnostics', 'diagnostic_datadash')
    render json: :ok
  end

  def up
    render json: :ok
  end

  private

  def question_health_index_helper(activities_endpoint, datadash_endpoint)
    sql = """
      SELECT
        question_uid,
        COUNT(distinct id) as responses,
        SUM(CASE WHEN optimal IS null AND parent_id IS null THEN 1 ELSE 0 END) as unmatched_responses,
        COALESCE(SUM(count), 0) as total_attempts,
        SUM(CASE WHEN count > 4 THEN count ELSE 0 END) as common_matched_attempts,<commit_msg>Comment out these questions health checks for now. (#5435)<commit_after>class StatsController < ApplicationController

  def question_health_index
    # TODO - This query takes 327 seconds on average (almost 6 minutes) to run, commenting out for now
    #question_health_index_helper('lessons', 'datadash')
    render json: :ok
  end

  def diagnostic_question_health_index
    # TODO - This query takes 186 seconds on average (3 minutes) to run, commenting out for now
    #question_health_index_helper('diagnostics', 'diagnostic_datadash')
    render json: :ok
  end

  def up
    render json: :ok
  end

  private

  def question_health_index_helper(activities_endpoint, datadash_endpoint)
    sql = """
      SELECT
        question_uid,
        COUNT(distinct id) as responses,
        SUM(CASE WHEN optimal IS null AND parent_id IS null THEN 1 ELSE 0 END) as unmatched_responses,
        COALESCE(SUM(count), 0) as total_attempts,
        SUM(CASE WHEN count > 4 THEN count ELSE 0 END) as common_matched_attempts,
{'fraction_non_alphanumeric': 0.0625, 'fraction_numerical': 0.012276785714285714, 'mean_word_length': 3.7308707124010554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5708469', 'n_tokens_mistral': 573, 'n_tokens_neox': 510, 'n_words': 174}