<commit_before>class Issue < ActiveRecord::Base
  belongs_to :created_by, class_name: "User"
  belongs_to :category, class_name: "IssueCategory"
  has_many :threads, class_name: "MessageThread"

  validates :title, presence: true
  validates :description, presence: true
  validates :location, presence: true

  validates :created_by, presence: true
  validates :category, presence: true

  self.rgeo_factory_generator = RGeo::Geos.factory_generator

  # Define an approximate centre of the issue, for convenience.
  # Note that the line or polygon might be nowhere near this centre
  def centre
    case self.location.geometry_type
    when RGeo::Feature::Point
      return self.location
    else
      return self.location.envelope.centroid
    end
  end

  def loc_json=(json_str)
    # Not clear why the factory is needed, should be taken care of by setting the srid on the factory_generator
    # but that doesn't work.
    factory = RGeo::Geos::Factory.new(srid: 4326)
    self.location = RGeo::GeoJSON.decode(json_str, :geo_factory => factory, :json_parser => :json).geometry
  end

  def loc_json
    if self.location
      RGeo::GeoJSON.encode(self.location)
    else
      ""
    end
  end
end<commit_msg>GeoJSON.encode returns a hash, not a json string. Fix.<commit_after>class Issue < ActiveRecord::Base
  belongs_to :created_by, class_name: "User"
  belongs_to :category, class_name: "IssueCategory"
  has_many :threads, class_name: "MessageThread"

  validates :title, presence: true
  validates :description, presence: true
  validates :location, presence: true

  validates :created_by, presence: true
  validates :category, presence: true

  self.rgeo_factory_generator = RGeo::Geos.factory_generator

  # Define an approximate centre of the issue, for convenience.
  # Note that the line or polygon might be nowhere near this centre
  def centre
    case self.location.geometry_type
    when RGeo::Feature::Point
      return self.location
    else
      return self.location.envelope.centroid
    end
  end

  def loc_json=(json_str)
    # Not clear why the factory is needed, should be taken care of by setting the srid on the factory_generator
    # but that doesn't work.
    factory = RGeo::Geos::Factory.new(srid: 4326)
    self.location = RGeo::GeoJSON.decode(json_str, :geo_factory => factory, :json_parser => :json).geometry
  end

  def loc_json
    if self.location
      RGeo::GeoJSON.encode(self.location).to_json
    else
      ""
    end
  end
end
{'fraction_non_alphanumeric': 0.08101571946795647, 'fraction_numerical': 0.0032245062474808546, 'mean_word_length': 3.8382066276803117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3904995', 'n_tokens_mistral': 772, 'n_tokens_neox': 751, 'n_words': 237}