<commit_before>module Pupils
  class SchoolsController < ApplicationController
    include ActionView::Helpers::NumberHelper
    include ActivityTypeFilterable

    load_and_authorize_resource
    before_action :redirect_if_inactive

    def show
      authorize! :show_pupils_dash, @school
      @dashboard_alerts = @school.latest_dashboard_alerts.pupil_dashboard.sample(2).map do |dashboard_alert|
        TemplateInterpolation.new(
          dashboard_alert.content_version,
          with_objects: {
            find_out_more: dashboard_alert.find_out_more,
            alert: dashboard_alert.alert
          },
          proxy: [:colour]
        ).interpolate(
          :pupil_dashboard_title,
          with: dashboard_alert.alert.template_variables
        )
      end
      activity_setup(@school)
      equivalence_setup(@school)

      @temperature_observations = @school.observations.temperature
    end

  private

    def redirect_if_inactive
      redirect_to teachers_school_path(@school), notice: 'Pupil dashboard unavailable: School is not active' unless @school.active?
    end

    def activity_setup(school)
      @activities_count = school.activities.count
      @first = school.activities.empty?
      @suggestion = NextActivitySuggesterWithFilter.new(school, activity_type_filter).suggest_from_activity_history.first
    end

    def equivalence_setup(school)
      @equivalences = school.equivalences.relevant
      @equivalences_content = @equivalences.includes(:content_version).map do |equivalence|
        TemplateInterpolation.new(
          equivalence.content_version,
          with_objects: { equivalence_type: equivalence.content_version.equivalence_type },<commit_msg>Rely on abilities for hiding pupil dash<commit_after>module Pupils
  class SchoolsController < ApplicationController
    include ActionView::Helpers::NumberHelper
    include ActivityTypeFilterable

    load_and_authorize_resource

    def show
      authorize! :show_pupils_dash, @school
      @dashboard_alerts = @school.latest_dashboard_alerts.pupil_dashboard.sample(2).map do |dashboard_alert|
        TemplateInterpolation.new(
          dashboard_alert.content_version,
          with_objects: {
            find_out_more: dashboard_alert.find_out_more,
            alert: dashboard_alert.alert
          },
          proxy: [:colour]
        ).interpolate(
          :pupil_dashboard_title,
          with: dashboard_alert.alert.template_variables
        )
      end
      activity_setup(@school)
      equivalence_setup(@school)

      @temperature_observations = @school.observations.temperature
    end

  private

    def activity_setup(school)
      @activities_count = school.activities.count
      @first = school.activities.empty?
      @suggestion = NextActivitySuggesterWithFilter.new(school, activity_type_filter).suggest_from_activity_history.first
    end

    def equivalence_setup(school)
      @equivalences = school.equivalences.relevant
      @equivalences_content = @equivalences.includes(:content_version).map do |equivalence|
        TemplateInterpolation.new(
          equivalence.content_version,
          with_objects: { equivalence_type: equivalence.content_version.equivalence_type },
{'fraction_non_alphanumeric': 0.06947890818858561, 'fraction_numerical': 0.0006203473945409429, 'mean_word_length': 3.3817934782608696, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6071660', 'n_tokens_mistral': 911, 'n_tokens_neox': 880, 'n_words': 147}