<commit_before>- activity_productions = ActivityProduction
- if @activity_production_ids
  - activity_productions = activity_productions.where(id: @activity_production_ids)
- data = []

- if @campaigns && activity_productions.where.not(support_shape: nil).any?
  :ruby
    activity_productions.of_campaign(@campaigns).find_each do |support|
      next unless support.support_shape
      popup_content = []

      # for support

      #popup_content << {label: :campaign.tl, value: link_to(@campaigns.name, backend_campaign_path(@campaigns))}
      popup_content << { label: ActivityProduction.human_attribute_name(:net_surface_area), value: support.human_support_shape_area }
      popup_content << { label: ActivityProduction.human_attribute_name(:activity), value: link_to(support.activity_name, backend_activity_path(support.activity)) }
      if support_input_cost = support.input_cost and support_input_cost.to_d > 0.0
        popup_content << {label: :costs_per_hectare.tl}
        popup_content << {value: "#{:inputs.tl} : #{support_input_cost.to_s.to_f.round(2)}"}
      end
      if support_tool_cost = support.tool_cost and support_tool_cost.to_d > 0.0
        popup_content << {value: "#{:tools.tl} : #{support_tool_cost.to_s.to_f.round(2)}"}
      end
      if support_time_cost = support.time_cost and support_time_cost.to_d > 0.0
        popup_content << {value: "#{:times.tl} : #{support_time_cost.to_s.to_f.round(2)}"}
      end

      #nitrogen_concentration = support.soil_enrichment_indicator_content_per_area(:nitrogen_concentration)
      #phosphorus_concentration = support.soil_enrichment_indicator_content_per_area(:phosphorus_concentration)
      #potassium_concentration = support.soil_enrichment_indicator_content_per_area(:potassium_concentration)

      # TODO refactor
      #if nitrogen_concentration
      #  popup_content << {label: :item_concentration_per_hectare.tl}
      #  symbol = Nomen::ChemicalElement[:nitrogen].symbol
      #  popup_content << {value: "#{symbol} : #{nitrogen_concentration.in(:unity_per_hectare).round(2).l}"}
      #end

      #if phosphorus_concentration
      #  symbol = Nomen::ChemicalElement[:phosphorus].symbol
      #  popup_content << {value: "#{symbol} : #{phosphorus_concentration.in(:unity_per_hectare).round(2).l}"}
      #end

      #if potassium_concentration
      #  symbol = Nomen::ChemicalElement[:potassium].symbol
      #  popup_content << {value: "#{symbol} : #{potassium_concentration.in(:unity_per_hectare).round(2).l}"}
      #end

      # TODO refactor
      #measure_unit = "#{mass_unit.to_s}_per_#{surface_unit.to_s}"
      #yield_symbol = Nomen::Unit[measure_unit.to_sym]
      surface_unit_name = :hectare

      grass_yield = nil
      grain_yield = nil

      # case fodder (hay, grass) in ton per hectare
      if support.usage == 'fodder' || support.usage == 'fiber'
        matter = :grass
        label = :grass_yield
        mass_unit_name = :ton
        grass_yield = support.harvest_yield(matter, procedure_category: :harvesting,
                          size_indicator_name: :net_mass,
                          size_unit_name: mass_unit_name,
                          surface_unit_name: surface_unit_name)
      # case grain in quintal per hectare
      elsif support.usage == 'grain' || support.usage == 'seed'
        matter = :grain
        label = :grain_yield
        mass_unit_name = :quintal
        grain_yield = support.harvest_yield(matter, procedure_category: :harvesting,
                          size_indicator_name: :net_mass,
                          size_unit_name: mass_unit_name,
                          surface_unit_name: surface_unit_name)
      else
        matter = :grain
        label = :grain_yield
        mass_unit_name = :quintal
        grain_yield = support.harvest_yield(matter, procedure_category: :harvesting,
                          size_indicator_name: :net_mass,
                          size_unit_name: mass_unit_name,
                          surface_unit_name: surface_unit_name)
      end



      if params[:visualization] == "grain_yield"
        popup_content << {label: label.tl, value: grain_yield.round(2).l}
      end

      #if support.net_surface_area
      #  popup_content << {label: CultivableZone.human_attribute_name(:net_surface_area), value: support.net_surface_area.in_hectare.round(2).l}
      #end

      interventions = support.interventions
      if interventions.any?
        spent_time = interventions.map(&:working_duration).compact.sum
        popup_content << {label: :interventions_count.tl, value: "#{interventions.count} #{:during.tl.downcase!} #{:x_hours.tl(count: (spent_time/3600).round(2))}"}

        last_intervention = interventions.max{|a,b| a.started_at <=> b.started_at }
        popup_content << {label: :last_intervention.tl, value: link_to( last_intervention.name, backend_intervention_path(last_intervention)) }
      end

      popup_content << render('popup', production: support)

      item = {
        name:       support.name,
        shape:      support.support_shape,
        shape_color: support.activity.color,
        activity:   support.activity.name,
        tool_cost:  support.tool_cost.to_s.to_f.round(2),
        input_cost: support.input_cost.to_s.to_f.round(2),
        time_cost:  support.time_cost.to_s.to_f.round(2),
        # nitrogen_concentration:   nitrogen_concentration.to_s.to_f.round(2),
        # phosphorus_concentration: phosphorus_concentration.to_s.to_f.round(2),
        # potassium_concentration:  potassium_concentration.to_s.to_f.round(2),
        interventions_count: interventions.count,<commit_msg>Prevents missing grains value in map cells<commit_after>- activity_productions = ActivityProduction
- if @activity_production_ids
  - activity_productions = activity_productions.where(id: @activity_production_ids)
- data = []

- if @campaigns && activity_productions.where.not(support_shape: nil).any?
  :ruby
    activity_productions.of_campaign(@campaigns).find_each do |support|
      next unless support.support_shape
      popup_content = []

      # for support

      #popup_content << {label: :campaign.tl, value: link_to(@campaigns.name, backend_campaign_path(@campaigns))}
      popup_content << { label: ActivityProduction.human_attribute_name(:net_surface_area), value: support.human_support_shape_area }
      popup_content << { label: ActivityProduction.human_attribute_name(:activity), value: link_to(support.activity_name, backend_activity_path(support.activity)) }
      if support_input_cost = support.input_cost and support_input_cost.to_d > 0.0
        popup_content << {label: :costs_per_hectare.tl}
        popup_content << {value: "#{:inputs.tl} : #{support_input_cost.to_s.to_f.round(2)}"}
      end
      if support_tool_cost = support.tool_cost and support_tool_cost.to_d > 0.0
        popup_content << {value: "#{:tools.tl} : #{support_tool_cost.to_s.to_f.round(2)}"}
      end
      if support_time_cost = support.time_cost and support_time_cost.to_d > 0.0
        popup_content << {value: "#{:times.tl} : #{support_time_cost.to_s.to_f.round(2)}"}
      end

      #nitrogen_concentration = support.soil_enrichment_indicator_content_per_area(:nitrogen_concentration)
      #phosphorus_concentration = support.soil_enrichment_indicator_content_per_area(:phosphorus_concentration)
      #potassium_concentration = support.soil_enrichment_indicator_content_per_area(:potassium_concentration)

      # TODO refactor
      #if nitrogen_concentration
      #  popup_content << {label: :item_concentration_per_hectare.tl}
      #  symbol = Nomen::ChemicalElement[:nitrogen].symbol
      #  popup_content << {value: "#{symbol} : #{nitrogen_concentration.in(:unity_per_hectare).round(2).l}"}
      #end

      #if phosphorus_concentration
      #  symbol = Nomen::ChemicalElement[:phosphorus].symbol
      #  popup_content << {value: "#{symbol} : #{phosphorus_concentration.in(:unity_per_hectare).round(2).l}"}
      #end

      #if potassium_concentration
      #  symbol = Nomen::ChemicalElement[:potassium].symbol
      #  popup_content << {value: "#{symbol} : #{potassium_concentration.in(:unity_per_hectare).round(2).l}"}
      #end

      # TODO refactor
      #measure_unit = "#{mass_unit.to_s}_per_#{surface_unit.to_s}"
      #yield_symbol = Nomen::Unit[measure_unit.to_sym]
      surface_unit_name = :hectare

      grass_yield = nil
      grain_yield = nil

      # case fodder (hay, grass) in ton per hectare
      if support.usage == 'fodder' || support.usage == 'fiber'
        matter = :grass
        label = :grass_yield
        mass_unit_name = :ton
        grass_yield = support.harvest_yield(matter, procedure_category: :harvesting,
                          size_indicator_name: :net_mass,
                          size_unit_name: mass_unit_name,
                          surface_unit_name: surface_unit_name)
      # case grain in quintal per hectare
      elsif support.usage == 'grain' || support.usage == 'seed'
        matter = :grain
        label = :grain_yield
        mass_unit_name = :quintal
        grain_yield = support.harvest_yield(matter, procedure_category: :harvesting,
                          size_indicator_name: :net_mass,
                          size_unit_name: mass_unit_name,
                          surface_unit_name: surface_unit_name)
      else
        matter = :grain
        label = :grain_yield
        mass_unit_name = :quintal
        grain_yield = support.harvest_yield(matter, procedure_category: :harvesting,
                          size_indicator_name: :net_mass,
                          size_unit_name: mass_unit_name,
                          surface_unit_name: surface_unit_name)
      end



      if params[:visualization] == "grain_yield" && grain_yield && label
        popup_content << { label: label.tl, value: grain_yield.round(2).l }
      end

      #if support.net_surface_area
      #  popup_content << {label: CultivableZone.human_attribute_name(:net_surface_area), value: support.net_surface_area.in_hectare.round(2).l}
      #end

      interventions = support.interventions
      if interventions.any?
        spent_time = interventions.map(&:working_duration).compact.sum
        popup_content << { label: :interventions_count.tl, value: "#{interventions.count} #{:during.tl.downcase!} #{:x_hours.tl(count: (spent_time/3600).round(2))}" }

        last_intervention = interventions.max{|a,b| a.started_at <=> b.started_at }
        popup_content << { label: :last_intervention.tl, value: link_to( last_intervention.name, backend_intervention_path(last_intervention)) }
      end

      popup_content << render('popup', production: support)

      item = {
        name:       support.name,
        shape:      support.support_shape,
        shape_color: support.activity.color,
        activity:   support.activity.name,
        tool_cost:  support.tool_cost.to_s.to_f.round(2),
        input_cost: support.input_cost.to_s.to_f.round(2),
        time_cost:  support.time_cost.to_s.to_f.round(2),
        # nitrogen_concentration:   nitrogen_concentration.to_s.to_f.round(2),
        # phosphorus_concentration: phosphorus_concentration.to_s.to_f.round(2),
        # potassium_concentration:  potassium_concentration.to_s.to_f.round(2),
        interventions_count: interventions.count,
{'fraction_non_alphanumeric': 0.10701041850609218, 'fraction_numerical': 0.004414621225498852, 'mean_word_length': 3.2170513775130307, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 11, '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': '4222344', 'n_tokens_mistral': 3802, 'n_tokens_neox': 3501, 'n_words': 547}