<commit_before># Attributes:
# * sensor_id [integer] - Sensor that recorded the reading
# * value [float]       - Sensor reading
#
# * id [integer, primary, not null] - primary key
# * created_at [datetime, not null] - creation time
# * updated_at [datetime, not null] - last update time
class SensorReading < ActiveRecord::Base
  belongs_to :sensor

  validates :value, presence: true, numericality: true
  validates :sensor_id, presence: true

  def as_json( options = {} )
    super( options.merge(
      only: [ :value, :created_at ]
    ))
  end

  def value
    case sensor.device.user.temperature_scale
    when 'F'
      read_attribute( :value )
    when 'C'
      fahrenheit_to_celcius( read_attribute(:value) )
    else
      read_attribute( :value )
    end
  end

  private

  def fahrenheit_to_celcius(degrees)
    (degrees.to_f - 32) / 1.8
  end
end
<commit_msg>Convert setpoint to appropriate scale.<commit_after># Attributes:
# * sensor_id [integer] - Sensor that recorded the reading
# * value [float]       - Sensor reading
#
# * id [integer, primary, not null] - primary key
# * created_at [datetime, not null] - creation time
# * updated_at [datetime, not null] - last update time
class SensorReading < ActiveRecord::Base
  belongs_to :sensor

  validates :value, presence: true, numericality: true
  validates :sensor_id, presence: true

  def as_json( options = {} )
    super( options.merge(
      only: [ :value, :setpoint, :created_at ]
    ))
  end

  def value
    case sensor.device.user.temperature_scale
    when 'F'
      read_attribute( :value )
    when 'C'
      fahrenheit_to_celcius( read_attribute(:value) )
    else
      read_attribute( :value )
    end
  end

  def setpoint
    case sensor.device.user.temperature_scale
    when 'F'
      read_attribute( :setpoint )
    when 'C'
      fahrenheit_to_celcius( read_attribute(:setpoint) )
    else
      read_attribute( :setpoint )
    end
  end

  private

  def fahrenheit_to_celcius(degrees)
    (degrees.to_f - 32) / 1.8
  end
end

{'fraction_non_alphanumeric': 0.0983201581027668, 'fraction_numerical': 0.003952569169960474, 'mean_word_length': 3.107505070993915, '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': '7432710', 'n_tokens_mistral': 675, 'n_tokens_neox': 659, 'n_words': 186}