<commit_before>module Management
  class SchoolsController < ApplicationController
    load_and_authorize_resource

    include SchoolAggregation
    include DashboardEnergyCharts
    include DashboardAlerts
    include DashboardTimeline

    before_action :check_aggregated_school_in_cache

    def show
      authorize! :show_management_dash, @school
      @charts = setup_charts(@school.configuration)
      @dashboard_alerts = setup_alerts(@school.latest_dashboard_alerts.management_dashboard, :management_dashboard_title)
      @observations = setup_timeline(@school.observations)
      @management_priorities = setup_priorities
    end


    private

    def setup_priorities
      @school.latest_management_priorities.sample(5).map do |priority|
        template_variables = priority.alert.template_variables.with_indifferent_access
        TemplateInterpolation.new(
          priority.content_version,
          with_objects: {
            find_out_more: priority.find_out_more,
            average_capital_cost: template_variables[:average_capital_cost],
            average_payback_years: template_variables[:average_payback_years],
            average_one_year_saving_gbp: template_variables[:average_one_year_saving_gbp],
            average_ten_year_saving_gbp: template_variables[:ten_year_saving_gbp_low] # TODO: replace when variable gets implemented
          },
          proxy: [:colour]
        ).interpolate(
          :management_priorities_title,
          with: priority.alert.template_variables
        )
      end
    end
  end
end<commit_msg>Keep consistent order of management priorities<commit_after>module Management
  class SchoolsController < ApplicationController
    load_and_authorize_resource

    include SchoolAggregation
    include DashboardEnergyCharts
    include DashboardAlerts
    include DashboardTimeline

    before_action :check_aggregated_school_in_cache

    def show
      authorize! :show_management_dash, @school
      @charts = setup_charts(@school.configuration)
      @dashboard_alerts = setup_alerts(@school.latest_dashboard_alerts.management_dashboard, :management_dashboard_title)
      @observations = setup_timeline(@school.observations)
      @management_priorities = setup_priorities
    end


    private

    def setup_priorities
      @school.latest_management_priorities.limit(5).map do |priority|
        template_variables = priority.alert.template_variables.with_indifferent_access
        TemplateInterpolation.new(
          priority.content_version,
          with_objects: {
            find_out_more: priority.find_out_more,
            average_capital_cost: template_variables[:average_capital_cost],
            average_payback_years: template_variables[:average_payback_years],
            average_one_year_saving_gbp: template_variables[:average_one_year_saving_gbp],
            average_ten_year_saving_gbp: template_variables[:ten_year_saving_gbp_low] # TODO: replace when variable gets implemented
          },
          proxy: [:colour]
        ).interpolate(
          :management_priorities_title,
          with: priority.alert.template_variables
        )
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.056116015132408575, 'fraction_numerical': 0.0006305170239596469, 'mean_word_length': 3.6119186046511627, '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': '4256689', 'n_tokens_mistral': 884, 'n_tokens_neox': 839, 'n_words': 140}