module DailyRep::Dbops

Public Instance Methods

check_history_notif(entity, parameter, timescope=(Time.now - 6.hour)) click to toggle source
# File lib/dailyrep/Dbops.rb, line 3
def check_history_notif entity, parameter, timescope=(Time.now - 6.hour)
  sql = History.select("val").where(entity: entity, parameter: parameter, notified: 'Y').where('created_at > ?', timescope).order('id desc').first
  if !sql.nil? then
    sql.val
  else
    nil
  end
end
check_row_exists(entity, parameter, val, timescope=(Time.now - 99.years)) click to toggle source
# File lib/dailyrep/Dbops.rb, line 12
def check_row_exists entity, parameter, val, timescope=(Time.now - 99.years)
  count = History.where(entity: entity, parameter: parameter, val: val).where('created_at > ?', timescope).count
  if count == 0 then false else true end
end
write_hist(entity, parameter, val, notified=0) click to toggle source
# File lib/dailyrep/Dbops.rb, line 17
def write_hist entity, parameter, val, notified=0
  case notified
  when 1 then
    notified = 'Y'
  else
    notified = 'N'
  end
  History.create(entity: entity, parameter: parameter, val: val, notified: notified)
end