<commit_before># frozen_string_literal: true
class OfficeLocation < ApplicationRecord
  include VCardable

  belongs_to    :rep, foreign_key: :bioguide_id, primary_key: :bioguide_id
  has_many      :issues

  geocoded_by      :city_state_zip
  after_validation :geocode, if: :needs_geocoding?
  scope            :find_with_rep, ->(id) { where(id: id).includes(rep: :office_locations) }

  dragonfly_accessor :qr_code
  attr_reader        :distance

  FACTORY = RGeo::Geographic.simple_mercator_factory

  def set_lonlat
    update lonlat: FACTORY.point(longitude, latitude)
  end

  def needs_geocoding?
    latitude.blank? || longitude.blank?
  end

  def geocode
    super
    set_lonlat
  end

  def add_qr_code_img
    self.qr_code = RQRCode::QRCode.new(v_card, size: 22, level: :h).as_png(size: 360).to_string
    qr_code.name = "#{rep.last}_#{office_type}_#{id}.png"
    save
  end

  def add_v_card
    v_card = make_vcard
    update_attribute :v_card, v_card.to_s
  end
<commit_msg>get rid of unnecessary query during vcard download<commit_after># frozen_string_literal: true
class OfficeLocation < ApplicationRecord
  include VCardable

  belongs_to    :rep, foreign_key: :bioguide_id, primary_key: :bioguide_id
  has_many      :issues

  geocoded_by      :city_state_zip
  after_validation :geocode, if: :needs_geocoding?
  scope            :find_with_rep, ->(id) { where(id: id).includes(:rep) }

  dragonfly_accessor :qr_code
  attr_reader        :distance

  FACTORY = RGeo::Geographic.simple_mercator_factory

  def set_lonlat
    update lonlat: FACTORY.point(longitude, latitude)
  end

  def needs_geocoding?
    latitude.blank? || longitude.blank?
  end

  def geocode
    super
    set_lonlat
  end

  def add_qr_code_img
    self.qr_code = RQRCode::QRCode.new(v_card, size: 22, level: :h).as_png(size: 360).to_string
    qr_code.name = "#{rep.last}_#{office_type}_#{id}.png"
    save
  end

  def add_v_card
    v_card = make_vcard
    update_attribute :v_card, v_card.to_s
  end

{'fraction_non_alphanumeric': 0.0895447723861931, 'fraction_numerical': 0.0050025012506253125, 'mean_word_length': 3.728132387706856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '492884', 'n_tokens_mistral': 778, 'n_tokens_neox': 735, 'n_words': 150}