<commit_before>module Api
  module V1
    class CommoditiesController < ApiController
      before_action :find_commodity, only: [:show, :changes]

      def show
        @measures = MeasurePresenter.new(
          @commodity.measures_dataset.eager(
            { footnotes: :footnote_descriptions },
            { measure_type: :measure_type_description },
            { measure_components: [{ duty_expression: :duty_expression_description },
                                   { measurement_unit: :measurement_unit_description },
                                   :monetary_unit,
                                   :measurement_unit_qualifier] },
            { measure_conditions: [{ measure_action: :measure_action_description},
                                   { certificate: :certificate_descriptions },
                                   { certificate_type: :certificate_type_description },
                                   { measurement_unit: :measurement_unit_description },
                                   :monetary_unit,
                                   :measurement_unit_qualifier,
                                   { measure_condition_code: :measure_condition_code_description },
                                   { measure_condition_components: [:measure_condition,
                                                                    :duty_expression,
                                                                    :measurement_unit,
                                                                    :monetary_unit,
                                                                    :measurement_unit_qualifier]
                                   }]
            },
            { quota_order_number: :quota_definition },
            { excluded_geographical_areas: :geographical_area_descriptions },
            :additional_code,
            :full_temporary_stop_regulations,
            :measure_partial_temporary_stops
          ).all, @commodity
        ).validate!

        @geographical_areas = GeographicalArea.actual.where("geographical_area_sid IN ?", @measures.map(&:geographical_area_sid)).
            eager(:geographical_area_descriptions, { contained_geographical_areas: :geographical_area_descriptions }).all

        @commodity_cache_key = "commodity-#{@commodity.goods_nomenclature_sid}-#{actual_date}"
        respond_with @commodity
      end

      def changes
        key = "commodity-#{@commodity.goods_nomenclature_sid}-#{actual_date}/changes"
        @changes = Rails.cache.fetch(key, expires_at: actual_date.end_of_day) do<commit_msg>measures ordering on commodity page<commit_after>module Api
  module V1
    class CommoditiesController < ApiController
      before_action :find_commodity, only: [:show, :changes]

      def show
        @measures = MeasurePresenter.new(
          @commodity.measures_dataset.eager(
            { footnotes: :footnote_descriptions },
            { measure_type: :measure_type_description },
            { measure_components: [{ duty_expression: :duty_expression_description },
                                   { measurement_unit: :measurement_unit_description },
                                   :monetary_unit,
                                   :measurement_unit_qualifier] },
            { measure_conditions: [{ measure_action: :measure_action_description},
                                   { certificate: :certificate_descriptions },
                                   { certificate_type: :certificate_type_description },
                                   { measurement_unit: :measurement_unit_description },
                                   :monetary_unit,
                                   :measurement_unit_qualifier,
                                   { measure_condition_code: :measure_condition_code_description },
                                   { measure_condition_components: [:measure_condition,
                                                                    :duty_expression,
                                                                    :measurement_unit,
                                                                    :monetary_unit,
                                                                    :measurement_unit_qualifier]
                                   }]
            },
            { quota_order_number: :quota_definition },
            { excluded_geographical_areas: :geographical_area_descriptions },
            :additional_code,
            :full_temporary_stop_regulations,
            :measure_partial_temporary_stops
          ).join_table(
            :inner, :geographical_areas, geographical_areas__geographical_area_sid: :measures__geographical_area_sid
          ).order(
            Sequel.asc(:measures__national, nulls: :last), Sequel.asc(:measures__geographical_area_id)
          ).all, @commodity
        ).validate!

        @geographical_areas = GeographicalArea.actual.where("geographical_area_sid IN ?", @measures.map(&:geographical_area_sid)).
            eager(:geographical_area_descriptions, { contained_geographical_areas: :geographical_area_descriptions }).all

        @commodity_cache_key = "commodity-#{@commodity.goods_nomenclature_sid}-#{actual_date}"
        respond_with @commodity
      end

      def changes
        key = "commodity-#{@commodity.goods_nomenclature_sid}-#{actual_date}/changes"
        @changes = Rails.cache.fetch(key, expires_at: actual_date.end_of_day) do
{'fraction_non_alphanumeric': 0.07175544572579169, 'fraction_numerical': 0.0003660992128866923, 'mean_word_length': 1.5688763516690174, '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': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2133505', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1244, 'n_words': 171}